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"
41 AttributeDescription *desc,
47 char accessmaskbuf[ACCESSMASK_MAXLEN];
48 slap_access_t access = ACL_AUTH;
50 rc = access_allowed_mask( op, e, desc, nval, ACL_AUTH, NULL, &mask );
52 fprintf( stderr, "%s%s%s: %s\n",
53 desc->ad_cname.bv_val,
54 ( val && !BER_BVISNULL( val ) ) ? "=" : "",
55 ( val && !BER_BVISNULL( val ) ) ?
56 ( desc == slap_schema.si_ad_userPassword ? "****" : val->bv_val ) : "",
57 accessmask2str( mask, accessmaskbuf, 1 ) );
63 slapacl( int argc, char **argv )
65 int rc = EXIT_SUCCESS;
66 const char *progname = "slapacl";
67 Connection conn = { 0 };
69 char opbuf[OPERATION_BUFFER_SIZE];
71 Entry e = { 0 }, *ep = &e;
74 slap_tool_init( progname, SLAPACL, argc, argv );
76 argv = &argv[ optind ];
79 op = (Operation *)opbuf;
80 connection_fake_init( &conn, op, &conn );
82 conn.c_listener = &listener;
83 conn.c_listener_url = listener_url;
84 conn.c_peer_domain = peer_domain;
85 conn.c_peer_name = peer_name;
86 conn.c_sock_name = sock_name;
88 op->o_transport_ssf = transport_ssf;
89 op->o_tls_ssf = tls_ssf;
90 op->o_sasl_ssf = sasl_ssf;
92 if ( !BER_BVISNULL( &authcID ) ) {
93 rc = slap_sasl_getdn( &conn, op, &authcID, NULL,
94 &authcDN, SLAP_GETDN_AUTHCID );
95 if ( rc != LDAP_SUCCESS ) {
96 fprintf( stderr, "ID: <%s> check failed %d (%s)\n",
98 ldap_err2string( rc ) );
103 } else if ( !BER_BVISNULL( &authcDN ) ) {
106 rc = dnNormalize( 0, NULL, NULL, &authcDN, &ndn, NULL );
107 if ( rc != LDAP_SUCCESS ) {
108 fprintf( stderr, "autchDN=\"%s\" normalization failed %d (%s)\n",
110 ldap_err2string( rc ) );
114 ch_free( authcDN.bv_val );
119 if ( !BER_BVISNULL( &authcDN ) ) {
120 fprintf( stderr, "DN: \"%s\"\n", authcDN.bv_val );
123 assert( !BER_BVISNULL( &baseDN ) );
124 rc = dnPrettyNormal( NULL, &baseDN, &e.e_name, &e.e_nname, NULL );
125 if ( rc != LDAP_SUCCESS ) {
126 fprintf( stderr, "base=\"%s\" normalization failed %d (%s)\n",
128 ldap_err2string( rc ) );
134 if ( !BER_BVISNULL( &authcDN ) ) {
142 if ( !be->be_entry_open ||
143 !be->be_entry_close ||
147 fprintf( stderr, "%s: target database "
148 "doesn't support necessary operations; "
149 "you may try with \"-u\" (dry run).\n",
155 if ( be->be_entry_open( be, 0 ) != 0 ) {
156 fprintf( stderr, "%s: could not open database.\n",
162 id = be->be_dn2id_get( be, &e.e_nname );
164 fprintf( stderr, "%s: unable to fetch ID of DN \"%s\"\n",
165 progname, e.e_nname.bv_val );
169 if ( be->be_id2entry_get( be, id, &ep ) != 0 ) {
170 fprintf( stderr, "%s: unable to fetch entry \"%s\" (%lu)\n",
171 progname, e.e_nname.bv_val, id );
180 (void)print_access( op, ep, slap_schema.si_ad_entry, NULL, NULL );
181 (void)print_access( op, ep, slap_schema.si_ad_children, NULL, NULL );
183 for ( a = ep->e_attrs; a; a = a->a_next ) {
186 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
187 (void)print_access( op, ep, a->a_desc,
195 for ( ; argc--; argv++ ) {
197 AttributeDescription *desc = NULL;
198 struct berval val = BER_BVNULL,
201 char accessmaskbuf[ACCESSMASK_MAXLEN];
203 slap_access_t access = ACL_AUTH;
205 if ( attr == NULL ) {
209 val.bv_val = strchr( attr, ':' );
210 if ( val.bv_val != NULL ) {
211 val.bv_val[0] = '\0';
213 val.bv_len = strlen( val.bv_val );
217 accessstr = strchr( attr, '/' );
218 if ( accessstr != NULL ) {
221 access = str2access( accessstr );
222 if ( access == ACL_INVALID_ACCESS ) {
223 fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
225 if ( continuemode ) {
232 rc = slap_str2ad( attr, &desc, &text );
233 if ( rc != LDAP_SUCCESS ) {
234 fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
235 attr, rc, ldap_err2string( rc ) );
236 if ( continuemode ) {
242 rc = access_allowed_mask( op, ep, desc, valp, access,
246 fprintf( stderr, "%s access to %s%s%s: %s\n",
248 desc->ad_cname.bv_val,
249 val.bv_val ? "=" : "",
250 val.bv_val ? val.bv_val : "",
251 rc ? "ALLOWED" : "DENIED" );
254 fprintf( stderr, "%s%s%s: %s\n",
255 desc->ad_cname.bv_val,
256 val.bv_val ? "=" : "",
257 val.bv_val ? val.bv_val : "",
258 accessmask2str( mask, accessmaskbuf, 1 ) );
265 ber_memfree( e.e_name.bv_val );
266 ber_memfree( e.e_nname.bv_val );
269 be_entry_release_r( op, ep );
271 be->be_entry_close( be );