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