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";
47 lutil_log_initialize( argc, argv );
49 slap_tool_init( progname, SLAPACL, argc, argv );
51 argv = &argv[ optind ];
54 memset( &conn, 0, sizeof( Connection ) );
55 memset( &op, 0, sizeof( Operation ) );
57 connection_fake_init( &conn, &op, &conn );
59 if ( !BER_BVISNULL( &authcID ) ) {
60 rc = slap_sasl_getdn( &conn, &op, &authcID, NULL, &authcDN, SLAP_GETDN_AUTHCID );
61 if ( rc != LDAP_SUCCESS ) {
62 fprintf( stderr, "ID: <%s> check failed %d (%s)\n",
64 ldap_err2string( rc ) );
69 } else if ( !BER_BVISNULL( &authcDN ) ) {
72 rc = dnNormalize( 0, NULL, NULL, &authcDN, &ndn, NULL );
73 if ( rc != LDAP_SUCCESS ) {
74 fprintf( stderr, "autchDN=\"%s\" normalization failed %d (%s)\n",
76 ldap_err2string( rc ) );
80 ch_free( authcDN.bv_val );
85 if ( !BER_BVISNULL( &authcDN ) ) {
86 fprintf( stderr, "DN: \"%s\"\n", authcDN.bv_val );
89 assert( !BER_BVISNULL( &baseDN ) );
90 rc = dnPrettyNormal( NULL, &baseDN, &e.e_name, &e.e_nname, NULL );
91 if ( rc != LDAP_SUCCESS ) {
92 fprintf( stderr, "base=\"%s\" normalization failed %d (%s)\n",
94 ldap_err2string( rc ) );
100 if ( !BER_BVISNULL( &authcDN ) ) {
105 for ( ; argc--; argv++ ) {
107 AttributeDescription *desc = NULL;
111 char accessmaskbuf[ACCESSMASK_MAXLEN];
113 slap_access_t access = ACL_AUTH;
115 val.bv_val = strchr( argv[0], ':' );
116 if ( val.bv_val != NULL ) {
117 val.bv_val[0] = '\0';
119 val.bv_len = strlen( val.bv_val );
122 accessstr = strchr( argv[0], '/' );
123 if ( accessstr != NULL ) {
126 access = str2access( accessstr );
127 if ( access == ACL_INVALID_ACCESS ) {
128 fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
129 accessstr, argv[0] );
130 if ( continuemode ) {
137 rc = slap_str2ad( argv[0], &desc, &text );
138 if ( rc != LDAP_SUCCESS ) {
139 fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
140 argv[0], rc, ldap_err2string( rc ) );
141 if ( continuemode ) {
147 rc = access_allowed_mask( &op, &e, desc, &val, access,
151 fprintf( stderr, "%s access to %s%s%s: %s\n",
153 desc->ad_cname.bv_val,
154 val.bv_val ? "=" : "",
155 val.bv_val ? val.bv_val : "",
156 rc ? "ALLOWED" : "DENIED" );
159 fprintf( stderr, "%s%s%s: %s\n",
160 desc->ad_cname.bv_val,
161 val.bv_val ? "=" : "",
162 val.bv_val ? val.bv_val : "",
163 accessmask2str( mask, accessmaskbuf ) );