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 ) );
70 if ( !BER_BVISNULL( &authcDN ) ) {
71 fprintf( stderr, "DN: \"%s\"\n", authcDN.bv_val );
74 assert( !BER_BVISNULL( &baseDN ) );
75 rc = dnPrettyNormal( NULL, &baseDN, &e.e_name, &e.e_nname, NULL );
76 if ( rc != LDAP_SUCCESS ) {
77 fprintf( stderr, "base=\"%s\" normalization failed %d (%s)\n",
79 ldap_err2string( rc ) );
85 if ( !BER_BVISNULL( &authcDN ) ) {
90 for ( ; argc--; argv++ ) {
92 AttributeDescription *desc = NULL;
96 char accessmaskbuf[ACCESSMASK_MAXLEN];
98 slap_access_t access = ACL_AUTH;
100 val.bv_val = strchr( argv[0], ':' );
101 if ( val.bv_val != NULL ) {
102 val.bv_val[0] = '\0';
104 val.bv_len = strlen( val.bv_val );
107 accessstr = strchr( argv[0], '/' );
108 if ( accessstr != NULL ) {
111 access = str2access( accessstr );
112 if ( access == ACL_INVALID_ACCESS ) {
113 fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
114 accessstr, argv[0] );
115 if ( continuemode ) {
122 rc = slap_str2ad( argv[0], &desc, &text );
123 if ( rc != LDAP_SUCCESS ) {
124 fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
125 argv[0], rc, ldap_err2string( rc ) );
126 if ( continuemode ) {
132 (void)access_allowed_mask( &op, &e, desc, &val, access,
135 fprintf( stderr, "%s%s%s: %s\n",
136 desc->ad_cname.bv_val,
137 val.bv_val ? "=" : "",
138 val.bv_val ? val.bv_val : "",
139 accessmask2str( mask, accessmaskbuf ) );