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";
42 Connection conn = {0};
43 char opbuf[OPERATION_BUFFER_SIZE];
48 slap_tool_init( progname, SLAPACL, argc, argv );
50 argv = &argv[ optind ];
53 op = (Operation *)opbuf;
54 connection_fake_init( &conn, op, &conn );
56 if ( !BER_BVISNULL( &authcID ) ) {
57 rc = slap_sasl_getdn( &conn, op, &authcID, NULL,
58 &authcDN, SLAP_GETDN_AUTHCID );
59 if ( rc != LDAP_SUCCESS ) {
60 fprintf( stderr, "ID: <%s> check failed %d (%s)\n",
62 ldap_err2string( rc ) );
67 } else if ( !BER_BVISNULL( &authcDN ) ) {
70 rc = dnNormalize( 0, NULL, NULL, &authcDN, &ndn, NULL );
71 if ( rc != LDAP_SUCCESS ) {
72 fprintf( stderr, "autchDN=\"%s\" normalization failed %d (%s)\n",
74 ldap_err2string( rc ) );
78 ch_free( authcDN.bv_val );
83 if ( !BER_BVISNULL( &authcDN ) ) {
84 fprintf( stderr, "DN: \"%s\"\n", authcDN.bv_val );
87 assert( !BER_BVISNULL( &baseDN ) );
88 rc = dnPrettyNormal( NULL, &baseDN, &e.e_name, &e.e_nname, NULL );
89 if ( rc != LDAP_SUCCESS ) {
90 fprintf( stderr, "base=\"%s\" normalization failed %d (%s)\n",
92 ldap_err2string( rc ) );
98 if ( !BER_BVISNULL( &authcDN ) ) {
105 attr = slap_schema.si_ad_entry->ad_cname.bv_val;
108 for ( ; argc--; argv++ ) {
110 AttributeDescription *desc = NULL;
114 char accessmaskbuf[ACCESSMASK_MAXLEN];
116 slap_access_t access = ACL_AUTH;
118 if ( attr == NULL ) {
122 val.bv_val = strchr( attr, ':' );
123 if ( val.bv_val != NULL ) {
124 val.bv_val[0] = '\0';
126 val.bv_len = strlen( val.bv_val );
129 accessstr = strchr( attr, '/' );
130 if ( accessstr != NULL ) {
133 access = str2access( accessstr );
134 if ( access == ACL_INVALID_ACCESS ) {
135 fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
137 if ( continuemode ) {
144 rc = slap_str2ad( attr, &desc, &text );
145 if ( rc != LDAP_SUCCESS ) {
146 fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
147 attr, rc, ldap_err2string( rc ) );
148 if ( continuemode ) {
154 rc = access_allowed_mask( op, &e, desc, &val, access,
158 fprintf( stderr, "%s access to %s%s%s: %s\n",
160 desc->ad_cname.bv_val,
161 val.bv_val ? "=" : "",
162 val.bv_val ? val.bv_val : "",
163 rc ? "ALLOWED" : "DENIED" );
166 fprintf( stderr, "%s%s%s: %s\n",
167 desc->ad_cname.bv_val,
168 val.bv_val ? "=" : "",
169 val.bv_val ? val.bv_val : "",
170 accessmask2str( mask, accessmaskbuf ) );