1/* 2 * Copyright (c) 1997-1999 Erez Zadok
| 1/* 2 * Copyright (c) 1997-1999 Erez Zadok
|
| 3 * Copyright (c) 1997-2003 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 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 *
| 4 * Copyright (c) 1989 Jan-Simon Pendry 5 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 6 * Copyright (c) 1989 The Regents of the University of California. 7 * All rights reserved. 8 * 9 * This code is derived from software contributed to Berkeley by 10 * Jan-Simon Pendry at Imperial College, London. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgment: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * %W% (Berkeley) %G% 41 *
|
41 * $Id: fsinfo.c,v 1.4 1999/02/04 07:24:44 ezk Exp $ 42 * $FreeBSD: head/contrib/amd/fsinfo/fsinfo.c 51300 1999-09-15 05:45:17Z obrien $
| 42 * $Id: fsinfo.c,v 1.5.2.5 2003/07/18 04:50:20 ezk Exp $ 43 * $FreeBSD: head/contrib/amd/fsinfo/fsinfo.c 119682 2003-09-02 15:42:57Z mbr $
|
43 * 44 */ 45 46/* 47 * fsinfo 48 */ 49 50#ifdef HAVE_CONFIG_H 51# include <config.h> 52#endif /* HAVE_CONFIG_H */ 53#include <am_defs.h> 54#include <fsi_data.h> 55#include <fsinfo.h> 56#include <fsi_gram.h> 57 58/* globals */ 59char **g_argv; 60char *autodir = "/a"; 61char *progname; 62char hostname[MAXHOSTNAMELEN + 1]; 63char *username; 64char idvbuf[1024]; 65dict *dict_of_hosts; 66dict *dict_of_volnames; 67int errors; 68int file_io_errors; 69int parse_errors; 70int verbose; 71qelem *list_of_automounts; 72qelem *list_of_hosts; 73 74/* 75 * Output file prefixes 76 */ 77char *bootparams_pref; 78char *dumpset_pref; 79char *exportfs_pref; 80char *fstab_pref; 81char *mount_pref; 82 83 84/* 85 * Argument cracking... 86 */ 87static void 88fsi_get_args(int c, char *v[]) 89{ 90 int ch; 91 int usage = 0; 92 char *iptr = idvbuf; 93 94 /* 95 * Determine program name 96 */ 97 if (v[0]) { 98 progname = strrchr(v[0], '/'); 99 if (progname && progname[1]) 100 progname++; 101 else 102 progname = v[0]; 103 } 104 105 if (!progname) 106 progname = "fsinfo"; 107 108 while ((ch = getopt(c, v, "a:b:d:e:f:h:m:D:U:I:qv")) != -1) 109 110 switch (ch) { 111 112 case 'a': 113 autodir = optarg; 114 break; 115 116 case 'b': 117 if (bootparams_pref) 118 fatal("-b option specified twice"); 119 bootparams_pref = optarg; 120 break; 121 122 case 'd': 123 if (dumpset_pref) 124 fatal("-d option specified twice"); 125 dumpset_pref = optarg; 126 break; 127 128 case 'h': 129 strncpy(hostname, optarg, sizeof(hostname) - 1); 130 break; 131 132 case 'e': 133 if (exportfs_pref) 134 fatal("-e option specified twice"); 135 exportfs_pref = optarg; 136 break; 137 138 case 'f': 139 if (fstab_pref) 140 fatal("-f option specified twice"); 141 fstab_pref = optarg; 142 break; 143 144 case 'm': 145 if (mount_pref) 146 fatal("-m option specified twice"); 147 mount_pref = optarg; 148 break; 149 150 case 'q': 151 verbose = -1; 152 break; 153 154 case 'v': 155 verbose = 1; 156 break; 157 158 case 'I': 159 case 'D': 160 case 'U': 161 sprintf(iptr, "-%c%s ", ch, optarg); 162 iptr += strlen(iptr); 163 break; 164 165 default: 166 usage++; 167 break; 168 } 169 170 if (c != optind) { 171 g_argv = v + optind - 1; 172 if (yywrap()) 173 fatal("Cannot read any input files"); 174 } else { 175 usage++; 176 } 177 178 if (usage) { 179 fprintf(stderr, 180 "\ 181Usage: %s [-v] [-a autodir] [-h hostname] [-b bootparams] [-d dumpsets]\n\ 182\t[-e exports] [-f fstabs] [-m automounts]\n\ 183\t[-I dir] [-D|-U string[=string]] config ...\n", progname); 184 exit(1); 185 } 186 187 if (g_argv[0])
| 44 * 45 */ 46 47/* 48 * fsinfo 49 */ 50 51#ifdef HAVE_CONFIG_H 52# include <config.h> 53#endif /* HAVE_CONFIG_H */ 54#include <am_defs.h> 55#include <fsi_data.h> 56#include <fsinfo.h> 57#include <fsi_gram.h> 58 59/* globals */ 60char **g_argv; 61char *autodir = "/a"; 62char *progname; 63char hostname[MAXHOSTNAMELEN + 1]; 64char *username; 65char idvbuf[1024]; 66dict *dict_of_hosts; 67dict *dict_of_volnames; 68int errors; 69int file_io_errors; 70int parse_errors; 71int verbose; 72qelem *list_of_automounts; 73qelem *list_of_hosts; 74 75/* 76 * Output file prefixes 77 */ 78char *bootparams_pref; 79char *dumpset_pref; 80char *exportfs_pref; 81char *fstab_pref; 82char *mount_pref; 83 84 85/* 86 * Argument cracking... 87 */ 88static void 89fsi_get_args(int c, char *v[]) 90{ 91 int ch; 92 int usage = 0; 93 char *iptr = idvbuf; 94 95 /* 96 * Determine program name 97 */ 98 if (v[0]) { 99 progname = strrchr(v[0], '/'); 100 if (progname && progname[1]) 101 progname++; 102 else 103 progname = v[0]; 104 } 105 106 if (!progname) 107 progname = "fsinfo"; 108 109 while ((ch = getopt(c, v, "a:b:d:e:f:h:m:D:U:I:qv")) != -1) 110 111 switch (ch) { 112 113 case 'a': 114 autodir = optarg; 115 break; 116 117 case 'b': 118 if (bootparams_pref) 119 fatal("-b option specified twice"); 120 bootparams_pref = optarg; 121 break; 122 123 case 'd': 124 if (dumpset_pref) 125 fatal("-d option specified twice"); 126 dumpset_pref = optarg; 127 break; 128 129 case 'h': 130 strncpy(hostname, optarg, sizeof(hostname) - 1); 131 break; 132 133 case 'e': 134 if (exportfs_pref) 135 fatal("-e option specified twice"); 136 exportfs_pref = optarg; 137 break; 138 139 case 'f': 140 if (fstab_pref) 141 fatal("-f option specified twice"); 142 fstab_pref = optarg; 143 break; 144 145 case 'm': 146 if (mount_pref) 147 fatal("-m option specified twice"); 148 mount_pref = optarg; 149 break; 150 151 case 'q': 152 verbose = -1; 153 break; 154 155 case 'v': 156 verbose = 1; 157 break; 158 159 case 'I': 160 case 'D': 161 case 'U': 162 sprintf(iptr, "-%c%s ", ch, optarg); 163 iptr += strlen(iptr); 164 break; 165 166 default: 167 usage++; 168 break; 169 } 170 171 if (c != optind) { 172 g_argv = v + optind - 1; 173 if (yywrap()) 174 fatal("Cannot read any input files"); 175 } else { 176 usage++; 177 } 178 179 if (usage) { 180 fprintf(stderr, 181 "\ 182Usage: %s [-v] [-a autodir] [-h hostname] [-b bootparams] [-d dumpsets]\n\ 183\t[-e exports] [-f fstabs] [-m automounts]\n\ 184\t[-I dir] [-D|-U string[=string]] config ...\n", progname); 185 exit(1); 186 } 187 188 if (g_argv[0])
|
188 log("g_argv[0] = %s", g_argv[0]);
| 189 fsi_log("g_argv[0] = %s", g_argv[0]);
|
189 else
| 190 else
|
190 log("g_argv[0] = (nil)");
| 191 fsi_log("g_argv[0] = (nil)");
|
191} 192 193 194/* 195 * Determine username of caller 196 */ 197static char * 198find_username(void) 199{ 200 char *u = getlogin(); 201 202 if (!u) { 203 struct passwd *pw = getpwuid(getuid()); 204 if (pw) 205 u = pw->pw_name; 206 } 207 208 if (!u) 209 u = getenv("USER"); 210 if (!u) 211 u = getenv("LOGNAME"); 212 if (!u) 213 u = "root"; 214 215 return strdup(u); 216} 217 218 219/* 220 * MAIN 221 */ 222int 223main(int argc, char *argv[]) 224{ 225 /* 226 * Process arguments 227 */ 228 fsi_get_args(argc, argv); 229 230 /* 231 * If no hostname given then use the local name 232 */ 233 if (!*hostname && gethostname(hostname, sizeof(hostname)) < 0) { 234 perror("gethostname"); 235 exit(1); 236 } 237 238 /* 239 * Get the username 240 */ 241 username = find_username(); 242 243 /* 244 * New hosts and automounts 245 */ 246 list_of_hosts = new_que(); 247 list_of_automounts = new_que(); 248 249 /* 250 * New dictionaries 251 */ 252 dict_of_volnames = new_dict(); 253 dict_of_hosts = new_dict(); 254 255 /* 256 * Parse input 257 */ 258 show_area_being_processed("read config", 11); 259 if (yyparse()) 260 errors = 1; 261 errors += file_io_errors + parse_errors; 262 263 if (errors == 0) { 264 /* 265 * Do semantic analysis of input 266 */ 267 analyze_hosts(list_of_hosts); 268 analyze_automounts(list_of_automounts); 269 } 270 271 /* 272 * Give up if errors 273 */ 274 if (errors == 0) { 275 /* 276 * Output data files 277 */ 278 279 write_atab(list_of_automounts); 280 write_bootparams(list_of_hosts); 281 write_dumpset(list_of_hosts); 282 write_exportfs(list_of_hosts); 283 write_fstab(list_of_hosts); 284 } 285 col_cleanup(1); 286 287 exit(errors); 288 return errors; /* should never reach here */ 289}
| 192} 193 194 195/* 196 * Determine username of caller 197 */ 198static char * 199find_username(void) 200{ 201 char *u = getlogin(); 202 203 if (!u) { 204 struct passwd *pw = getpwuid(getuid()); 205 if (pw) 206 u = pw->pw_name; 207 } 208 209 if (!u) 210 u = getenv("USER"); 211 if (!u) 212 u = getenv("LOGNAME"); 213 if (!u) 214 u = "root"; 215 216 return strdup(u); 217} 218 219 220/* 221 * MAIN 222 */ 223int 224main(int argc, char *argv[]) 225{ 226 /* 227 * Process arguments 228 */ 229 fsi_get_args(argc, argv); 230 231 /* 232 * If no hostname given then use the local name 233 */ 234 if (!*hostname && gethostname(hostname, sizeof(hostname)) < 0) { 235 perror("gethostname"); 236 exit(1); 237 } 238 239 /* 240 * Get the username 241 */ 242 username = find_username(); 243 244 /* 245 * New hosts and automounts 246 */ 247 list_of_hosts = new_que(); 248 list_of_automounts = new_que(); 249 250 /* 251 * New dictionaries 252 */ 253 dict_of_volnames = new_dict(); 254 dict_of_hosts = new_dict(); 255 256 /* 257 * Parse input 258 */ 259 show_area_being_processed("read config", 11); 260 if (yyparse()) 261 errors = 1; 262 errors += file_io_errors + parse_errors; 263 264 if (errors == 0) { 265 /* 266 * Do semantic analysis of input 267 */ 268 analyze_hosts(list_of_hosts); 269 analyze_automounts(list_of_automounts); 270 } 271 272 /* 273 * Give up if errors 274 */ 275 if (errors == 0) { 276 /* 277 * Output data files 278 */ 279 280 write_atab(list_of_automounts); 281 write_bootparams(list_of_hosts); 282 write_dumpset(list_of_hosts); 283 write_exportfs(list_of_hosts); 284 write_fstab(list_of_hosts); 285 } 286 col_cleanup(1); 287 288 exit(errors); 289 return errors; /* should never reach here */ 290}
|