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