1/* 2 * Copyright (c) 1997-1998 Erez Zadok 3 * Copyright (c) 1989 Jan-Simon Pendry 4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1989 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 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 acknowledgement:
|
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. 26 * 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 37 * SUCH DAMAGE. 38 * 39 * %W% (Berkeley) %G% 40 *
|
41 * $Id: fsinfo.c,v 1.1.1.1 1998/08/23 22:07:20 obrien Exp $
|
41 * $Id: fsinfo.c,v 1.2 1998/08/23 22:52:08 obrien Exp $ |
42 * 43 */ 44 45/* 46 * fsinfo 47 */ 48 49#ifdef HAVE_CONFIG_H 50# include <config.h> 51#endif /* HAVE_CONFIG_H */ 52#include <am_defs.h> 53#include <fsi_data.h> 54#include <fsinfo.h> 55#include <fsi_gram.h> 56 57/* globals */ 58char **g_argv; 59char *autodir = "/a"; 60char *progname;
|
61char *username;
|
61char hostname[MAXHOSTNAMELEN + 1];
|
62char *username; |
63char idvbuf[1024]; 64dict *dict_of_hosts; 65dict *dict_of_volnames; 66int errors; 67int file_io_errors; 68int parse_errors; 69int verbose; 70qelem *list_of_automounts; 71qelem *list_of_hosts; 72 73/* 74 * Output file prefixes 75 */ 76char *bootparams_pref; 77char *dumpset_pref; 78char *exportfs_pref; 79char *fstab_pref; 80char *mount_pref; 81 82/* dummy variables */
|
83int orig_umask, foreground, debug_flags;
|
83#if 0 |
84pid_t mypid; 85serv_state amd_state;
|
86int foreground, orig_umask; 87int debug_flags; 88#endif |
89 90 91/* 92 * Argument cracking... 93 */ 94static void 95fsi_get_args(int c, char *v[]) 96{ 97 int ch; 98 int usage = 0; 99 char *iptr = idvbuf; 100 101 /* 102 * Determine program name 103 */ 104 if (v[0]) { 105 progname = strrchr(v[0], '/'); 106 if (progname && progname[1]) 107 progname++; 108 else 109 progname = v[0]; 110 } 111 112 if (!progname) 113 progname = "fsinfo"; 114 115 while ((ch = getopt(c, v, "a:b:d:e:f:h:m:D:U:I:qv")) != -1) 116 117 switch (ch) { 118 119 case 'a': 120 autodir = optarg; 121 break; 122 123 case 'b': 124 if (bootparams_pref) 125 fatal("-b option specified twice"); 126 bootparams_pref = optarg; 127 break; 128 129 case 'd': 130 if (dumpset_pref) 131 fatal("-d option specified twice"); 132 dumpset_pref = optarg; 133 break; 134 135 case 'h': 136 strncpy(hostname, optarg, sizeof(hostname) - 1); 137 break; 138 139 case 'e': 140 if (exportfs_pref) 141 fatal("-e option specified twice"); 142 exportfs_pref = optarg; 143 break; 144 145 case 'f': 146 if (fstab_pref) 147 fatal("-f option specified twice"); 148 fstab_pref = optarg; 149 break; 150 151 case 'm': 152 if (mount_pref) 153 fatal("-m option specified twice"); 154 mount_pref = optarg; 155 break; 156 157 case 'q': 158 verbose = -1; 159 break; 160 161 case 'v': 162 verbose = 1; 163 break; 164 165 case 'I': 166 case 'D': 167 case 'U': 168 sprintf(iptr, "-%c%s ", ch, optarg); 169 iptr += strlen(iptr); 170 break; 171 172 default: 173 usage++; 174 break; 175 } 176 177 if (c != optind) { 178 g_argv = v + optind - 1; 179 if (yywrap()) 180 fatal("Cannot read any input files"); 181 } else { 182 usage++; 183 } 184 185 if (usage) { 186 fprintf(stderr, 187 "\ 188Usage: %s [-v] [-a autodir] [-h hostname] [-b bootparams] [-d dumpsets]\n\ 189\t[-e exports] [-f fstabs] [-m automounts]\n\ 190\t[-I dir] [-D|-U string[=string]] config ...\n", progname); 191 exit(1); 192 } 193 194 if (g_argv[0]) 195 log("g_argv[0] = %s", g_argv[0]); 196 else 197 log("g_argv[0] = (nil)"); 198} 199 200 201/* 202 * Determine username of caller 203 */ 204static char * 205find_username(void) 206{ 207 char *u = getlogin(); 208 209 if (!u) { 210 struct passwd *pw = getpwuid(getuid()); 211 if (pw) 212 u = pw->pw_name; 213 } 214 215 if (!u) 216 u = getenv("USER"); 217 if (!u) 218 u = getenv("LOGNAME"); 219 if (!u) 220 u = "root"; 221 222 return strdup(u); 223} 224 225 226/* 227 * MAIN 228 */ 229int 230main(int argc, char *argv[]) 231{ 232 /* 233 * Process arguments 234 */ 235 fsi_get_args(argc, argv); 236 237 /* 238 * If no hostname given then use the local name 239 */ 240 if (!*hostname && gethostname(hostname, sizeof(hostname)) < 0) { 241 perror("gethostname"); 242 exit(1); 243 } 244 245 /* 246 * Get the username 247 */ 248 username = find_username(); 249 250 /* 251 * New hosts and automounts 252 */ 253 list_of_hosts = new_que(); 254 list_of_automounts = new_que(); 255 256 /* 257 * New dictionaries 258 */ 259 dict_of_volnames = new_dict(); 260 dict_of_hosts = new_dict(); 261 262 /* 263 * Parse input 264 */ 265 show_area_being_processed("read config", 11); 266 if (yyparse()) 267 errors = 1; 268 errors += file_io_errors + parse_errors; 269 270 if (errors == 0) { 271 /* 272 * Do semantic analysis of input 273 */ 274 analyze_hosts(list_of_hosts); 275 analyze_automounts(list_of_automounts); 276 } 277 278 /* 279 * Give up if errors 280 */ 281 if (errors == 0) { 282 /* 283 * Output data files 284 */ 285 286 write_atab(list_of_automounts); 287 write_bootparams(list_of_hosts); 288 write_dumpset(list_of_hosts); 289 write_exportfs(list_of_hosts); 290 write_fstab(list_of_hosts); 291 } 292 col_cleanup(1); 293 294 exit(errors); 295 return errors; /* should never reach here */ 296}
|