2004-04-20 08:08:44 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2008-01-08 08:19:56 +08:00
|
|
|
* Copyright 2004-2008 The OpenLDAP Foundation.
|
2004-04-20 08:08:44 +08:00
|
|
|
* Portions Copyright 2004 Pierangelo Masarati.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Pierangelo Masarati for inclusion
|
|
|
|
* in OpenLDAP Software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
|
|
|
|
#include <lber.h>
|
|
|
|
#include <ldif.h>
|
|
|
|
#include <lutil.h>
|
|
|
|
|
|
|
|
#include "slapcommon.h"
|
|
|
|
|
2005-04-03 09:20:36 +08:00
|
|
|
static int
|
|
|
|
print_access(
|
|
|
|
Operation *op,
|
|
|
|
Entry *e,
|
|
|
|
AttributeDescription *desc,
|
|
|
|
struct berval *val,
|
|
|
|
struct berval *nval )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
slap_mask_t mask;
|
|
|
|
char accessmaskbuf[ACCESSMASK_MAXLEN];
|
|
|
|
|
|
|
|
rc = access_allowed_mask( op, e, desc, nval, ACL_AUTH, NULL, &mask );
|
|
|
|
|
|
|
|
fprintf( stderr, "%s%s%s: %s\n",
|
|
|
|
desc->ad_cname.bv_val,
|
|
|
|
( val && !BER_BVISNULL( val ) ) ? "=" : "",
|
|
|
|
( val && !BER_BVISNULL( val ) ) ?
|
2006-08-29 15:28:22 +08:00
|
|
|
( desc == slap_schema.si_ad_userPassword ?
|
|
|
|
"****" : val->bv_val ) : "",
|
2005-04-03 09:20:36 +08:00
|
|
|
accessmask2str( mask, accessmaskbuf, 1 ) );
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
int
|
|
|
|
slapacl( int argc, char **argv )
|
|
|
|
{
|
|
|
|
int rc = EXIT_SUCCESS;
|
|
|
|
const char *progname = "slapacl";
|
2005-03-31 06:29:35 +08:00
|
|
|
Connection conn = { 0 };
|
|
|
|
Listener listener;
|
2005-10-13 07:17:28 +08:00
|
|
|
OperationBuffer opbuf;
|
2005-09-05 04:07:17 +08:00
|
|
|
Operation *op = NULL;
|
2005-04-01 05:21:16 +08:00
|
|
|
Entry e = { 0 }, *ep = &e;
|
2004-11-17 21:43:04 +08:00
|
|
|
char *attr = NULL;
|
2005-04-13 04:33:45 +08:00
|
|
|
int doclose = 0;
|
2005-04-13 06:13:42 +08:00
|
|
|
BackendDB *bd;
|
2004-04-20 08:08:44 +08:00
|
|
|
|
|
|
|
slap_tool_init( progname, SLAPACL, argc, argv );
|
|
|
|
|
2005-04-13 06:13:42 +08:00
|
|
|
if ( !dryrun ) {
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
|
|
|
|
if ( bd != be && backend_startup( bd ) ) {
|
|
|
|
fprintf( stderr, "backend_startup(#%d%s%s) failed\n",
|
|
|
|
i,
|
|
|
|
bd->be_suffix ? ": " : "",
|
|
|
|
bd->be_suffix ? bd->be_suffix[0].bv_val : "" );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
2005-04-13 08:00:06 +08:00
|
|
|
|
|
|
|
i++;
|
2005-04-13 06:13:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
argv = &argv[ optind ];
|
|
|
|
argc -= optind;
|
|
|
|
|
2007-05-19 07:54:26 +08:00
|
|
|
connection_fake_init( &conn, &opbuf, &conn );
|
|
|
|
op = &opbuf.ob_op;
|
2004-04-20 08:08:44 +08:00
|
|
|
|
2005-03-31 06:29:35 +08:00
|
|
|
conn.c_listener = &listener;
|
|
|
|
conn.c_listener_url = listener_url;
|
|
|
|
conn.c_peer_domain = peer_domain;
|
|
|
|
conn.c_peer_name = peer_name;
|
|
|
|
conn.c_sock_name = sock_name;
|
|
|
|
op->o_ssf = ssf;
|
|
|
|
op->o_transport_ssf = transport_ssf;
|
|
|
|
op->o_tls_ssf = tls_ssf;
|
|
|
|
op->o_sasl_ssf = sasl_ssf;
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
if ( !BER_BVISNULL( &authcID ) ) {
|
2005-04-13 03:36:56 +08:00
|
|
|
if ( !BER_BVISNULL( &authcDN ) ) {
|
|
|
|
fprintf( stderr, "both authcID=\"%s\" "
|
|
|
|
"and authcDN=\"%s\" provided\n",
|
|
|
|
authcID.bv_val, authcDN.bv_val );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
2004-11-27 08:57:37 +08:00
|
|
|
rc = slap_sasl_getdn( &conn, op, &authcID, NULL,
|
2004-11-17 21:43:04 +08:00
|
|
|
&authcDN, SLAP_GETDN_AUTHCID );
|
2004-04-20 08:08:44 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2005-04-13 03:36:56 +08:00
|
|
|
fprintf( stderr, "authcID: <%s> check failed %d (%s)\n",
|
2004-04-20 08:08:44 +08:00
|
|
|
authcID.bv_val, rc,
|
|
|
|
ldap_err2string( rc ) );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
2004-07-17 22:45:07 +08:00
|
|
|
|
|
|
|
} else if ( !BER_BVISNULL( &authcDN ) ) {
|
|
|
|
struct berval ndn;
|
|
|
|
|
|
|
|
rc = dnNormalize( 0, NULL, NULL, &authcDN, &ndn, NULL );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "autchDN=\"%s\" normalization failed %d (%s)\n",
|
|
|
|
authcDN.bv_val, rc,
|
|
|
|
ldap_err2string( rc ) );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
ch_free( authcDN.bv_val );
|
|
|
|
authcDN = ndn;
|
2004-04-20 08:08:44 +08:00
|
|
|
}
|
|
|
|
|
2005-04-13 03:36:56 +08:00
|
|
|
if ( !BER_BVISNULL( &authzID ) ) {
|
|
|
|
if ( !BER_BVISNULL( &authzDN ) ) {
|
|
|
|
fprintf( stderr, "both authzID=\"%s\" "
|
|
|
|
"and authzDN=\"%s\" provided\n",
|
|
|
|
authzID.bv_val, authzDN.bv_val );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = slap_sasl_getdn( &conn, op, &authzID, NULL,
|
|
|
|
&authzDN, SLAP_GETDN_AUTHZID );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "authzID: <%s> check failed %d (%s)\n",
|
|
|
|
authzID.bv_val, rc,
|
|
|
|
ldap_err2string( rc ) );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ( !BER_BVISNULL( &authzDN ) ) {
|
|
|
|
struct berval ndn;
|
|
|
|
|
|
|
|
rc = dnNormalize( 0, NULL, NULL, &authzDN, &ndn, NULL );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "autchDN=\"%s\" normalization failed %d (%s)\n",
|
|
|
|
authzDN.bv_val, rc,
|
|
|
|
ldap_err2string( rc ) );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
ch_free( authzDN.bv_val );
|
|
|
|
authzDN = ndn;
|
|
|
|
}
|
|
|
|
|
2004-07-17 22:45:07 +08:00
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
if ( !BER_BVISNULL( &authcDN ) ) {
|
2005-04-13 03:36:56 +08:00
|
|
|
fprintf( stderr, "authcDN: \"%s\"\n", authcDN.bv_val );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !BER_BVISNULL( &authzDN ) ) {
|
|
|
|
fprintf( stderr, "authzDN: \"%s\"\n", authzDN.bv_val );
|
2004-04-20 08:08:44 +08:00
|
|
|
}
|
|
|
|
|
2005-04-13 04:33:45 +08:00
|
|
|
if ( !BER_BVISNULL( &authzDN ) ) {
|
|
|
|
op->o_dn = authzDN;
|
|
|
|
op->o_ndn = authzDN;
|
|
|
|
|
|
|
|
if ( !BER_BVISNULL( &authcDN ) ) {
|
|
|
|
op->o_conn->c_dn = authcDN;
|
|
|
|
op->o_conn->c_ndn = authcDN;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
op->o_conn->c_dn = authzDN;
|
|
|
|
op->o_conn->c_ndn = authzDN;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ( !BER_BVISNULL( &authcDN ) ) {
|
|
|
|
op->o_conn->c_dn = authcDN;
|
|
|
|
op->o_conn->c_ndn = authcDN;
|
|
|
|
op->o_dn = authcDN;
|
|
|
|
op->o_ndn = authcDN;
|
|
|
|
}
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
assert( !BER_BVISNULL( &baseDN ) );
|
|
|
|
rc = dnPrettyNormal( NULL, &baseDN, &e.e_name, &e.e_nname, NULL );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "base=\"%s\" normalization failed %d (%s)\n",
|
|
|
|
baseDN.bv_val, rc,
|
|
|
|
ldap_err2string( rc ) );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
2004-11-27 08:57:37 +08:00
|
|
|
op->o_bd = be;
|
2005-04-13 08:00:06 +08:00
|
|
|
if ( op->o_bd == NULL ) {
|
|
|
|
/* NOTE: if no database could be found (e.g. because
|
|
|
|
* accessing the rootDSE or so), use the frontendDB
|
|
|
|
* rules; might need work */
|
|
|
|
op->o_bd = frontendDB;
|
|
|
|
}
|
|
|
|
|
2005-04-13 08:01:53 +08:00
|
|
|
if ( !dryrun ) {
|
2005-04-01 05:21:16 +08:00
|
|
|
ID id;
|
|
|
|
|
2005-04-13 08:01:53 +08:00
|
|
|
if ( be == NULL ) {
|
|
|
|
fprintf( stderr, "%s: no target database "
|
|
|
|
"has been found for baseDN=\"%s\"; "
|
|
|
|
"you may try with \"-u\" (dry run).\n",
|
|
|
|
baseDN.bv_val, progname );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
2005-04-01 05:21:16 +08:00
|
|
|
if ( !be->be_entry_open ||
|
|
|
|
!be->be_entry_close ||
|
|
|
|
!be->be_dn2id_get ||
|
2007-08-11 12:19:53 +08:00
|
|
|
!be->be_entry_get )
|
2005-04-01 05:21:16 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "%s: target database "
|
|
|
|
"doesn't support necessary operations; "
|
|
|
|
"you may try with \"-u\" (dry run).\n",
|
|
|
|
progname );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( be->be_entry_open( be, 0 ) != 0 ) {
|
|
|
|
fprintf( stderr, "%s: could not open database.\n",
|
|
|
|
progname );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
2005-04-13 04:33:45 +08:00
|
|
|
doclose = 1;
|
|
|
|
|
2005-04-01 05:21:16 +08:00
|
|
|
id = be->be_dn2id_get( be, &e.e_nname );
|
|
|
|
if ( id == NOID ) {
|
|
|
|
fprintf( stderr, "%s: unable to fetch ID of DN \"%s\"\n",
|
|
|
|
progname, e.e_nname.bv_val );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
}
|
2007-08-11 12:19:53 +08:00
|
|
|
ep = be->be_entry_get( be, id );
|
|
|
|
if ( ep == NULL ) {
|
2005-04-01 05:21:16 +08:00
|
|
|
fprintf( stderr, "%s: unable to fetch entry \"%s\" (%lu)\n",
|
|
|
|
progname, e.e_nname.bv_val, id );
|
|
|
|
rc = 1;
|
|
|
|
goto destroy;
|
|
|
|
|
|
|
|
}
|
2005-04-03 09:20:36 +08:00
|
|
|
|
|
|
|
if ( argc == 0 ) {
|
|
|
|
Attribute *a;
|
|
|
|
|
|
|
|
(void)print_access( op, ep, slap_schema.si_ad_entry, NULL, NULL );
|
|
|
|
(void)print_access( op, ep, slap_schema.si_ad_children, NULL, NULL );
|
|
|
|
|
|
|
|
for ( a = ep->e_attrs; a; a = a->a_next ) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ ) {
|
|
|
|
(void)print_access( op, ep, a->a_desc,
|
|
|
|
&a->a_vals[ i ],
|
|
|
|
&a->a_nvals[ i ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-01 05:21:16 +08:00
|
|
|
}
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
for ( ; argc--; argv++ ) {
|
|
|
|
slap_mask_t mask;
|
|
|
|
AttributeDescription *desc = NULL;
|
2005-01-07 21:37:22 +08:00
|
|
|
struct berval val = BER_BVNULL,
|
|
|
|
*valp = NULL;
|
2004-04-20 08:08:44 +08:00
|
|
|
const char *text;
|
|
|
|
char accessmaskbuf[ACCESSMASK_MAXLEN];
|
|
|
|
char *accessstr;
|
|
|
|
slap_access_t access = ACL_AUTH;
|
|
|
|
|
2004-11-17 21:43:04 +08:00
|
|
|
if ( attr == NULL ) {
|
|
|
|
attr = argv[ 0 ];
|
|
|
|
}
|
|
|
|
|
|
|
|
val.bv_val = strchr( attr, ':' );
|
2004-04-20 08:08:44 +08:00
|
|
|
if ( val.bv_val != NULL ) {
|
|
|
|
val.bv_val[0] = '\0';
|
|
|
|
val.bv_val++;
|
|
|
|
val.bv_len = strlen( val.bv_val );
|
2005-01-07 21:37:22 +08:00
|
|
|
valp = &val;
|
2004-04-20 08:08:44 +08:00
|
|
|
}
|
|
|
|
|
2004-11-17 21:43:04 +08:00
|
|
|
accessstr = strchr( attr, '/' );
|
2004-04-20 08:08:44 +08:00
|
|
|
if ( accessstr != NULL ) {
|
2006-05-11 06:23:24 +08:00
|
|
|
int invalid = 0;
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
accessstr[0] = '\0';
|
|
|
|
accessstr++;
|
|
|
|
access = str2access( accessstr );
|
2006-05-11 06:23:24 +08:00
|
|
|
switch ( access ) {
|
|
|
|
case ACL_INVALID_ACCESS:
|
2004-04-20 08:08:44 +08:00
|
|
|
fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
|
2004-11-17 21:43:04 +08:00
|
|
|
accessstr, attr );
|
2006-05-11 06:23:24 +08:00
|
|
|
invalid = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_NONE:
|
|
|
|
fprintf( stderr, "\"none\" not allowed for attribute \"%s\"\n",
|
|
|
|
attr );
|
|
|
|
invalid = 1;
|
|
|
|
break;
|
2006-05-26 00:15:49 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2006-05-11 06:23:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( invalid ) {
|
2004-04-26 08:17:58 +08:00
|
|
|
if ( continuemode ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2004-04-20 08:08:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-17 21:43:04 +08:00
|
|
|
rc = slap_str2ad( attr, &desc, &text );
|
2004-04-20 08:08:44 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
|
2004-11-17 21:43:04 +08:00
|
|
|
attr, rc, ldap_err2string( rc ) );
|
2004-04-26 08:17:58 +08:00
|
|
|
if ( continuemode ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2004-04-20 08:08:44 +08:00
|
|
|
}
|
|
|
|
|
2005-04-01 05:21:16 +08:00
|
|
|
rc = access_allowed_mask( op, ep, desc, valp, access,
|
2004-04-20 08:08:44 +08:00
|
|
|
NULL, &mask );
|
|
|
|
|
2004-07-17 23:15:59 +08:00
|
|
|
if ( accessstr ) {
|
|
|
|
fprintf( stderr, "%s access to %s%s%s: %s\n",
|
|
|
|
accessstr,
|
|
|
|
desc->ad_cname.bv_val,
|
|
|
|
val.bv_val ? "=" : "",
|
|
|
|
val.bv_val ? val.bv_val : "",
|
|
|
|
rc ? "ALLOWED" : "DENIED" );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
fprintf( stderr, "%s%s%s: %s\n",
|
|
|
|
desc->ad_cname.bv_val,
|
|
|
|
val.bv_val ? "=" : "",
|
|
|
|
val.bv_val ? val.bv_val : "",
|
2005-02-22 20:02:34 +08:00
|
|
|
accessmask2str( mask, accessmaskbuf, 1 ) );
|
2004-07-17 23:15:59 +08:00
|
|
|
}
|
|
|
|
rc = 0;
|
2004-11-17 21:43:04 +08:00
|
|
|
attr = NULL;
|
2004-04-20 08:08:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
destroy:;
|
2005-04-13 04:33:45 +08:00
|
|
|
if ( !BER_BVISNULL( &e.e_name ) ) {
|
|
|
|
ber_memfree( e.e_name.bv_val );
|
|
|
|
}
|
|
|
|
if ( !BER_BVISNULL( &e.e_nname ) ) {
|
|
|
|
ber_memfree( e.e_nname.bv_val );
|
|
|
|
}
|
2005-04-13 03:36:56 +08:00
|
|
|
if ( !dryrun && be ) {
|
2007-08-11 12:19:53 +08:00
|
|
|
if ( ep && ep != &e ) {
|
2005-04-01 05:21:16 +08:00
|
|
|
be_entry_release_r( op, ep );
|
|
|
|
}
|
2005-04-13 04:33:45 +08:00
|
|
|
if ( doclose ) {
|
|
|
|
be->be_entry_close( be );
|
|
|
|
}
|
2005-04-13 06:13:42 +08:00
|
|
|
|
|
|
|
LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) {
|
|
|
|
if ( bd != be ) {
|
|
|
|
backend_shutdown( bd );
|
|
|
|
}
|
|
|
|
}
|
2005-04-01 05:21:16 +08:00
|
|
|
}
|
|
|
|
|
2008-11-03 21:23:05 +08:00
|
|
|
if ( slap_tool_destroy())
|
|
|
|
rc = EXIT_FAILURE;
|
2004-04-20 08:08:44 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|