env.c (80030) | env.c (97165) |
---|---|
1/* Copyright 1988,1990,1993,1994 by Paul Vixie 2 * All rights reserved 3 * 4 * Distribute freely, except: don't remove my name from the source or 5 * documentation (don't take credit for my work), mark your changes (don't 6 * get me blamed for your possible bugs), don't alter or remove this 7 * notice. May be sold if buildable source is provided to buyer. No 8 * warrantee of any kind, express or implied, is included with this 9 * software; use at your own risk, responsibility for damages (if any) to 10 * anyone resulting from the use of this software rests entirely with the 11 * user. 12 * 13 * Send bug reports, bug fixes, enhancements, requests, flames, etc., and 14 * I'll try to keep a version up to date. I can be reached as follows: 15 * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul 16 */ 17 18#if !defined(lint) && !defined(LINT) 19static const char rcsid[] = | 1/* Copyright 1988,1990,1993,1994 by Paul Vixie 2 * All rights reserved 3 * 4 * Distribute freely, except: don't remove my name from the source or 5 * documentation (don't take credit for my work), mark your changes (don't 6 * get me blamed for your possible bugs), don't alter or remove this 7 * notice. May be sold if buildable source is provided to buyer. No 8 * warrantee of any kind, express or implied, is included with this 9 * software; use at your own risk, responsibility for damages (if any) to 10 * anyone resulting from the use of this software rests entirely with the 11 * user. 12 * 13 * Send bug reports, bug fixes, enhancements, requests, flames, etc., and 14 * I'll try to keep a version up to date. I can be reached as follows: 15 * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul 16 */ 17 18#if !defined(lint) && !defined(LINT) 19static const char rcsid[] = |
20 "$FreeBSD: head/usr.sbin/cron/lib/env.c 80030 2001-07-20 06:46:48Z davidn $"; | 20 "$FreeBSD: head/usr.sbin/cron/lib/env.c 97165 2002-05-23 13:16:30Z roberto $"; |
21#endif 22 23 24#include "cron.h" 25 26 27char ** 28env_init() --- 111 unchanged lines hidden (view full) --- 140int 141load_env(envstr, f) 142 char *envstr; 143 FILE *f; 144{ 145 long filepos; 146 int fileline; 147 char name[MAX_ENVSTR], val[MAX_ENVSTR]; | 21#endif 22 23 24#include "cron.h" 25 26 27char ** 28env_init() --- 111 unchanged lines hidden (view full) --- 140int 141load_env(envstr, f) 142 char *envstr; 143 FILE *f; 144{ 145 long filepos; 146 int fileline; 147 char name[MAX_ENVSTR], val[MAX_ENVSTR]; |
148 int fields; | 148 char quotechar, *c, *str; 149 int state; |
149 | 150 |
151 /* The following states are traversed in order: */ 152#define NAMEI 0 /* First char of NAME, may be quote */ 153#define NAME 1 /* Subsequent chars of NAME */ 154#define EQ1 2 /* After end of name, looking for '=' sign */ 155#define EQ2 3 /* After '=', skipping whitespace */ 156#define VALUEI 4 /* First char of VALUE, may be quote */ 157#define VALUE 5 /* Subsequent chars of VALUE */ 158#define FINI 6 /* All done, skipping trailing whitespace */ 159#define ERROR 7 /* Error */ 160 |
|
150 filepos = ftell(f); 151 fileline = LineNumber; 152 skip_comments(f); 153 if (EOF == get_string(envstr, MAX_ENVSTR, f, "\n")) 154 return (ERR); 155 | 161 filepos = ftell(f); 162 fileline = LineNumber; 163 skip_comments(f); 164 if (EOF == get_string(envstr, MAX_ENVSTR, f, "\n")) 165 return (ERR); 166 |
156 Debug(DPARS, ("load_env, read <%s>\n", envstr)) | 167 Debug(DPARS, ("load_env, read <%s>\n", envstr)); |
157 | 168 |
158 name[0] = val[0] = '\0'; 159 fields = sscanf(envstr, "%[^ =] = %[^\n#]", name, val); 160 if (fields != 2) { 161 Debug(DPARS, ("load_env, not 2 fields (%d)\n", fields)) | 169 bzero (name, sizeof name); 170 bzero (val, sizeof val); 171 str = name; 172 state = NAMEI; 173 quotechar = '\0'; 174 c = envstr; 175 while (state != ERROR && *c) { 176 switch (state) { 177 case NAMEI: 178 case VALUEI: 179 if (*c == '\'' || *c == '"') 180 quotechar = *c++; 181 ++state; 182 /* FALLTHROUGH */ 183 case NAME: 184 case VALUE: 185 if (quotechar) { 186 if (*c == quotechar) { 187 state++; 188 c++; 189 break; 190 } 191 if (state == NAME && *c == '=') { 192 state = ERROR; 193 break; 194 } 195 } else { 196 if (isspace (*c)) { 197 state++; 198 c++; 199 break; 200 } 201 if (state == NAME && *c == '=') { 202 state++; 203 break; 204 } 205 } 206 *str++ = *c++; 207 break; 208 209 case EQ1: 210 if (*c == '=') { 211 state++; 212 str = val; 213 quotechar = '\0'; 214 } else { 215 if (!isspace (*c)) 216 state = ERROR; 217 } 218 c++; 219 break; 220 case EQ2: 221 case FINI: 222 if (isspace (*c)) 223 c++; 224 else 225 state++; 226 break; 227 } 228 } 229 if (state != FINI && !(state == VALUE && !quotechar)) { 230 Debug(DPARS, ("load_env, parse error, state = %d\n", state)) |
162 fseek(f, filepos, 0); 163 Set_LineNum(fileline); 164 return (FALSE); 165 } 166 | 231 fseek(f, filepos, 0); 232 Set_LineNum(fileline); 233 return (FALSE); 234 } 235 |
167 /* 2 fields from scanf; looks like an env setting | 236 /* 2 fields from parser; looks like an env setting |
168 */ 169 | 237 */ 238 |
170 /* 171 * process value string 172 */ 173 /*local*/{ 174 int len = strdtb(val); 175 176 if (len >= 2) { 177 if (val[0] == '\'' || val[0] == '"') { 178 if (val[len-1] == val[0]) { 179 val[len-1] = '\0'; 180 (void) strcpy(val, val+1); 181 } 182 } 183 } 184 } 185 | |
186 if (strlen(name) + 1 + strlen(val) >= MAX_ENVSTR-1) 187 return (FALSE); 188 (void) sprintf(envstr, "%s=%s", name, val); 189 Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr)) 190 return (TRUE); 191} 192 193 --- 16 unchanged lines hidden --- | 239 if (strlen(name) + 1 + strlen(val) >= MAX_ENVSTR-1) 240 return (FALSE); 241 (void) sprintf(envstr, "%s=%s", name, val); 242 Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr)) 243 return (TRUE); 244} 245 246 --- 16 unchanged lines hidden --- |