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};
48 slap_tool_init( progname, SLAPACL, argc, argv );
50 argv = &argv[ optind ];
53 connection_fake_init( &conn, &op, &ohdr, &conn );
55 if ( !BER_BVISNULL( &authcID ) ) {
56 rc = slap_sasl_getdn( &conn, &op, &authcID, NULL,
57 &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 ) ) {
104 attr = slap_schema.si_ad_entry->ad_cname.bv_val;
107 for ( ; argc--; argv++ ) {
109 AttributeDescription *desc = NULL;
113 char accessmaskbuf[ACCESSMASK_MAXLEN];
115 slap_access_t access = ACL_AUTH;
117 if ( attr == NULL ) {
121 val.bv_val = strchr( attr, ':' );
122 if ( val.bv_val != NULL ) {
123 val.bv_val[0] = '\0';
125 val.bv_len = strlen( val.bv_val );
128 accessstr = strchr( attr, '/' );
129 if ( accessstr != NULL ) {
132 access = str2access( accessstr );
133 if ( access == ACL_INVALID_ACCESS ) {
134 fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
136 if ( continuemode ) {
143 rc = slap_str2ad( attr, &desc, &text );
144 if ( rc != LDAP_SUCCESS ) {
145 fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
146 attr, rc, ldap_err2string( rc ) );
147 if ( continuemode ) {
153 rc = access_allowed_mask( &op, &e, desc, &val, access,
157 fprintf( stderr, "%s access to %s%s%s: %s\n",
159 desc->ad_cname.bv_val,
160 val.bv_val ? "=" : "",
161 val.bv_val ? val.bv_val : "",
162 rc ? "ALLOWED" : "DENIED" );
165 fprintf( stderr, "%s%s%s: %s\n",
166 desc->ad_cname.bv_val,
167 val.bv_val ? "=" : "",
168 val.bv_val ? val.bv_val : "",
169 accessmask2str( mask, accessmaskbuf ) );