1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 * Copyright 2004 The OpenLDAP Foundation.
4 * Portions Copyright 2004 Pierangelo Masarati.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This work was initially developed by Pierangelo Masarati for inclusion
17 * in OpenLDAP Software.
24 #include <ac/stdlib.h>
27 #include <ac/string.h>
28 #include <ac/socket.h>
29 #include <ac/unistd.h>
35 #include "slapcommon.h"
38 slapacl( int argc, char **argv )
40 int rc = EXIT_SUCCESS;
41 const char *progname = "slapacl";
46 slap_tool_init( progname, SLAPACL, argc, argv );
48 argv = &argv[ optind ];
51 memset( &conn, 0, sizeof( Connection ) );
52 memset( &op, 0, sizeof( Operation ) );
54 connection_fake_init( &conn, &op, &conn );
56 if ( !BER_BVISNULL( &authcID ) ) {
57 rc = slap_sasl_getdn( &conn, &op, &authcID, NULL, &authcDN, SLAP_GETDN_AUTHCID );
58 if ( rc != LDAP_SUCCESS ) {
59 fprintf( stderr, "ID: <%s> check failed %d (%s)\n",
61 ldap_err2string( rc ) );
66 } else if ( !BER_BVISNULL( &authcDN ) ) {
69 rc = dnNormalize( 0, NULL, NULL, &authcDN, &ndn, NULL );
70 if ( rc != LDAP_SUCCESS ) {
71 fprintf( stderr, "autchDN=\"%s\" normalization failed %d (%s)\n",
73 ldap_err2string( rc ) );
77 ch_free( authcDN.bv_val );
82 if ( !BER_BVISNULL( &authcDN ) ) {
83 fprintf( stderr, "DN: \"%s\"\n", authcDN.bv_val );
86 assert( !BER_BVISNULL( &baseDN ) );
87 rc = dnPrettyNormal( NULL, &baseDN, &e.e_name, &e.e_nname, NULL );
88 if ( rc != LDAP_SUCCESS ) {
89 fprintf( stderr, "base=\"%s\" normalization failed %d (%s)\n",
91 ldap_err2string( rc ) );
97 if ( !BER_BVISNULL( &authcDN ) ) {
102 for ( ; argc--; argv++ ) {
104 AttributeDescription *desc = NULL;
108 char accessmaskbuf[ACCESSMASK_MAXLEN];
110 slap_access_t access = ACL_AUTH;
112 val.bv_val = strchr( argv[0], ':' );
113 if ( val.bv_val != NULL ) {
114 val.bv_val[0] = '\0';
116 val.bv_len = strlen( val.bv_val );
119 accessstr = strchr( argv[0], '/' );
120 if ( accessstr != NULL ) {
123 access = str2access( accessstr );
124 if ( access == ACL_INVALID_ACCESS ) {
125 fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
126 accessstr, argv[0] );
127 if ( continuemode ) {
134 rc = slap_str2ad( argv[0], &desc, &text );
135 if ( rc != LDAP_SUCCESS ) {
136 fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
137 argv[0], rc, ldap_err2string( rc ) );
138 if ( continuemode ) {
144 rc = access_allowed_mask( &op, &e, desc, &val, access,
148 fprintf( stderr, "%s access to %s%s%s: %s\n",
150 desc->ad_cname.bv_val,
151 val.bv_val ? "=" : "",
152 val.bv_val ? val.bv_val : "",
153 rc ? "ALLOWED" : "DENIED" );
156 fprintf( stderr, "%s%s%s: %s\n",
157 desc->ad_cname.bv_val,
158 val.bv_val ? "=" : "",
159 val.bv_val ? val.bv_val : "",
160 accessmask2str( mask, accessmaskbuf ) );