systems.c (d24f017be800e31ad16d74ae3366abab383cefe0) | systems.c (565e35e50e2cdac423588a3d18742544bde128b0) |
---|---|
1/* 2 * System configuration routines 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * | 1/* 2 * System configuration routines 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * |
20 * $Id: systems.c,v 1.35.2.4 1998/04/03 19:25:58 brian Exp $ | 20 * $Id: systems.c,v 1.35.2.5 1998/04/06 09:12:37 brian Exp $ |
21 * 22 * TODO: 23 */ 24#include <sys/param.h> 25 26#include <ctype.h> 27#include <pwd.h> 28#include <stdio.h> --- 123 unchanged lines hidden (view full) --- 152{ 153 if (!strncasecmp(line, "include", 7) && issep(line[7])) { 154 InterpretArg(line+8, arg); 155 return CTRL_INCLUDE; 156 } 157 return CTRL_UNKNOWN; 158} 159 | 21 * 22 * TODO: 23 */ 24#include <sys/param.h> 25 26#include <ctype.h> 27#include <pwd.h> 28#include <stdio.h> --- 123 unchanged lines hidden (view full) --- 152{ 153 if (!strncasecmp(line, "include", 7) && issep(line[7])) { 154 InterpretArg(line+8, arg); 155 return CTRL_INCLUDE; 156 } 157 return CTRL_UNKNOWN; 158} 159 |
160/* Initialised in ValidSystem(), set in ReadSystem(), used by ValidSystem() */ 161static int modeok; |
|
160static int userok; | 162static int userok; |
163static int modereq; |
|
161 162int 163AllowUsers(struct cmdargs const *arg) 164{ 165 /* arg->bundle may be NULL (see ValidSystem()) ! */ 166 int f; 167 char *user; 168 --- 8 unchanged lines hidden (view full) --- 177 178 return 0; 179} 180 181static struct { 182 int mode; 183 const char *name; 184} modes[] = { | 164 165int 166AllowUsers(struct cmdargs const *arg) 167{ 168 /* arg->bundle may be NULL (see ValidSystem()) ! */ 169 int f; 170 char *user; 171 --- 8 unchanged lines hidden (view full) --- 180 181 return 0; 182} 183 184static struct { 185 int mode; 186 const char *name; 187} modes[] = { |
185 { MODE_INTER, "interactive" }, 186 { MODE_AUTO, "auto" }, 187 { MODE_DIRECT, "direct" }, 188 { MODE_DEDICATED, "dedicated" }, 189 { MODE_DDIAL, "ddial" }, 190 { MODE_BACKGROUND, "background" }, 191 { ~0, "*" }, | 188 { PHYS_MANUAL, "interactive" }, 189 { PHYS_DEMAND, "auto" }, 190 { PHYS_STDIN, "direct" }, 191 { PHYS_DEDICATED, "dedicated" }, 192 { PHYS_PERM, "ddial" }, 193 { PHYS_1OFF, "background" }, 194 { PHYS_ALL, "*" }, |
192 { 0, 0 } 193}; 194 | 195 { 0, 0 } 196}; 197 |
195static int modeok; | 198const char * 199mode2Nam(int mode) 200{ 201 int m; |
196 | 202 |
203 for (m = 0; modes[m].mode; m++) 204 if (modes[m].mode == mode) 205 return modes[m].name; 206 207 return "unknown"; 208} 209 |
|
197int 198AllowModes(struct cmdargs const *arg) 199{ 200 /* arg->bundle may be NULL (see ValidSystem()) ! */ 201 int f; 202 int m; 203 int allowed; 204 205 allowed = 0; 206 for (f = 0; f < arg->argc; f++) { 207 for (m = 0; modes[m].mode; m++) 208 if (!strcasecmp(modes[m].name, arg->argv[f])) { 209 allowed |= modes[m].mode; 210 break; 211 } 212 if (modes[m].mode == 0) 213 LogPrintf(LogWARN, "allow modes: %s: Invalid mode\n", arg->argv[f]); 214 } 215 | 210int 211AllowModes(struct cmdargs const *arg) 212{ 213 /* arg->bundle may be NULL (see ValidSystem()) ! */ 214 int f; 215 int m; 216 int allowed; 217 218 allowed = 0; 219 for (f = 0; f < arg->argc; f++) { 220 for (m = 0; modes[m].mode; m++) 221 if (!strcasecmp(modes[m].name, arg->argv[f])) { 222 allowed |= modes[m].mode; 223 break; 224 } 225 if (modes[m].mode == 0) 226 LogPrintf(LogWARN, "allow modes: %s: Invalid mode\n", arg->argv[f]); 227 } 228 |
216 modeok = (mode | allowed) == allowed ? 1 : 0; | 229 modeok = modereq & allowed ? 1 : 0; |
217 return 0; 218} 219 220static char * 221strip(char *line) 222{ 223 int len; 224 --- 124 unchanged lines hidden (view full) --- 349 break; 350 } 351 } 352 fclose(fp); 353 return -1; 354} 355 356int | 230 return 0; 231} 232 233static char * 234strip(char *line) 235{ 236 int len; 237 --- 124 unchanged lines hidden (view full) --- 362 break; 363 } 364 } 365 fclose(fp); 366 return -1; 367} 368 369int |
357ValidSystem(const char *name, struct prompt *prompt) | 370ValidSystem(const char *name, struct prompt *prompt, int mode) |
358{ 359 /* 360 * Note: The ReadSystem() calls only result in calls to the Allow* 361 * functions. arg->bundle will be set to NULL for these commands ! 362 */ 363 if (ID0realuid() == 0) 364 return userok = modeok = 1; 365 userok = 0; 366 modeok = 1; | 371{ 372 /* 373 * Note: The ReadSystem() calls only result in calls to the Allow* 374 * functions. arg->bundle will be set to NULL for these commands ! 375 */ 376 if (ID0realuid() == 0) 377 return userok = modeok = 1; 378 userok = 0; 379 modeok = 1; |
380 modereq = mode; |
|
367 ReadSystem(NULL, "default", CONFFILE, 0, prompt); 368 if (name != NULL) 369 ReadSystem(NULL, name, CONFFILE, 0, prompt); 370 return userok && modeok; 371} 372 373int 374SelectSystem(struct bundle *bundle, const char *name, const char *file, 375 struct prompt *prompt) 376{ 377 userok = modeok = 1; | 381 ReadSystem(NULL, "default", CONFFILE, 0, prompt); 382 if (name != NULL) 383 ReadSystem(NULL, name, CONFFILE, 0, prompt); 384 return userok && modeok; 385} 386 387int 388SelectSystem(struct bundle *bundle, const char *name, const char *file, 389 struct prompt *prompt) 390{ 391 userok = modeok = 1; |
392 modereq = PHYS_ALL; |
|
378 return ReadSystem(bundle, name, file, 1, prompt); 379} | 393 return ReadSystem(bundle, name, file, 1, prompt); 394} |
380 381int 382LoadCommand(struct cmdargs const *arg) 383{ 384 const char *name; 385 386 if (arg->argc > 0) 387 name = *arg->argv; 388 else 389 name = "default"; 390 391 if (!ValidSystem(name, arg->prompt)) { 392 LogPrintf(LogERROR, "%s: Label not allowed\n", name); 393 return 1; 394 } else if (SelectSystem(arg->bundle, name, CONFFILE, arg->prompt) < 0) { 395 LogPrintf(LogWARN, "%s: label not found.\n", name); 396 return -1; 397 } else 398 SetLabel(arg->argc ? name : NULL); 399 return 0; 400} 401 402int 403SaveCommand(struct cmdargs const *arg) 404{ 405 LogPrintf(LogWARN, "save command is not implemented (yet).\n"); 406 return 1; 407} | |