]> git.sur5r.net Git - openldap/blob - servers/slurpd/args.c
Fixup bugs created by merge.
[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
21 #include <ac/string.h>
22 #include <ac/time.h>
23
24 #include <lber.h>
25 #include <ldap.h>
26
27 #include "slurp.h"
28 #include "globals.h"
29
30
31 static int
32 usage( char *name )
33 {
34     fprintf( stderr, "usage: %s\t[-d debug-level] [-s syslog-level]\n", name );
35     fprintf( stderr, "\t\t[-f slapd-config-file] [-r replication-log-file]\n" );
36 #ifdef HAVE_KERBEROS
37     fprintf( stderr, "\t\t[-t tmp-dir] [-o] [-k srvtab-file]\n" );
38 #else /* HAVE_KERBEROS */
39     fprintf( stderr, "\t\t[-t tmp-dir] [-o]\n" );
40 #endif /* HAVE_KERBEROS */
41 }
42
43
44
45 /*
46  * Interpret argv, and fill in any appropriate globals.
47  */
48 int
49 doargs(
50     int         argc,
51     char        **argv,
52     Globals     *g
53 )
54 {
55     int         i;
56     extern char *optarg;
57     int         rflag = 0;
58
59     if ( (g->myname = strrchr( argv[0], '/' )) == NULL ) {
60         g->myname = strdup( argv[0] );
61     } else {
62         g->myname = strdup( g->myname + 1 );
63     }
64
65     while ( (i = getopt( argc, argv, "hd:f:r:t:k:o" )) != EOF ) {
66         switch ( i ) {
67 #ifdef LDAP_DEBUG
68         case 'd':       /* turn on debugging */
69             if ( optarg[0] == '?' ) {
70                 printf( "Debug levels:\n" );
71                 printf( "\tLDAP_DEBUG_TRACE\t%d\n",
72                         LDAP_DEBUG_TRACE );
73                 printf( "\tLDAP_DEBUG_PACKETS\t%d\n",
74                         LDAP_DEBUG_PACKETS );
75                 printf( "\tLDAP_DEBUG_ARGS\t\t%d\n",
76                         LDAP_DEBUG_ARGS );
77                 printf( "\tLDAP_DEBUG_CONNS\t%d\n",
78                         LDAP_DEBUG_CONNS );
79                 printf( "\tLDAP_DEBUG_BER\t\t%d\n",
80                         LDAP_DEBUG_BER );
81                 printf( "\tLDAP_DEBUG_FILTER\t%d\n",
82                         LDAP_DEBUG_FILTER );
83                 printf( "\tLDAP_DEBUG_CONFIG\t%d\n",
84                         LDAP_DEBUG_CONFIG );
85                 printf( "\tLDAP_DEBUG_ACL\t\t%d\n",
86                         LDAP_DEBUG_ACL );
87                 printf( "\tLDAP_DEBUG_ANY\t\t%d\n",
88                         LDAP_DEBUG_ANY );
89                 return( -1 );
90             } else {
91                 ldap_debug = atoi( optarg );
92             }
93             break;
94 #else /* LDAP_DEBUG */
95         case 'd':       /* can't enable debugging - not built with debug code */
96             fprintf( stderr, "must compile with LDAP_DEBUG for debugging\n" );
97             break;
98 #endif /* LDAP_DEBUG */
99         case 'f':       /* slapd config file */
100             g->slapd_configfile = strdup( optarg );
101             break;
102         case 'r':       /* slapd replog file */
103             strcpy( g->slapd_replogfile, optarg );
104             rflag++;
105             break;
106         case 't':       /* dir to use for our copies of replogs */
107             g->slurpd_rdir = strdup( optarg );
108             break;
109         case 'k':       /* name of kerberos srvtab file */
110 #ifdef HAVE_KERBEROS
111             g->default_srvtab = strdup( optarg );
112 #else /* HAVE_KERBEROS */
113             fprintf( stderr, "must compile with KERBEROS to use -k option\n" );
114 #endif /* HAVE_KERBEROS */
115             break;
116         case 'h':
117             usage( g->myname );
118             return( -1 );
119         case 'o':
120             g->one_shot_mode = 1;
121             break;
122         default:
123             usage( g->myname );
124             return( -1 );
125         }
126     }
127
128     if ( g->one_shot_mode && !rflag ) {
129         fprintf( stderr, "If -o flag is given, -r flag must also be given.\n" );
130         usage( g->myname );
131         return( -1 );
132     }
133
134     /* Set location/name of our private copy of the slapd replog file */
135     sprintf( g->slurpd_replogfile, "%s/%s", g->slurpd_rdir,
136             DEFAULT_SLURPD_REPLOGFILE );
137
138     /* Set location/name of the slurpd status file */
139     sprintf( g->slurpd_status_file, "%s/%s", g->slurpd_rdir,
140             DEFAULT_SLURPD_STATUS_FILE );
141
142 #ifdef LOG_LOCAL4
143     openlog( g->myname, OPENLOG_OPTIONS, LOG_LOCAL4 );
144 #else
145     openlog( g->myname, OPENLOG_OPTIONS );
146 #endif
147
148     return 0;
149
150 }
151
152