]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
b19ccc9e | 2 | * "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $" |
ef416fc2 | 3 | * |
4 | * Configuration routines for the Common UNIX Printing System (CUPS). | |
5 | * | |
d1c13e16 | 6 | * Copyright 2007-2009 by Apple Inc. |
7594b224 | 7 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. |
ef416fc2 | 8 | * |
9 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 10 | * property of Apple Inc. and are protected by Federal copyright |
11 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 14 | * |
15 | * Contents: | |
16 | * | |
e07d4801 | 17 | * cupsdAddAlias() - Add a host alias. |
b94498cf | 18 | * cupsdCheckPermissions() - Fix the mode and ownership of a file or |
fa73b229 | 19 | * directory. |
e07d4801 | 20 | * cupsdFreeAliases() - Free all of the alias entries. |
b94498cf | 21 | * cupsdReadConfiguration() - Read the cupsd.conf file. |
ef416fc2 | 22 | * get_address() - Get an address + port number from a line. |
23 | * get_addr_and_mask() - Get an IP address and netmask. | |
e07d4801 MS |
24 | * parse_aaa() - Parse authentication, authorization, and access |
25 | * control lines. | |
49d87452 | 26 | * parse_fatal_errors() - Parse FatalErrors values in a string. |
bd7854cb | 27 | * parse_groups() - Parse system group names in a string. |
28 | * parse_protocols() - Parse browse protocols in a string. | |
ef416fc2 | 29 | * read_configuration() - Read a configuration file. |
30 | * read_location() - Read a <Location path> definition. | |
31 | * read_policy() - Read a <Policy name> definition. | |
32 | */ | |
33 | ||
34 | /* | |
35 | * Include necessary headers... | |
36 | */ | |
37 | ||
38 | #include "cupsd.h" | |
39 | #include <stdarg.h> | |
40 | #include <grp.h> | |
41 | #include <sys/utsname.h> | |
b94498cf | 42 | #include <syslog.h> |
ef416fc2 | 43 | |
ef416fc2 | 44 | |
45 | /* | |
46 | * Possibly missing network definitions... | |
47 | */ | |
48 | ||
49 | #ifndef INADDR_NONE | |
50 | # define INADDR_NONE 0xffffffff | |
51 | #endif /* !INADDR_NONE */ | |
52 | ||
53 | ||
54 | /* | |
55 | * Configuration variable structure... | |
56 | */ | |
57 | ||
58 | typedef enum | |
59 | { | |
60 | CUPSD_VARTYPE_INTEGER, /* Integer option */ | |
61 | CUPSD_VARTYPE_STRING, /* String option */ | |
76cd9e37 MS |
62 | CUPSD_VARTYPE_BOOLEAN, /* Boolean option */ |
63 | CUPSD_VARTYPE_PATHNAME /* File/directory name option */ | |
ef416fc2 | 64 | } cupsd_vartype_t; |
65 | ||
66 | typedef struct | |
67 | { | |
68 | char *name; /* Name of variable */ | |
69 | void *ptr; /* Pointer to variable */ | |
70 | cupsd_vartype_t type; /* Type (int, string, address) */ | |
71 | } cupsd_var_t; | |
72 | ||
73 | ||
74 | /* | |
75 | * Local globals... | |
76 | */ | |
77 | ||
ac884b6a | 78 | static const cupsd_var_t variables[] = |
ef416fc2 | 79 | { |
80 | { "AccessLog", &AccessLog, CUPSD_VARTYPE_STRING }, | |
7594b224 | 81 | #ifdef __APPLE__ |
82 | { "AppleQuotas", &AppleQuotas, CUPSD_VARTYPE_BOOLEAN }, | |
83 | #endif /* __APPLE__ */ | |
ef416fc2 | 84 | { "AutoPurgeJobs", &JobAutoPurge, CUPSD_VARTYPE_BOOLEAN }, |
85 | { "BrowseInterval", &BrowseInterval, CUPSD_VARTYPE_INTEGER }, | |
b423cd4c | 86 | #ifdef HAVE_LDAP |
87 | { "BrowseLDAPBindDN", &BrowseLDAPBindDN, CUPSD_VARTYPE_STRING }, | |
1ff0402e | 88 | # ifdef HAVE_LDAP_SSL |
76cd9e37 | 89 | { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile, CUPSD_VARTYPE_PATHNAME }, |
1ff0402e | 90 | # endif /* HAVE_LDAP_SSL */ |
b423cd4c | 91 | { "BrowseLDAPDN", &BrowseLDAPDN, CUPSD_VARTYPE_STRING }, |
92 | { "BrowseLDAPPassword", &BrowseLDAPPassword, CUPSD_VARTYPE_STRING }, | |
93 | { "BrowseLDAPServer", &BrowseLDAPServer, CUPSD_VARTYPE_STRING }, | |
94 | #endif /* HAVE_LDAP */ | |
ef416fc2 | 95 | { "BrowseLocalOptions", &BrowseLocalOptions, CUPSD_VARTYPE_STRING }, |
96 | { "BrowsePort", &BrowsePort, CUPSD_VARTYPE_INTEGER }, | |
97 | { "BrowseRemoteOptions", &BrowseRemoteOptions, CUPSD_VARTYPE_STRING }, | |
98 | { "BrowseShortNames", &BrowseShortNames, CUPSD_VARTYPE_BOOLEAN }, | |
99 | { "BrowseTimeout", &BrowseTimeout, CUPSD_VARTYPE_INTEGER }, | |
b19ccc9e | 100 | { "BrowseWebIF", &BrowseWebIF, CUPSD_VARTYPE_BOOLEAN }, |
ef416fc2 | 101 | { "Browsing", &Browsing, CUPSD_VARTYPE_BOOLEAN }, |
102 | { "CacheDir", &CacheDir, CUPSD_VARTYPE_STRING }, | |
103 | { "Classification", &Classification, CUPSD_VARTYPE_STRING }, | |
104 | { "ClassifyOverride", &ClassifyOverride, CUPSD_VARTYPE_BOOLEAN }, | |
105 | { "ConfigFilePerm", &ConfigFilePerm, CUPSD_VARTYPE_INTEGER }, | |
106 | { "DataDir", &DataDir, CUPSD_VARTYPE_STRING }, | |
107 | { "DefaultCharset", &DefaultCharset, CUPSD_VARTYPE_STRING }, | |
108 | { "DefaultLanguage", &DefaultLanguage, CUPSD_VARTYPE_STRING }, | |
109 | { "DefaultLeaseDuration", &DefaultLeaseDuration, CUPSD_VARTYPE_INTEGER }, | |
c5571a1d | 110 | { "DefaultPaperSize", &DefaultPaperSize, CUPSD_VARTYPE_STRING }, |
ef416fc2 | 111 | { "DefaultPolicy", &DefaultPolicy, CUPSD_VARTYPE_STRING }, |
fa73b229 | 112 | { "DefaultShared", &DefaultShared, CUPSD_VARTYPE_BOOLEAN }, |
3dfe78b3 | 113 | { "DirtyCleanInterval", &DirtyCleanInterval, CUPSD_VARTYPE_INTEGER }, |
ef416fc2 | 114 | { "DocumentRoot", &DocumentRoot, CUPSD_VARTYPE_STRING }, |
115 | { "ErrorLog", &ErrorLog, CUPSD_VARTYPE_STRING }, | |
323c5de1 | 116 | { "ErrorPolicy", &ErrorPolicy, CUPSD_VARTYPE_STRING }, |
ef416fc2 | 117 | { "FileDevice", &FileDevice, CUPSD_VARTYPE_BOOLEAN }, |
118 | { "FilterLimit", &FilterLimit, CUPSD_VARTYPE_INTEGER }, | |
119 | { "FilterNice", &FilterNice, CUPSD_VARTYPE_INTEGER }, | |
120 | { "FontPath", &FontPath, CUPSD_VARTYPE_STRING }, | |
db0bd74a | 121 | { "HideImplicitMembers", &HideImplicitMembers, CUPSD_VARTYPE_BOOLEAN }, |
ef416fc2 | 122 | { "ImplicitClasses", &ImplicitClasses, CUPSD_VARTYPE_BOOLEAN }, |
123 | { "ImplicitAnyClasses", &ImplicitAnyClasses, CUPSD_VARTYPE_BOOLEAN }, | |
238c3832 | 124 | { "JobKillDelay", &JobKillDelay, CUPSD_VARTYPE_INTEGER }, |
ef416fc2 | 125 | { "JobRetryLimit", &JobRetryLimit, CUPSD_VARTYPE_INTEGER }, |
126 | { "JobRetryInterval", &JobRetryInterval, CUPSD_VARTYPE_INTEGER }, | |
127 | { "KeepAliveTimeout", &KeepAliveTimeout, CUPSD_VARTYPE_INTEGER }, | |
128 | { "KeepAlive", &KeepAlive, CUPSD_VARTYPE_BOOLEAN }, | |
f7deaa1a | 129 | #ifdef HAVE_LAUNCHD |
130 | { "LaunchdTimeout", &LaunchdTimeout, CUPSD_VARTYPE_INTEGER }, | |
131 | { "LaunchdConf", &LaunchdConf, CUPSD_VARTYPE_STRING }, | |
132 | #endif /* HAVE_LAUNCHD */ | |
ef416fc2 | 133 | { "LimitRequestBody", &MaxRequestSize, CUPSD_VARTYPE_INTEGER }, |
134 | { "ListenBackLog", &ListenBackLog, CUPSD_VARTYPE_INTEGER }, | |
135 | { "LogFilePerm", &LogFilePerm, CUPSD_VARTYPE_INTEGER }, | |
2e4ff8af | 136 | { "LPDConfigFile", &LPDConfigFile, CUPSD_VARTYPE_STRING }, |
ef416fc2 | 137 | { "MaxActiveJobs", &MaxActiveJobs, CUPSD_VARTYPE_INTEGER }, |
138 | { "MaxClients", &MaxClients, CUPSD_VARTYPE_INTEGER }, | |
139 | { "MaxClientsPerHost", &MaxClientsPerHost, CUPSD_VARTYPE_INTEGER }, | |
140 | { "MaxCopies", &MaxCopies, CUPSD_VARTYPE_INTEGER }, | |
141 | { "MaxEvents", &MaxEvents, CUPSD_VARTYPE_INTEGER }, | |
142 | { "MaxJobs", &MaxJobs, CUPSD_VARTYPE_INTEGER }, | |
143 | { "MaxJobsPerPrinter", &MaxJobsPerPrinter, CUPSD_VARTYPE_INTEGER }, | |
144 | { "MaxJobsPerUser", &MaxJobsPerUser, CUPSD_VARTYPE_INTEGER }, | |
145 | { "MaxLeaseDuration", &MaxLeaseDuration, CUPSD_VARTYPE_INTEGER }, | |
146 | { "MaxLogSize", &MaxLogSize, CUPSD_VARTYPE_INTEGER }, | |
147 | { "MaxPrinterHistory", &MaxPrinterHistory, CUPSD_VARTYPE_INTEGER }, | |
148 | { "MaxRequestSize", &MaxRequestSize, CUPSD_VARTYPE_INTEGER }, | |
149 | { "MaxSubscriptions", &MaxSubscriptions, CUPSD_VARTYPE_INTEGER }, | |
150 | { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob, CUPSD_VARTYPE_INTEGER }, | |
151 | { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter, CUPSD_VARTYPE_INTEGER }, | |
152 | { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser, CUPSD_VARTYPE_INTEGER }, | |
dfd5680b | 153 | { "MultipleOperationTimeout", &MultipleOperationTimeout, CUPSD_VARTYPE_INTEGER }, |
ef416fc2 | 154 | { "PageLog", &PageLog, CUPSD_VARTYPE_STRING }, |
01ce6322 | 155 | { "PageLogFormat", &PageLogFormat, CUPSD_VARTYPE_STRING }, |
ef416fc2 | 156 | { "PreserveJobFiles", &JobFiles, CUPSD_VARTYPE_BOOLEAN }, |
157 | { "PreserveJobHistory", &JobHistory, CUPSD_VARTYPE_BOOLEAN }, | |
158 | { "Printcap", &Printcap, CUPSD_VARTYPE_STRING }, | |
159 | { "PrintcapGUI", &PrintcapGUI, CUPSD_VARTYPE_STRING }, | |
160 | { "ReloadTimeout", &ReloadTimeout, CUPSD_VARTYPE_INTEGER }, | |
161 | { "RemoteRoot", &RemoteRoot, CUPSD_VARTYPE_STRING }, | |
162 | { "RequestRoot", &RequestRoot, CUPSD_VARTYPE_STRING }, | |
163 | { "RIPCache", &RIPCache, CUPSD_VARTYPE_STRING }, | |
ef416fc2 | 164 | { "RootCertDuration", &RootCertDuration, CUPSD_VARTYPE_INTEGER }, |
165 | { "ServerAdmin", &ServerAdmin, CUPSD_VARTYPE_STRING }, | |
76cd9e37 | 166 | { "ServerBin", &ServerBin, CUPSD_VARTYPE_PATHNAME }, |
ef416fc2 | 167 | #ifdef HAVE_SSL |
76cd9e37 | 168 | { "ServerCertificate", &ServerCertificate, CUPSD_VARTYPE_PATHNAME }, |
ef416fc2 | 169 | # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS) |
76cd9e37 | 170 | { "ServerKey", &ServerKey, CUPSD_VARTYPE_PATHNAME }, |
ef416fc2 | 171 | # endif /* HAVE_LIBSSL || HAVE_GNUTLS */ |
172 | #endif /* HAVE_SSL */ | |
173 | { "ServerName", &ServerName, CUPSD_VARTYPE_STRING }, | |
76cd9e37 | 174 | { "ServerRoot", &ServerRoot, CUPSD_VARTYPE_PATHNAME }, |
2e4ff8af | 175 | { "SMBConfigFile", &SMBConfigFile, CUPSD_VARTYPE_STRING }, |
ef416fc2 | 176 | { "StateDir", &StateDir, CUPSD_VARTYPE_STRING }, |
f7deaa1a | 177 | #ifdef HAVE_AUTHORIZATION_H |
178 | { "SystemGroupAuthKey", &SystemGroupAuthKey, CUPSD_VARTYPE_STRING }, | |
179 | #endif /* HAVE_AUTHORIZATION_H */ | |
76cd9e37 | 180 | { "TempDir", &TempDir, CUPSD_VARTYPE_PATHNAME }, |
e00b005a | 181 | { "Timeout", &Timeout, CUPSD_VARTYPE_INTEGER }, |
182 | { "UseNetworkDefault", &UseNetworkDefault, CUPSD_VARTYPE_BOOLEAN } | |
ef416fc2 | 183 | }; |
184 | #define NUM_VARS (sizeof(variables) / sizeof(variables[0])) | |
185 | ||
186 | ||
ac884b6a | 187 | static const unsigned ones[4] = |
ef416fc2 | 188 | { |
189 | 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff | |
190 | }; | |
ac884b6a | 191 | static const unsigned zeros[4] = |
ef416fc2 | 192 | { |
193 | 0x00000000, 0x00000000, 0x00000000, 0x00000000 | |
194 | }; | |
195 | ||
196 | ||
197 | /* | |
198 | * Local functions... | |
199 | */ | |
e07d4801 | 200 | |
ef416fc2 | 201 | static http_addrlist_t *get_address(const char *value, int defport); |
202 | static int get_addr_and_mask(const char *value, unsigned *ip, | |
203 | unsigned *mask); | |
204 | static int parse_aaa(cupsd_location_t *loc, char *line, | |
205 | char *value, int linenum); | |
49d87452 | 206 | static int parse_fatal_errors(const char *s); |
bd7854cb | 207 | static int parse_groups(const char *s); |
208 | static int parse_protocols(const char *s); | |
ef416fc2 | 209 | static int read_configuration(cups_file_t *fp); |
210 | static int read_location(cups_file_t *fp, char *name, int linenum); | |
211 | static int read_policy(cups_file_t *fp, char *name, int linenum); | |
212 | ||
213 | ||
e07d4801 MS |
214 | /* |
215 | * 'cupsdAddAlias()' - Add a host alias. | |
216 | */ | |
217 | ||
218 | void | |
219 | cupsdAddAlias(cups_array_t *aliases, /* I - Array of aliases */ | |
220 | const char *name) /* I - Name to add */ | |
221 | { | |
222 | cupsd_alias_t *a; /* New alias */ | |
223 | size_t namelen; /* Length of name */ | |
224 | ||
225 | ||
226 | namelen = strlen(name); | |
227 | ||
228 | if ((a = (cupsd_alias_t *)malloc(sizeof(cupsd_alias_t) + namelen)) == NULL) | |
229 | return; | |
230 | ||
231 | a->namelen = namelen; | |
232 | strcpy(a->name, name); /* OK since a->name is allocated */ | |
233 | ||
234 | cupsArrayAdd(aliases, a); | |
235 | } | |
236 | ||
237 | ||
b94498cf | 238 | /* |
239 | * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory. | |
240 | */ | |
241 | ||
242 | int /* O - 0 on success, -1 on error, 1 on warning */ | |
243 | cupsdCheckPermissions( | |
244 | const char *filename, /* I - File/directory name */ | |
245 | const char *suffix, /* I - Additional file/directory name */ | |
246 | int mode, /* I - Permissions */ | |
247 | int user, /* I - Owner */ | |
248 | int group, /* I - Group */ | |
249 | int is_dir, /* I - 1 = directory, 0 = file */ | |
250 | int create_dir) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */ | |
251 | { | |
252 | int dir_created = 0; /* Did we create a directory? */ | |
253 | char pathname[1024]; /* File name with prefix */ | |
254 | struct stat fileinfo; /* Stat buffer */ | |
49d87452 | 255 | int is_symlink; /* Is "filename" a symlink? */ |
b94498cf | 256 | |
257 | ||
258 | /* | |
259 | * Prepend the given root to the filename before testing it... | |
260 | */ | |
261 | ||
262 | if (suffix) | |
263 | { | |
264 | snprintf(pathname, sizeof(pathname), "%s/%s", filename, suffix); | |
265 | filename = pathname; | |
266 | } | |
267 | ||
268 | /* | |
269 | * See if we can stat the file/directory... | |
270 | */ | |
271 | ||
49d87452 | 272 | if (lstat(filename, &fileinfo)) |
b94498cf | 273 | { |
274 | if (errno == ENOENT && create_dir) | |
275 | { | |
276 | if (create_dir > 0) | |
277 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Creating missing directory \"%s\"", | |
278 | filename); | |
279 | ||
280 | if (mkdir(filename, mode)) | |
281 | { | |
282 | if (create_dir > 0) | |
283 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
284 | "Unable to create directory \"%s\" - %s", filename, | |
285 | strerror(errno)); | |
286 | else | |
287 | syslog(LOG_ERR, "Unable to create directory \"%s\" - %s", filename, | |
288 | strerror(errno)); | |
289 | ||
290 | return (-1); | |
291 | } | |
292 | ||
d1c13e16 MS |
293 | dir_created = 1; |
294 | fileinfo.st_mode = mode | S_IFDIR; | |
b94498cf | 295 | } |
296 | else | |
297 | return (create_dir ? -1 : 1); | |
298 | } | |
299 | ||
49d87452 MS |
300 | if ((is_symlink = S_ISLNK(fileinfo.st_mode)) != 0) |
301 | { | |
302 | if (stat(filename, &fileinfo)) | |
303 | { | |
304 | cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is a bad symlink - %s", | |
305 | filename, strerror(errno)); | |
306 | return (-1); | |
307 | } | |
308 | } | |
309 | ||
b94498cf | 310 | /* |
49d87452 | 311 | * Make sure it's a regular file or a directory as needed... |
b94498cf | 312 | */ |
313 | ||
314 | if (!dir_created && !is_dir && !S_ISREG(fileinfo.st_mode)) | |
315 | { | |
316 | cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a regular file!", filename); | |
317 | return (-1); | |
318 | } | |
319 | ||
320 | if (!dir_created && is_dir && !S_ISDIR(fileinfo.st_mode)) | |
321 | { | |
322 | if (create_dir >= 0) | |
323 | cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory!", filename); | |
324 | else | |
325 | syslog(LOG_ERR, "\"%s\" is not a directory!", filename); | |
326 | ||
327 | return (-1); | |
328 | } | |
329 | ||
49d87452 MS |
330 | /* |
331 | * If the filename is a symlink, do not change permissions (STR #2937)... | |
332 | */ | |
333 | ||
334 | if (is_symlink) | |
335 | return (0); | |
336 | ||
b94498cf | 337 | /* |
338 | * Fix owner, group, and mode as needed... | |
339 | */ | |
340 | ||
341 | if (dir_created || fileinfo.st_uid != user || fileinfo.st_gid != group) | |
342 | { | |
343 | if (create_dir >= 0) | |
344 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing ownership of \"%s\"", | |
345 | filename); | |
346 | ||
347 | if (chown(filename, user, group) && !getuid()) | |
348 | { | |
349 | if (create_dir >= 0) | |
350 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
351 | "Unable to change ownership of \"%s\" - %s", filename, | |
352 | strerror(errno)); | |
353 | else | |
354 | syslog(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename, | |
355 | strerror(errno)); | |
356 | ||
357 | return (1); | |
358 | } | |
359 | } | |
360 | ||
361 | if (dir_created || (fileinfo.st_mode & 07777) != mode) | |
362 | { | |
363 | if (create_dir >= 0) | |
364 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing access permissions of \"%s\"", | |
365 | filename); | |
366 | ||
367 | if (chmod(filename, mode)) | |
368 | { | |
369 | if (create_dir >= 0) | |
370 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
371 | "Unable to change permissions of \"%s\" - %s", filename, | |
372 | strerror(errno)); | |
373 | else | |
374 | syslog(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename, | |
375 | strerror(errno)); | |
376 | ||
377 | return (1); | |
378 | } | |
379 | } | |
380 | ||
381 | /* | |
382 | * Everything is OK... | |
383 | */ | |
384 | ||
385 | return (0); | |
386 | } | |
387 | ||
388 | ||
e07d4801 MS |
389 | /* |
390 | * 'cupsdFreeAliases()' - Free all of the alias entries. | |
391 | */ | |
392 | ||
393 | void | |
394 | cupsdFreeAliases(cups_array_t *aliases) /* I - Array of aliases */ | |
395 | { | |
396 | cupsd_alias_t *a; /* Current alias */ | |
397 | ||
398 | ||
399 | for (a = (cupsd_alias_t *)cupsArrayFirst(aliases); | |
400 | a; | |
401 | a = (cupsd_alias_t *)cupsArrayNext(aliases)) | |
402 | free(a); | |
403 | ||
404 | cupsArrayDelete(aliases); | |
405 | } | |
406 | ||
407 | ||
ef416fc2 | 408 | /* |
409 | * 'cupsdReadConfiguration()' - Read the cupsd.conf file. | |
410 | */ | |
411 | ||
412 | int /* O - 1 on success, 0 otherwise */ | |
413 | cupsdReadConfiguration(void) | |
414 | { | |
415 | int i; /* Looping var */ | |
416 | cups_file_t *fp; /* Configuration file */ | |
417 | int status; /* Return status */ | |
418 | char temp[1024], /* Temporary buffer */ | |
dd1abb6b | 419 | mimedir[1024], /* MIME directory */ |
ef416fc2 | 420 | *slash; /* Directory separator */ |
ef416fc2 | 421 | cups_lang_t *language; /* Language */ |
422 | struct passwd *user; /* Default user */ | |
423 | struct group *group; /* Default group */ | |
424 | char *old_serverroot, /* Old ServerRoot */ | |
425 | *old_requestroot; /* Old RequestRoot */ | |
f11a948a | 426 | int old_remote_port; /* Old RemotePort */ |
b423cd4c | 427 | const char *tmpdir; /* TMPDIR environment variable */ |
428 | struct stat tmpinfo; /* Temporary directory info */ | |
2e4ff8af | 429 | cupsd_policy_t *p; /* Policy */ |
b423cd4c | 430 | |
ef416fc2 | 431 | |
ef416fc2 | 432 | /* |
433 | * Save the old root paths... | |
434 | */ | |
435 | ||
436 | old_serverroot = NULL; | |
437 | cupsdSetString(&old_serverroot, ServerRoot); | |
438 | old_requestroot = NULL; | |
439 | cupsdSetString(&old_requestroot, RequestRoot); | |
440 | ||
441 | /* | |
442 | * Reset the server configuration data... | |
443 | */ | |
444 | ||
445 | cupsdDeleteAllLocations(); | |
446 | ||
447 | if (NumBrowsers > 0) | |
448 | { | |
449 | free(Browsers); | |
e53920b9 | 450 | Browsers = NULL; |
ef416fc2 | 451 | |
452 | NumBrowsers = 0; | |
453 | } | |
454 | ||
455 | if (NumPolled > 0) | |
456 | { | |
457 | free(Polled); | |
458 | ||
459 | NumPolled = 0; | |
460 | } | |
461 | ||
462 | if (NumRelays > 0) | |
463 | { | |
464 | for (i = 0; i < NumRelays; i ++) | |
5bd77a73 | 465 | if (Relays[i].from.type == CUPSD_AUTH_NAME) |
ef416fc2 | 466 | free(Relays[i].from.mask.name.name); |
467 | ||
468 | free(Relays); | |
469 | ||
470 | NumRelays = 0; | |
471 | } | |
472 | ||
bd7854cb | 473 | cupsdDeleteAllListeners(); |
ef416fc2 | 474 | |
f11a948a MS |
475 | old_remote_port = RemotePort; |
476 | RemotePort = 0; | |
d1c13e16 | 477 | |
ef416fc2 | 478 | /* |
479 | * String options... | |
480 | */ | |
481 | ||
e07d4801 MS |
482 | cupsdFreeAliases(ServerAlias); |
483 | ServerAlias = NULL; | |
484 | ||
d1c13e16 MS |
485 | cupsdClearString(&ServerName); |
486 | cupsdClearString(&ServerAdmin); | |
ef416fc2 | 487 | cupsdSetString(&ServerBin, CUPS_SERVERBIN); |
488 | cupsdSetString(&RequestRoot, CUPS_REQUESTS); | |
489 | cupsdSetString(&CacheDir, CUPS_CACHEDIR); | |
490 | cupsdSetString(&DataDir, CUPS_DATADIR); | |
491 | cupsdSetString(&DocumentRoot, CUPS_DOCROOT); | |
492 | cupsdSetString(&AccessLog, CUPS_LOGDIR "/access_log"); | |
493 | cupsdSetString(&ErrorLog, CUPS_LOGDIR "/error_log"); | |
494 | cupsdSetString(&PageLog, CUPS_LOGDIR "/page_log"); | |
01ce6322 MS |
495 | cupsdSetString(&PageLogFormat, |
496 | "%p %j %u %T %P %C %{job-billing} " | |
497 | "%{job-originating-host-name} %{job-name} %{media} %{sides}"); | |
e53920b9 | 498 | cupsdSetString(&Printcap, CUPS_DEFAULT_PRINTCAP); |
ef416fc2 | 499 | cupsdSetString(&PrintcapGUI, "/usr/bin/glpoptions"); |
500 | cupsdSetString(&FontPath, CUPS_FONTPATH); | |
501 | cupsdSetString(&RemoteRoot, "remroot"); | |
ae71f5de | 502 | cupsdSetString(&ServerHeader, "CUPS/1.4"); |
ef416fc2 | 503 | cupsdSetString(&StateDir, CUPS_STATEDIR); |
504 | ||
ed486911 | 505 | if (!strcmp(CUPS_DEFAULT_PRINTCAP, "/etc/printers.conf")) |
506 | PrintcapFormat = PRINTCAP_SOLARIS; | |
0af14961 MS |
507 | else if (!strcmp(CUPS_DEFAULT_PRINTCAP, |
508 | "/Library/Preferences/org.cups.printers.plist")) | |
509 | PrintcapFormat = PRINTCAP_PLIST; | |
ed486911 | 510 | else |
511 | PrintcapFormat = PRINTCAP_BSD; | |
512 | ||
ef416fc2 | 513 | strlcpy(temp, ConfigurationFile, sizeof(temp)); |
514 | if ((slash = strrchr(temp, '/')) != NULL) | |
515 | *slash = '\0'; | |
516 | ||
517 | cupsdSetString(&ServerRoot, temp); | |
518 | ||
519 | cupsdClearString(&Classification); | |
520 | ClassifyOverride = 0; | |
521 | ||
522 | #ifdef HAVE_SSL | |
523 | # ifdef HAVE_CDSASSL | |
fa73b229 | 524 | cupsdSetString(&ServerCertificate, "/Library/Keychains/System.keychain"); |
ef416fc2 | 525 | # else |
526 | cupsdSetString(&ServerCertificate, "ssl/server.crt"); | |
527 | cupsdSetString(&ServerKey, "ssl/server.key"); | |
528 | # endif /* HAVE_CDSASSL */ | |
529 | #endif /* HAVE_SSL */ | |
530 | ||
531 | language = cupsLangDefault(); | |
532 | ||
533 | if (!strcmp(language->language, "C") || !strcmp(language->language, "POSIX")) | |
534 | cupsdSetString(&DefaultLanguage, "en"); | |
535 | else | |
536 | cupsdSetString(&DefaultLanguage, language->language); | |
537 | ||
538 | cupsdSetString(&DefaultCharset, _cupsEncodingName(language->encoding)); | |
539 | ||
c5571a1d MS |
540 | cupsdClearString(&DefaultPaperSize); |
541 | ||
ef416fc2 | 542 | cupsdSetString(&RIPCache, "8m"); |
543 | ||
b423cd4c | 544 | cupsdSetString(&TempDir, NULL); |
ef416fc2 | 545 | |
ef416fc2 | 546 | /* |
547 | * Find the default user... | |
548 | */ | |
549 | ||
550 | if ((user = getpwnam(CUPS_DEFAULT_USER)) != NULL) | |
551 | User = user->pw_uid; | |
552 | else | |
553 | { | |
554 | /* | |
555 | * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos- | |
556 | * complement number...) | |
557 | */ | |
558 | ||
559 | User = 65534; | |
560 | } | |
561 | ||
562 | endpwent(); | |
563 | ||
564 | /* | |
d6ae789d | 565 | * Find the default group... |
ef416fc2 | 566 | */ |
567 | ||
d6ae789d | 568 | group = getgrnam(CUPS_DEFAULT_GROUP); |
ef416fc2 | 569 | endgrent(); |
570 | ||
d6ae789d | 571 | if (group) |
ef416fc2 | 572 | Group = group->gr_gid; |
573 | else | |
574 | { | |
575 | /* | |
d6ae789d | 576 | * Fallback to group "nobody"... |
ef416fc2 | 577 | */ |
578 | ||
d6ae789d | 579 | group = getgrnam("nobody"); |
580 | endgrent(); | |
581 | ||
582 | if (group) | |
583 | Group = group->gr_gid; | |
584 | else | |
585 | { | |
586 | /* | |
587 | * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos- | |
588 | * complement number...) | |
589 | */ | |
590 | ||
591 | Group = 65534; | |
592 | } | |
ef416fc2 | 593 | } |
594 | ||
595 | /* | |
596 | * Numeric options... | |
597 | */ | |
598 | ||
dfd5680b MS |
599 | AccessLogLevel = CUPSD_ACCESSLOG_ACTIONS; |
600 | ConfigFilePerm = CUPS_DEFAULT_CONFIG_FILE_PERM; | |
601 | FatalErrors = parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS); | |
602 | DefaultAuthType = CUPSD_AUTH_BASIC; | |
4744bd90 | 603 | #ifdef HAVE_SSL |
dfd5680b MS |
604 | DefaultEncryption = HTTP_ENCRYPT_REQUIRED; |
605 | SSLOptions = CUPSD_SSL_NONE; | |
4744bd90 | 606 | #endif /* HAVE_SSL */ |
dfd5680b | 607 | DirtyCleanInterval = DEFAULT_KEEPALIVE; |
238c3832 | 608 | JobKillDelay = DEFAULT_TIMEOUT; |
dfd5680b MS |
609 | JobRetryLimit = 5; |
610 | JobRetryInterval = 300; | |
611 | FileDevice = FALSE; | |
612 | FilterLevel = 0; | |
613 | FilterLimit = 0; | |
614 | FilterNice = 0; | |
615 | HostNameLookups = FALSE; | |
616 | ImplicitClasses = CUPS_DEFAULT_IMPLICIT_CLASSES; | |
617 | ImplicitAnyClasses = FALSE; | |
618 | HideImplicitMembers = TRUE; | |
619 | KeepAlive = TRUE; | |
620 | KeepAliveTimeout = DEFAULT_KEEPALIVE; | |
621 | ListenBackLog = SOMAXCONN; | |
622 | LogFilePerm = CUPS_DEFAULT_LOG_FILE_PERM; | |
623 | LogLevel = CUPSD_LOG_WARN; | |
624 | LogTimeFormat = CUPSD_TIME_STANDARD; | |
625 | MaxClients = 100; | |
626 | MaxClientsPerHost = 0; | |
627 | MaxLogSize = 1024 * 1024; | |
628 | MaxPrinterHistory = 10; | |
629 | MaxRequestSize = 0; | |
630 | MultipleOperationTimeout = DEFAULT_TIMEOUT; | |
631 | ReloadTimeout = DEFAULT_KEEPALIVE; | |
632 | RootCertDuration = 300; | |
633 | Timeout = DEFAULT_TIMEOUT; | |
634 | NumSystemGroups = 0; | |
635 | ||
636 | BrowseInterval = DEFAULT_INTERVAL; | |
637 | BrowsePort = ippPort(); | |
638 | BrowseLocalProtocols = parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS); | |
639 | BrowseRemoteProtocols = parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS); | |
640 | BrowseShortNames = CUPS_DEFAULT_BROWSE_SHORT_NAMES; | |
641 | BrowseTimeout = DEFAULT_TIMEOUT; | |
642 | BrowseWebIF = FALSE; | |
643 | Browsing = CUPS_DEFAULT_BROWSING; | |
644 | DefaultShared = CUPS_DEFAULT_DEFAULT_SHARED; | |
ef416fc2 | 645 | |
2e4ff8af MS |
646 | cupsdSetString(&LPDConfigFile, CUPS_DEFAULT_LPD_CONFIG_FILE); |
647 | cupsdSetString(&SMBConfigFile, CUPS_DEFAULT_SMB_CONFIG_FILE); | |
648 | ||
ef416fc2 | 649 | cupsdClearString(&BrowseLocalOptions); |
650 | cupsdClearString(&BrowseRemoteOptions); | |
651 | ||
323c5de1 | 652 | cupsdSetString(&ErrorPolicy, "stop-printer"); |
653 | ||
b423cd4c | 654 | #ifdef HAVE_LDAP |
655 | cupsdClearString(&BrowseLDAPBindDN); | |
656 | cupsdClearString(&BrowseLDAPDN); | |
657 | cupsdClearString(&BrowseLDAPPassword); | |
658 | cupsdClearString(&BrowseLDAPServer); | |
1ff0402e | 659 | # ifdef HAVE_LDAP_SSL |
bc44d920 | 660 | cupsdClearString(&BrowseLDAPCACertFile); |
1ff0402e | 661 | # endif /* HAVE_LDAP_SSL */ |
b423cd4c | 662 | #endif /* HAVE_LDAP */ |
663 | ||
ef416fc2 | 664 | JobHistory = DEFAULT_HISTORY; |
665 | JobFiles = DEFAULT_FILES; | |
666 | JobAutoPurge = 0; | |
667 | MaxJobs = 500; | |
668 | MaxActiveJobs = 0; | |
669 | MaxJobsPerUser = 0; | |
670 | MaxJobsPerPrinter = 0; | |
f7deaa1a | 671 | MaxCopies = CUPS_DEFAULT_MAX_COPIES; |
ef416fc2 | 672 | |
673 | cupsdDeleteAllPolicies(); | |
674 | cupsdClearString(&DefaultPolicy); | |
675 | ||
f7deaa1a | 676 | #ifdef HAVE_AUTHORIZATION_H |
677 | cupsdClearString(&SystemGroupAuthKey); | |
678 | #endif /* HAVE_AUTHORIZATION_H */ | |
679 | ||
ef416fc2 | 680 | MaxSubscriptions = 100; |
681 | MaxSubscriptionsPerJob = 0; | |
682 | MaxSubscriptionsPerPrinter = 0; | |
683 | MaxSubscriptionsPerUser = 0; | |
684 | DefaultLeaseDuration = 86400; | |
685 | MaxLeaseDuration = 0; | |
686 | ||
a4d04587 | 687 | #ifdef HAVE_LAUNCHD |
688 | LaunchdTimeout = DEFAULT_TIMEOUT + 10; | |
689 | cupsdSetString(&LaunchdConf, CUPS_DEFAULT_LAUNCHD_CONF); | |
690 | #endif /* HAVE_LAUNCHD */ | |
691 | ||
7594b224 | 692 | #ifdef __APPLE__ |
693 | AppleQuotas = TRUE; | |
694 | #endif /* __APPLE__ */ | |
695 | ||
ef416fc2 | 696 | /* |
697 | * Read the configuration file... | |
698 | */ | |
699 | ||
700 | if ((fp = cupsFileOpen(ConfigurationFile, "r")) == NULL) | |
701 | return (0); | |
702 | ||
703 | status = read_configuration(fp); | |
704 | ||
705 | cupsFileClose(fp); | |
706 | ||
707 | if (!status) | |
708 | return (0); | |
709 | ||
4744bd90 | 710 | RunUser = getuid(); |
ef416fc2 | 711 | |
d1c13e16 | 712 | cupsdLogMessage(CUPSD_LOG_INFO, "Remote access is %s.", |
f11a948a | 713 | RemotePort ? "enabled" : "disabled"); |
d1c13e16 | 714 | |
8ca02f3c | 715 | /* |
716 | * See if the ServerName is an IP address... | |
717 | */ | |
718 | ||
f11a948a MS |
719 | if (ServerName) |
720 | { | |
721 | if (!ServerAlias) | |
722 | ServerAlias = cupsArrayNew(NULL, NULL); | |
723 | ||
724 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", ServerName); | |
725 | } | |
726 | else | |
d1c13e16 | 727 | { |
e07d4801 | 728 | if (gethostname(temp, sizeof(temp))) |
d1c13e16 MS |
729 | { |
730 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get hostname: %s", | |
731 | strerror(errno)); | |
732 | strlcpy(temp, "localhost", sizeof(temp)); | |
733 | } | |
734 | ||
735 | cupsdSetString(&ServerName, temp); | |
e07d4801 MS |
736 | |
737 | if (!ServerAlias) | |
738 | ServerAlias = cupsArrayNew(NULL, NULL); | |
739 | ||
740 | cupsdAddAlias(ServerAlias, temp); | |
741 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", temp); | |
742 | ||
f11a948a | 743 | if (HostNameLookups || RemotePort) |
e07d4801 MS |
744 | { |
745 | struct hostent *host; /* Host entry to get FQDN */ | |
746 | ||
747 | if ((host = gethostbyname(temp)) != NULL) | |
748 | { | |
749 | if (strcasecmp(temp, host->h_name)) | |
750 | { | |
751 | cupsdSetString(&ServerName, host->h_name); | |
752 | cupsdAddAlias(ServerAlias, host->h_name); | |
753 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", | |
754 | host->h_name); | |
755 | } | |
756 | ||
757 | if (host->h_aliases) | |
758 | { | |
759 | for (i = 0; host->h_aliases[i]; i ++) | |
760 | if (strcasecmp(temp, host->h_aliases[i])) | |
761 | { | |
762 | cupsdAddAlias(ServerAlias, host->h_aliases[i]); | |
763 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", | |
764 | host->h_aliases[i]); | |
765 | } | |
766 | } | |
767 | } | |
768 | } | |
769 | ||
770 | /* | |
771 | * Make sure we have the base hostname added as an alias, too! | |
772 | */ | |
773 | ||
774 | if ((slash = strchr(temp, '.')) != NULL) | |
775 | { | |
776 | *slash = '\0'; | |
777 | cupsdAddAlias(ServerAlias, temp); | |
778 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", temp); | |
779 | } | |
d1c13e16 MS |
780 | } |
781 | ||
8ca02f3c | 782 | for (slash = ServerName; isdigit(*slash & 255) || *slash == '.'; slash ++); |
783 | ||
784 | ServerNameIsIP = !*slash; | |
785 | ||
d1c13e16 MS |
786 | /* |
787 | * Make sure ServerAdmin is initialized... | |
788 | */ | |
789 | ||
790 | if (!ServerAdmin) | |
791 | cupsdSetStringf(&ServerAdmin, "root@%s", ServerName); | |
792 | ||
ef416fc2 | 793 | /* |
794 | * Use the default system group if none was supplied in cupsd.conf... | |
795 | */ | |
796 | ||
797 | if (NumSystemGroups == 0) | |
bd7854cb | 798 | { |
799 | if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS)) | |
800 | { | |
801 | /* | |
802 | * Find the group associated with GID 0... | |
803 | */ | |
804 | ||
805 | group = getgrgid(0); | |
806 | endgrent(); | |
807 | ||
808 | if (group != NULL) | |
809 | cupsdSetString(&SystemGroups[0], group->gr_name); | |
810 | else | |
811 | cupsdSetString(&SystemGroups[0], "unknown"); | |
812 | ||
813 | SystemGroupIDs[0] = 0; | |
814 | NumSystemGroups = 1; | |
815 | } | |
816 | } | |
ef416fc2 | 817 | |
818 | /* | |
819 | * Get the access control list for browsing... | |
820 | */ | |
821 | ||
822 | BrowseACL = cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL"); | |
823 | ||
824 | /* | |
825 | * Open the system log for cupsd if necessary... | |
826 | */ | |
827 | ||
828 | #ifdef HAVE_VSYSLOG | |
829 | if (!strcmp(AccessLog, "syslog") || | |
830 | !strcmp(ErrorLog, "syslog") || | |
831 | !strcmp(PageLog, "syslog")) | |
832 | openlog("cupsd", LOG_PID | LOG_NOWAIT | LOG_NDELAY, LOG_LPR); | |
833 | #endif /* HAVE_VSYSLOG */ | |
834 | ||
835 | /* | |
836 | * Log the configuration file that was used... | |
837 | */ | |
838 | ||
839 | cupsdLogMessage(CUPSD_LOG_INFO, "Loaded configuration file \"%s\"", | |
840 | ConfigurationFile); | |
841 | ||
842 | /* | |
843 | * Validate the Group and SystemGroup settings - they cannot be the same, | |
844 | * otherwise the CGI programs will be able to authenticate as root without | |
845 | * a password! | |
846 | */ | |
847 | ||
848 | if (!RunUser) | |
849 | { | |
850 | for (i = 0; i < NumSystemGroups; i ++) | |
851 | if (Group == SystemGroupIDs[i]) | |
852 | break; | |
853 | ||
854 | if (i < NumSystemGroups) | |
855 | { | |
856 | /* | |
857 | * Log the error and reset the group to a safe value... | |
858 | */ | |
859 | ||
860 | cupsdLogMessage(CUPSD_LOG_NOTICE, | |
861 | "Group and SystemGroup cannot use the same groups!"); | |
862 | cupsdLogMessage(CUPSD_LOG_INFO, "Resetting Group to \"nobody\"..."); | |
863 | ||
864 | group = getgrnam("nobody"); | |
865 | endgrent(); | |
866 | ||
867 | if (group != NULL) | |
868 | Group = group->gr_gid; | |
869 | else | |
870 | { | |
871 | /* | |
872 | * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos- | |
873 | * complement number...) | |
874 | */ | |
875 | ||
876 | Group = 65534; | |
877 | } | |
878 | } | |
879 | } | |
880 | ||
881 | /* | |
882 | * Check that we have at least one listen/port line; if not, report this | |
883 | * as an error and exit! | |
884 | */ | |
885 | ||
bd7854cb | 886 | if (cupsArrayCount(Listeners) == 0) |
ef416fc2 | 887 | { |
888 | /* | |
889 | * No listeners! | |
890 | */ | |
891 | ||
892 | cupsdLogMessage(CUPSD_LOG_EMERG, | |
49d87452 MS |
893 | "No valid Listen or Port lines were found in the " |
894 | "configuration file!"); | |
ef416fc2 | 895 | |
896 | /* | |
897 | * Commit suicide... | |
898 | */ | |
899 | ||
900 | cupsdEndProcess(getpid(), 0); | |
901 | } | |
902 | ||
903 | /* | |
904 | * Set the default locale using the language and charset... | |
905 | */ | |
906 | ||
907 | cupsdSetStringf(&DefaultLocale, "%s.%s", DefaultLanguage, DefaultCharset); | |
908 | ||
909 | /* | |
910 | * Update all relative filenames to include the full path from ServerRoot... | |
911 | */ | |
912 | ||
913 | if (DocumentRoot[0] != '/') | |
914 | cupsdSetStringf(&DocumentRoot, "%s/%s", ServerRoot, DocumentRoot); | |
915 | ||
916 | if (RequestRoot[0] != '/') | |
917 | cupsdSetStringf(&RequestRoot, "%s/%s", ServerRoot, RequestRoot); | |
918 | ||
919 | if (ServerBin[0] != '/') | |
920 | cupsdSetStringf(&ServerBin, "%s/%s", ServerRoot, ServerBin); | |
921 | ||
922 | if (StateDir[0] != '/') | |
923 | cupsdSetStringf(&StateDir, "%s/%s", ServerRoot, StateDir); | |
924 | ||
925 | if (CacheDir[0] != '/') | |
926 | cupsdSetStringf(&CacheDir, "%s/%s", ServerRoot, CacheDir); | |
927 | ||
928 | #ifdef HAVE_SSL | |
929 | if (ServerCertificate[0] != '/') | |
930 | cupsdSetStringf(&ServerCertificate, "%s/%s", ServerRoot, ServerCertificate); | |
931 | ||
49d87452 MS |
932 | if (!strncmp(ServerRoot, ServerCertificate, strlen(ServerRoot)) && |
933 | cupsdCheckPermissions(ServerCertificate, NULL, 0600, RunUser, Group, | |
934 | 0, 0) < 0 && | |
935 | (FatalErrors & CUPSD_FATAL_PERMISSIONS)) | |
936 | return (0); | |
ef416fc2 | 937 | |
938 | # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS) | |
939 | if (ServerKey[0] != '/') | |
940 | cupsdSetStringf(&ServerKey, "%s/%s", ServerRoot, ServerKey); | |
941 | ||
49d87452 MS |
942 | if (!strncmp(ServerRoot, ServerKey, strlen(ServerRoot)) && |
943 | cupsdCheckPermissions(ServerKey, NULL, 0600, RunUser, Group, 0, 0) < 0 && | |
944 | (FatalErrors & CUPSD_FATAL_PERMISSIONS)) | |
945 | return (0); | |
ef416fc2 | 946 | # endif /* HAVE_LIBSSL || HAVE_GNUTLS */ |
947 | #endif /* HAVE_SSL */ | |
948 | ||
949 | /* | |
950 | * Make sure that directories and config files are owned and | |
951 | * writable by the user and group in the cupsd.conf file... | |
952 | */ | |
953 | ||
ae71f5de MS |
954 | snprintf(temp, sizeof(temp), "%s/rss", CacheDir); |
955 | ||
49d87452 MS |
956 | if ((cupsdCheckPermissions(RequestRoot, NULL, 0710, RunUser, |
957 | Group, 1, 1) < 0 || | |
958 | cupsdCheckPermissions(CacheDir, NULL, 0775, RunUser, | |
959 | Group, 1, 1) < 0 || | |
960 | cupsdCheckPermissions(temp, NULL, 0775, RunUser, | |
961 | Group, 1, 1) < 0 || | |
962 | cupsdCheckPermissions(StateDir, NULL, 0755, RunUser, | |
963 | Group, 1, 1) < 0 || | |
964 | cupsdCheckPermissions(StateDir, "certs", RunUser ? 0711 : 0511, User, | |
965 | SystemGroupIDs[0], 1, 1) < 0 || | |
966 | cupsdCheckPermissions(ServerRoot, NULL, 0755, RunUser, | |
967 | Group, 1, 0) < 0 || | |
968 | cupsdCheckPermissions(ServerRoot, "ppd", 0755, RunUser, | |
969 | Group, 1, 1) < 0 || | |
970 | cupsdCheckPermissions(ServerRoot, "ssl", 0700, RunUser, | |
971 | Group, 1, 0) < 0 || | |
972 | cupsdCheckPermissions(ServerRoot, "cupsd.conf", ConfigFilePerm, RunUser, | |
973 | Group, 0, 0) < 0 || | |
974 | cupsdCheckPermissions(ServerRoot, "classes.conf", 0600, RunUser, | |
975 | Group, 0, 0) < 0 || | |
976 | cupsdCheckPermissions(ServerRoot, "printers.conf", 0600, RunUser, | |
977 | Group, 0, 0) < 0 || | |
978 | cupsdCheckPermissions(ServerRoot, "passwd.md5", 0600, User, | |
979 | Group, 0, 0) < 0) && | |
980 | (FatalErrors & CUPSD_FATAL_PERMISSIONS)) | |
d09495fa | 981 | return (0); |
ef416fc2 | 982 | |
b423cd4c | 983 | /* |
984 | * Update TempDir to the default if it hasn't been set already... | |
985 | */ | |
986 | ||
987 | if (!TempDir) | |
988 | { | |
989 | if ((tmpdir = getenv("TMPDIR")) != NULL) | |
990 | { | |
991 | /* | |
992 | * TMPDIR is defined, see if it is OK for us to use... | |
993 | */ | |
994 | ||
995 | if (stat(tmpdir, &tmpinfo)) | |
996 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to access TMPDIR (%s): %s", | |
997 | tmpdir, strerror(errno)); | |
998 | else if (!S_ISDIR(tmpinfo.st_mode)) | |
999 | cupsdLogMessage(CUPSD_LOG_ERROR, "TMPDIR (%s) is not a directory!", | |
1000 | tmpdir); | |
1001 | else if ((tmpinfo.st_uid != User || !(tmpinfo.st_mode & S_IWUSR)) && | |
1002 | (tmpinfo.st_gid != Group || !(tmpinfo.st_mode & S_IWGRP)) && | |
1003 | !(tmpinfo.st_mode & S_IWOTH)) | |
1004 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1005 | "TMPDIR (%s) has the wrong permissions!", tmpdir); | |
1006 | else | |
1007 | cupsdSetString(&TempDir, tmpdir); | |
b423cd4c | 1008 | } |
1009 | ||
1010 | if (!TempDir) | |
d09495fa | 1011 | { |
1012 | cupsdLogMessage(CUPSD_LOG_INFO, "Using default TempDir of %s/tmp...", | |
1013 | RequestRoot); | |
b423cd4c | 1014 | cupsdSetStringf(&TempDir, "%s/tmp", RequestRoot); |
d09495fa | 1015 | } |
b423cd4c | 1016 | } |
1017 | ||
ef416fc2 | 1018 | /* |
b94498cf | 1019 | * Make sure the temporary directory has the right permissions... |
ef416fc2 | 1020 | */ |
1021 | ||
ef416fc2 | 1022 | if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)) || |
1023 | access(TempDir, 0)) | |
1024 | { | |
1025 | /* | |
1026 | * Update ownership and permissions if the CUPS temp directory | |
1027 | * is under the spool directory or does not exist... | |
1028 | */ | |
1029 | ||
49d87452 MS |
1030 | if (cupsdCheckPermissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0 && |
1031 | (FatalErrors & CUPSD_FATAL_PERMISSIONS)) | |
d09495fa | 1032 | return (0); |
ef416fc2 | 1033 | } |
1034 | ||
ef416fc2 | 1035 | /* |
1036 | * Setup environment variables... | |
1037 | */ | |
1038 | ||
1039 | cupsdInitEnv(); | |
1040 | ||
c5571a1d MS |
1041 | /* |
1042 | * Update default paper size setting as needed... | |
1043 | */ | |
1044 | ||
1045 | if (!DefaultPaperSize) | |
1046 | { | |
1047 | #ifdef HAVE_LIBPAPER | |
1048 | char *paper_result; /* Paper size name from libpaper */ | |
1049 | ||
1050 | if ((paper_result = systempapername()) != NULL) | |
1051 | cupsdSetString(&DefaultPaperSize, paper_result); | |
1052 | else | |
1053 | #endif /* HAVE_LIBPAPER */ | |
1054 | if (!DefaultLanguage || | |
1055 | !strcasecmp(DefaultLanguage, "C") || | |
1056 | !strcasecmp(DefaultLanguage, "POSIX") || | |
1057 | !strcasecmp(DefaultLanguage, "en") || | |
1058 | !strncasecmp(DefaultLanguage, "en.", 3) || | |
1059 | !strncasecmp(DefaultLanguage, "en_US", 5) || | |
1060 | !strncasecmp(DefaultLanguage, "en_CA", 5) || | |
1061 | !strncasecmp(DefaultLanguage, "fr_CA", 5)) | |
1062 | { | |
1063 | /* | |
1064 | * These are the only locales that will default to "letter" size... | |
1065 | */ | |
1066 | ||
1067 | cupsdSetString(&DefaultPaperSize, "Letter"); | |
1068 | } | |
1069 | else | |
1070 | cupsdSetString(&DefaultPaperSize, "A4"); | |
1071 | } | |
1072 | ||
1073 | /* | |
1074 | * Update classification setting as needed... | |
1075 | */ | |
1076 | ||
1077 | if (Classification && !strcasecmp(Classification, "none")) | |
1078 | cupsdClearString(&Classification); | |
1079 | ||
1080 | if (Classification) | |
1081 | cupsdLogMessage(CUPSD_LOG_INFO, "Security set to \"%s\"", Classification); | |
1082 | ||
ef416fc2 | 1083 | /* |
1084 | * Check the MaxClients setting, and then allocate memory for it... | |
1085 | */ | |
1086 | ||
1087 | if (MaxClients > (MaxFDs / 3) || MaxClients <= 0) | |
1088 | { | |
1089 | if (MaxClients > 0) | |
49d87452 MS |
1090 | cupsdLogMessage(CUPSD_LOG_INFO, |
1091 | "MaxClients limited to 1/3 (%d) of the file descriptor " | |
1092 | "limit (%d)...", | |
1093 | MaxFDs / 3, MaxFDs); | |
ef416fc2 | 1094 | |
1095 | MaxClients = MaxFDs / 3; | |
1096 | } | |
1097 | ||
bd7854cb | 1098 | cupsdLogMessage(CUPSD_LOG_INFO, "Configured for up to %d clients.", |
1099 | MaxClients); | |
ef416fc2 | 1100 | |
1101 | /* | |
1102 | * Check the MaxActiveJobs setting; limit to 1/3 the available | |
1103 | * file descriptors, since we need a pipe for each job... | |
1104 | */ | |
1105 | ||
1106 | if (MaxActiveJobs > (MaxFDs / 3)) | |
1107 | MaxActiveJobs = MaxFDs / 3; | |
1108 | ||
ef416fc2 | 1109 | /* |
1110 | * Update the MaxClientsPerHost value, as needed... | |
1111 | */ | |
1112 | ||
1113 | if (MaxClientsPerHost <= 0) | |
1114 | MaxClientsPerHost = MaxClients; | |
1115 | ||
1116 | if (MaxClientsPerHost > MaxClients) | |
1117 | MaxClientsPerHost = MaxClients; | |
1118 | ||
1119 | cupsdLogMessage(CUPSD_LOG_INFO, | |
1120 | "Allowing up to %d client connections per host.", | |
1121 | MaxClientsPerHost); | |
1122 | ||
8ca02f3c | 1123 | /* |
1124 | * Make sure that BrowseTimeout is at least twice the interval... | |
1125 | */ | |
1126 | ||
1127 | if (BrowseTimeout < (2 * BrowseInterval) || BrowseTimeout <= 0) | |
1128 | { | |
1129 | cupsdLogMessage(CUPSD_LOG_ALERT, "Invalid BrowseTimeout value %d!", | |
1130 | BrowseTimeout); | |
1131 | ||
1132 | if (BrowseInterval) | |
1133 | BrowseTimeout = BrowseInterval * 2; | |
1134 | else | |
1135 | BrowseTimeout = DEFAULT_TIMEOUT; | |
1136 | ||
1137 | cupsdLogMessage(CUPSD_LOG_ALERT, "Reset BrowseTimeout to %d!", | |
1138 | BrowseTimeout); | |
1139 | } | |
1140 | ||
ef416fc2 | 1141 | /* |
1142 | * Update the default policy, as needed... | |
1143 | */ | |
1144 | ||
1145 | if (DefaultPolicy) | |
1146 | DefaultPolicyPtr = cupsdFindPolicy(DefaultPolicy); | |
1147 | else | |
1148 | DefaultPolicyPtr = NULL; | |
1149 | ||
1150 | if (!DefaultPolicyPtr) | |
1151 | { | |
ef416fc2 | 1152 | cupsd_location_t *po; /* New policy operation */ |
1153 | ||
1154 | ||
1155 | if (DefaultPolicy) | |
1156 | cupsdLogMessage(CUPSD_LOG_ERROR, "Default policy \"%s\" not found!", | |
1157 | DefaultPolicy); | |
1158 | ||
e1d6a774 | 1159 | cupsdSetString(&DefaultPolicy, "default"); |
1160 | ||
ef416fc2 | 1161 | if ((DefaultPolicyPtr = cupsdFindPolicy("default")) != NULL) |
1162 | cupsdLogMessage(CUPSD_LOG_INFO, | |
1163 | "Using policy \"default\" as the default!"); | |
1164 | else | |
1165 | { | |
1166 | cupsdLogMessage(CUPSD_LOG_INFO, | |
1167 | "Creating CUPS default administrative policy:"); | |
1168 | ||
1169 | DefaultPolicyPtr = p = cupsdAddPolicy("default"); | |
1170 | ||
1171 | cupsdLogMessage(CUPSD_LOG_INFO, "<Policy default>"); | |
1172 | cupsdLogMessage(CUPSD_LOG_INFO, | |
1173 | "<Limit Send-Document Send-URI Cancel-Job Hold-Job " | |
1174 | "Release-Job Restart-Job Purge-Jobs " | |
1175 | "Set-Job-Attributes Create-Job-Subscription " | |
1176 | "Renew-Subscription Cancel-Subscription " | |
1177 | "Get-Notifications Reprocess-Job Cancel-Current-Job " | |
1178 | "Suspend-Current-Job Resume-Job CUPS-Move-Job " | |
2e4ff8af | 1179 | "CUPS-Authenticate-Job CUPS-Get-Document>"); |
ef416fc2 | 1180 | cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow"); |
1181 | ||
1182 | po = cupsdAddPolicyOp(p, NULL, IPP_SEND_DOCUMENT); | |
5bd77a73 MS |
1183 | po->order_type = CUPSD_AUTH_ALLOW; |
1184 | po->level = CUPSD_AUTH_USER; | |
ef416fc2 | 1185 | |
1186 | cupsdAddName(po, "@OWNER"); | |
1187 | cupsdAddName(po, "@SYSTEM"); | |
1188 | cupsdLogMessage(CUPSD_LOG_INFO, "Require user @OWNER @SYSTEM"); | |
1189 | ||
1190 | cupsdAddPolicyOp(p, po, IPP_SEND_URI); | |
1191 | cupsdAddPolicyOp(p, po, IPP_CANCEL_JOB); | |
1192 | cupsdAddPolicyOp(p, po, IPP_HOLD_JOB); | |
1193 | cupsdAddPolicyOp(p, po, IPP_RELEASE_JOB); | |
1194 | cupsdAddPolicyOp(p, po, IPP_RESTART_JOB); | |
1195 | cupsdAddPolicyOp(p, po, IPP_PURGE_JOBS); | |
1196 | cupsdAddPolicyOp(p, po, IPP_SET_JOB_ATTRIBUTES); | |
1197 | cupsdAddPolicyOp(p, po, IPP_CREATE_JOB_SUBSCRIPTION); | |
1198 | cupsdAddPolicyOp(p, po, IPP_RENEW_SUBSCRIPTION); | |
1199 | cupsdAddPolicyOp(p, po, IPP_CANCEL_SUBSCRIPTION); | |
1200 | cupsdAddPolicyOp(p, po, IPP_GET_NOTIFICATIONS); | |
1201 | cupsdAddPolicyOp(p, po, IPP_REPROCESS_JOB); | |
1202 | cupsdAddPolicyOp(p, po, IPP_CANCEL_CURRENT_JOB); | |
1203 | cupsdAddPolicyOp(p, po, IPP_SUSPEND_CURRENT_JOB); | |
1204 | cupsdAddPolicyOp(p, po, IPP_RESUME_JOB); | |
1205 | cupsdAddPolicyOp(p, po, CUPS_MOVE_JOB); | |
1206 | cupsdAddPolicyOp(p, po, CUPS_AUTHENTICATE_JOB); | |
2e4ff8af | 1207 | cupsdAddPolicyOp(p, po, CUPS_GET_DOCUMENT); |
ef416fc2 | 1208 | |
1209 | cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>"); | |
1210 | ||
1211 | cupsdLogMessage(CUPSD_LOG_INFO, | |
1212 | "<Limit Pause-Printer Resume-Printer " | |
1213 | "Set-Printer-Attributes Enable-Printer " | |
1214 | "Disable-Printer Pause-Printer-After-Current-Job " | |
1215 | "Hold-New-Jobs Release-Held-New-Jobs " | |
1216 | "Deactivate-Printer Activate-Printer Restart-Printer " | |
1217 | "Shutdown-Printer Startup-Printer Promote-Job " | |
1218 | "Schedule-Job-After CUPS-Add-Printer " | |
1219 | "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class " | |
1220 | "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>"); | |
1221 | cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow"); | |
bc44d920 | 1222 | cupsdLogMessage(CUPSD_LOG_INFO, "AuthType Default"); |
ef416fc2 | 1223 | |
1224 | po = cupsdAddPolicyOp(p, NULL, IPP_PAUSE_PRINTER); | |
5bd77a73 MS |
1225 | po->order_type = CUPSD_AUTH_ALLOW; |
1226 | po->type = CUPSD_AUTH_DEFAULT; | |
1227 | po->level = CUPSD_AUTH_USER; | |
ef416fc2 | 1228 | |
1229 | cupsdAddName(po, "@SYSTEM"); | |
1230 | cupsdLogMessage(CUPSD_LOG_INFO, "Require user @SYSTEM"); | |
1231 | ||
1232 | cupsdAddPolicyOp(p, po, IPP_RESUME_PRINTER); | |
1233 | cupsdAddPolicyOp(p, po, IPP_SET_PRINTER_ATTRIBUTES); | |
1234 | cupsdAddPolicyOp(p, po, IPP_ENABLE_PRINTER); | |
1235 | cupsdAddPolicyOp(p, po, IPP_DISABLE_PRINTER); | |
1236 | cupsdAddPolicyOp(p, po, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB); | |
1237 | cupsdAddPolicyOp(p, po, IPP_HOLD_NEW_JOBS); | |
1238 | cupsdAddPolicyOp(p, po, IPP_RELEASE_HELD_NEW_JOBS); | |
1239 | cupsdAddPolicyOp(p, po, IPP_DEACTIVATE_PRINTER); | |
1240 | cupsdAddPolicyOp(p, po, IPP_ACTIVATE_PRINTER); | |
1241 | cupsdAddPolicyOp(p, po, IPP_RESTART_PRINTER); | |
1242 | cupsdAddPolicyOp(p, po, IPP_SHUTDOWN_PRINTER); | |
1243 | cupsdAddPolicyOp(p, po, IPP_STARTUP_PRINTER); | |
1244 | cupsdAddPolicyOp(p, po, IPP_PROMOTE_JOB); | |
1245 | cupsdAddPolicyOp(p, po, IPP_SCHEDULE_JOB_AFTER); | |
1246 | cupsdAddPolicyOp(p, po, CUPS_ADD_PRINTER); | |
1247 | cupsdAddPolicyOp(p, po, CUPS_DELETE_PRINTER); | |
1248 | cupsdAddPolicyOp(p, po, CUPS_ADD_CLASS); | |
1249 | cupsdAddPolicyOp(p, po, CUPS_DELETE_CLASS); | |
1250 | cupsdAddPolicyOp(p, po, CUPS_ACCEPT_JOBS); | |
1251 | cupsdAddPolicyOp(p, po, CUPS_REJECT_JOBS); | |
1252 | cupsdAddPolicyOp(p, po, CUPS_SET_DEFAULT); | |
1253 | ||
1254 | cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>"); | |
1255 | ||
1256 | cupsdLogMessage(CUPSD_LOG_INFO, "<Limit All>"); | |
1257 | cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow"); | |
1258 | ||
1259 | po = cupsdAddPolicyOp(p, NULL, IPP_ANY_OPERATION); | |
5bd77a73 | 1260 | po->order_type = CUPSD_AUTH_ALLOW; |
ef416fc2 | 1261 | |
1262 | cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>"); | |
1263 | cupsdLogMessage(CUPSD_LOG_INFO, "</Policy>"); | |
1264 | } | |
1265 | } | |
1266 | ||
bd7854cb | 1267 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: NumPolicies=%d", |
2e4ff8af MS |
1268 | cupsArrayCount(Policies)); |
1269 | for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies); | |
1270 | p; | |
1271 | i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies)) | |
bd7854cb | 1272 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
2e4ff8af | 1273 | "cupsdReadConfiguration: Policies[%d]=\"%s\"", i, p->name); |
ef416fc2 | 1274 | |
1275 | /* | |
1276 | * If we are doing a full reload or the server root has changed, flush | |
1277 | * the jobs, printers, etc. and start from scratch... | |
1278 | */ | |
1279 | ||
1280 | if (NeedReload == RELOAD_ALL || | |
f11a948a | 1281 | old_remote_port != RemotePort || |
ef416fc2 | 1282 | !old_serverroot || !ServerRoot || strcmp(old_serverroot, ServerRoot) || |
1283 | !old_requestroot || !RequestRoot || strcmp(old_requestroot, RequestRoot)) | |
1284 | { | |
fa73b229 | 1285 | mime_type_t *type; /* Current type */ |
1286 | char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE]; | |
1287 | /* MIME type name */ | |
1288 | ||
1289 | ||
ef416fc2 | 1290 | cupsdLogMessage(CUPSD_LOG_INFO, "Full reload is required."); |
1291 | ||
1292 | /* | |
1293 | * Free all memory... | |
1294 | */ | |
1295 | ||
1296 | cupsdDeleteAllSubscriptions(); | |
1297 | cupsdFreeAllJobs(); | |
ef416fc2 | 1298 | cupsdDeleteAllPrinters(); |
1299 | ||
1300 | DefaultPrinter = NULL; | |
1301 | ||
1302 | if (MimeDatabase != NULL) | |
1303 | mimeDelete(MimeDatabase); | |
1304 | ||
1305 | if (NumMimeTypes) | |
1306 | { | |
1307 | for (i = 0; i < NumMimeTypes; i ++) | |
757d2cad | 1308 | _cupsStrFree(MimeTypes[i]); |
ef416fc2 | 1309 | |
1310 | free(MimeTypes); | |
1311 | } | |
1312 | ||
1313 | /* | |
1314 | * Read the MIME type and conversion database... | |
1315 | */ | |
1316 | ||
1317 | snprintf(temp, sizeof(temp), "%s/filter", ServerBin); | |
dd1abb6b | 1318 | snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir); |
ef416fc2 | 1319 | |
75bd9771 MS |
1320 | MimeDatabase = mimeLoadTypes(NULL, mimedir); |
1321 | MimeDatabase = mimeLoadTypes(MimeDatabase, ServerRoot); | |
1322 | MimeDatabase = mimeLoadFilters(MimeDatabase, mimedir, temp); | |
1323 | MimeDatabase = mimeLoadFilters(MimeDatabase, ServerRoot, temp); | |
ef416fc2 | 1324 | |
1325 | if (!MimeDatabase) | |
1326 | { | |
1327 | cupsdLogMessage(CUPSD_LOG_EMERG, | |
75bd9771 MS |
1328 | "Unable to load MIME database from \"%s\" or \"%s\"!", |
1329 | mimedir, ServerRoot); | |
49d87452 MS |
1330 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
1331 | return (0); | |
ef416fc2 | 1332 | } |
1333 | ||
1334 | cupsdLogMessage(CUPSD_LOG_INFO, | |
75bd9771 MS |
1335 | "Loaded MIME database from \"%s\" and \"%s\": %d types, " |
1336 | "%d filters...", mimedir, ServerRoot, | |
1337 | mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase)); | |
ef416fc2 | 1338 | |
1339 | /* | |
1340 | * Create a list of MIME types for the document-format-supported | |
1341 | * attribute... | |
1342 | */ | |
1343 | ||
fa73b229 | 1344 | NumMimeTypes = mimeNumTypes(MimeDatabase); |
ef416fc2 | 1345 | if (!mimeType(MimeDatabase, "application", "octet-stream")) |
1346 | NumMimeTypes ++; | |
1347 | ||
91c84a35 | 1348 | if ((MimeTypes = calloc(NumMimeTypes, sizeof(const char *))) == NULL) |
ef416fc2 | 1349 | { |
91c84a35 MS |
1350 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1351 | "Unable to allocate memory for %d MIME types!", | |
1352 | NumMimeTypes); | |
1353 | NumMimeTypes = 0; | |
ef416fc2 | 1354 | } |
91c84a35 MS |
1355 | else |
1356 | { | |
1357 | for (i = 0, type = mimeFirstType(MimeDatabase); | |
1358 | type; | |
1359 | i ++, type = mimeNextType(MimeDatabase)) | |
1360 | { | |
1361 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); | |
1362 | ||
1363 | MimeTypes[i] = _cupsStrAlloc(mimetype); | |
1364 | } | |
ef416fc2 | 1365 | |
91c84a35 MS |
1366 | if (i < NumMimeTypes) |
1367 | MimeTypes[i] = _cupsStrAlloc("application/octet-stream"); | |
1368 | } | |
bd7854cb | 1369 | |
1370 | if (LogLevel == CUPSD_LOG_DEBUG2) | |
1371 | { | |
1372 | mime_filter_t *filter; /* Current filter */ | |
1373 | ||
1374 | ||
1375 | for (type = mimeFirstType(MimeDatabase); | |
1376 | type; | |
1377 | type = mimeNextType(MimeDatabase)) | |
1378 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: type %s/%s", | |
1379 | type->super, type->type); | |
1380 | ||
1381 | for (filter = mimeFirstFilter(MimeDatabase); | |
1382 | filter; | |
1383 | filter = mimeNextFilter(MimeDatabase)) | |
1384 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
1385 | "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s", | |
1386 | filter->src->super, filter->src->type, | |
1387 | filter->dst->super, filter->dst->type, | |
1388 | filter->cost, filter->filter); | |
1389 | } | |
ef416fc2 | 1390 | |
1391 | /* | |
1392 | * Load banners... | |
1393 | */ | |
1394 | ||
1395 | snprintf(temp, sizeof(temp), "%s/banners", DataDir); | |
1396 | cupsdLoadBanners(temp); | |
1397 | ||
1398 | /* | |
1399 | * Load printers and classes... | |
1400 | */ | |
1401 | ||
1402 | cupsdLoadAllPrinters(); | |
1403 | cupsdLoadAllClasses(); | |
1404 | cupsdLoadRemoteCache(); | |
3dfe78b3 | 1405 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); |
ef416fc2 | 1406 | |
1407 | cupsdCreateCommonData(); | |
1408 | ||
1409 | /* | |
1410 | * Load queued jobs... | |
1411 | */ | |
1412 | ||
1413 | cupsdLoadAllJobs(); | |
1414 | ||
1415 | /* | |
1416 | * Load subscriptions... | |
1417 | */ | |
1418 | ||
1419 | cupsdLoadAllSubscriptions(); | |
1420 | ||
1421 | cupsdLogMessage(CUPSD_LOG_INFO, "Full reload complete."); | |
1422 | } | |
1423 | else | |
1424 | { | |
1425 | /* | |
1426 | * Not a full reload, so recreate the common printer attributes... | |
1427 | */ | |
1428 | ||
1429 | cupsdCreateCommonData(); | |
1430 | ||
1431 | /* | |
1432 | * Update all printers as needed... | |
1433 | */ | |
1434 | ||
1435 | cupsdUpdatePrinters(); | |
3dfe78b3 | 1436 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); |
ef416fc2 | 1437 | |
1438 | cupsdLogMessage(CUPSD_LOG_INFO, "Partial reload complete."); | |
1439 | } | |
1440 | ||
1441 | /* | |
1442 | * Reset the reload state... | |
1443 | */ | |
1444 | ||
1445 | NeedReload = RELOAD_NONE; | |
1446 | ||
1447 | cupsdClearString(&old_serverroot); | |
1448 | cupsdClearString(&old_requestroot); | |
1449 | ||
ef416fc2 | 1450 | return (1); |
1451 | } | |
1452 | ||
1453 | ||
1454 | /* | |
1455 | * 'get_address()' - Get an address + port number from a line. | |
1456 | */ | |
1457 | ||
1458 | static http_addrlist_t * /* O - Pointer to list if address good, NULL if bad */ | |
1459 | get_address(const char *value, /* I - Value string */ | |
1460 | int defport) /* I - Default port */ | |
1461 | { | |
1462 | char buffer[1024], /* Hostname + port number buffer */ | |
1463 | defpname[255], /* Default port name */ | |
1464 | *hostname, /* Hostname or IP */ | |
1465 | *portname; /* Port number or name */ | |
1466 | http_addrlist_t *addrlist; /* Address list */ | |
1467 | ||
1468 | ||
1469 | /* | |
1470 | * Check for an empty value... | |
1471 | */ | |
1472 | ||
1473 | if (!*value) | |
1474 | { | |
1475 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad (empty) address!"); | |
1476 | return (NULL); | |
1477 | } | |
1478 | ||
1479 | /* | |
1480 | * Grab a hostname and port number; if there is no colon and the port name | |
1481 | * is only digits, then we have a port number by itself... | |
1482 | */ | |
1483 | ||
1484 | strlcpy(buffer, value, sizeof(buffer)); | |
1485 | ||
1486 | if ((portname = strrchr(buffer, ':')) != NULL && !strchr(portname, ']')) | |
1487 | { | |
1488 | *portname++ = '\0'; | |
1489 | hostname = buffer; | |
1490 | } | |
1491 | else | |
1492 | { | |
1493 | for (portname = buffer; isdigit(*portname & 255); portname ++); | |
1494 | ||
1495 | if (*portname) | |
1496 | { | |
1497 | /* | |
1498 | * Use the default port... | |
1499 | */ | |
1500 | ||
1501 | sprintf(defpname, "%d", defport); | |
1502 | portname = defpname; | |
1503 | hostname = buffer; | |
1504 | } | |
1505 | else | |
1506 | { | |
1507 | /* | |
1508 | * The buffer contains just a port number... | |
1509 | */ | |
1510 | ||
1511 | portname = buffer; | |
1512 | hostname = NULL; | |
1513 | } | |
1514 | } | |
1515 | ||
1516 | if (hostname && !strcmp(hostname, "*")) | |
1517 | hostname = NULL; | |
1518 | ||
1519 | /* | |
1520 | * Now lookup the address using httpAddrGetList()... | |
1521 | */ | |
1522 | ||
1523 | if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) == NULL) | |
1524 | cupsdLogMessage(CUPSD_LOG_ERROR, "Hostname lookup for \"%s\" failed!", | |
1525 | hostname ? hostname : "(nil)"); | |
1526 | ||
1527 | return (addrlist); | |
1528 | } | |
1529 | ||
1530 | ||
1531 | /* | |
1532 | * 'get_addr_and_mask()' - Get an IP address and netmask. | |
1533 | */ | |
1534 | ||
1535 | static int /* O - 1 on success, 0 on failure */ | |
1536 | get_addr_and_mask(const char *value, /* I - String from config file */ | |
1537 | unsigned *ip, /* O - Address value */ | |
1538 | unsigned *mask) /* O - Mask value */ | |
1539 | { | |
1540 | int i, j, /* Looping vars */ | |
1541 | family, /* Address family */ | |
1542 | ipcount; /* Count of fields in address */ | |
1543 | unsigned ipval; /* Value */ | |
1544 | const char *maskval, /* Pointer to start of mask value */ | |
1545 | *ptr, /* Pointer into value */ | |
1546 | *ptr2; /* ... */ | |
ef416fc2 | 1547 | |
1548 | ||
1549 | /* | |
1550 | * Get the address... | |
1551 | */ | |
1552 | ||
b86bc4cf | 1553 | ip[0] = ip[1] = ip[2] = ip[3] = 0x00000000; |
ed486911 | 1554 | mask[0] = mask[1] = mask[2] = mask[3] = 0xffffffff; |
ef416fc2 | 1555 | |
1556 | if ((maskval = strchr(value, '/')) != NULL) | |
1557 | maskval ++; | |
1558 | else | |
1559 | maskval = value + strlen(value); | |
1560 | ||
1561 | #ifdef AF_INET6 | |
1562 | /* | |
1563 | * Check for an IPv6 address... | |
1564 | */ | |
1565 | ||
1566 | if (*value == '[') | |
1567 | { | |
1568 | /* | |
1569 | * Parse hexadecimal IPv6 address... | |
1570 | */ | |
1571 | ||
1572 | family = AF_INET6; | |
1573 | ||
1574 | for (i = 0, ptr = value + 1; *ptr && i < 8; i ++) | |
1575 | { | |
1576 | if (*ptr == ']') | |
1577 | break; | |
1578 | else if (!strncmp(ptr, "::", 2)) | |
1579 | { | |
1580 | for (ptr2 = strchr(ptr + 2, ':'), j = 0; | |
1581 | ptr2; | |
1582 | ptr2 = strchr(ptr2 + 1, ':'), j ++); | |
1583 | ||
1584 | i = 7 - j; | |
ed486911 | 1585 | ptr ++; |
ef416fc2 | 1586 | } |
1587 | else if (isxdigit(*ptr & 255)) | |
1588 | { | |
1589 | ipval = strtoul(ptr, (char **)&ptr, 16); | |
1590 | ||
1591 | if (ipval > 0xffff) | |
1592 | return (0); | |
1593 | ||
1594 | if (i & 1) | |
ed486911 | 1595 | ip[i / 2] |= ipval; |
ef416fc2 | 1596 | else |
ed486911 | 1597 | ip[i / 2] |= ipval << 16; |
ef416fc2 | 1598 | } |
1599 | else | |
1600 | return (0); | |
1601 | ||
1602 | while (*ptr == ':') | |
1603 | ptr ++; | |
1604 | } | |
1605 | ||
ed486911 | 1606 | if (*ptr != ']') |
1607 | return (0); | |
1608 | ||
1609 | ptr ++; | |
ef416fc2 | 1610 | |
1611 | if (*ptr && *ptr != '/') | |
1612 | return (0); | |
1613 | } | |
1614 | else | |
1615 | #endif /* AF_INET6 */ | |
1616 | { | |
1617 | /* | |
1618 | * Parse dotted-decimal IPv4 address... | |
1619 | */ | |
1620 | ||
ed486911 | 1621 | unsigned val[4]; /* IPv4 address values */ |
ef416fc2 | 1622 | |
ef416fc2 | 1623 | |
ed486911 | 1624 | family = AF_INET; |
1625 | ipcount = sscanf(value, "%u.%u.%u.%u", val + 0, val + 1, val + 2, val + 3); | |
1626 | ||
ef416fc2 | 1627 | /* |
ed486911 | 1628 | * Range check the IP numbers... |
ef416fc2 | 1629 | */ |
1630 | ||
ed486911 | 1631 | for (i = 0; i < ipcount; i ++) |
1632 | if (val[i] > 255) | |
1633 | return (0); | |
ef416fc2 | 1634 | |
ed486911 | 1635 | /* |
1636 | * Make sure the trailing values are zeroed, as some C libraries like | |
1637 | * glibc apparently like to fill the unused arguments with garbage... | |
1638 | */ | |
ef416fc2 | 1639 | |
ed486911 | 1640 | for (i = ipcount; i < 4; i ++) |
1641 | val[i] = 0; | |
ef416fc2 | 1642 | |
ed486911 | 1643 | /* |
1644 | * Merge everything into a 32-bit IPv4 address in ip[3]... | |
1645 | */ | |
ef416fc2 | 1646 | |
ed486911 | 1647 | ip[3] = (((((val[0] << 8) | val[1]) << 8) | val[2]) << 8) | val[3]; |
ef416fc2 | 1648 | |
ed486911 | 1649 | if (ipcount < 4) |
1650 | mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff; | |
1651 | } | |
ef416fc2 | 1652 | |
ed486911 | 1653 | if (*maskval) |
1654 | { | |
1655 | /* | |
1656 | * Get the netmask value(s)... | |
1657 | */ | |
1658 | ||
1659 | memset(mask, 0, sizeof(unsigned) * 4); | |
ef416fc2 | 1660 | |
ef416fc2 | 1661 | if (strchr(maskval, '.')) |
1662 | { | |
1663 | /* | |
1664 | * Get dotted-decimal mask... | |
1665 | */ | |
1666 | ||
ed486911 | 1667 | if (family != AF_INET) |
1668 | return (0); | |
1669 | ||
ef416fc2 | 1670 | if (sscanf(maskval, "%u.%u.%u.%u", mask + 0, mask + 1, mask + 2, mask + 3) != 4) |
1671 | return (0); | |
1672 | ||
1673 | mask[3] |= ((((mask[0] << 8) | mask[1]) << 8) | mask[2]) << 8; | |
1674 | mask[0] = mask[1] = mask[2] = 0; | |
1675 | } | |
1676 | else | |
1677 | { | |
1678 | /* | |
1679 | * Get address/bits format... | |
1680 | */ | |
1681 | ||
1682 | i = atoi(maskval); | |
1683 | ||
1684 | #ifdef AF_INET6 | |
1685 | if (family == AF_INET6) | |
1686 | { | |
ed486911 | 1687 | if (i > 128) |
1688 | return (0); | |
1689 | ||
ef416fc2 | 1690 | i = 128 - i; |
1691 | ||
1692 | if (i <= 96) | |
1693 | mask[0] = 0xffffffff; | |
1694 | else | |
1695 | mask[0] = (0xffffffff << (i - 96)) & 0xffffffff; | |
1696 | ||
1697 | if (i <= 64) | |
1698 | mask[1] = 0xffffffff; | |
1699 | else if (i >= 96) | |
1700 | mask[1] = 0; | |
1701 | else | |
1702 | mask[1] = (0xffffffff << (i - 64)) & 0xffffffff; | |
1703 | ||
1704 | if (i <= 32) | |
1705 | mask[2] = 0xffffffff; | |
1706 | else if (i >= 64) | |
1707 | mask[2] = 0; | |
1708 | else | |
1709 | mask[2] = (0xffffffff << (i - 32)) & 0xffffffff; | |
1710 | ||
1711 | if (i == 0) | |
1712 | mask[3] = 0xffffffff; | |
1713 | else if (i >= 32) | |
1714 | mask[3] = 0; | |
1715 | else | |
1716 | mask[3] = (0xffffffff << i) & 0xffffffff; | |
1717 | } | |
1718 | else | |
1719 | #endif /* AF_INET6 */ | |
1720 | { | |
ed486911 | 1721 | if (i > 32) |
1722 | return (0); | |
ef416fc2 | 1723 | |
1724 | mask[0] = 0xffffffff; | |
1725 | mask[1] = 0xffffffff; | |
1726 | mask[2] = 0xffffffff; | |
1727 | ||
ed486911 | 1728 | if (i < 32) |
1729 | mask[3] = (0xffffffff << (32 - i)) & 0xffffffff; | |
ef416fc2 | 1730 | else |
1731 | mask[3] = 0xffffffff; | |
1732 | } | |
1733 | } | |
1734 | } | |
ef416fc2 | 1735 | |
1736 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
1737 | "get_addr_and_mask(value=\"%s\", " | |
b86bc4cf | 1738 | "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])", |
ef416fc2 | 1739 | value, ip[0], ip[1], ip[2], ip[3], mask[0], mask[1], mask[2], |
1740 | mask[3]); | |
1741 | ||
1742 | /* | |
1743 | * Check for a valid netmask; no fallback like in CUPS 1.1.x! | |
1744 | */ | |
1745 | ||
1746 | if ((ip[0] & ~mask[0]) != 0 || | |
1747 | (ip[1] & ~mask[1]) != 0 || | |
1748 | (ip[2] & ~mask[2]) != 0 || | |
1749 | (ip[3] & ~mask[3]) != 0) | |
1750 | return (0); | |
1751 | ||
1752 | return (1); | |
1753 | } | |
1754 | ||
1755 | ||
1756 | /* | |
1757 | * 'parse_aaa()' - Parse authentication, authorization, and access control lines. | |
1758 | */ | |
1759 | ||
1760 | static int /* O - 1 on success, 0 on failure */ | |
1761 | parse_aaa(cupsd_location_t *loc, /* I - Location */ | |
1762 | char *line, /* I - Line from file */ | |
1763 | char *value, /* I - Start of value data */ | |
1764 | int linenum) /* I - Current line number */ | |
1765 | { | |
1766 | char *valptr; /* Pointer into value */ | |
1767 | unsigned ip[4], /* IP address components */ | |
1768 | mask[4]; /* IP netmask components */ | |
1769 | ||
1770 | ||
1771 | if (!strcasecmp(line, "Encryption")) | |
1772 | { | |
1773 | /* | |
1774 | * "Encryption xxx" - set required encryption level... | |
1775 | */ | |
1776 | ||
1777 | if (!strcasecmp(value, "never")) | |
1778 | loc->encryption = HTTP_ENCRYPT_NEVER; | |
1779 | else if (!strcasecmp(value, "always")) | |
1780 | { | |
1781 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1782 | "Encryption value \"%s\" on line %d is invalid in this " | |
1783 | "context. Using \"required\" instead.", value, linenum); | |
1784 | ||
1785 | loc->encryption = HTTP_ENCRYPT_REQUIRED; | |
1786 | } | |
1787 | else if (!strcasecmp(value, "required")) | |
1788 | loc->encryption = HTTP_ENCRYPT_REQUIRED; | |
1789 | else if (!strcasecmp(value, "ifrequested")) | |
1790 | loc->encryption = HTTP_ENCRYPT_IF_REQUESTED; | |
1791 | else | |
1792 | { | |
1793 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1794 | "Unknown Encryption value %s on line %d.", value, linenum); | |
1795 | return (0); | |
1796 | } | |
1797 | } | |
1798 | else if (!strcasecmp(line, "Order")) | |
1799 | { | |
1800 | /* | |
1801 | * "Order Deny,Allow" or "Order Allow,Deny"... | |
1802 | */ | |
1803 | ||
1804 | if (!strncasecmp(value, "deny", 4)) | |
5bd77a73 | 1805 | loc->order_type = CUPSD_AUTH_ALLOW; |
ef416fc2 | 1806 | else if (!strncasecmp(value, "allow", 5)) |
5bd77a73 | 1807 | loc->order_type = CUPSD_AUTH_DENY; |
ef416fc2 | 1808 | else |
1809 | { | |
1810 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown Order value %s on line %d.", | |
1811 | value, linenum); | |
1812 | return (0); | |
1813 | } | |
1814 | } | |
1815 | else if (!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny")) | |
1816 | { | |
1817 | /* | |
1818 | * Allow [From] host/ip... | |
1819 | * Deny [From] host/ip... | |
1820 | */ | |
1821 | ||
0af14961 | 1822 | while (*value) |
ef416fc2 | 1823 | { |
0af14961 MS |
1824 | if (!strncasecmp(value, "from", 4)) |
1825 | { | |
1826 | /* | |
1827 | * Strip leading "from"... | |
1828 | */ | |
ef416fc2 | 1829 | |
0af14961 | 1830 | value += 4; |
ef416fc2 | 1831 | |
0af14961 MS |
1832 | while (isspace(*value & 255)) |
1833 | value ++; | |
ef416fc2 | 1834 | |
0af14961 MS |
1835 | if (!*value) |
1836 | break; | |
1837 | } | |
ef416fc2 | 1838 | |
ef416fc2 | 1839 | /* |
0af14961 | 1840 | * Find the end of the value... |
ef416fc2 | 1841 | */ |
1842 | ||
0af14961 MS |
1843 | for (valptr = value; *valptr && !isspace(*valptr & 255); valptr ++); |
1844 | ||
1845 | while (isspace(*valptr & 255)) | |
1846 | *valptr++ = '\0'; | |
1847 | ||
ef416fc2 | 1848 | /* |
0af14961 MS |
1849 | * Figure out what form the allow/deny address takes: |
1850 | * | |
1851 | * All | |
1852 | * None | |
1853 | * *.domain.com | |
1854 | * .domain.com | |
1855 | * host.domain.com | |
1856 | * nnn.* | |
1857 | * nnn.nnn.* | |
1858 | * nnn.nnn.nnn.* | |
1859 | * nnn.nnn.nnn.nnn | |
1860 | * nnn.nnn.nnn.nnn/mm | |
1861 | * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm | |
ef416fc2 | 1862 | */ |
1863 | ||
0af14961 MS |
1864 | if (!strcasecmp(value, "all")) |
1865 | { | |
1866 | /* | |
1867 | * All hosts... | |
1868 | */ | |
1869 | ||
1870 | if (!strcasecmp(line, "Allow")) | |
1871 | cupsdAllowIP(loc, zeros, zeros); | |
1872 | else | |
1873 | cupsdDenyIP(loc, zeros, zeros); | |
1874 | } | |
1875 | else if (!strcasecmp(value, "none")) | |
1876 | { | |
1877 | /* | |
1878 | * No hosts... | |
1879 | */ | |
1880 | ||
1881 | if (!strcasecmp(line, "Allow")) | |
1882 | cupsdAllowIP(loc, ones, zeros); | |
1883 | else | |
1884 | cupsdDenyIP(loc, ones, zeros); | |
1885 | } | |
ed486911 | 1886 | #ifdef AF_INET6 |
0af14961 MS |
1887 | else if (value[0] == '*' || value[0] == '.' || |
1888 | (!isdigit(value[0] & 255) && value[0] != '[')) | |
ed486911 | 1889 | #else |
0af14961 | 1890 | else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255)) |
ed486911 | 1891 | #endif /* AF_INET6 */ |
0af14961 MS |
1892 | { |
1893 | /* | |
1894 | * Host or domain name... | |
1895 | */ | |
ef416fc2 | 1896 | |
0af14961 MS |
1897 | if (value[0] == '*') |
1898 | value ++; | |
ef416fc2 | 1899 | |
0af14961 MS |
1900 | if (!strcasecmp(line, "Allow")) |
1901 | cupsdAllowHost(loc, value); | |
1902 | else | |
1903 | cupsdDenyHost(loc, value); | |
1904 | } | |
ef416fc2 | 1905 | else |
ef416fc2 | 1906 | { |
0af14961 MS |
1907 | /* |
1908 | * One of many IP address forms... | |
1909 | */ | |
1910 | ||
1911 | if (!get_addr_and_mask(value, ip, mask)) | |
1912 | { | |
1913 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.", | |
1914 | value, linenum); | |
1915 | return (0); | |
1916 | } | |
1917 | ||
1918 | if (!strcasecmp(line, "Allow")) | |
1919 | cupsdAllowIP(loc, ip, mask); | |
1920 | else | |
1921 | cupsdDenyIP(loc, ip, mask); | |
ef416fc2 | 1922 | } |
1923 | ||
0af14961 MS |
1924 | /* |
1925 | * Advance to next value... | |
1926 | */ | |
1927 | ||
1928 | value = valptr; | |
ef416fc2 | 1929 | } |
1930 | } | |
1931 | else if (!strcasecmp(line, "AuthType")) | |
1932 | { | |
1933 | /* | |
bc44d920 | 1934 | * AuthType {none,basic,digest,basicdigest,negotiate,default} |
ef416fc2 | 1935 | */ |
1936 | ||
1937 | if (!strcasecmp(value, "none")) | |
1938 | { | |
5bd77a73 MS |
1939 | loc->type = CUPSD_AUTH_NONE; |
1940 | loc->level = CUPSD_AUTH_ANON; | |
ef416fc2 | 1941 | } |
1942 | else if (!strcasecmp(value, "basic")) | |
1943 | { | |
5bd77a73 | 1944 | loc->type = CUPSD_AUTH_BASIC; |
ef416fc2 | 1945 | |
5bd77a73 MS |
1946 | if (loc->level == CUPSD_AUTH_ANON) |
1947 | loc->level = CUPSD_AUTH_USER; | |
ef416fc2 | 1948 | } |
1949 | else if (!strcasecmp(value, "digest")) | |
1950 | { | |
5bd77a73 | 1951 | loc->type = CUPSD_AUTH_DIGEST; |
ef416fc2 | 1952 | |
5bd77a73 MS |
1953 | if (loc->level == CUPSD_AUTH_ANON) |
1954 | loc->level = CUPSD_AUTH_USER; | |
ef416fc2 | 1955 | } |
1956 | else if (!strcasecmp(value, "basicdigest")) | |
1957 | { | |
5bd77a73 | 1958 | loc->type = CUPSD_AUTH_BASICDIGEST; |
ef416fc2 | 1959 | |
5bd77a73 MS |
1960 | if (loc->level == CUPSD_AUTH_ANON) |
1961 | loc->level = CUPSD_AUTH_USER; | |
bc44d920 | 1962 | } |
1963 | else if (!strcasecmp(value, "default")) | |
1964 | { | |
5bd77a73 | 1965 | loc->type = CUPSD_AUTH_DEFAULT; |
bc44d920 | 1966 | |
5bd77a73 MS |
1967 | if (loc->level == CUPSD_AUTH_ANON) |
1968 | loc->level = CUPSD_AUTH_USER; | |
ef416fc2 | 1969 | } |
f7deaa1a | 1970 | #ifdef HAVE_GSSAPI |
7594b224 | 1971 | else if (!strcasecmp(value, "negotiate")) |
f7deaa1a | 1972 | { |
5bd77a73 | 1973 | loc->type = CUPSD_AUTH_NEGOTIATE; |
f7deaa1a | 1974 | |
5bd77a73 MS |
1975 | if (loc->level == CUPSD_AUTH_ANON) |
1976 | loc->level = CUPSD_AUTH_USER; | |
f7deaa1a | 1977 | } |
1978 | #endif /* HAVE_GSSAPI */ | |
ef416fc2 | 1979 | else |
1980 | { | |
1981 | cupsdLogMessage(CUPSD_LOG_WARN, | |
1982 | "Unknown authorization type %s on line %d.", | |
1983 | value, linenum); | |
1984 | return (0); | |
1985 | } | |
1986 | } | |
1987 | else if (!strcasecmp(line, "AuthClass")) | |
1988 | { | |
1989 | /* | |
1990 | * AuthClass anonymous, user, system, group | |
1991 | */ | |
1992 | ||
1993 | if (!strcasecmp(value, "anonymous")) | |
1994 | { | |
5bd77a73 MS |
1995 | loc->type = CUPSD_AUTH_NONE; |
1996 | loc->level = CUPSD_AUTH_ANON; | |
ef416fc2 | 1997 | |
1998 | cupsdLogMessage(CUPSD_LOG_WARN, | |
1999 | "\"AuthClass %s\" is deprecated; consider removing " | |
2000 | "it from line %d.", | |
2001 | value, linenum); | |
2002 | } | |
2003 | else if (!strcasecmp(value, "user")) | |
2004 | { | |
5bd77a73 | 2005 | loc->level = CUPSD_AUTH_USER; |
ef416fc2 | 2006 | |
2007 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2008 | "\"AuthClass %s\" is deprecated; consider using " | |
2009 | "\"Require valid-user\" on line %d.", | |
2010 | value, linenum); | |
2011 | } | |
2012 | else if (!strcasecmp(value, "group")) | |
2013 | { | |
5bd77a73 | 2014 | loc->level = CUPSD_AUTH_GROUP; |
ef416fc2 | 2015 | |
2016 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2017 | "\"AuthClass %s\" is deprecated; consider using " | |
09a101d6 | 2018 | "\"Require user @groupname\" on line %d.", |
ef416fc2 | 2019 | value, linenum); |
2020 | } | |
2021 | else if (!strcasecmp(value, "system")) | |
2022 | { | |
5bd77a73 | 2023 | loc->level = CUPSD_AUTH_GROUP; |
ef416fc2 | 2024 | |
2025 | cupsdAddName(loc, "@SYSTEM"); | |
2026 | ||
2027 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2028 | "\"AuthClass %s\" is deprecated; consider using " | |
09a101d6 | 2029 | "\"Require user @SYSTEM\" on line %d.", |
ef416fc2 | 2030 | value, linenum); |
2031 | } | |
2032 | else | |
2033 | { | |
2034 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2035 | "Unknown authorization class %s on line %d.", | |
2036 | value, linenum); | |
2037 | return (0); | |
2038 | } | |
2039 | } | |
2040 | else if (!strcasecmp(line, "AuthGroupName")) | |
2041 | { | |
2042 | cupsdAddName(loc, value); | |
2043 | ||
2044 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2045 | "\"AuthGroupName %s\" directive is deprecated; consider " | |
09a101d6 | 2046 | "using \"Require user @%s\" on line %d.", |
ef416fc2 | 2047 | value, value, linenum); |
2048 | } | |
2049 | else if (!strcasecmp(line, "Require")) | |
2050 | { | |
2051 | /* | |
2052 | * Apache synonym for AuthClass and AuthGroupName... | |
2053 | * | |
2054 | * Get initial word: | |
2055 | * | |
2056 | * Require valid-user | |
2057 | * Require group names | |
2058 | * Require user names | |
2059 | */ | |
2060 | ||
2061 | for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++); | |
2062 | ||
2063 | if (*valptr) | |
2064 | *valptr++ = '\0'; | |
2065 | ||
2066 | if (!strcasecmp(value, "valid-user") || | |
2067 | !strcasecmp(value, "user")) | |
5bd77a73 | 2068 | loc->level = CUPSD_AUTH_USER; |
ef416fc2 | 2069 | else if (!strcasecmp(value, "group")) |
5bd77a73 | 2070 | loc->level = CUPSD_AUTH_GROUP; |
ef416fc2 | 2071 | else |
2072 | { | |
2073 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Require type %s on line %d.", | |
2074 | value, linenum); | |
2075 | return (0); | |
2076 | } | |
2077 | ||
2078 | /* | |
2079 | * Get the list of names from the line... | |
2080 | */ | |
2081 | ||
2082 | for (value = valptr; *value;) | |
2083 | { | |
2084 | while (isspace(*value & 255)) | |
2085 | value ++; | |
2086 | ||
f7deaa1a | 2087 | #ifdef HAVE_AUTHORIZATION_H |
2088 | if (!strncmp(value, "@AUTHKEY(", 9)) | |
2089 | { | |
2090 | /* | |
2091 | * Grab "@AUTHKEY(name)" value... | |
2092 | */ | |
2093 | ||
2094 | for (valptr = value + 9; *valptr != ')' && *valptr; valptr ++); | |
2095 | ||
2096 | if (*valptr) | |
2097 | *valptr++ = '\0'; | |
2098 | } | |
2099 | else | |
2100 | #endif /* HAVE_AUTHORIZATION_H */ | |
ef416fc2 | 2101 | if (*value == '\"' || *value == '\'') |
2102 | { | |
2103 | /* | |
2104 | * Grab quoted name... | |
2105 | */ | |
2106 | ||
2107 | for (valptr = value + 1; *valptr != *value && *valptr; valptr ++); | |
2108 | ||
2109 | value ++; | |
2110 | } | |
2111 | else | |
2112 | { | |
2113 | /* | |
2114 | * Grab literal name. | |
2115 | */ | |
2116 | ||
2117 | for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++); | |
2118 | } | |
2119 | ||
2120 | if (*valptr) | |
2121 | *valptr++ = '\0'; | |
2122 | ||
2123 | cupsdAddName(loc, value); | |
2124 | ||
2125 | for (value = valptr; isspace(*value & 255); value ++); | |
2126 | } | |
2127 | } | |
2128 | else if (!strcasecmp(line, "Satisfy")) | |
2129 | { | |
2130 | if (!strcasecmp(value, "all")) | |
5bd77a73 | 2131 | loc->satisfy = CUPSD_AUTH_SATISFY_ALL; |
ef416fc2 | 2132 | else if (!strcasecmp(value, "any")) |
5bd77a73 | 2133 | loc->satisfy = CUPSD_AUTH_SATISFY_ANY; |
ef416fc2 | 2134 | else |
2135 | { | |
2136 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Satisfy value %s on line %d.", | |
2137 | value, linenum); | |
2138 | return (0); | |
2139 | } | |
2140 | } | |
2141 | else | |
2142 | return (0); | |
2143 | ||
2144 | return (1); | |
2145 | } | |
2146 | ||
2147 | ||
49d87452 MS |
2148 | /* |
2149 | * 'parse_fatal_errors()' - Parse FatalErrors values in a string. | |
2150 | */ | |
2151 | ||
2152 | static int /* O - FatalErrors bits */ | |
2153 | parse_fatal_errors(const char *s) /* I - FatalErrors string */ | |
2154 | { | |
2155 | int fatal; /* FatalErrors bits */ | |
2156 | char value[1024], /* Value string */ | |
2157 | *valstart, /* Pointer into value */ | |
2158 | *valend; /* End of value */ | |
2159 | ||
2160 | ||
2161 | /* | |
2162 | * Empty FatalErrors line yields NULL pointer... | |
2163 | */ | |
2164 | ||
2165 | if (!s) | |
2166 | return (CUPSD_FATAL_NONE); | |
2167 | ||
2168 | /* | |
2169 | * Loop through the value string,... | |
2170 | */ | |
2171 | ||
2172 | strlcpy(value, s, sizeof(value)); | |
2173 | ||
2174 | fatal = CUPSD_FATAL_NONE; | |
2175 | ||
2176 | for (valstart = value; *valstart;) | |
2177 | { | |
2178 | /* | |
2179 | * Get the current space/comma-delimited kind name... | |
2180 | */ | |
2181 | ||
2182 | for (valend = valstart; *valend; valend ++) | |
2183 | if (isspace(*valend & 255) || *valend == ',') | |
2184 | break; | |
2185 | ||
2186 | if (*valend) | |
2187 | *valend++ = '\0'; | |
2188 | ||
2189 | /* | |
2190 | * Add the error to the bitmask... | |
2191 | */ | |
2192 | ||
2193 | if (!strcasecmp(valstart, "all")) | |
2194 | fatal = CUPSD_FATAL_ALL; | |
2195 | else if (!strcasecmp(valstart, "browse")) | |
2196 | fatal |= CUPSD_FATAL_BROWSE; | |
2197 | else if (!strcasecmp(valstart, "-browse")) | |
2198 | fatal &= ~CUPSD_FATAL_BROWSE; | |
2199 | else if (!strcasecmp(valstart, "config")) | |
2200 | fatal |= CUPSD_FATAL_CONFIG; | |
2201 | else if (!strcasecmp(valstart, "-config")) | |
2202 | fatal &= ~CUPSD_FATAL_CONFIG; | |
2203 | else if (!strcasecmp(valstart, "listen")) | |
2204 | fatal |= CUPSD_FATAL_LISTEN; | |
2205 | else if (!strcasecmp(valstart, "-listen")) | |
2206 | fatal &= ~CUPSD_FATAL_LISTEN; | |
2207 | else if (!strcasecmp(valstart, "log")) | |
2208 | fatal |= CUPSD_FATAL_LOG; | |
2209 | else if (!strcasecmp(valstart, "-log")) | |
2210 | fatal &= ~CUPSD_FATAL_LOG; | |
2211 | else if (!strcasecmp(valstart, "permissions")) | |
2212 | fatal |= CUPSD_FATAL_PERMISSIONS; | |
2213 | else if (!strcasecmp(valstart, "-permissions")) | |
2214 | fatal &= ~CUPSD_FATAL_PERMISSIONS; | |
2215 | else if (strcasecmp(valstart, "none")) | |
2216 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2217 | "Unknown FatalErrors kind \"%s\" ignored!", valstart); | |
2218 | ||
2219 | for (valstart = valend; *valstart; valstart ++) | |
2220 | if (!isspace(*valstart & 255) || *valstart != ',') | |
2221 | break; | |
2222 | } | |
2223 | ||
2224 | return (fatal); | |
2225 | } | |
2226 | ||
2227 | ||
bd7854cb | 2228 | /* |
2229 | * 'parse_groups()' - Parse system group names in a string. | |
2230 | */ | |
2231 | ||
2232 | static int /* O - 1 on success, 0 on failure */ | |
2233 | parse_groups(const char *s) /* I - Space-delimited groups */ | |
2234 | { | |
2235 | int status; /* Return status */ | |
2236 | char value[1024], /* Value string */ | |
2237 | *valstart, /* Pointer into value */ | |
2238 | *valend, /* End of value */ | |
2239 | quote; /* Quote character */ | |
2240 | struct group *group; /* Group */ | |
2241 | ||
2242 | ||
2243 | /* | |
2244 | * Make a copy of the string and parse out the groups... | |
2245 | */ | |
2246 | ||
2247 | strlcpy(value, s, sizeof(value)); | |
2248 | ||
2249 | status = 1; | |
2250 | valstart = value; | |
2251 | ||
2252 | while (*valstart && NumSystemGroups < MAX_SYSTEM_GROUPS) | |
2253 | { | |
2254 | if (*valstart == '\'' || *valstart == '\"') | |
2255 | { | |
2256 | /* | |
2257 | * Scan quoted name... | |
2258 | */ | |
2259 | ||
2260 | quote = *valstart++; | |
2261 | ||
2262 | for (valend = valstart; *valend; valend ++) | |
2263 | if (*valend == quote) | |
2264 | break; | |
2265 | } | |
2266 | else | |
2267 | { | |
2268 | /* | |
2269 | * Scan space or comma-delimited name... | |
2270 | */ | |
2271 | ||
2272 | for (valend = valstart; *valend; valend ++) | |
2273 | if (isspace(*valend) || *valend == ',') | |
2274 | break; | |
2275 | } | |
2276 | ||
2277 | if (*valend) | |
2278 | *valend++ = '\0'; | |
2279 | ||
2280 | group = getgrnam(valstart); | |
2281 | if (group) | |
2282 | { | |
2283 | cupsdSetString(SystemGroups + NumSystemGroups, valstart); | |
2284 | SystemGroupIDs[NumSystemGroups] = group->gr_gid; | |
2285 | ||
2286 | NumSystemGroups ++; | |
2287 | } | |
2288 | else | |
2289 | status = 0; | |
2290 | ||
2291 | endgrent(); | |
2292 | ||
2293 | valstart = valend; | |
2294 | ||
2295 | while (*valstart == ',' || isspace(*valstart)) | |
2296 | valstart ++; | |
2297 | } | |
2298 | ||
2299 | return (status); | |
2300 | } | |
2301 | ||
2302 | ||
2303 | /* | |
2304 | * 'parse_protocols()' - Parse browse protocols in a string. | |
2305 | */ | |
2306 | ||
2307 | static int /* O - Browse protocol bits */ | |
2308 | parse_protocols(const char *s) /* I - Space-delimited protocols */ | |
2309 | { | |
2310 | int protocols; /* Browse protocol bits */ | |
2311 | char value[1024], /* Value string */ | |
2312 | *valstart, /* Pointer into value */ | |
2313 | *valend; /* End of value */ | |
2314 | ||
2315 | ||
d09495fa | 2316 | /* |
2317 | * Empty protocol line yields NULL pointer... | |
2318 | */ | |
2319 | ||
2320 | if (!s) | |
2321 | return (0); | |
2322 | ||
bd7854cb | 2323 | /* |
2324 | * Loop through the value string,... | |
2325 | */ | |
2326 | ||
2327 | strlcpy(value, s, sizeof(value)); | |
2328 | ||
2329 | protocols = 0; | |
2330 | ||
2331 | for (valstart = value; *valstart;) | |
2332 | { | |
2333 | /* | |
2334 | * Get the current space/comma-delimited protocol name... | |
2335 | */ | |
2336 | ||
2337 | for (valend = valstart; *valend; valend ++) | |
2338 | if (isspace(*valend & 255) || *valend == ',') | |
2339 | break; | |
2340 | ||
2341 | if (*valend) | |
2342 | *valend++ = '\0'; | |
2343 | ||
2344 | /* | |
2345 | * Add the protocol to the bitmask... | |
2346 | */ | |
2347 | ||
2348 | if (!strcasecmp(valstart, "cups")) | |
2349 | protocols |= BROWSE_CUPS; | |
2350 | else if (!strcasecmp(valstart, "slp")) | |
2351 | protocols |= BROWSE_SLP; | |
2352 | else if (!strcasecmp(valstart, "ldap")) | |
2353 | protocols |= BROWSE_LDAP; | |
a41f09e2 MS |
2354 | else if (!strcasecmp(valstart, "dnssd") || |
2355 | !strcasecmp(valstart, "dns-sd") || | |
2356 | !strcasecmp(valstart, "bonjour")) | |
bd7854cb | 2357 | protocols |= BROWSE_DNSSD; |
2e4ff8af MS |
2358 | else if (!strcasecmp(valstart, "lpd")) |
2359 | protocols |= BROWSE_LPD; | |
2360 | else if (!strcasecmp(valstart, "smb")) | |
2361 | protocols |= BROWSE_SMB; | |
bd7854cb | 2362 | else if (!strcasecmp(valstart, "all")) |
2363 | protocols |= BROWSE_ALL; | |
b86bc4cf | 2364 | else if (strcasecmp(valstart, "none")) |
a41f09e2 MS |
2365 | cupsdLogMessage(CUPSD_LOG_ERROR, |
2366 | "Unknown browse protocol \"%s\" ignored!", valstart); | |
bd7854cb | 2367 | |
2368 | for (valstart = valend; *valstart; valstart ++) | |
2369 | if (!isspace(*valstart & 255) || *valstart != ',') | |
2370 | break; | |
2371 | } | |
2372 | ||
2373 | return (protocols); | |
2374 | } | |
2375 | ||
2376 | ||
ef416fc2 | 2377 | /* |
2378 | * 'read_configuration()' - Read a configuration file. | |
2379 | */ | |
2380 | ||
2381 | static int /* O - 1 on success, 0 on failure */ | |
2382 | read_configuration(cups_file_t *fp) /* I - File to read from */ | |
2383 | { | |
2384 | int i; /* Looping var */ | |
2385 | int linenum; /* Current line number */ | |
2386 | char line[HTTP_MAX_BUFFER], | |
2387 | /* Line from file */ | |
2388 | temp[HTTP_MAX_BUFFER], | |
2389 | /* Temporary buffer for value */ | |
2390 | temp2[HTTP_MAX_BUFFER], | |
2391 | /* Temporary buffer 2 for value */ | |
2392 | *ptr, /* Pointer into line/temp */ | |
2393 | *value, /* Pointer to value */ | |
bd7854cb | 2394 | *valueptr; /* Pointer into value */ |
ef416fc2 | 2395 | int valuelen; /* Length of value */ |
ac884b6a | 2396 | cupsd_var_t const *var; /* Current variable */ |
ef416fc2 | 2397 | http_addrlist_t *addrlist, /* Address list */ |
2398 | *addr; /* Current address */ | |
2399 | unsigned ip[4], /* Address value */ | |
2400 | mask[4]; /* Netmask value */ | |
2401 | cupsd_dirsvc_relay_t *relay; /* Relay data */ | |
2402 | cupsd_dirsvc_poll_t *pollp; /* Polling data */ | |
2403 | cupsd_location_t *location; /* Browse location */ | |
2404 | cups_file_t *incfile; /* Include file */ | |
2405 | char incname[1024]; /* Include filename */ | |
2406 | struct group *group; /* Group */ | |
2407 | ||
2408 | ||
2409 | /* | |
2410 | * Loop through each line in the file... | |
2411 | */ | |
2412 | ||
2413 | linenum = 0; | |
2414 | ||
2415 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
2416 | { | |
2417 | /* | |
2418 | * Decode the directive... | |
2419 | */ | |
2420 | ||
c934a06c | 2421 | if (!strcasecmp(line, "Include") && value) |
ef416fc2 | 2422 | { |
2423 | /* | |
2424 | * Include filename | |
2425 | */ | |
2426 | ||
2427 | if (value[0] == '/') | |
2428 | strlcpy(incname, value, sizeof(incname)); | |
2429 | else | |
2430 | snprintf(incname, sizeof(incname), "%s/%s", ServerRoot, value); | |
2431 | ||
2432 | if ((incfile = cupsFileOpen(incname, "rb")) == NULL) | |
2433 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2434 | "Unable to include config file \"%s\" - %s", | |
2435 | incname, strerror(errno)); | |
2436 | else | |
2437 | { | |
2438 | read_configuration(incfile); | |
2439 | cupsFileClose(incfile); | |
2440 | } | |
2441 | } | |
c934a06c | 2442 | else if (!strcasecmp(line, "<Location") && value) |
ef416fc2 | 2443 | { |
2444 | /* | |
2445 | * <Location path> | |
2446 | */ | |
2447 | ||
c934a06c MS |
2448 | linenum = read_location(fp, value, linenum); |
2449 | if (linenum == 0) | |
2450 | return (0); | |
ef416fc2 | 2451 | } |
c934a06c | 2452 | else if (!strcasecmp(line, "<Policy") && value) |
ef416fc2 | 2453 | { |
2454 | /* | |
2455 | * <Policy name> | |
2456 | */ | |
2457 | ||
c934a06c MS |
2458 | linenum = read_policy(fp, value, linenum); |
2459 | if (linenum == 0) | |
2460 | return (0); | |
ef416fc2 | 2461 | } |
49d87452 MS |
2462 | else if (!strcasecmp(line, "FatalErrors")) |
2463 | FatalErrors = parse_fatal_errors(value); | |
c934a06c | 2464 | else if (!strcasecmp(line, "FaxRetryInterval") && value) |
ef416fc2 | 2465 | { |
c934a06c MS |
2466 | JobRetryInterval = atoi(value); |
2467 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2468 | "FaxRetryInterval is deprecated; use " | |
2469 | "JobRetryInterval on line %d.", linenum); | |
ef416fc2 | 2470 | } |
c934a06c | 2471 | else if (!strcasecmp(line, "FaxRetryLimit") && value) |
ef416fc2 | 2472 | { |
c934a06c MS |
2473 | JobRetryLimit = atoi(value); |
2474 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2475 | "FaxRetryLimit is deprecated; use " | |
2476 | "JobRetryLimit on line %d.", linenum); | |
ef416fc2 | 2477 | } |
2478 | else if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen") | |
2479 | #ifdef HAVE_SSL | |
2480 | || !strcasecmp(line, "SSLPort") || !strcasecmp(line, "SSLListen") | |
2481 | #endif /* HAVE_SSL */ | |
2482 | ) | |
2483 | { | |
2484 | /* | |
2485 | * Add listening address(es) to the list... | |
2486 | */ | |
2487 | ||
2488 | cupsd_listener_t *lis; /* New listeners array */ | |
2489 | ||
2490 | ||
2491 | /* | |
2492 | * Get the address list... | |
2493 | */ | |
2494 | ||
2495 | addrlist = get_address(value, IPP_PORT); | |
2496 | ||
2497 | if (!addrlist) | |
2498 | { | |
2499 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad %s address %s at line %d.", line, | |
2500 | value, linenum); | |
2501 | continue; | |
2502 | } | |
2503 | ||
2504 | /* | |
2505 | * Add each address... | |
2506 | */ | |
2507 | ||
2508 | for (addr = addrlist; addr; addr = addr->next) | |
2509 | { | |
49d87452 MS |
2510 | /* |
2511 | * See if this address is already present... | |
2512 | */ | |
2513 | ||
2514 | for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners); | |
2515 | lis; | |
2516 | lis = (cupsd_listener_t *)cupsArrayNext(Listeners)) | |
2517 | if (httpAddrEqual(&(addr->addr), &(lis->address)) && | |
2518 | _httpAddrPort(&(addr->addr)) == _httpAddrPort(&(lis->address))) | |
2519 | break; | |
2520 | ||
2521 | if (lis) | |
2522 | { | |
2523 | httpAddrString(&lis->address, temp, sizeof(temp)); | |
2524 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2525 | "Duplicate listen address \"%s\" ignored!", temp); | |
2526 | continue; | |
2527 | } | |
2528 | ||
ef416fc2 | 2529 | /* |
2530 | * Allocate another listener... | |
2531 | */ | |
2532 | ||
bd7854cb | 2533 | if (!Listeners) |
2534 | Listeners = cupsArrayNew(NULL, NULL); | |
ef416fc2 | 2535 | |
bd7854cb | 2536 | if (!Listeners) |
ef416fc2 | 2537 | { |
2538 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2539 | "Unable to allocate %s at line %d - %s.", | |
2540 | line, linenum, strerror(errno)); | |
2541 | break; | |
2542 | } | |
2543 | ||
bd7854cb | 2544 | if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL) |
2545 | { | |
2546 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2547 | "Unable to allocate %s at line %d - %s.", | |
2548 | line, linenum, strerror(errno)); | |
2549 | break; | |
2550 | } | |
2551 | ||
2552 | cupsArrayAdd(Listeners, lis); | |
ef416fc2 | 2553 | |
2554 | /* | |
2555 | * Copy the current address and log it... | |
2556 | */ | |
2557 | ||
ef416fc2 | 2558 | memcpy(&(lis->address), &(addr->addr), sizeof(lis->address)); |
a4d04587 | 2559 | lis->fd = -1; |
ef416fc2 | 2560 | |
2561 | #ifdef HAVE_SSL | |
2562 | if (!strcasecmp(line, "SSLPort") || !strcasecmp(line, "SSLListen")) | |
2563 | lis->encryption = HTTP_ENCRYPT_ALWAYS; | |
2564 | #endif /* HAVE_SSL */ | |
2565 | ||
a4d04587 | 2566 | httpAddrString(&lis->address, temp, sizeof(temp)); |
2567 | ||
ef416fc2 | 2568 | #ifdef AF_INET6 |
2569 | if (lis->address.addr.sa_family == AF_INET6) | |
2570 | cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv6)", temp, | |
2571 | ntohs(lis->address.ipv6.sin6_port)); | |
2572 | else | |
2573 | #endif /* AF_INET6 */ | |
2574 | #ifdef AF_LOCAL | |
2575 | if (lis->address.addr.sa_family == AF_LOCAL) | |
2576 | cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s (Domain)", temp); | |
2577 | else | |
2578 | #endif /* AF_LOCAL */ | |
2579 | cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv4)", temp, | |
2580 | ntohs(lis->address.ipv4.sin_port)); | |
d1c13e16 MS |
2581 | |
2582 | if (!httpAddrLocalhost(&(lis->address))) | |
f11a948a MS |
2583 | { |
2584 | #ifdef AF_INET6 | |
2585 | if (lis->address.addr.sa_family == AF_INET6) | |
2586 | RemotePort = ntohs(lis->address.ipv6.sin6_port); | |
2587 | else | |
2588 | #endif /* AF_INET6 */ | |
2589 | RemotePort = ntohs(lis->address.ipv4.sin_port); | |
2590 | } | |
ef416fc2 | 2591 | } |
2592 | ||
2593 | /* | |
2594 | * Free the list... | |
2595 | */ | |
2596 | ||
2597 | httpAddrFreeList(addrlist); | |
2598 | } | |
c934a06c | 2599 | else if (!strcasecmp(line, "BrowseAddress") && value) |
ef416fc2 | 2600 | { |
2601 | /* | |
2602 | * Add a browse address to the list... | |
2603 | */ | |
2604 | ||
2605 | cupsd_dirsvc_addr_t *dira; /* New browse address array */ | |
2606 | ||
2607 | ||
2608 | if (NumBrowsers == 0) | |
2609 | dira = malloc(sizeof(cupsd_dirsvc_addr_t)); | |
2610 | else | |
2611 | dira = realloc(Browsers, (NumBrowsers + 1) * sizeof(cupsd_dirsvc_addr_t)); | |
2612 | ||
2613 | if (!dira) | |
2614 | { | |
2615 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2616 | "Unable to allocate BrowseAddress at line %d - %s.", | |
2617 | linenum, strerror(errno)); | |
2618 | continue; | |
2619 | } | |
2620 | ||
2621 | Browsers = dira; | |
2622 | dira += NumBrowsers; | |
2623 | ||
2624 | memset(dira, 0, sizeof(cupsd_dirsvc_addr_t)); | |
2625 | ||
2626 | if (!strcasecmp(value, "@LOCAL")) | |
2627 | { | |
2628 | /* | |
2629 | * Send browse data to all local interfaces... | |
2630 | */ | |
2631 | ||
2632 | strcpy(dira->iface, "*"); | |
2633 | NumBrowsers ++; | |
2634 | } | |
2635 | else if (!strncasecmp(value, "@IF(", 4)) | |
2636 | { | |
2637 | /* | |
2638 | * Send browse data to the named interface... | |
2639 | */ | |
2640 | ||
2641 | strlcpy(dira->iface, value + 4, sizeof(Browsers[0].iface)); | |
2642 | ||
2643 | ptr = dira->iface + strlen(dira->iface) - 1; | |
2644 | if (*ptr == ')') | |
2645 | *ptr = '\0'; | |
2646 | ||
2647 | NumBrowsers ++; | |
2648 | } | |
2649 | else if ((addrlist = get_address(value, BrowsePort)) != NULL) | |
2650 | { | |
2651 | /* | |
2652 | * Only IPv4 addresses are supported... | |
2653 | */ | |
2654 | ||
2655 | for (addr = addrlist; addr; addr = addr->next) | |
2656 | if (addr->addr.addr.sa_family == AF_INET) | |
2657 | break; | |
2658 | ||
2659 | if (addr) | |
2660 | { | |
2661 | memcpy(&(dira->to), &(addrlist->addr), sizeof(dira->to)); | |
2662 | httpAddrString(&(dira->to), temp, sizeof(temp)); | |
2663 | ||
2664 | cupsdLogMessage(CUPSD_LOG_INFO, | |
2665 | "Sending browsing info to %s:%d (IPv4)", | |
2666 | temp, ntohs(dira->to.ipv4.sin_port)); | |
2667 | ||
2668 | NumBrowsers ++; | |
2669 | } | |
2670 | else | |
2671 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad BrowseAddress %s at line %d.", | |
2672 | value, linenum); | |
2673 | ||
2674 | httpAddrFreeList(addrlist); | |
2675 | } | |
2676 | else | |
2677 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad BrowseAddress %s at line %d.", | |
2678 | value, linenum); | |
2679 | } | |
c934a06c | 2680 | else if (!strcasecmp(line, "BrowseOrder") && value) |
ef416fc2 | 2681 | { |
2682 | /* | |
2683 | * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"... | |
2684 | */ | |
2685 | ||
2686 | if ((location = cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL) | |
2687 | location = cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL"); | |
2688 | ||
2689 | if (location == NULL) | |
2690 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2691 | "Unable to initialize browse access control list!"); | |
2692 | else if (!strncasecmp(value, "deny", 4)) | |
5bd77a73 | 2693 | location->order_type = CUPSD_AUTH_ALLOW; |
ef416fc2 | 2694 | else if (!strncasecmp(value, "allow", 5)) |
5bd77a73 | 2695 | location->order_type = CUPSD_AUTH_DENY; |
ef416fc2 | 2696 | else |
2697 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2698 | "Unknown BrowseOrder value %s on line %d.", | |
2699 | value, linenum); | |
2700 | } | |
2701 | else if (!strcasecmp(line, "BrowseProtocols") || | |
2702 | !strcasecmp(line, "BrowseLocalProtocols") || | |
2703 | !strcasecmp(line, "BrowseRemoteProtocols")) | |
2704 | { | |
2705 | /* | |
bd7854cb | 2706 | * "BrowseProtocols name [... name]" |
2707 | * "BrowseLocalProtocols name [... name]" | |
2708 | * "BrowseRemoteProtocols name [... name]" | |
ef416fc2 | 2709 | */ |
2710 | ||
bd7854cb | 2711 | int protocols = parse_protocols(value); |
ef416fc2 | 2712 | |
bd7854cb | 2713 | if (protocols < 0) |
ef416fc2 | 2714 | { |
bd7854cb | 2715 | cupsdLogMessage(CUPSD_LOG_ERROR, |
2716 | "Unknown browse protocol \"%s\" on line %d.", | |
2717 | value, linenum); | |
2718 | break; | |
ef416fc2 | 2719 | } |
bd7854cb | 2720 | |
2721 | if (strcasecmp(line, "BrowseLocalProtocols")) | |
2722 | BrowseRemoteProtocols = protocols; | |
2723 | if (strcasecmp(line, "BrowseRemoteProtocols")) | |
2724 | BrowseLocalProtocols = protocols; | |
ef416fc2 | 2725 | } |
c934a06c MS |
2726 | else if ((!strcasecmp(line, "BrowseAllow") || |
2727 | !strcasecmp(line, "BrowseDeny")) && value) | |
ef416fc2 | 2728 | { |
2729 | /* | |
2730 | * BrowseAllow [From] host/ip... | |
2731 | * BrowseDeny [From] host/ip... | |
2732 | */ | |
2733 | ||
2734 | if ((location = cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL) | |
2735 | location = cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL"); | |
2736 | ||
2737 | if (location == NULL) | |
2738 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2739 | "Unable to initialize browse access control list!"); | |
2740 | else | |
2741 | { | |
0af14961 | 2742 | while (*value) |
ef416fc2 | 2743 | { |
0af14961 MS |
2744 | if (!strncasecmp(value, "from", 4)) |
2745 | { | |
2746 | /* | |
2747 | * Strip leading "from"... | |
2748 | */ | |
ef416fc2 | 2749 | |
0af14961 | 2750 | value += 4; |
ef416fc2 | 2751 | |
0af14961 MS |
2752 | while (isspace(*value & 255)) |
2753 | value ++; | |
ef416fc2 | 2754 | |
0af14961 MS |
2755 | if (!*value) |
2756 | break; | |
2757 | } | |
ef416fc2 | 2758 | |
ef416fc2 | 2759 | /* |
0af14961 | 2760 | * Find the end of the value... |
ef416fc2 | 2761 | */ |
2762 | ||
0af14961 MS |
2763 | for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++); |
2764 | ||
2765 | while (isspace(*valueptr & 255)) | |
2766 | *valueptr++ = '\0'; | |
2767 | ||
ef416fc2 | 2768 | /* |
0af14961 MS |
2769 | * Figure out what form the allow/deny address takes: |
2770 | * | |
2771 | * All | |
2772 | * None | |
2773 | * *.domain.com | |
2774 | * .domain.com | |
2775 | * host.domain.com | |
2776 | * nnn.* | |
2777 | * nnn.nnn.* | |
2778 | * nnn.nnn.nnn.* | |
2779 | * nnn.nnn.nnn.nnn | |
2780 | * nnn.nnn.nnn.nnn/mm | |
2781 | * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm | |
ef416fc2 | 2782 | */ |
2783 | ||
0af14961 MS |
2784 | if (!strcasecmp(value, "all")) |
2785 | { | |
2786 | /* | |
2787 | * All hosts... | |
2788 | */ | |
2789 | ||
2790 | if (!strcasecmp(line, "BrowseAllow")) | |
2791 | cupsdAllowIP(location, zeros, zeros); | |
2792 | else | |
2793 | cupsdDenyIP(location, zeros, zeros); | |
2794 | } | |
2795 | else if (!strcasecmp(value, "none")) | |
2796 | { | |
2797 | /* | |
2798 | * No hosts... | |
2799 | */ | |
2800 | ||
2801 | if (!strcasecmp(line, "BrowseAllow")) | |
2802 | cupsdAllowIP(location, ones, zeros); | |
2803 | else | |
2804 | cupsdDenyIP(location, ones, zeros); | |
2805 | } | |
ed486911 | 2806 | #ifdef AF_INET6 |
0af14961 MS |
2807 | else if (value[0] == '*' || value[0] == '.' || |
2808 | (!isdigit(value[0] & 255) && value[0] != '[')) | |
ed486911 | 2809 | #else |
0af14961 | 2810 | else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255)) |
ed486911 | 2811 | #endif /* AF_INET6 */ |
0af14961 MS |
2812 | { |
2813 | /* | |
2814 | * Host or domain name... | |
2815 | */ | |
ef416fc2 | 2816 | |
0af14961 MS |
2817 | if (value[0] == '*') |
2818 | value ++; | |
ef416fc2 | 2819 | |
0af14961 MS |
2820 | if (!strcasecmp(line, "BrowseAllow")) |
2821 | cupsdAllowHost(location, value); | |
2822 | else | |
2823 | cupsdDenyHost(location, value); | |
2824 | } | |
ef416fc2 | 2825 | else |
ef416fc2 | 2826 | { |
0af14961 MS |
2827 | /* |
2828 | * One of many IP address forms... | |
2829 | */ | |
2830 | ||
2831 | if (!get_addr_and_mask(value, ip, mask)) | |
2832 | { | |
2833 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.", | |
2834 | value, linenum); | |
2835 | break; | |
2836 | } | |
2837 | ||
2838 | if (!strcasecmp(line, "BrowseAllow")) | |
2839 | cupsdAllowIP(location, ip, mask); | |
2840 | else | |
2841 | cupsdDenyIP(location, ip, mask); | |
ef416fc2 | 2842 | } |
2843 | ||
0af14961 MS |
2844 | /* |
2845 | * Advance to next value... | |
2846 | */ | |
2847 | ||
2848 | value = valueptr; | |
ef416fc2 | 2849 | } |
2850 | } | |
2851 | } | |
c934a06c | 2852 | else if (!strcasecmp(line, "BrowseRelay") && value) |
ef416fc2 | 2853 | { |
2854 | /* | |
2855 | * BrowseRelay [from] source [to] destination | |
2856 | */ | |
2857 | ||
2858 | if (NumRelays == 0) | |
2859 | relay = malloc(sizeof(cupsd_dirsvc_relay_t)); | |
2860 | else | |
2861 | relay = realloc(Relays, (NumRelays + 1) * sizeof(cupsd_dirsvc_relay_t)); | |
2862 | ||
2863 | if (!relay) | |
2864 | { | |
2865 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2866 | "Unable to allocate BrowseRelay at line %d - %s.", | |
2867 | linenum, strerror(errno)); | |
2868 | continue; | |
2869 | } | |
2870 | ||
2871 | Relays = relay; | |
2872 | relay += NumRelays; | |
2873 | ||
2874 | memset(relay, 0, sizeof(cupsd_dirsvc_relay_t)); | |
2875 | ||
2876 | if (!strncasecmp(value, "from ", 5)) | |
2877 | { | |
2878 | /* | |
2879 | * Strip leading "from"... | |
2880 | */ | |
2881 | ||
2882 | value += 5; | |
2883 | ||
2884 | while (isspace(*value)) | |
2885 | value ++; | |
2886 | } | |
2887 | ||
2888 | /* | |
2889 | * Figure out what form the from address takes: | |
2890 | * | |
2891 | * *.domain.com | |
2892 | * .domain.com | |
2893 | * host.domain.com | |
2894 | * nnn.* | |
2895 | * nnn.nnn.* | |
2896 | * nnn.nnn.nnn.* | |
2897 | * nnn.nnn.nnn.nnn | |
2898 | * nnn.nnn.nnn.nnn/mm | |
2899 | * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm | |
2900 | */ | |
2901 | ||
ed486911 | 2902 | #ifdef AF_INET6 |
2903 | if (value[0] == '*' || value[0] == '.' || | |
2904 | (!isdigit(value[0] & 255) && value[0] != '[')) | |
2905 | #else | |
2906 | if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255)) | |
2907 | #endif /* AF_INET6 */ | |
ef416fc2 | 2908 | { |
2909 | /* | |
2910 | * Host or domain name... | |
2911 | */ | |
2912 | ||
2913 | if (value[0] == '*') | |
2914 | value ++; | |
2915 | ||
2916 | strlcpy(temp, value, sizeof(temp)); | |
2917 | if ((ptr = strchr(temp, ' ')) != NULL) | |
2918 | *ptr = '\0'; | |
2919 | ||
5bd77a73 | 2920 | relay->from.type = CUPSD_AUTH_NAME; |
91c84a35 MS |
2921 | |
2922 | if ((relay->from.mask.name.name = strdup(temp)) == NULL) | |
2923 | { | |
2924 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2925 | "Unable to allocate BrowseRelay name at line %d - %s.", | |
2926 | linenum, strerror(errno)); | |
2927 | continue; | |
2928 | } | |
2929 | ||
ef416fc2 | 2930 | relay->from.mask.name.length = strlen(temp); |
2931 | } | |
2932 | else | |
2933 | { | |
2934 | /* | |
2935 | * One of many IP address forms... | |
2936 | */ | |
2937 | ||
2938 | if (!get_addr_and_mask(value, ip, mask)) | |
2939 | { | |
2940 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.", | |
2941 | value, linenum); | |
2942 | break; | |
2943 | } | |
2944 | ||
5bd77a73 | 2945 | relay->from.type = CUPSD_AUTH_IP; |
ef416fc2 | 2946 | memcpy(relay->from.mask.ip.address, ip, |
2947 | sizeof(relay->from.mask.ip.address)); | |
2948 | memcpy(relay->from.mask.ip.netmask, mask, | |
2949 | sizeof(relay->from.mask.ip.netmask)); | |
2950 | } | |
2951 | ||
2952 | /* | |
2953 | * Skip value and trailing whitespace... | |
2954 | */ | |
2955 | ||
2956 | for (; *value; value ++) | |
2957 | if (isspace(*value)) | |
2958 | break; | |
2959 | ||
2960 | while (isspace(*value)) | |
2961 | value ++; | |
2962 | ||
2963 | if (!strncasecmp(value, "to ", 3)) | |
2964 | { | |
2965 | /* | |
2966 | * Strip leading "to"... | |
2967 | */ | |
2968 | ||
2969 | value += 3; | |
2970 | ||
2971 | while (isspace(*value)) | |
2972 | value ++; | |
2973 | } | |
2974 | ||
2975 | /* | |
2976 | * Get "to" address and port... | |
2977 | */ | |
2978 | ||
2979 | if ((addrlist = get_address(value, BrowsePort)) != NULL) | |
2980 | { | |
2981 | /* | |
2982 | * Only IPv4 addresses are supported... | |
2983 | */ | |
2984 | ||
2985 | for (addr = addrlist; addr; addr = addr->next) | |
2986 | if (addr->addr.addr.sa_family == AF_INET) | |
2987 | break; | |
2988 | ||
2989 | if (addr) | |
2990 | { | |
2991 | memcpy(&(relay->to), &(addrlist->addr), sizeof(relay->to)); | |
2992 | ||
2993 | httpAddrString(&(relay->to), temp, sizeof(temp)); | |
2994 | ||
5bd77a73 | 2995 | if (relay->from.type == CUPSD_AUTH_IP) |
ef416fc2 | 2996 | snprintf(temp2, sizeof(temp2), "%u.%u.%u.%u/%u.%u.%u.%u", |
3d8365b8 | 2997 | relay->from.mask.ip.address[0] >> 24, |
2998 | (relay->from.mask.ip.address[0] >> 16) & 255, | |
2999 | (relay->from.mask.ip.address[0] >> 8) & 255, | |
3000 | relay->from.mask.ip.address[0] & 255, | |
3001 | relay->from.mask.ip.netmask[0] >> 24, | |
3002 | (relay->from.mask.ip.netmask[0] >> 16) & 255, | |
3003 | (relay->from.mask.ip.netmask[0] >> 8) & 255, | |
3004 | relay->from.mask.ip.netmask[0] & 255); | |
ef416fc2 | 3005 | else |
3006 | strlcpy(temp2, relay->from.mask.name.name, sizeof(temp2)); | |
3007 | ||
3008 | cupsdLogMessage(CUPSD_LOG_INFO, "Relaying from %s to %s:%d (IPv4)", | |
8ca02f3c | 3009 | temp2, temp, ntohs(relay->to.ipv4.sin_port)); |
ef416fc2 | 3010 | |
3011 | NumRelays ++; | |
3012 | } | |
3013 | else | |
3014 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad relay address %s at line %d.", | |
3015 | value, linenum); | |
3016 | ||
3017 | httpAddrFreeList(addrlist); | |
3018 | } | |
3019 | else | |
3020 | { | |
5bd77a73 | 3021 | if (relay->from.type == CUPSD_AUTH_NAME) |
ef416fc2 | 3022 | free(relay->from.mask.name.name); |
3023 | ||
3024 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad relay address %s at line %d.", | |
3025 | value, linenum); | |
3026 | } | |
3027 | } | |
c934a06c | 3028 | else if (!strcasecmp(line, "BrowsePoll") && value) |
ef416fc2 | 3029 | { |
3030 | /* | |
3031 | * BrowsePoll address[:port] | |
3032 | */ | |
3033 | ||
3034 | char *portname; /* Port name */ | |
3035 | int portnum; /* Port number */ | |
3036 | struct servent *service; /* Service */ | |
3037 | ||
3038 | ||
3039 | /* | |
3040 | * Extract the port name from the address... | |
3041 | */ | |
3042 | ||
3043 | if ((portname = strrchr(value, ':')) != NULL && !strchr(portname, ']')) | |
3044 | { | |
3045 | *portname++ = '\0'; | |
3046 | ||
3047 | if (isdigit(*portname & 255)) | |
3048 | portnum = atoi(portname); | |
3049 | else if ((service = getservbyname(portname, NULL)) != NULL) | |
3050 | portnum = ntohs(service->s_port); | |
3051 | else | |
3052 | { | |
3053 | cupsdLogMessage(CUPSD_LOG_ERROR, "Lookup of service \"%s\" failed!", | |
3054 | portname); | |
3055 | continue; | |
3056 | } | |
3057 | } | |
3058 | else | |
3059 | portnum = ippPort(); | |
3060 | ||
3061 | /* | |
3062 | * Add the poll entry... | |
3063 | */ | |
3064 | ||
3065 | if (NumPolled == 0) | |
3066 | pollp = malloc(sizeof(cupsd_dirsvc_poll_t)); | |
3067 | else | |
3068 | pollp = realloc(Polled, (NumPolled + 1) * sizeof(cupsd_dirsvc_poll_t)); | |
3069 | ||
3070 | if (!pollp) | |
3071 | { | |
3072 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3073 | "Unable to allocate BrowsePoll at line %d - %s.", | |
3074 | linenum, strerror(errno)); | |
3075 | continue; | |
3076 | } | |
3077 | ||
3078 | Polled = pollp; | |
3079 | pollp += NumPolled; | |
3080 | ||
3081 | NumPolled ++; | |
3082 | memset(pollp, 0, sizeof(cupsd_dirsvc_poll_t)); | |
3083 | ||
3084 | strlcpy(pollp->hostname, value, sizeof(pollp->hostname)); | |
3085 | pollp->port = portnum; | |
3086 | ||
3087 | cupsdLogMessage(CUPSD_LOG_INFO, "Polling %s:%d", pollp->hostname, | |
3088 | pollp->port); | |
3089 | } | |
c934a06c | 3090 | else if (!strcasecmp(line, "DefaultAuthType") && value) |
ef416fc2 | 3091 | { |
3092 | /* | |
bc44d920 | 3093 | * DefaultAuthType {basic,digest,basicdigest,negotiate} |
ef416fc2 | 3094 | */ |
3095 | ||
c24d2134 | 3096 | if (!strcasecmp(value, "none")) |
5bd77a73 | 3097 | DefaultAuthType = CUPSD_AUTH_NONE; |
c24d2134 | 3098 | else if (!strcasecmp(value, "basic")) |
5bd77a73 | 3099 | DefaultAuthType = CUPSD_AUTH_BASIC; |
ef416fc2 | 3100 | else if (!strcasecmp(value, "digest")) |
5bd77a73 | 3101 | DefaultAuthType = CUPSD_AUTH_DIGEST; |
ef416fc2 | 3102 | else if (!strcasecmp(value, "basicdigest")) |
5bd77a73 | 3103 | DefaultAuthType = CUPSD_AUTH_BASICDIGEST; |
f7deaa1a | 3104 | #ifdef HAVE_GSSAPI |
7594b224 | 3105 | else if (!strcasecmp(value, "negotiate")) |
5bd77a73 | 3106 | DefaultAuthType = CUPSD_AUTH_NEGOTIATE; |
f7deaa1a | 3107 | #endif /* HAVE_GSSAPI */ |
ef416fc2 | 3108 | else |
3109 | { | |
3110 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3111 | "Unknown default authorization type %s on line %d.", | |
3112 | value, linenum); | |
49d87452 MS |
3113 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3114 | return (0); | |
ef416fc2 | 3115 | } |
3116 | } | |
4744bd90 | 3117 | #ifdef HAVE_SSL |
3118 | else if (!strcasecmp(line, "DefaultEncryption")) | |
3119 | { | |
3120 | /* | |
3121 | * DefaultEncryption {Never,IfRequested,Required} | |
3122 | */ | |
3123 | ||
3124 | if (!value || !strcasecmp(value, "never")) | |
3125 | DefaultEncryption = HTTP_ENCRYPT_NEVER; | |
3126 | else if (!strcasecmp(value, "required")) | |
3127 | DefaultEncryption = HTTP_ENCRYPT_REQUIRED; | |
3128 | else if (!strcasecmp(value, "ifrequested")) | |
3129 | DefaultEncryption = HTTP_ENCRYPT_IF_REQUESTED; | |
3130 | else | |
3131 | { | |
3132 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3133 | "Unknown default encryption %s on line %d.", | |
3134 | value, linenum); | |
49d87452 MS |
3135 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3136 | return (0); | |
4744bd90 | 3137 | } |
3138 | } | |
3139 | #endif /* HAVE_SSL */ | |
c934a06c | 3140 | else if (!strcasecmp(line, "User") && value) |
ef416fc2 | 3141 | { |
3142 | /* | |
3143 | * User ID to run as... | |
3144 | */ | |
3145 | ||
c934a06c | 3146 | if (isdigit(value[0] & 255)) |
ef416fc2 | 3147 | { |
3148 | int uid = atoi(value); | |
3149 | ||
3150 | if (!uid) | |
3151 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3152 | "Will not use User 0 as specified on line %d " | |
3153 | "for security reasons. You must use a non-" | |
3154 | "privileged account instead.", | |
3155 | linenum); | |
3156 | else | |
3157 | User = atoi(value); | |
3158 | } | |
c934a06c | 3159 | else |
ef416fc2 | 3160 | { |
3161 | struct passwd *p; /* Password information */ | |
3162 | ||
3163 | endpwent(); | |
3164 | p = getpwnam(value); | |
3165 | ||
3166 | if (p) | |
3167 | { | |
3168 | if (!p->pw_uid) | |
3169 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3170 | "Will not use User %s (UID=0) as specified on line " | |
3171 | "%d for security reasons. You must use a non-" | |
3172 | "privileged account instead.", | |
3173 | value, linenum); | |
3174 | else | |
3175 | User = p->pw_uid; | |
3176 | } | |
3177 | else | |
3178 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3179 | "Unknown User \"%s\" on line %d, ignoring!", | |
3180 | value, linenum); | |
3181 | } | |
ef416fc2 | 3182 | } |
c934a06c | 3183 | else if (!strcasecmp(line, "Group") && value) |
ef416fc2 | 3184 | { |
3185 | /* | |
3186 | * Group ID to run as... | |
3187 | */ | |
3188 | ||
3189 | if (isdigit(value[0])) | |
3190 | Group = atoi(value); | |
3191 | else | |
3192 | { | |
3193 | endgrent(); | |
3194 | group = getgrnam(value); | |
3195 | ||
3196 | if (group != NULL) | |
3197 | Group = group->gr_gid; | |
3198 | else | |
3199 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3200 | "Unknown Group \"%s\" on line %d, ignoring!", | |
3201 | value, linenum); | |
3202 | } | |
3203 | } | |
c934a06c | 3204 | else if (!strcasecmp(line, "SystemGroup") && value) |
ef416fc2 | 3205 | { |
3206 | /* | |
bd7854cb | 3207 | * SystemGroup (admin) group(s)... |
ef416fc2 | 3208 | */ |
3209 | ||
bd7854cb | 3210 | if (!parse_groups(value)) |
3211 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3212 | "Unknown SystemGroup \"%s\" on line %d, ignoring!", | |
3213 | value, linenum); | |
ef416fc2 | 3214 | } |
c934a06c | 3215 | else if (!strcasecmp(line, "HostNameLookups") && value) |
ef416fc2 | 3216 | { |
3217 | /* | |
3218 | * Do hostname lookups? | |
3219 | */ | |
3220 | ||
dd1abb6b MS |
3221 | if (!strcasecmp(value, "off") || !strcasecmp(value, "no") || |
3222 | !strcasecmp(value, "false")) | |
ef416fc2 | 3223 | HostNameLookups = 0; |
dd1abb6b MS |
3224 | else if (!strcasecmp(value, "on") || !strcasecmp(value, "yes") || |
3225 | !strcasecmp(value, "true")) | |
ef416fc2 | 3226 | HostNameLookups = 1; |
3227 | else if (!strcasecmp(value, "double")) | |
3228 | HostNameLookups = 2; | |
3229 | else | |
3230 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown HostNameLookups %s on line %d.", | |
3231 | value, linenum); | |
3232 | } | |
1f0275e3 MS |
3233 | else if (!strcasecmp(line, "AccessLogLevel") && value) |
3234 | { | |
3235 | /* | |
3236 | * Amount of logging to do to access log... | |
3237 | */ | |
3238 | ||
3239 | if (!strcasecmp(value, "all")) | |
3240 | AccessLogLevel = CUPSD_ACCESSLOG_ALL; | |
3241 | else if (!strcasecmp(value, "actions")) | |
3242 | AccessLogLevel = CUPSD_ACCESSLOG_ACTIONS; | |
3243 | else if (!strcasecmp(value, "config")) | |
3244 | AccessLogLevel = CUPSD_ACCESSLOG_CONFIG; | |
3245 | else | |
3246 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown AccessLogLevel %s on line %d.", | |
3247 | value, linenum); | |
3248 | } | |
c934a06c | 3249 | else if (!strcasecmp(line, "LogLevel") && value) |
ef416fc2 | 3250 | { |
3251 | /* | |
1f0275e3 | 3252 | * Amount of logging to do to error log... |
ef416fc2 | 3253 | */ |
3254 | ||
3255 | if (!strcasecmp(value, "debug2")) | |
3256 | LogLevel = CUPSD_LOG_DEBUG2; | |
3257 | else if (!strcasecmp(value, "debug")) | |
3258 | LogLevel = CUPSD_LOG_DEBUG; | |
3259 | else if (!strcasecmp(value, "info")) | |
3260 | LogLevel = CUPSD_LOG_INFO; | |
3261 | else if (!strcasecmp(value, "notice")) | |
3262 | LogLevel = CUPSD_LOG_NOTICE; | |
3263 | else if (!strcasecmp(value, "warn")) | |
3264 | LogLevel = CUPSD_LOG_WARN; | |
3265 | else if (!strcasecmp(value, "error")) | |
3266 | LogLevel = CUPSD_LOG_ERROR; | |
3267 | else if (!strcasecmp(value, "crit")) | |
3268 | LogLevel = CUPSD_LOG_CRIT; | |
3269 | else if (!strcasecmp(value, "alert")) | |
3270 | LogLevel = CUPSD_LOG_ALERT; | |
3271 | else if (!strcasecmp(value, "emerg")) | |
3272 | LogLevel = CUPSD_LOG_EMERG; | |
3273 | else if (!strcasecmp(value, "none")) | |
3274 | LogLevel = CUPSD_LOG_NONE; | |
3275 | else | |
3276 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogLevel %s on line %d.", | |
3277 | value, linenum); | |
3278 | } | |
dfd5680b MS |
3279 | else if (!strcasecmp(line, "LogTimeFormat") && value) |
3280 | { | |
3281 | /* | |
3282 | * Amount of logging to do to error log... | |
3283 | */ | |
3284 | ||
3285 | if (!strcasecmp(value, "standard")) | |
3286 | LogTimeFormat = CUPSD_TIME_STANDARD; | |
3287 | else if (!strcasecmp(value, "usecs")) | |
3288 | LogTimeFormat = CUPSD_TIME_USECS; | |
3289 | else | |
3290 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogTimeFormat %s on line %d.", | |
3291 | value, linenum); | |
3292 | } | |
c934a06c | 3293 | else if (!strcasecmp(line, "PrintcapFormat") && value) |
ef416fc2 | 3294 | { |
3295 | /* | |
3296 | * Format of printcap file? | |
3297 | */ | |
3298 | ||
3299 | if (!strcasecmp(value, "bsd")) | |
3300 | PrintcapFormat = PRINTCAP_BSD; | |
0af14961 MS |
3301 | else if (!strcasecmp(value, "plist")) |
3302 | PrintcapFormat = PRINTCAP_PLIST; | |
ef416fc2 | 3303 | else if (!strcasecmp(value, "solaris")) |
3304 | PrintcapFormat = PRINTCAP_SOLARIS; | |
3305 | else | |
3306 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown PrintcapFormat %s on line %d.", | |
3307 | value, linenum); | |
3308 | } | |
c934a06c | 3309 | else if (!strcasecmp(line, "ServerTokens") && value) |
ef416fc2 | 3310 | { |
3311 | /* | |
3312 | * Set the string used for the Server header... | |
3313 | */ | |
3314 | ||
3315 | struct utsname plat; /* Platform info */ | |
3316 | ||
3317 | ||
3318 | uname(&plat); | |
3319 | ||
3320 | if (!strcasecmp(value, "ProductOnly")) | |
3321 | cupsdSetString(&ServerHeader, "CUPS"); | |
3322 | else if (!strcasecmp(value, "Major")) | |
3323 | cupsdSetString(&ServerHeader, "CUPS/1"); | |
3324 | else if (!strcasecmp(value, "Minor")) | |
ae71f5de | 3325 | cupsdSetString(&ServerHeader, "CUPS/1.4"); |
ef416fc2 | 3326 | else if (!strcasecmp(value, "Minimal")) |
3327 | cupsdSetString(&ServerHeader, CUPS_MINIMAL); | |
3328 | else if (!strcasecmp(value, "OS")) | |
3329 | cupsdSetStringf(&ServerHeader, CUPS_MINIMAL " (%s)", plat.sysname); | |
3330 | else if (!strcasecmp(value, "Full")) | |
3331 | cupsdSetStringf(&ServerHeader, CUPS_MINIMAL " (%s) IPP/1.1", | |
3332 | plat.sysname); | |
3333 | else if (!strcasecmp(value, "None")) | |
3334 | cupsdClearString(&ServerHeader); | |
3335 | else | |
3336 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown ServerTokens %s on line %d.", | |
3337 | value, linenum); | |
3338 | } | |
c934a06c | 3339 | else if (!strcasecmp(line, "PassEnv") && value) |
ef416fc2 | 3340 | { |
3341 | /* | |
3342 | * PassEnv variable [... variable] | |
3343 | */ | |
3344 | ||
3345 | for (; *value;) | |
3346 | { | |
3347 | for (valuelen = 0; value[valuelen]; valuelen ++) | |
3348 | if (isspace(value[valuelen]) || value[valuelen] == ',') | |
3349 | break; | |
3350 | ||
3351 | if (value[valuelen]) | |
3352 | { | |
3353 | value[valuelen] = '\0'; | |
3354 | valuelen ++; | |
3355 | } | |
3356 | ||
3357 | cupsdSetEnv(value, NULL); | |
3358 | ||
3359 | for (value += valuelen; *value; value ++) | |
3360 | if (!isspace(*value) || *value != ',') | |
3361 | break; | |
3362 | } | |
3363 | } | |
e07d4801 MS |
3364 | else if (!strcasecmp(line, "ServerAlias") && value) |
3365 | { | |
3366 | if (!ServerAlias) | |
3367 | ServerAlias = cupsArrayNew(NULL, NULL); | |
3368 | ||
3369 | cupsdAddAlias(ServerAlias, value); | |
3370 | } | |
c934a06c | 3371 | else if (!strcasecmp(line, "SetEnv") && value) |
ef416fc2 | 3372 | { |
3373 | /* | |
3374 | * SetEnv variable value | |
3375 | */ | |
3376 | ||
3377 | for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++); | |
3378 | ||
3379 | if (*valueptr) | |
3380 | { | |
3381 | /* | |
3382 | * Found a value... | |
3383 | */ | |
3384 | ||
3385 | while (isspace(*valueptr & 255)) | |
3386 | *valueptr++ = '\0'; | |
3387 | ||
3388 | cupsdSetEnv(value, valueptr); | |
3389 | } | |
3390 | else | |
3391 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3392 | "Missing value for SetEnv directive on line %d.", | |
3393 | linenum); | |
3394 | } | |
58dc1933 | 3395 | #ifdef HAVE_SSL |
b19ccc9e MS |
3396 | else if (!strcasecmp(line, "SSLOptions")) |
3397 | { | |
3398 | /* | |
3399 | * SSLOptions options | |
3400 | */ | |
3401 | ||
3402 | if (!value || !strcasecmp(value, "none")) | |
3403 | SSLOptions = CUPSD_SSL_NONE; | |
3404 | else if (!strcasecmp(value, "noemptyfragments")) | |
3405 | SSLOptions = CUPSD_SSL_NOEMPTY; | |
3406 | else | |
3407 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3408 | "Unknown value \"%s\" for SSLOptions directive on " | |
3409 | "line %d.", value, linenum); | |
3410 | } | |
58dc1933 | 3411 | #endif /* HAVE_SSL */ |
ef416fc2 | 3412 | else |
3413 | { | |
3414 | /* | |
3415 | * Find a simple variable in the list... | |
3416 | */ | |
3417 | ||
3418 | for (i = NUM_VARS, var = variables; i > 0; i --, var ++) | |
3419 | if (!strcasecmp(line, var->name)) | |
3420 | break; | |
3421 | ||
3422 | if (i == 0) | |
3423 | { | |
3424 | /* | |
3425 | * Unknown directive! Output an error message and continue... | |
3426 | */ | |
3427 | ||
c934a06c MS |
3428 | if (!value) |
3429 | cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value for %s on line %d.", | |
3430 | line, linenum); | |
3431 | else | |
3432 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown directive %s on line %d.", | |
3433 | line, linenum); | |
ef416fc2 | 3434 | continue; |
3435 | } | |
3436 | ||
3437 | switch (var->type) | |
3438 | { | |
3439 | case CUPSD_VARTYPE_INTEGER : | |
a74454a7 | 3440 | if (!value) |
3441 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3442 | "Missing integer value for %s on line %d!", | |
3443 | line, linenum); | |
3444 | else | |
ef416fc2 | 3445 | { |
3446 | int n; /* Number */ | |
3447 | char *units; /* Units */ | |
3448 | ||
3449 | ||
3450 | n = strtol(value, &units, 0); | |
3451 | ||
3452 | if (units && *units) | |
3453 | { | |
3454 | if (tolower(units[0] & 255) == 'g') | |
3455 | n *= 1024 * 1024 * 1024; | |
3456 | else if (tolower(units[0] & 255) == 'm') | |
3457 | n *= 1024 * 1024; | |
3458 | else if (tolower(units[0] & 255) == 'k') | |
3459 | n *= 1024; | |
3460 | else if (tolower(units[0] & 255) == 't') | |
3461 | n *= 262144; | |
3462 | } | |
3463 | ||
8ca02f3c | 3464 | if (n < 0) |
3465 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3466 | "Bad negative integer value for %s on line %d!", | |
3467 | line, linenum); | |
3468 | else | |
3469 | *((int *)var->ptr) = n; | |
ef416fc2 | 3470 | } |
3471 | break; | |
3472 | ||
3473 | case CUPSD_VARTYPE_BOOLEAN : | |
a74454a7 | 3474 | if (!value) |
3475 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3476 | "Missing boolean value for %s on line %d!", | |
3477 | line, linenum); | |
3478 | else if (!strcasecmp(value, "true") || | |
3479 | !strcasecmp(value, "on") || | |
3480 | !strcasecmp(value, "enabled") || | |
3481 | !strcasecmp(value, "yes") || | |
3482 | atoi(value) != 0) | |
ef416fc2 | 3483 | *((int *)var->ptr) = TRUE; |
3484 | else if (!strcasecmp(value, "false") || | |
3485 | !strcasecmp(value, "off") || | |
3486 | !strcasecmp(value, "disabled") || | |
3487 | !strcasecmp(value, "no") || | |
3488 | !strcasecmp(value, "0")) | |
3489 | *((int *)var->ptr) = FALSE; | |
3490 | else | |
3491 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3492 | "Unknown boolean value %s on line %d.", | |
3493 | value, linenum); | |
3494 | break; | |
3495 | ||
76cd9e37 | 3496 | case CUPSD_VARTYPE_PATHNAME : |
c934a06c MS |
3497 | if (!value) |
3498 | { | |
3499 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3500 | "Missing pathname value for %s on line %d!", | |
3501 | line, linenum); | |
3502 | break; | |
3503 | } | |
3504 | ||
3505 | if (value[0] == '/') | |
76cd9e37 MS |
3506 | strlcpy(temp, value, sizeof(temp)); |
3507 | else | |
3508 | snprintf(temp, sizeof(temp), "%s/%s", ServerRoot, value); | |
3509 | ||
3510 | if (access(temp, 0)) | |
3511 | { | |
3512 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3513 | "File or directory for \"%s %s\" on line %d " | |
3514 | "does not exist!", line, value, linenum); | |
3515 | break; | |
3516 | } | |
3517 | ||
ef416fc2 | 3518 | case CUPSD_VARTYPE_STRING : |
3519 | cupsdSetString((char **)var->ptr, value); | |
3520 | break; | |
3521 | } | |
3522 | } | |
3523 | } | |
3524 | ||
3525 | return (1); | |
3526 | } | |
3527 | ||
3528 | ||
3529 | /* | |
3530 | * 'read_location()' - Read a <Location path> definition. | |
3531 | */ | |
3532 | ||
3533 | static int /* O - New line number or 0 on error */ | |
3534 | read_location(cups_file_t *fp, /* I - Configuration file */ | |
3535 | char *location, /* I - Location name/path */ | |
3536 | int linenum) /* I - Current line number */ | |
3537 | { | |
3538 | cupsd_location_t *loc, /* New location */ | |
3539 | *parent; /* Parent location */ | |
3540 | char line[HTTP_MAX_BUFFER], | |
3541 | /* Line buffer */ | |
3542 | *value, /* Value for directive */ | |
3543 | *valptr; /* Pointer into value */ | |
3544 | ||
3545 | ||
3546 | if ((parent = cupsdAddLocation(location)) == NULL) | |
3547 | return (0); | |
3548 | ||
5bd77a73 | 3549 | parent->limit = CUPSD_AUTH_LIMIT_ALL; |
ef416fc2 | 3550 | loc = parent; |
3551 | ||
3552 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
3553 | { | |
3554 | /* | |
3555 | * Decode the directive... | |
3556 | */ | |
3557 | ||
3558 | if (!strcasecmp(line, "</Location>")) | |
3559 | return (linenum); | |
3560 | else if (!strcasecmp(line, "<Limit") || | |
3561 | !strcasecmp(line, "<LimitExcept")) | |
3562 | { | |
3563 | if (!value) | |
3564 | { | |
3565 | cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum); | |
49d87452 MS |
3566 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3567 | return (0); | |
b19ccc9e MS |
3568 | else |
3569 | continue; | |
ef416fc2 | 3570 | } |
3571 | ||
3572 | if ((loc = cupsdCopyLocation(&parent)) == NULL) | |
3573 | return (0); | |
3574 | ||
3575 | loc->limit = 0; | |
3576 | while (*value) | |
3577 | { | |
3578 | for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++); | |
3579 | ||
3580 | if (*valptr) | |
3581 | *valptr++ = '\0'; | |
3582 | ||
3583 | if (!strcmp(value, "ALL")) | |
5bd77a73 | 3584 | loc->limit = CUPSD_AUTH_LIMIT_ALL; |
ef416fc2 | 3585 | else if (!strcmp(value, "GET")) |
5bd77a73 | 3586 | loc->limit |= CUPSD_AUTH_LIMIT_GET; |
ef416fc2 | 3587 | else if (!strcmp(value, "HEAD")) |
5bd77a73 | 3588 | loc->limit |= CUPSD_AUTH_LIMIT_HEAD; |
ef416fc2 | 3589 | else if (!strcmp(value, "OPTIONS")) |
5bd77a73 | 3590 | loc->limit |= CUPSD_AUTH_LIMIT_OPTIONS; |
ef416fc2 | 3591 | else if (!strcmp(value, "POST")) |
5bd77a73 | 3592 | loc->limit |= CUPSD_AUTH_LIMIT_POST; |
ef416fc2 | 3593 | else if (!strcmp(value, "PUT")) |
5bd77a73 | 3594 | loc->limit |= CUPSD_AUTH_LIMIT_PUT; |
ef416fc2 | 3595 | else if (!strcmp(value, "TRACE")) |
5bd77a73 | 3596 | loc->limit |= CUPSD_AUTH_LIMIT_TRACE; |
ef416fc2 | 3597 | else |
3598 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown request type %s on line %d!", | |
3599 | value, linenum); | |
3600 | ||
3601 | for (value = valptr; isspace(*value & 255); value ++); | |
3602 | } | |
3603 | ||
3604 | if (!strcasecmp(line, "<LimitExcept")) | |
5bd77a73 | 3605 | loc->limit = CUPSD_AUTH_LIMIT_ALL ^ loc->limit; |
ef416fc2 | 3606 | |
3607 | parent->limit &= ~loc->limit; | |
3608 | } | |
ac884b6a MS |
3609 | else if (!strcasecmp(line, "</Limit>") || |
3610 | !strcasecmp(line, "</LimitExcept>")) | |
ef416fc2 | 3611 | loc = parent; |
3612 | else if (!parse_aaa(loc, line, value, linenum)) | |
3613 | { | |
3614 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3615 | "Unknown Location directive %s on line %d.", | |
3616 | line, linenum); | |
49d87452 MS |
3617 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3618 | return (0); | |
ef416fc2 | 3619 | } |
3620 | } | |
3621 | ||
3622 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3623 | "Unexpected end-of-file at line %d while reading location!", | |
3624 | linenum); | |
3625 | ||
49d87452 | 3626 | return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum); |
ef416fc2 | 3627 | } |
3628 | ||
3629 | ||
3630 | /* | |
3631 | * 'read_policy()' - Read a <Policy name> definition. | |
3632 | */ | |
3633 | ||
3634 | static int /* O - New line number or 0 on error */ | |
3635 | read_policy(cups_file_t *fp, /* I - Configuration file */ | |
3636 | char *policy, /* I - Location name/path */ | |
3637 | int linenum) /* I - Current line number */ | |
3638 | { | |
3639 | int i; /* Looping var */ | |
3640 | cupsd_policy_t *pol; /* Policy */ | |
3641 | cupsd_location_t *op; /* Policy operation */ | |
3642 | int num_ops; /* Number of IPP operations */ | |
3643 | ipp_op_t ops[100]; /* Operations */ | |
3644 | char line[HTTP_MAX_BUFFER], | |
3645 | /* Line buffer */ | |
3646 | *value, /* Value for directive */ | |
3647 | *valptr; /* Pointer into value */ | |
3648 | ||
3649 | ||
3650 | /* | |
3651 | * Create the policy... | |
3652 | */ | |
3653 | ||
3654 | if ((pol = cupsdAddPolicy(policy)) == NULL) | |
3655 | return (0); | |
3656 | ||
3657 | /* | |
3658 | * Read from the file... | |
3659 | */ | |
3660 | ||
3661 | op = NULL; | |
3662 | num_ops = 0; | |
3663 | ||
3664 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
3665 | { | |
3666 | /* | |
3667 | * Decode the directive... | |
3668 | */ | |
3669 | ||
3670 | if (!strcasecmp(line, "</Policy>")) | |
3671 | { | |
3672 | if (op) | |
3673 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3674 | "Missing </Limit> before </Policy> on line %d!", | |
3675 | linenum); | |
3676 | ||
2e4ff8af MS |
3677 | /* |
3678 | * Verify that we have an explicit policy for CUPS-Get-Document | |
3679 | * (ensures that upgrades do not introduce new security issues...) | |
3680 | */ | |
3681 | ||
3682 | if ((op = cupsdFindPolicyOp(pol, CUPS_GET_DOCUMENT)) == NULL || | |
3683 | op->op == IPP_ANY_OPERATION) | |
3684 | { | |
3685 | if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL && | |
3686 | op->op != IPP_ANY_OPERATION) | |
3687 | { | |
3688 | /* | |
3689 | * Add a new limit for CUPS-Get-Document using the Send-Document | |
3690 | * limit as a template... | |
3691 | */ | |
3692 | ||
3693 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3694 | "No limit for CUPS-Get-Document defined in policy %s " | |
3695 | "- using Send-Document's policy", pol->name); | |
3696 | ||
3697 | cupsdAddPolicyOp(pol, op, CUPS_GET_DOCUMENT); | |
3698 | } | |
3699 | } | |
3700 | ||
ef416fc2 | 3701 | return (linenum); |
3702 | } | |
3703 | else if (!strcasecmp(line, "<Limit") && !op) | |
3704 | { | |
3705 | if (!value) | |
3706 | { | |
3707 | cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum); | |
49d87452 MS |
3708 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3709 | return (0); | |
b19ccc9e MS |
3710 | else |
3711 | continue; | |
ef416fc2 | 3712 | } |
3713 | ||
3714 | /* | |
3715 | * Scan for IPP operation names... | |
3716 | */ | |
3717 | ||
3718 | num_ops = 0; | |
3719 | ||
3720 | while (*value) | |
3721 | { | |
3722 | for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++); | |
3723 | ||
3724 | if (*valptr) | |
3725 | *valptr++ = '\0'; | |
3726 | ||
3727 | if (num_ops < (int)(sizeof(ops) / sizeof(ops[0]))) | |
3728 | { | |
3729 | if (!strcasecmp(value, "All")) | |
3730 | ops[num_ops] = IPP_ANY_OPERATION; | |
3731 | else if ((ops[num_ops] = ippOpValue(value)) == IPP_BAD_OPERATION) | |
3732 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3733 | "Bad IPP operation name \"%s\" on line %d!", | |
3734 | value, linenum); | |
3735 | else | |
3736 | num_ops ++; | |
3737 | } | |
3738 | else | |
3739 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3740 | "Too many operations listed on line %d!", | |
3741 | linenum); | |
3742 | ||
3743 | for (value = valptr; isspace(*value & 255); value ++); | |
3744 | } | |
3745 | ||
3746 | /* | |
3747 | * If none are specified, apply the policy to all operations... | |
3748 | */ | |
3749 | ||
3750 | if (num_ops == 0) | |
3751 | { | |
3752 | ops[0] = IPP_ANY_OPERATION; | |
3753 | num_ops = 1; | |
3754 | } | |
3755 | ||
3756 | /* | |
3757 | * Add a new policy for the first operation... | |
3758 | */ | |
3759 | ||
3760 | op = cupsdAddPolicyOp(pol, NULL, ops[0]); | |
3761 | } | |
3762 | else if (!strcasecmp(line, "</Limit>") && op) | |
3763 | { | |
3764 | /* | |
3765 | * Finish the current operation limit... | |
3766 | */ | |
3767 | ||
3768 | if (num_ops > 1) | |
3769 | { | |
3770 | /* | |
3771 | * Copy the policy to the other operations... | |
3772 | */ | |
3773 | ||
3774 | for (i = 1; i < num_ops; i ++) | |
3775 | cupsdAddPolicyOp(pol, op, ops[i]); | |
3776 | } | |
3777 | ||
3778 | op = NULL; | |
3779 | } | |
3780 | else if (!op) | |
3781 | { | |
3782 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3783 | "Missing <Limit ops> directive before %s on line %d.", | |
3784 | line, linenum); | |
49d87452 MS |
3785 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3786 | return (0); | |
ef416fc2 | 3787 | } |
3788 | else if (!parse_aaa(op, line, value, linenum)) | |
3789 | { | |
3790 | if (op) | |
3791 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3792 | "Unknown Policy Limit directive %s on line %d.", | |
3793 | line, linenum); | |
3794 | else | |
3795 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3796 | "Unknown Policy directive %s on line %d.", | |
3797 | line, linenum); | |
3798 | ||
49d87452 MS |
3799 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3800 | return (0); | |
ef416fc2 | 3801 | } |
3802 | } | |
3803 | ||
3804 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3805 | "Unexpected end-of-file at line %d while reading policy \"%s\"!", | |
3806 | linenum, policy); | |
3807 | ||
49d87452 | 3808 | return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum); |
ef416fc2 | 3809 | } |
3810 | ||
3811 | ||
3812 | /* | |
b19ccc9e | 3813 | * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $". |
ef416fc2 | 3814 | */ |