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