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