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