systems.c (55252) | systems.c (58045) |
---|---|
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 * $FreeBSD: head/usr.sbin/ppp/systems.c 55252 1999-12-30 03:36:11Z brian $ | 20 * $FreeBSD: head/usr.sbin/ppp/systems.c 58045 2000-03-14 01:47:31Z brian $ |
21 * 22 * TODO: 23 */ 24#include <sys/param.h> 25 26#include <ctype.h> 27#include <pwd.h> 28#include <stdio.h> --- 25 unchanged lines hidden (view full) --- 54 55void 56CloseSecret(FILE *fp) 57{ 58 fclose(fp); 59} 60 61/* Move string from ``from'' to ``to'', interpreting ``~'' and $.... */ | 21 * 22 * TODO: 23 */ 24#include <sys/param.h> 25 26#include <ctype.h> 27#include <pwd.h> 28#include <stdio.h> --- 25 unchanged lines hidden (view full) --- 54 55void 56CloseSecret(FILE *fp) 57{ 58 fclose(fp); 59} 60 61/* Move string from ``from'' to ``to'', interpreting ``~'' and $.... */ |
62static const char * | 62const char * |
63InterpretArg(const char *from, char *to) 64{ | 63InterpretArg(const char *from, char *to) 64{ |
65 const char *env; | |
66 char *ptr, *startto, *endto; | 65 char *ptr, *startto, *endto; |
67 int len; | 66 struct passwd *pwd; 67 int len, instring; 68 const char *env; |
68 | 69 |
70 instring = 0; |
|
69 startto = to; 70 endto = to + LINE_LEN - 1; 71 72 while(issep(*from)) 73 from++; 74 | 71 startto = to; 72 endto = to + LINE_LEN - 1; 73 74 while(issep(*from)) 75 from++; 76 |
75 if (*from == '~') { 76 struct passwd *pwd; | 77 while (*from != '\0') { 78 switch (*from) { 79 case '"': 80 instring = !instring; 81 *to++ = *from++; 82 break; 83 case '\\': 84 switch (*++from) { 85 case '$': 86 case '~': 87 break; /* Swallow the escapes */ |
77 | 88 |
78 ptr = strchr(++from, '/'); 79 len = ptr ? ptr - from : strlen(from); 80 if (len == 0) { 81 pwd = getpwuid(ID0realuid()); 82 } else { 83 strncpy(to, from, len); 84 to[len] = '\0'; 85 pwd = getpwnam(to); 86 } 87 strncpy(to, pwd ? pwd->pw_dir : _PATH_PPP, endto - to); 88 endpwent(); 89 90 *endto = '\0'; 91 to += strlen(to); 92 from += len; 93 } 94 95 while (to < endto && !issep(*from) && *from != '#' && *from != '\0') { 96 if (*from == '$') { 97 if (from[1] == '$') { 98 *to = '\0'; /* For an empty var name below */ 99 from += 2; 100 } else if (from[1] == '{') { 101 ptr = strchr(from+2, '}'); 102 if (ptr) { 103 len = ptr - from - 2; 104 if (endto - to < len ) 105 len = endto - to; 106 if (len) { 107 strncpy(to, from+2, len); 108 to[len] = '\0'; 109 from = ptr+1; | 89 default: 90 *to++ = '\\'; /* Pass the escapes on, maybe skipping \# */ 91 break; 92 } 93 *to++ = *from++; 94 break; 95 case '$': 96 if (from[1] == '$') { 97 *to = '\0'; /* For an empty var name below */ 98 from += 2; 99 } else if (from[1] == '{') { 100 ptr = strchr(from+2, '}'); 101 if (ptr) { 102 len = ptr - from - 2; 103 if (endto - to < len ) 104 len = endto - to; 105 if (len) { 106 strncpy(to, from+2, len); 107 to[len] = '\0'; 108 from = ptr+1; 109 } else { 110 *to++ = *from++; 111 continue; 112 } |
110 } else { 111 *to++ = *from++; 112 continue; 113 } 114 } else { | 113 } else { 114 *to++ = *from++; 115 continue; 116 } 117 } else { |
115 *to++ = *from++; 116 continue; | 118 ptr = to; 119 for (from++; (isalnum(*from) || *from == '_') && ptr < endto; from++) 120 *ptr++ = *from; 121 *ptr = '\0'; |
117 } | 122 } |
118 } else { 119 ptr = to; 120 for (from++; (isalnum(*from) || *from == '_') && ptr < endto; from++) 121 *ptr++ = *from; 122 *ptr = '\0'; 123 } 124 if (*to == '\0') 125 *to++ = '$'; 126 else if ((env = getenv(to)) != NULL) { 127 strncpy(to, env, endto - to); 128 *endto = '\0'; 129 to += strlen(to); 130 } 131 } else { 132 if (*from == '\\') 133 from++; 134 *to++ = *from++; | 123 if (*to == '\0') 124 *to++ = '$'; 125 else if ((env = getenv(to)) != NULL) { 126 strncpy(to, env, endto - to); 127 *endto = '\0'; 128 to += strlen(to); 129 } 130 break; 131 132 case '~': 133 ptr = strchr(++from, '/'); 134 len = ptr ? ptr - from : strlen(from); 135 if (len == 0) 136 pwd = getpwuid(ID0realuid()); 137 else { 138 strncpy(to, from, len); 139 to[len] = '\0'; 140 pwd = getpwnam(to); 141 } 142 if (pwd == NULL) 143 *to++ = '~'; 144 else { 145 strncpy(to, pwd->pw_dir, endto - to); 146 *endto = '\0'; 147 to += strlen(to); 148 from += len; 149 } 150 endpwent(); 151 break; 152 153 case '#': 154 if (!instring) 155 while (*from != '\0') 156 *to++ = *from++; 157 break; 158 159 default: 160 *to++ = *from++; 161 break; |
135 } 136 } 137 138 while (to > startto) { 139 to--; 140 if (!issep(*to)) { 141 to++; 142 break; 143 } 144 } 145 *to = '\0'; 146 | 162 } 163 } 164 165 while (to > startto) { 166 to--; 167 if (!issep(*to)) { 168 to++; 169 break; 170 } 171 } 172 *to = '\0'; 173 |
147 while (issep(*from)) 148 from++; 149 | |
150 return from; 151} 152 153#define CTRL_UNKNOWN (0) 154#define CTRL_INCLUDE (1) 155 156static int 157DecodeCtrlCommand(char *line, char *arg) --- 200 unchanged lines hidden (view full) --- 358 359 if (!indent) { /* start of next section */ 360 if (*cp != '!' && how == SYSTEM_EXEC) 361 cp = GetLabel(cp, filename, linenum); 362 break; 363 } 364 365 len = strlen(cp); | 174 return from; 175} 176 177#define CTRL_UNKNOWN (0) 178#define CTRL_INCLUDE (1) 179 180static int 181DecodeCtrlCommand(char *line, char *arg) --- 200 unchanged lines hidden (view full) --- 382 383 if (!indent) { /* start of next section */ 384 if (*cp != '!' && how == SYSTEM_EXEC) 385 cp = GetLabel(cp, filename, linenum); 386 break; 387 } 388 389 len = strlen(cp); |
366 if ((argc = command_Interpret(cp, len, argv)) < 0) | 390 if ((argc = command_Expand_Interpret(cp, len, argv, cp - line)) < 0) |
367 log_Printf(LogWARN, "%s: %d: Syntax error\n", filename, linenum); 368 else { 369 allowcmd = argc > 0 && !strcasecmp(argv[0], "allow"); 370 if ((how != SYSTEM_EXEC && allowcmd) || 371 (how == SYSTEM_EXEC && !allowcmd)) { 372 /* 373 * Disable any context so that warnings are given to everyone, 374 * including syslog. --- 71 unchanged lines hidden --- | 391 log_Printf(LogWARN, "%s: %d: Syntax error\n", filename, linenum); 392 else { 393 allowcmd = argc > 0 && !strcasecmp(argv[0], "allow"); 394 if ((how != SYSTEM_EXEC && allowcmd) || 395 (how == SYSTEM_EXEC && !allowcmd)) { 396 /* 397 * Disable any context so that warnings are given to everyone, 398 * including syslog. --- 71 unchanged lines hidden --- |