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