]> git.sur5r.net Git - openldap/blob - servers/slurpd/args.c
fix controls propagation (ITS#3813)
[openldap] / servers / slurpd / args.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2005 The OpenLDAP Foundation.
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 /* Portions Copyright (c) 1996 Regents of the University of Michigan.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms are permitted
19  * provided that this notice is preserved and that due credit is given
20  * to the University of Michigan at Ann Arbor. The name of the University
21  * may not be used to endorse or promote products derived from this
22  * software without specific prior written permission. This software
23  * is provided ``as is'' without express or implied warranty.
24  */
25 /* ACKNOWLEDGEMENTS:
26  * This work was originally developed by the University of Michigan
27  * (as part of U-MICH LDAP).
28  */
29
30 /*
31  * args.c - process command-line arguments, and set appropriate globals.
32  */
33
34 #include "portable.h"
35
36 #include <stdio.h>
37
38 #include <ac/stdlib.h>
39 #include <ac/string.h>
40 #include <ac/time.h>
41 #include <ac/unistd.h>
42
43 #include <ldap.h>
44 #include <lutil.h>
45
46 #include "slurp.h"
47 #include "globals.h"
48
49
50 static void
51 usage( char *name )
52 {
53     fprintf( stderr, "usage: %s\t[-d debug-level] [-s syslog-level]\n", name );
54     fprintf( stderr, "\t\t[-f slapd-config-file] [-r replication-log-file]\n" );
55 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
56     fprintf( stderr, "\t\t[-t tmp-dir] [-o] [-k srvtab-file]\n" );
57 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
58     fprintf( stderr, "\t\t[-t tmp-dir] [-o]\n" );
59 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
60     fprintf( stderr, "\t\t[-n service-name]\n" );
61 }
62
63
64
65 /*
66  * Interpret argv, and fill in any appropriate globals.
67  */
68 int
69 doargs(
70     int         argc,
71     char        **argv,
72     Globals     *g
73 )
74 {
75     int         i;
76     int         rflag = 0;
77
78     g->myname = strdup( lutil_progname( "slurpd", argc, argv ));
79
80     while ( (i = getopt( argc, argv, "d:f:n:or:t:V" )) != EOF ) {
81         switch ( i ) {
82         case 'd':       /* set debug level and 'do not detach' flag */
83             g->no_detach = 1;
84             if ( optarg[0] == '?' ) {
85 #ifdef LDAP_DEBUG
86                 printf( "Debug levels:\n" );
87                 printf( "\tLDAP_DEBUG_TRACE\t%d\n",
88                         LDAP_DEBUG_TRACE );
89                 printf( "\tLDAP_DEBUG_PACKETS\t%d\n",
90                         LDAP_DEBUG_PACKETS );
91                 printf( "\tLDAP_DEBUG_ARGS\t\t%d\n",
92                         LDAP_DEBUG_ARGS );
93                 printf( "\tLDAP_DEBUG_CONNS\t%d\n",
94                         LDAP_DEBUG_CONNS );
95                 printf( "\tLDAP_DEBUG_BER\t\t%d\n",
96                         LDAP_DEBUG_BER );
97                 printf( "\tLDAP_DEBUG_FILTER\t%d\n",
98                         LDAP_DEBUG_FILTER );
99                 printf( "\tLDAP_DEBUG_CONFIG\t%d\n",
100                         LDAP_DEBUG_CONFIG );
101                 printf( "\tLDAP_DEBUG_ACL\t\t%d\n",
102                         LDAP_DEBUG_ACL );
103                 printf( "\tLDAP_DEBUG_ANY\t\t%d\n",
104                         LDAP_DEBUG_ANY );
105                 puts( "\tThe -d flag also prevents slurpd from detaching." );
106 #endif /* LDAP_DEBUG */
107                 puts( "\tDebugging is disabled.  -d 0 prevents slurpd from detaching." );
108                 return( -1 );
109             }
110 #ifdef LDAP_DEBUG
111             ldap_debug |= atoi( optarg );
112 #else /* !LDAP_DEBUG */
113             if ( atoi( optarg ) != 0 )
114                 /* can't enable debugging - not built with debug code */
115                 fputs( "must compile with LDAP_DEBUG for debugging\n",
116                        stderr );
117 #endif /* LDAP_DEBUG */
118             break;
119         case 'f':       /* slapd config file */
120             LUTIL_SLASHPATH( optarg );
121             g->slapd_configfile = strdup( optarg );
122             break;
123         case 'n':       /* NT service name */
124             if ( g->serverName ) free( g->serverName );
125             g->serverName = strdup( optarg );
126             break;
127         case 'o':
128             g->one_shot_mode = 1;
129             break;
130         case 'r':       /* slapd replog file */
131             LUTIL_SLASHPATH( optarg );
132                 snprintf( g->slapd_replogfile, sizeof g->slapd_replogfile,
133                         "%s", optarg );
134             rflag++;
135             break;
136         case 't': {     /* dir to use for our copies of replogs */
137                 size_t sz;
138             LUTIL_SLASHPATH( optarg );
139             g->slurpd_rdir = (char *)malloc (sz = (strlen(optarg) + sizeof(LDAP_DIRSEP "replica")));
140             snprintf(g->slurpd_rdir, sz,
141                         "%s" LDAP_DIRSEP "replica", optarg);
142             } break;
143         case 'V':
144             (g->version)++;
145             break;
146         default:
147             usage( g->myname );
148             return( -1 );
149         }
150     }
151
152     if ( g->one_shot_mode && !rflag ) {
153         fprintf( stderr, "If -o flag is given, -r flag must also be given.\n" );
154         usage( g->myname );
155         return( -1 );
156     }
157
158     /* Set location/name of our private copy of the slapd replog file */
159     snprintf( g->slurpd_replogfile, sizeof g->slurpd_replogfile,
160                 "%s" LDAP_DIRSEP "%s", g->slurpd_rdir,
161             DEFAULT_SLURPD_REPLOGFILE );
162
163     /* Set location/name of the slurpd status file */
164     snprintf( g->slurpd_status_file, sizeof g->slurpd_status_file,
165                 "%s" LDAP_DIRSEP "%s", g->slurpd_rdir,
166             DEFAULT_SLURPD_STATUS_FILE );
167
168         ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug);
169         ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &ldap_debug);
170         ldif_debug = ldap_debug;
171
172 #ifdef LOG_LOCAL4
173     openlog( g->myname, OPENLOG_OPTIONS, LOG_LOCAL4 );
174 #elif LOG_DEBUG
175     openlog( g->myname, OPENLOG_OPTIONS );
176 #endif
177
178     return 0;
179 }