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