3 * Copyright (c) 1996 Regents of the University of Michigan.
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.
15 * args.c - process command-line arguments, and set appropriate globals.
22 #include <ac/stdlib.h>
23 #include <ac/string.h>
25 #include <ac/unistd.h>
37 fprintf( stderr, "usage: %s\t[-d debug-level] [-s syslog-level]\n", name );
38 fprintf( stderr, "\t\t[-f slapd-config-file] [-r replication-log-file]\n" );
40 fprintf( stderr, "\t\t[-t tmp-dir] [-o] [-k srvtab-file]\n" );
41 #else /* HAVE_KERBEROS */
42 fprintf( stderr, "\t\t[-t tmp-dir] [-o]\n" );
43 #endif /* HAVE_KERBEROS */
49 * Interpret argv, and fill in any appropriate globals.
61 if ( (g->myname = strrchr( argv[0], '/' )) == NULL ) {
62 g->myname = strdup( argv[0] );
64 g->myname = strdup( g->myname + 1 );
67 while ( (i = getopt( argc, argv, "hd:f:r:t:k:o" )) != EOF ) {
69 case 'd': /* set debug level and 'do not detach' flag */
71 if ( optarg[0] == '?' ) {
73 printf( "Debug levels:\n" );
74 printf( "\tLDAP_DEBUG_TRACE\t%d\n",
76 printf( "\tLDAP_DEBUG_PACKETS\t%d\n",
78 printf( "\tLDAP_DEBUG_ARGS\t\t%d\n",
80 printf( "\tLDAP_DEBUG_CONNS\t%d\n",
82 printf( "\tLDAP_DEBUG_BER\t\t%d\n",
84 printf( "\tLDAP_DEBUG_FILTER\t%d\n",
86 printf( "\tLDAP_DEBUG_CONFIG\t%d\n",
88 printf( "\tLDAP_DEBUG_ACL\t\t%d\n",
90 printf( "\tLDAP_DEBUG_ANY\t\t%d\n",
92 puts( "\tThe -d flag also prevents slurpd from detaching." );
93 #endif /* LDAP_DEBUG */
94 puts( "\tDebugging is disabled. -d 0 prevents slurpd from detaching." );
98 ldap_debug |= atoi( optarg );
99 #else /* !LDAP_DEBUG */
100 if ( atoi( optarg ) != 0 )
101 /* can't enable debugging - not built with debug code */
102 fputs( "must compile with LDAP_DEBUG for debugging\n",
104 #endif /* LDAP_DEBUG */
106 case 'f': /* slapd config file */
107 g->slapd_configfile = strdup( optarg );
109 case 'r': /* slapd replog file */
110 strcpy( g->slapd_replogfile, optarg );
113 case 't': /* dir to use for our copies of replogs */
114 g->slurpd_rdir = strdup( optarg );
116 case 'k': /* name of kerberos srvtab file */
118 g->default_srvtab = strdup( optarg );
119 #else /* HAVE_KERBEROS */
120 fprintf( stderr, "must compile with KERBEROS to use -k option\n" );
121 #endif /* HAVE_KERBEROS */
127 g->one_shot_mode = 1;
135 if ( g->one_shot_mode && !rflag ) {
136 fprintf( stderr, "If -o flag is given, -r flag must also be given.\n" );
141 /* Set location/name of our private copy of the slapd replog file */
142 sprintf( g->slurpd_replogfile, "%s/%s", g->slurpd_rdir,
143 DEFAULT_SLURPD_REPLOGFILE );
145 /* Set location/name of the slurpd status file */
146 sprintf( g->slurpd_status_file, "%s/%s", g->slurpd_rdir,
147 DEFAULT_SLURPD_STATUS_FILE );
149 ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug);
150 ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &ldap_debug);
151 ldif_debug = ldap_debug;
154 openlog( g->myname, OPENLOG_OPTIONS, LOG_LOCAL4 );
156 openlog( g->myname, OPENLOG_OPTIONS );