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