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