]> git.sur5r.net Git - openldap/blob - servers/slurpd/args.c
Add TLS Support
[openldap] / servers / slurpd / args.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright (c) 1996 Regents of the University of Michigan.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that this notice is preserved and that due credit is given
8  * to the University of Michigan at Ann Arbor. The name of the University
9  * may not be used to endorse or promote products derived from this
10  * software without specific prior written permission. This software
11  * is provided ``as is'' without express or implied warranty.
12  */
13
14 /*
15  * args.c - process command-line arguments, and set appropriate globals.
16  */
17
18 #include "portable.h"
19
20 #include <stdio.h>
21
22 #include <ac/stdlib.h>
23 #include <ac/string.h>
24 #include <ac/time.h>
25 #include <ac/unistd.h>
26
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 LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
39     fprintf( stderr, "\t\t[-t tmp-dir] [-o] [-k srvtab-file]\n" );
40 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
41     fprintf( stderr, "\t\t[-t tmp-dir] [-o]\n" );
42 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
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, "d:f:or:t:" )) != EOF ) {
67         switch ( i ) {
68         case 'd':       /* set debug level and 'do not detach' flag */
69             g->no_detach = 1;
70             if ( optarg[0] == '?' ) {
71 #ifdef LDAP_DEBUG
72                 printf( "Debug levels:\n" );
73                 printf( "\tLDAP_DEBUG_TRACE\t%d\n",
74                         LDAP_DEBUG_TRACE );
75                 printf( "\tLDAP_DEBUG_PACKETS\t%d\n",
76                         LDAP_DEBUG_PACKETS );
77                 printf( "\tLDAP_DEBUG_ARGS\t\t%d\n",
78                         LDAP_DEBUG_ARGS );
79                 printf( "\tLDAP_DEBUG_CONNS\t%d\n",
80                         LDAP_DEBUG_CONNS );
81                 printf( "\tLDAP_DEBUG_BER\t\t%d\n",
82                         LDAP_DEBUG_BER );
83                 printf( "\tLDAP_DEBUG_FILTER\t%d\n",
84                         LDAP_DEBUG_FILTER );
85                 printf( "\tLDAP_DEBUG_CONFIG\t%d\n",
86                         LDAP_DEBUG_CONFIG );
87                 printf( "\tLDAP_DEBUG_ACL\t\t%d\n",
88                         LDAP_DEBUG_ACL );
89                 printf( "\tLDAP_DEBUG_ANY\t\t%d\n",
90                         LDAP_DEBUG_ANY );
91                 puts( "\tThe -d flag also prevents slurpd from detaching." );
92 #endif /* LDAP_DEBUG */
93                 puts( "\tDebugging is disabled.  -d 0 prevents slurpd from detaching." );
94                 return( -1 );
95             }
96 #ifdef LDAP_DEBUG
97             ldap_debug |= atoi( optarg );
98 #else /* !LDAP_DEBUG */
99             if ( atoi( optarg ) != 0 )
100                 /* can't enable debugging - not built with debug code */
101                 fputs( "must compile with LDAP_DEBUG for debugging\n",
102                        stderr );
103 #endif /* LDAP_DEBUG */
104             break;
105         case 'f':       /* slapd config file */
106             g->slapd_configfile = strdup( optarg );
107             break;
108         case 'o':
109             g->one_shot_mode = 1;
110             break;
111         case 'r':       /* slapd replog file */
112             strncpy( g->slapd_replogfile, optarg,
113                         sizeof(g->slapd_replogfile)-1 );
114                 g->slapd_replogfile[sizeof(g->slapd_replogfile)-1] = '\0';
115             rflag++;
116             break;
117         case 't':       /* dir to use for our copies of replogs */
118             g->slurpd_rdir = (char *)malloc (strlen(optarg) + strlen("/replica") + 1);
119             sprintf(g->slurpd_rdir, "%s/replica", optarg);
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         ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug);
142         ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &ldap_debug);
143         ldif_debug = ldap_debug;
144
145 #ifdef LOG_LOCAL4
146     openlog( g->myname, OPENLOG_OPTIONS, LOG_LOCAL4 );
147 #elif LOG_DEBUG
148     openlog( g->myname, OPENLOG_OPTIONS );
149 #endif
150
151     return 0;
152 }