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
| 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 *
| 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;
| 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;
| |
62char hostname[MAXHOSTNAMELEN + 1];
| 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 */
| 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;
| 84pid_t mypid; 85serv_state amd_state;
|
| 86int foreground, orig_umask; 87int debug_flags; 88#endif
|
86 87 88/* 89 * Argument cracking... 90 */ 91static void 92fsi_get_args(int c, char *v[]) 93{ 94 int ch; 95 int usage = 0; 96 char *iptr = idvbuf; 97 98 /* 99 * Determine program name 100 */ 101 if (v[0]) { 102 progname = strrchr(v[0], '/'); 103 if (progname && progname[1]) 104 progname++; 105 else 106 progname = v[0]; 107 } 108 109 if (!progname) 110 progname = "fsinfo"; 111 112 while ((ch = getopt(c, v, "a:b:d:e:f:h:m:D:U:I:qv")) != -1) 113 114 switch (ch) { 115 116 case 'a': 117 autodir = optarg; 118 break; 119 120 case 'b': 121 if (bootparams_pref) 122 fatal("-b option specified twice"); 123 bootparams_pref = optarg; 124 break; 125 126 case 'd': 127 if (dumpset_pref) 128 fatal("-d option specified twice"); 129 dumpset_pref = optarg; 130 break; 131 132 case 'h': 133 strncpy(hostname, optarg, sizeof(hostname) - 1); 134 break; 135 136 case 'e': 137 if (exportfs_pref) 138 fatal("-e option specified twice"); 139 exportfs_pref = optarg; 140 break; 141 142 case 'f': 143 if (fstab_pref) 144 fatal("-f option specified twice"); 145 fstab_pref = optarg; 146 break; 147 148 case 'm': 149 if (mount_pref) 150 fatal("-m option specified twice"); 151 mount_pref = optarg; 152 break; 153 154 case 'q': 155 verbose = -1; 156 break; 157 158 case 'v': 159 verbose = 1; 160 break; 161 162 case 'I': 163 case 'D': 164 case 'U': 165 sprintf(iptr, "-%c%s ", ch, optarg); 166 iptr += strlen(iptr); 167 break; 168 169 default: 170 usage++; 171 break; 172 } 173 174 if (c != optind) { 175 g_argv = v + optind - 1; 176 if (yywrap()) 177 fatal("Cannot read any input files"); 178 } else { 179 usage++; 180 } 181 182 if (usage) { 183 fprintf(stderr, 184 "\ 185Usage: %s [-v] [-a autodir] [-h hostname] [-b bootparams] [-d dumpsets]\n\ 186\t[-e exports] [-f fstabs] [-m automounts]\n\ 187\t[-I dir] [-D|-U string[=string]] config ...\n", progname); 188 exit(1); 189 } 190 191 if (g_argv[0]) 192 log("g_argv[0] = %s", g_argv[0]); 193 else 194 log("g_argv[0] = (nil)"); 195} 196 197 198/* 199 * Determine username of caller 200 */ 201static char * 202find_username(void) 203{ 204 char *u = getlogin(); 205 206 if (!u) { 207 struct passwd *pw = getpwuid(getuid()); 208 if (pw) 209 u = pw->pw_name; 210 } 211 212 if (!u) 213 u = getenv("USER"); 214 if (!u) 215 u = getenv("LOGNAME"); 216 if (!u) 217 u = "root"; 218 219 return strdup(u); 220} 221 222 223/* 224 * MAIN 225 */ 226int 227main(int argc, char *argv[]) 228{ 229 /* 230 * Process arguments 231 */ 232 fsi_get_args(argc, argv); 233 234 /* 235 * If no hostname given then use the local name 236 */ 237 if (!*hostname && gethostname(hostname, sizeof(hostname)) < 0) { 238 perror("gethostname"); 239 exit(1); 240 } 241 242 /* 243 * Get the username 244 */ 245 username = find_username(); 246 247 /* 248 * New hosts and automounts 249 */ 250 list_of_hosts = new_que(); 251 list_of_automounts = new_que(); 252 253 /* 254 * New dictionaries 255 */ 256 dict_of_volnames = new_dict(); 257 dict_of_hosts = new_dict(); 258 259 /* 260 * Parse input 261 */ 262 show_area_being_processed("read config", 11); 263 if (yyparse()) 264 errors = 1; 265 errors += file_io_errors + parse_errors; 266 267 if (errors == 0) { 268 /* 269 * Do semantic analysis of input 270 */ 271 analyze_hosts(list_of_hosts); 272 analyze_automounts(list_of_automounts); 273 } 274 275 /* 276 * Give up if errors 277 */ 278 if (errors == 0) { 279 /* 280 * Output data files 281 */ 282 283 write_atab(list_of_automounts); 284 write_bootparams(list_of_hosts); 285 write_dumpset(list_of_hosts); 286 write_exportfs(list_of_hosts); 287 write_fstab(list_of_hosts); 288 } 289 col_cleanup(1); 290 291 exit(errors); 292 return errors; /* should never reach here */ 293}
| 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}
|