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