]> git.sur5r.net Git - openldap/blob - servers/slapd/slapacl.c
limit checking in syncrepl
[openldap] / servers / slapd / slapacl.c
1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
2  *
3  * Copyright 2004 The OpenLDAP Foundation.
4  * Portions Copyright 2004 Pierangelo Masarati.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
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>.
14  */
15 /* ACKNOWLEDGEMENTS:
16  * This work was initially developed by Pierangelo Masarati for inclusion
17  * in OpenLDAP Software.
18  */
19
20 #include "portable.h"
21
22 #include <stdio.h>
23
24 #include <ac/stdlib.h>
25
26 #include <ac/ctype.h>
27 #include <ac/string.h>
28 #include <ac/socket.h>
29 #include <ac/unistd.h>
30
31 #include <lber.h>
32 #include <ldif.h>
33 #include <lutil.h>
34
35 #include "slapcommon.h"
36
37 int
38 slapacl( int argc, char **argv )
39 {
40         int                     rc = EXIT_SUCCESS;
41         const char              *progname = "slapacl";
42         Connection              conn;
43         Operation               op;
44         Entry                   e = { 0 };
45
46 #ifdef NEW_LOGGING
47         lutil_log_initialize( argc, argv );
48 #endif
49         slap_tool_init( progname, SLAPACL, argc, argv );
50
51         argv = &argv[ optind ];
52         argc -= optind;
53
54         memset( &conn, 0, sizeof( Connection ) );
55         memset( &op, 0, sizeof( Operation ) );
56
57         connection_fake_init( &conn, &op, &conn );
58
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",
63                                         authcID.bv_val, rc,
64                                         ldap_err2string( rc ) );
65                         rc = 1;
66                         goto destroy;
67                 }
68         }
69
70         if ( !BER_BVISNULL( &authcDN ) ) {
71                 fprintf( stderr, "DN: \"%s\"\n", authcDN.bv_val );
72         }
73
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",
78                                 baseDN.bv_val, rc,
79                                 ldap_err2string( rc ) );
80                 rc = 1;
81                 goto destroy;
82         }
83
84         op.o_bd = be;
85         if ( !BER_BVISNULL( &authcDN ) ) {
86                 op.o_dn = authcDN;
87                 op.o_ndn = authcDN;
88         }
89
90         for ( ; argc--; argv++ ) {
91                 slap_mask_t             mask;
92                 AttributeDescription    *desc = NULL;
93                 int                     rc;
94                 struct berval           val;
95                 const char              *text;
96                 char                    accessmaskbuf[ACCESSMASK_MAXLEN];
97                 char                    *accessstr;
98                 slap_access_t           access = ACL_AUTH;
99
100                 val.bv_val = strchr( argv[0], ':' );
101                 if ( val.bv_val != NULL ) {
102                         val.bv_val[0] = '\0';
103                         val.bv_val++;
104                         val.bv_len = strlen( val.bv_val );
105                 }
106
107                 accessstr = strchr( argv[0], '/' );
108                 if ( accessstr != NULL ) {
109                         accessstr[0] = '\0';
110                         accessstr++;
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 ) {
116                                         continue;
117                                 }
118                                 break;
119                         }
120                 }
121
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 ) {
127                                 continue;
128                         }
129                         break;
130                 }
131
132                 (void)access_allowed_mask( &op, &e, desc, &val, access,
133                                 NULL, &mask );
134
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 ) );
140         }
141
142 destroy:;
143         slap_tool_destroy();
144
145         return rc;
146 }
147