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