2 * Copyright (c) 1997-1999 Erez Zadok
3 * Copyright (c) 1990 Jan-Simon Pendry
4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1990 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgment:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * $Id: get_args.c,v 1.4 1999/09/30 21:01:31 ezk Exp $
42 * $FreeBSD: src/contrib/amd/amd/get_args.c,v 1.5 1999/11/05 11:58:05 obrien Exp $
52 #endif /* HAVE_CONFIG_H */
56 /* include auto-generated version file */
57 #include <build_version.h>
59 char *conf_file = "/etc/amd.conf"; /* default amd configuration file */
60 char *conf_tag = NULL; /* default conf file tags to use */
62 int use_conf_file = 0; /* default don't use amd.conf file */
63 char *mnttab_file_name = NULL; /* symbol must be available always */
66 int debug_flags = D_AMQ /* Register AMQ */
67 | D_DAEMON; /* Enter daemon mode */
72 * Return the version string (dynamic buffer)
75 get_version_string(void)
77 static char *vers = NULL;
82 /* first get dynamic string listing all known networks */
83 wire_buf = print_wires();
85 wire_buf_len = strlen(wire_buf);
87 vers = xmalloc(2048 + wire_buf_len);
88 sprintf(vers, "%s\n%s\n%s\n%s\n",
89 "Copyright (c) 1997-1999 Erez Zadok",
90 "Copyright (c) 1990 Jan-Simon Pendry",
91 "Copyright (c) 1990 Imperial College of Science, Technology & Medicine",
92 "Copyright (c) 1990 The Regents of the University of California.");
93 sprintf(tmpbuf, "%s version %s (build %d).\n",
94 PACKAGE, VERSION, AMU_BUILD_VERSION);
96 sprintf(tmpbuf, "Built by %s@%s on date %s.\n",
97 USER_NAME, HOST_NAME, CONFIG_DATE);
99 sprintf(tmpbuf, "cpu=%s (%s-endian), arch=%s, karch=%s.\n",
100 cpu, endian, gopt.arch, gopt.karch);
101 strcat(vers, tmpbuf);
102 sprintf(tmpbuf, "full_os=%s, os=%s, osver=%s, vendor=%s.\n",
103 gopt.op_sys_full, gopt.op_sys, gopt.op_sys_ver, gopt.op_sys_vendor);
104 strcat(vers, tmpbuf);
106 strcat(vers, "Map support for: ");
107 mapc_showtypes(tmpbuf);
108 strcat(vers, tmpbuf);
109 strcat(vers, ".\nAMFS: ");
110 ops_showamfstypes(tmpbuf);
111 strcat(vers, tmpbuf);
112 strcat(vers, ".\nFS: ");
113 ops_showfstypes(tmpbuf);
114 strcat(vers, tmpbuf);
116 /* append list of networks if available */
118 strcat(vers, wire_buf);
127 get_args(int argc, char *argv[])
132 /* if no arguments were passed, try to use /etc/amd.conf file */
136 while ((opt_ch = getopt(argc, argv, "nprvSa:c:d:k:l:o:t:w:x:y:C:D:F:T:O:H")) != -1)
140 if (*optarg != '/') {
141 fprintf(stderr, "%s: -a option must begin with a '/'\n",
145 gopt.auto_dir = optarg;
149 gopt.am_timeo = atoi(optarg);
150 if (gopt.am_timeo <= 0)
151 gopt.am_timeo = AM_TTL;
155 gopt.sub_domain = optarg;
163 gopt.logfile = optarg;
167 gopt.flags |= CFM_NORMALIZE_HOSTNAMES;
171 gopt.op_sys_ver = optarg;
175 gopt.flags |= CFM_PRINT_PID;
179 gopt.flags |= CFM_RESTART_EXISTING_MOUNTS;
185 char *dot = strchr(optarg, '.');
189 gopt.amfs_auto_timeo = atoi(optarg);
192 gopt.amfs_auto_retrans = atoi(dot + 1);
199 fputs(get_version_string(), stderr);
204 gopt.am_timeo_w = atoi(optarg);
205 if (gopt.am_timeo_w <= 0)
206 gopt.am_timeo_w = AM_TTL_W;
210 usage += switch_option(optarg);
215 gopt.nis_domain = optarg;
216 #else /* not HAVE_MAP_NIS */
217 plog(XLOG_USER, "-y: option ignored. No NIS support available.");
218 #endif /* not HAVE_MAP_NIS */
222 gopt.cluster = optarg;
227 usage += debug_option(optarg);
228 #else /* not DEBUG */
229 fprintf(stderr, "%s: not compiled with DEBUG option -- sorry.\n",
231 #endif /* not DEBUG */
244 gopt.op_sys = optarg;
248 gopt.flags &= ~CFM_PROCESS_LOCK; /* turn process locking off */
261 * amd.conf file: if not command-line arguments were used, or if -F was
262 * specified, then use that amd.conf file. If the file cannot be opened,
263 * abort amd. If it can be found, open it, parse it, and then close it.
265 if (use_conf_file && conf_file) {
266 fp = fopen(conf_file, "r");
269 sprintf(buf, "Amd configuration file (%s)", conf_file);
276 if (process_last_regular_map() != 0)
280 /* make sure there are some default options defined */
281 if (xlog_level_init == ~0) {
285 usage += switch_option("debug");
288 /* log information regarding amd.conf file */
289 if (use_conf_file && conf_file)
290 plog(XLOG_INFO, "using configuration file %s", conf_file);
293 /* ensure that if ldap_base is specified, that also ldap_hostports is */
294 if (gopt.ldap_hostports && !gopt.ldap_base) {
295 fprintf(stderr, "must specify both ldap_hostports and ldap_base\n");
298 #endif /* HAVE_MAP_LDAP */
303 while (optind <= argc - 2) {
304 char *dir = argv[optind++];
305 char *map = argv[optind++];
307 if (argv[optind] && *argv[optind] == '-')
308 opts = &argv[optind++][1];
310 root_newmap(dir, opts, map, NULL);
313 if (optind == argc) {
315 * Append domain name to hostname.
316 * sub_domain overrides hostdomain
320 hostdomain = gopt.sub_domain;
321 if (*hostdomain == '.')
324 strcat(hostd, hostdomain);
326 #ifdef MOUNT_TABLE_ON_FILE
328 if (debug_flags & D_MTAB)
329 mnttab_file_name = DEBUG_MNTTAB;
332 mnttab_file_name = MNTTAB_FILE_NAME;
333 #else /* not MOUNT_TABLE_ON_FILE */
335 if (debug_flags & D_MTAB)
336 dlog("-D mtab option ignored");
338 #endif /* not MOUNT_TABLE_ON_FILE */
340 if (switch_to_logfile(gopt.logfile, orig_umask) != 0)
341 plog(XLOG_USER, "Cannot switch logfile");
344 * If the kernel architecture was not specified
345 * then use the machine architecture.
348 gopt.karch = gopt.arch;
350 if (gopt.cluster == 0)
351 gopt.cluster = hostdomain;
353 if (gopt.amfs_auto_timeo <= 0)
354 gopt.amfs_auto_timeo = AMFS_AUTO_TIMEO;
355 if (gopt.amfs_auto_retrans <= 0)
356 gopt.amfs_auto_retrans = AMFS_AUTO_RETRANS;
357 if (gopt.amfs_auto_retrans <= 0)
358 gopt.amfs_auto_retrans = 3; /* XXX */
364 "Usage: %s [-nprvHS] [-a mount_point] [-c cache_time] [-d domain]\n\
365 \t[-k kernel_arch] [-l logfile%s\n\
366 \t[-t timeout.retrans] [-w wait_timeout] [-C cluster_name]\n\
367 \t[-o op_sys_ver] [-O op_sys_name]\n\
368 \t[-F conf_file] [-T conf_tag]", am_get_progname(),
371 "|\"syslog[:facility]\"]"
372 # else /* not LOG_DAEMON */
374 # endif /* not LOG_DAEMON */
375 #else /* not HAVE_SYSLOG */
377 #endif /* not HAVE_SYSLOG */
381 fputs(" [-y nis-domain]\n", stderr);
382 #else /* not HAVE_MAP_NIS */
384 #endif /* HAVE_MAP_NIS */
386 show_opts('x', xlog_opt);
388 show_opts('D', dbg_opt);
390 fprintf(stderr, "\t[directory mapname [-map_options]] ...\n");