1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 * Copyright 2004-2005 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;
112 struct berval val = BER_BVNULL,
115 char accessmaskbuf[ACCESSMASK_MAXLEN];
117 slap_access_t access = ACL_AUTH;
119 if ( attr == NULL ) {
123 val.bv_val = strchr( attr, ':' );
124 if ( val.bv_val != NULL ) {
125 val.bv_val[0] = '\0';
127 val.bv_len = strlen( val.bv_val );
131 accessstr = strchr( attr, '/' );
132 if ( accessstr != NULL ) {
135 access = str2access( accessstr );
136 if ( access == ACL_INVALID_ACCESS ) {
137 fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
139 if ( continuemode ) {
146 rc = slap_str2ad( attr, &desc, &text );
147 if ( rc != LDAP_SUCCESS ) {
148 fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
149 attr, rc, ldap_err2string( rc ) );
150 if ( continuemode ) {
156 rc = access_allowed_mask( op, &e, desc, valp, access,
160 fprintf( stderr, "%s access to %s%s%s: %s\n",
162 desc->ad_cname.bv_val,
163 val.bv_val ? "=" : "",
164 val.bv_val ? val.bv_val : "",
165 rc ? "ALLOWED" : "DENIED" );
168 fprintf( stderr, "%s%s%s: %s\n",
169 desc->ad_cname.bv_val,
170 val.bv_val ? "=" : "",
171 val.bv_val ? val.bv_val : "",
172 accessmask2str( mask, accessmaskbuf, 1 ) );