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