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