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 );
61 if ( !BER_BVISNULL( &authcID ) ) {
62 rc = slap_sasl_getdn( &conn, &op, &authcID, NULL, &authcDN, SLAP_GETDN_AUTHCID );
63 if ( rc != LDAP_SUCCESS ) {
64 fprintf( stderr, "ID: <%s> check failed %d (%s)\n",
66 ldap_err2string( rc ) );
72 if ( !BER_BVISNULL( &authcDN ) ) {
73 fprintf( stderr, "DN: \"%s\"\n", authcDN.bv_val );
76 assert( !BER_BVISNULL( &baseDN ) );
77 rc = dnPrettyNormal( NULL, &baseDN, &e.e_name, &e.e_nname, NULL );
78 if ( rc != LDAP_SUCCESS ) {
79 fprintf( stderr, "base=\"%s\" normalization failed %d (%s)\n",
81 ldap_err2string( rc ) );
87 if ( !BER_BVISNULL( &authcDN ) ) {
92 for ( ; argc--; argv++ ) {
94 AttributeDescription *desc = NULL;
98 char accessmaskbuf[ACCESSMASK_MAXLEN];
100 slap_access_t access = ACL_AUTH;
102 val.bv_val = strchr( argv[0], ':' );
103 if ( val.bv_val != NULL ) {
104 val.bv_val[0] = '\0';
106 val.bv_len = strlen( val.bv_val );
109 accessstr = strchr( argv[0], '/' );
110 if ( accessstr != NULL ) {
113 access = str2access( accessstr );
114 if ( access == ACL_INVALID_ACCESS ) {
115 fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
116 accessstr, argv[0] );
121 rc = slap_str2ad( argv[0], &desc, &text );
122 if ( rc != LDAP_SUCCESS ) {
123 fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
124 argv[0], rc, ldap_err2string( rc ) );
128 rc = access_allowed_mask( &op, &e, desc, &val, access,
131 fprintf( stderr, "%s%s%s: %s\n",
132 desc->ad_cname.bv_val,
133 val.bv_val ? "=" : "",
134 val.bv_val ? val.bv_val : "",
135 accessmask2str( mask, accessmaskbuf ) );