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