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