]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
f2d18633 | 2 | * "$Id$" |
ef416fc2 | 3 | * |
10d09e33 | 4 | * Configuration routines for the CUPS scheduler. |
ef416fc2 | 5 | * |
8a259669 | 6 | * Copyright 2007-2013 by Apple Inc. |
7594b224 | 7 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. |
ef416fc2 | 8 | * |
9 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 10 | * property of Apple Inc. and are protected by Federal copyright |
11 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 14 | * |
15 | * Contents: | |
16 | * | |
c41769ff | 17 | * cupsdAddAlias() - Add a host alias. |
b94498cf | 18 | * cupsdCheckPermissions() - Fix the mode and ownership of a file or |
c41769ff | 19 | * directory. |
dcb445bc | 20 | * cupsdDefaultAuthType() - Get the default AuthType. |
e07d4801 | 21 | * cupsdFreeAliases() - Free all of the alias entries. |
b94498cf | 22 | * cupsdReadConfiguration() - Read the cupsd.conf file. |
c41769ff | 23 | * get_address() - Get an address + port number from a line. |
ef416fc2 | 24 | * get_addr_and_mask() - Get an IP address and netmask. |
c41769ff MS |
25 | * mime_error_cb() - Log a MIME error. |
26 | * parse_aaa() - Parse authentication, authorization, and access | |
27 | * control lines. | |
49d87452 | 28 | * parse_fatal_errors() - Parse FatalErrors values in a string. |
c41769ff MS |
29 | * parse_groups() - Parse system group names in a string. |
30 | * parse_protocols() - Parse browse protocols in a string. | |
31 | * parse_variable() - Parse a variable line. | |
32 | * read_cupsd_conf() - Read the cupsd.conf configuration file. | |
33 | * read_cups_files_conf() - Read the cups-files.conf configuration file. | |
34 | * read_location() - Read a <Location path> definition. | |
35 | * read_policy() - Read a <Policy name> definition. | |
10d09e33 | 36 | * set_policy_defaults() - Set default policy values as needed. |
ef416fc2 | 37 | */ |
38 | ||
39 | /* | |
40 | * Include necessary headers... | |
41 | */ | |
42 | ||
43 | #include "cupsd.h" | |
44 | #include <stdarg.h> | |
45 | #include <grp.h> | |
46 | #include <sys/utsname.h> | |
b94498cf | 47 | #include <syslog.h> |
ef416fc2 | 48 | |
97c9a8d7 MS |
49 | #ifdef HAVE_LIBPAPER |
50 | # include <paper.h> | |
51 | #endif /* HAVE_LIBPAPER */ | |
52 | ||
ef416fc2 | 53 | |
54 | /* | |
55 | * Possibly missing network definitions... | |
56 | */ | |
57 | ||
58 | #ifndef INADDR_NONE | |
59 | # define INADDR_NONE 0xffffffff | |
60 | #endif /* !INADDR_NONE */ | |
61 | ||
62 | ||
63 | /* | |
64 | * Configuration variable structure... | |
65 | */ | |
66 | ||
67 | typedef enum | |
68 | { | |
69 | CUPSD_VARTYPE_INTEGER, /* Integer option */ | |
82cc1f9a | 70 | CUPSD_VARTYPE_TIME, /* Time interval option */ |
ef416fc2 | 71 | CUPSD_VARTYPE_STRING, /* String option */ |
76cd9e37 MS |
72 | CUPSD_VARTYPE_BOOLEAN, /* Boolean option */ |
73 | CUPSD_VARTYPE_PATHNAME /* File/directory name option */ | |
ef416fc2 | 74 | } cupsd_vartype_t; |
75 | ||
76 | typedef struct | |
77 | { | |
a2326b5b | 78 | const char *name; /* Name of variable */ |
ef416fc2 | 79 | void *ptr; /* Pointer to variable */ |
80 | cupsd_vartype_t type; /* Type (int, string, address) */ | |
81 | } cupsd_var_t; | |
82 | ||
83 | ||
84 | /* | |
85 | * Local globals... | |
86 | */ | |
87 | ||
c41769ff | 88 | static const cupsd_var_t cupsd_vars[] = |
ef416fc2 | 89 | { |
ef416fc2 | 90 | { "AutoPurgeJobs", &JobAutoPurge, CUPSD_VARTYPE_BOOLEAN }, |
37e7e6e0 | 91 | #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) |
f3c17241 | 92 | { "BrowseDNSSDSubTypes", &DNSSDSubTypes, CUPSD_VARTYPE_STRING }, |
37e7e6e0 | 93 | #endif /* HAVE_DNSSD || HAVE_AVAHI */ |
b19ccc9e | 94 | { "BrowseWebIF", &BrowseWebIF, CUPSD_VARTYPE_BOOLEAN }, |
ef416fc2 | 95 | { "Browsing", &Browsing, CUPSD_VARTYPE_BOOLEAN }, |
ef416fc2 | 96 | { "Classification", &Classification, CUPSD_VARTYPE_STRING }, |
97 | { "ClassifyOverride", &ClassifyOverride, CUPSD_VARTYPE_BOOLEAN }, | |
ef416fc2 | 98 | { "DefaultLanguage", &DefaultLanguage, CUPSD_VARTYPE_STRING }, |
82cc1f9a | 99 | { "DefaultLeaseDuration", &DefaultLeaseDuration, CUPSD_VARTYPE_TIME }, |
c5571a1d | 100 | { "DefaultPaperSize", &DefaultPaperSize, CUPSD_VARTYPE_STRING }, |
ef416fc2 | 101 | { "DefaultPolicy", &DefaultPolicy, CUPSD_VARTYPE_STRING }, |
fa73b229 | 102 | { "DefaultShared", &DefaultShared, CUPSD_VARTYPE_BOOLEAN }, |
82cc1f9a | 103 | { "DirtyCleanInterval", &DirtyCleanInterval, CUPSD_VARTYPE_TIME }, |
323c5de1 | 104 | { "ErrorPolicy", &ErrorPolicy, CUPSD_VARTYPE_STRING }, |
ef416fc2 | 105 | { "FilterLimit", &FilterLimit, CUPSD_VARTYPE_INTEGER }, |
106 | { "FilterNice", &FilterNice, CUPSD_VARTYPE_INTEGER }, | |
dcb445bc MS |
107 | #ifdef HAVE_GSSAPI |
108 | { "GSSServiceName", &GSSServiceName, CUPSD_VARTYPE_STRING }, | |
109 | #endif /* HAVE_GSSAPI */ | |
82cc1f9a | 110 | { "JobKillDelay", &JobKillDelay, CUPSD_VARTYPE_TIME }, |
ef416fc2 | 111 | { "JobRetryLimit", &JobRetryLimit, CUPSD_VARTYPE_INTEGER }, |
82cc1f9a MS |
112 | { "JobRetryInterval", &JobRetryInterval, CUPSD_VARTYPE_TIME }, |
113 | { "KeepAliveTimeout", &KeepAliveTimeout, CUPSD_VARTYPE_TIME }, | |
ef416fc2 | 114 | { "KeepAlive", &KeepAlive, CUPSD_VARTYPE_BOOLEAN }, |
f7deaa1a | 115 | #ifdef HAVE_LAUNCHD |
82cc1f9a | 116 | { "LaunchdTimeout", &LaunchdTimeout, CUPSD_VARTYPE_TIME }, |
f7deaa1a | 117 | #endif /* HAVE_LAUNCHD */ |
ef416fc2 | 118 | { "LimitRequestBody", &MaxRequestSize, CUPSD_VARTYPE_INTEGER }, |
119 | { "ListenBackLog", &ListenBackLog, CUPSD_VARTYPE_INTEGER }, | |
178cb736 | 120 | { "LogDebugHistory", &LogDebugHistory, CUPSD_VARTYPE_INTEGER }, |
ef416fc2 | 121 | { "MaxActiveJobs", &MaxActiveJobs, CUPSD_VARTYPE_INTEGER }, |
122 | { "MaxClients", &MaxClients, CUPSD_VARTYPE_INTEGER }, | |
123 | { "MaxClientsPerHost", &MaxClientsPerHost, CUPSD_VARTYPE_INTEGER }, | |
124 | { "MaxCopies", &MaxCopies, CUPSD_VARTYPE_INTEGER }, | |
125 | { "MaxEvents", &MaxEvents, CUPSD_VARTYPE_INTEGER }, | |
82cc1f9a | 126 | { "MaxHoldTime", &MaxHoldTime, CUPSD_VARTYPE_TIME }, |
ef416fc2 | 127 | { "MaxJobs", &MaxJobs, CUPSD_VARTYPE_INTEGER }, |
128 | { "MaxJobsPerPrinter", &MaxJobsPerPrinter, CUPSD_VARTYPE_INTEGER }, | |
129 | { "MaxJobsPerUser", &MaxJobsPerUser, CUPSD_VARTYPE_INTEGER }, | |
dcb445bc | 130 | { "MaxJobTime", &MaxJobTime, CUPSD_VARTYPE_INTEGER }, |
82cc1f9a | 131 | { "MaxLeaseDuration", &MaxLeaseDuration, CUPSD_VARTYPE_TIME }, |
ef416fc2 | 132 | { "MaxLogSize", &MaxLogSize, CUPSD_VARTYPE_INTEGER }, |
ef416fc2 | 133 | { "MaxRequestSize", &MaxRequestSize, CUPSD_VARTYPE_INTEGER }, |
134 | { "MaxSubscriptions", &MaxSubscriptions, CUPSD_VARTYPE_INTEGER }, | |
135 | { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob, CUPSD_VARTYPE_INTEGER }, | |
136 | { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter, CUPSD_VARTYPE_INTEGER }, | |
137 | { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser, CUPSD_VARTYPE_INTEGER }, | |
82cc1f9a | 138 | { "MultipleOperationTimeout", &MultipleOperationTimeout, CUPSD_VARTYPE_TIME }, |
01ce6322 | 139 | { "PageLogFormat", &PageLogFormat, CUPSD_VARTYPE_STRING }, |
82cc1f9a MS |
140 | { "PreserveJobFiles", &JobFiles, CUPSD_VARTYPE_TIME }, |
141 | { "PreserveJobHistory", &JobHistory, CUPSD_VARTYPE_TIME }, | |
82cc1f9a | 142 | { "ReloadTimeout", &ReloadTimeout, CUPSD_VARTYPE_TIME }, |
ef416fc2 | 143 | { "RIPCache", &RIPCache, CUPSD_VARTYPE_STRING }, |
82cc1f9a | 144 | { "RootCertDuration", &RootCertDuration, CUPSD_VARTYPE_TIME }, |
ef416fc2 | 145 | { "ServerAdmin", &ServerAdmin, CUPSD_VARTYPE_STRING }, |
c41769ff MS |
146 | { "ServerName", &ServerName, CUPSD_VARTYPE_STRING }, |
147 | { "StrictConformance", &StrictConformance, CUPSD_VARTYPE_BOOLEAN }, | |
148 | { "Timeout", &Timeout, CUPSD_VARTYPE_TIME }, | |
149 | { "WebInterface", &WebInterface, CUPSD_VARTYPE_BOOLEAN } | |
150 | }; | |
151 | static const cupsd_var_t cupsfiles_vars[] = | |
152 | { | |
153 | { "AccessLog", &AccessLog, CUPSD_VARTYPE_STRING }, | |
154 | { "CacheDir", &CacheDir, CUPSD_VARTYPE_STRING }, | |
155 | { "ConfigFilePerm", &ConfigFilePerm, CUPSD_VARTYPE_INTEGER }, | |
156 | { "DataDir", &DataDir, CUPSD_VARTYPE_STRING }, | |
157 | { "DocumentRoot", &DocumentRoot, CUPSD_VARTYPE_STRING }, | |
158 | { "ErrorLog", &ErrorLog, CUPSD_VARTYPE_STRING }, | |
159 | { "FileDevice", &FileDevice, CUPSD_VARTYPE_BOOLEAN }, | |
160 | { "FontPath", &FontPath, CUPSD_VARTYPE_STRING }, | |
161 | { "LogFilePerm", &LogFilePerm, CUPSD_VARTYPE_INTEGER }, | |
162 | { "LPDConfigFile", &LPDConfigFile, CUPSD_VARTYPE_STRING }, | |
163 | { "PageLog", &PageLog, CUPSD_VARTYPE_STRING }, | |
164 | { "Printcap", &Printcap, CUPSD_VARTYPE_STRING }, | |
cb7f98ee | 165 | { "RemoteRoot", &RemoteRoot, CUPSD_VARTYPE_STRING }, |
c41769ff | 166 | { "RequestRoot", &RequestRoot, CUPSD_VARTYPE_STRING }, |
76cd9e37 | 167 | { "ServerBin", &ServerBin, CUPSD_VARTYPE_PATHNAME }, |
ef416fc2 | 168 | #ifdef HAVE_SSL |
76cd9e37 | 169 | { "ServerCertificate", &ServerCertificate, CUPSD_VARTYPE_PATHNAME }, |
ef416fc2 | 170 | # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS) |
76cd9e37 | 171 | { "ServerKey", &ServerKey, CUPSD_VARTYPE_PATHNAME }, |
ef416fc2 | 172 | # endif /* HAVE_LIBSSL || HAVE_GNUTLS */ |
173 | #endif /* HAVE_SSL */ | |
76cd9e37 | 174 | { "ServerRoot", &ServerRoot, CUPSD_VARTYPE_PATHNAME }, |
2e4ff8af | 175 | { "SMBConfigFile", &SMBConfigFile, CUPSD_VARTYPE_STRING }, |
ef416fc2 | 176 | { "StateDir", &StateDir, CUPSD_VARTYPE_STRING }, |
8a259669 | 177 | { "SyncOnClose", &SyncOnClose, CUPSD_VARTYPE_BOOLEAN }, |
f7deaa1a | 178 | #ifdef HAVE_AUTHORIZATION_H |
179 | { "SystemGroupAuthKey", &SystemGroupAuthKey, CUPSD_VARTYPE_STRING }, | |
180 | #endif /* HAVE_AUTHORIZATION_H */ | |
c41769ff | 181 | { "TempDir", &TempDir, CUPSD_VARTYPE_PATHNAME } |
ef416fc2 | 182 | }; |
ef416fc2 | 183 | |
c41769ff MS |
184 | static int default_auth_type = CUPSD_AUTH_AUTO; |
185 | /* Default AuthType, if not specified */ | |
ef416fc2 | 186 | |
ac884b6a | 187 | static const unsigned ones[4] = |
ef416fc2 | 188 | { |
189 | 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff | |
190 | }; | |
ac884b6a | 191 | static const unsigned zeros[4] = |
ef416fc2 | 192 | { |
193 | 0x00000000, 0x00000000, 0x00000000, 0x00000000 | |
194 | }; | |
195 | ||
196 | ||
197 | /* | |
198 | * Local functions... | |
199 | */ | |
e07d4801 | 200 | |
ef416fc2 | 201 | static http_addrlist_t *get_address(const char *value, int defport); |
202 | static int get_addr_and_mask(const char *value, unsigned *ip, | |
203 | unsigned *mask); | |
eac3a0a0 | 204 | static void mime_error_cb(void *ctx, const char *message); |
ef416fc2 | 205 | static int parse_aaa(cupsd_location_t *loc, char *line, |
206 | char *value, int linenum); | |
49d87452 | 207 | static int parse_fatal_errors(const char *s); |
bd7854cb | 208 | static int parse_groups(const char *s); |
209 | static int parse_protocols(const char *s); | |
c41769ff MS |
210 | static int parse_variable(const char *filename, int linenum, |
211 | const char *line, const char *value, | |
212 | size_t num_vars, | |
213 | const cupsd_var_t *vars); | |
214 | static int read_cupsd_conf(cups_file_t *fp); | |
215 | static int read_cups_files_conf(cups_file_t *fp); | |
ef416fc2 | 216 | static int read_location(cups_file_t *fp, char *name, int linenum); |
217 | static int read_policy(cups_file_t *fp, char *name, int linenum); | |
10d09e33 | 218 | static void set_policy_defaults(cupsd_policy_t *pol); |
ef416fc2 | 219 | |
220 | ||
e07d4801 MS |
221 | /* |
222 | * 'cupsdAddAlias()' - Add a host alias. | |
223 | */ | |
224 | ||
225 | void | |
226 | cupsdAddAlias(cups_array_t *aliases, /* I - Array of aliases */ | |
227 | const char *name) /* I - Name to add */ | |
228 | { | |
229 | cupsd_alias_t *a; /* New alias */ | |
230 | size_t namelen; /* Length of name */ | |
231 | ||
232 | ||
233 | namelen = strlen(name); | |
234 | ||
235 | if ((a = (cupsd_alias_t *)malloc(sizeof(cupsd_alias_t) + namelen)) == NULL) | |
236 | return; | |
237 | ||
238 | a->namelen = namelen; | |
5a9febac | 239 | memcpy(a->name, name, namelen + 1); /* OK since a->name is allocated */ |
e07d4801 MS |
240 | |
241 | cupsArrayAdd(aliases, a); | |
242 | } | |
243 | ||
244 | ||
b94498cf | 245 | /* |
246 | * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory. | |
247 | */ | |
248 | ||
249 | int /* O - 0 on success, -1 on error, 1 on warning */ | |
250 | cupsdCheckPermissions( | |
251 | const char *filename, /* I - File/directory name */ | |
252 | const char *suffix, /* I - Additional file/directory name */ | |
253 | int mode, /* I - Permissions */ | |
254 | int user, /* I - Owner */ | |
255 | int group, /* I - Group */ | |
256 | int is_dir, /* I - 1 = directory, 0 = file */ | |
257 | int create_dir) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */ | |
258 | { | |
259 | int dir_created = 0; /* Did we create a directory? */ | |
260 | char pathname[1024]; /* File name with prefix */ | |
261 | struct stat fileinfo; /* Stat buffer */ | |
49d87452 | 262 | int is_symlink; /* Is "filename" a symlink? */ |
b94498cf | 263 | |
264 | ||
265 | /* | |
266 | * Prepend the given root to the filename before testing it... | |
267 | */ | |
268 | ||
269 | if (suffix) | |
270 | { | |
271 | snprintf(pathname, sizeof(pathname), "%s/%s", filename, suffix); | |
272 | filename = pathname; | |
273 | } | |
274 | ||
275 | /* | |
276 | * See if we can stat the file/directory... | |
277 | */ | |
278 | ||
49d87452 | 279 | if (lstat(filename, &fileinfo)) |
b94498cf | 280 | { |
281 | if (errno == ENOENT && create_dir) | |
282 | { | |
283 | if (create_dir > 0) | |
284 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Creating missing directory \"%s\"", | |
285 | filename); | |
286 | ||
287 | if (mkdir(filename, mode)) | |
288 | { | |
289 | if (create_dir > 0) | |
290 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
291 | "Unable to create directory \"%s\" - %s", filename, | |
292 | strerror(errno)); | |
293 | else | |
294 | syslog(LOG_ERR, "Unable to create directory \"%s\" - %s", filename, | |
295 | strerror(errno)); | |
296 | ||
297 | return (-1); | |
298 | } | |
299 | ||
d1c13e16 MS |
300 | dir_created = 1; |
301 | fileinfo.st_mode = mode | S_IFDIR; | |
b94498cf | 302 | } |
303 | else | |
304 | return (create_dir ? -1 : 1); | |
305 | } | |
306 | ||
49d87452 MS |
307 | if ((is_symlink = S_ISLNK(fileinfo.st_mode)) != 0) |
308 | { | |
309 | if (stat(filename, &fileinfo)) | |
310 | { | |
311 | cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is a bad symlink - %s", | |
312 | filename, strerror(errno)); | |
313 | return (-1); | |
314 | } | |
315 | } | |
316 | ||
b94498cf | 317 | /* |
49d87452 | 318 | * Make sure it's a regular file or a directory as needed... |
b94498cf | 319 | */ |
320 | ||
321 | if (!dir_created && !is_dir && !S_ISREG(fileinfo.st_mode)) | |
322 | { | |
c8fef167 | 323 | cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a regular file.", filename); |
b94498cf | 324 | return (-1); |
325 | } | |
326 | ||
327 | if (!dir_created && is_dir && !S_ISDIR(fileinfo.st_mode)) | |
328 | { | |
329 | if (create_dir >= 0) | |
c8fef167 | 330 | cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory.", filename); |
b94498cf | 331 | else |
c8fef167 | 332 | syslog(LOG_ERR, "\"%s\" is not a directory.", filename); |
b94498cf | 333 | |
334 | return (-1); | |
335 | } | |
336 | ||
49d87452 MS |
337 | /* |
338 | * If the filename is a symlink, do not change permissions (STR #2937)... | |
339 | */ | |
340 | ||
341 | if (is_symlink) | |
342 | return (0); | |
343 | ||
b94498cf | 344 | /* |
345 | * Fix owner, group, and mode as needed... | |
346 | */ | |
347 | ||
348 | if (dir_created || fileinfo.st_uid != user || fileinfo.st_gid != group) | |
349 | { | |
350 | if (create_dir >= 0) | |
351 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing ownership of \"%s\"", | |
352 | filename); | |
353 | ||
354 | if (chown(filename, user, group) && !getuid()) | |
355 | { | |
356 | if (create_dir >= 0) | |
357 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
358 | "Unable to change ownership of \"%s\" - %s", filename, | |
359 | strerror(errno)); | |
360 | else | |
361 | syslog(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename, | |
362 | strerror(errno)); | |
363 | ||
364 | return (1); | |
365 | } | |
366 | } | |
367 | ||
368 | if (dir_created || (fileinfo.st_mode & 07777) != mode) | |
369 | { | |
370 | if (create_dir >= 0) | |
371 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing access permissions of \"%s\"", | |
372 | filename); | |
373 | ||
374 | if (chmod(filename, mode)) | |
375 | { | |
376 | if (create_dir >= 0) | |
377 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
378 | "Unable to change permissions of \"%s\" - %s", filename, | |
379 | strerror(errno)); | |
380 | else | |
381 | syslog(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename, | |
382 | strerror(errno)); | |
383 | ||
384 | return (1); | |
385 | } | |
386 | } | |
387 | ||
388 | /* | |
389 | * Everything is OK... | |
390 | */ | |
391 | ||
392 | return (0); | |
393 | } | |
394 | ||
395 | ||
dcb445bc MS |
396 | /* |
397 | * 'cupsdDefaultAuthType()' - Get the default AuthType. | |
398 | * | |
399 | * When the default_auth_type is "auto", this function tries to get the GSS | |
400 | * credentials for the server. If that succeeds we use Kerberos authentication, | |
401 | * otherwise we do a fallback to Basic authentication against the local user | |
402 | * accounts. | |
403 | */ | |
404 | ||
405 | int /* O - Default AuthType value */ | |
406 | cupsdDefaultAuthType(void) | |
407 | { | |
408 | #ifdef HAVE_GSSAPI | |
409 | OM_uint32 major_status, /* Major status code */ | |
410 | minor_status; /* Minor status code */ | |
411 | gss_name_t server_name; /* Server name */ | |
412 | gss_buffer_desc token = GSS_C_EMPTY_BUFFER; | |
413 | /* Service name token */ | |
414 | char buf[1024]; /* Service name buffer */ | |
415 | #endif /* HAVE_GSSAPI */ | |
416 | ||
417 | ||
418 | /* | |
419 | * If we have already determined the correct default AuthType, use it... | |
420 | */ | |
421 | ||
422 | if (default_auth_type != CUPSD_AUTH_AUTO) | |
423 | return (default_auth_type); | |
424 | ||
425 | #ifdef HAVE_GSSAPI | |
426 | # ifdef __APPLE__ | |
427 | /* | |
428 | * If the weak-linked GSSAPI/Kerberos library is not present, don't try | |
429 | * to use it... | |
430 | */ | |
431 | ||
432 | if (gss_init_sec_context == NULL) | |
433 | return (default_auth_type = CUPSD_AUTH_BASIC); | |
434 | # endif /* __APPLE__ */ | |
435 | ||
436 | /* | |
437 | * Try to obtain the server's GSS credentials (GSSServiceName@servername). If | |
438 | * that fails we must use Basic... | |
439 | */ | |
440 | ||
441 | snprintf(buf, sizeof(buf), "%s@%s", GSSServiceName, ServerName); | |
442 | ||
443 | token.value = buf; | |
444 | token.length = strlen(buf); | |
445 | server_name = GSS_C_NO_NAME; | |
446 | major_status = gss_import_name(&minor_status, &token, | |
447 | GSS_C_NT_HOSTBASED_SERVICE, | |
448 | &server_name); | |
449 | ||
450 | memset(&token, 0, sizeof(token)); | |
451 | ||
452 | if (GSS_ERROR(major_status)) | |
453 | { | |
454 | cupsdLogGSSMessage(CUPSD_LOG_DEBUG, major_status, minor_status, | |
455 | "cupsdDefaultAuthType: gss_import_name(%s) failed", buf); | |
456 | return (default_auth_type = CUPSD_AUTH_BASIC); | |
457 | } | |
458 | ||
459 | major_status = gss_display_name(&minor_status, server_name, &token, NULL); | |
460 | ||
461 | if (GSS_ERROR(major_status)) | |
462 | { | |
463 | cupsdLogGSSMessage(CUPSD_LOG_DEBUG, major_status, minor_status, | |
464 | "cupsdDefaultAuthType: gss_display_name(%s) failed", | |
465 | buf); | |
466 | return (default_auth_type = CUPSD_AUTH_BASIC); | |
467 | } | |
468 | ||
469 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
470 | "cupsdDefaultAuthType: Attempting to acquire Kerberos " | |
471 | "credentials for %s...", (char *)token.value); | |
472 | ||
473 | ServerCreds = GSS_C_NO_CREDENTIAL; | |
474 | major_status = gss_acquire_cred(&minor_status, server_name, GSS_C_INDEFINITE, | |
475 | GSS_C_NO_OID_SET, GSS_C_ACCEPT, | |
476 | &ServerCreds, NULL, NULL); | |
477 | if (GSS_ERROR(major_status)) | |
478 | { | |
479 | cupsdLogGSSMessage(CUPSD_LOG_DEBUG, major_status, minor_status, | |
480 | "cupsdDefaultAuthType: gss_acquire_cred(%s) failed", | |
481 | (char *)token.value); | |
482 | gss_release_name(&minor_status, &server_name); | |
483 | gss_release_buffer(&minor_status, &token); | |
484 | return (default_auth_type = CUPSD_AUTH_BASIC); | |
485 | } | |
486 | ||
487 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
488 | "cupsdDefaultAuthType: Kerberos credentials acquired " | |
489 | "successfully for %s.", (char *)token.value); | |
490 | ||
491 | gss_release_name(&minor_status, &server_name); | |
492 | gss_release_buffer(&minor_status, &token); | |
493 | ||
494 | HaveServerCreds = 1; | |
495 | ||
496 | return (default_auth_type = CUPSD_AUTH_NEGOTIATE); | |
497 | ||
498 | #else | |
499 | /* | |
500 | * No Kerberos support compiled in so just use Basic all the time... | |
501 | */ | |
502 | ||
503 | return (default_auth_type = CUPSD_AUTH_BASIC); | |
504 | #endif /* HAVE_GSSAPI */ | |
505 | } | |
506 | ||
507 | ||
e07d4801 MS |
508 | /* |
509 | * 'cupsdFreeAliases()' - Free all of the alias entries. | |
510 | */ | |
511 | ||
512 | void | |
513 | cupsdFreeAliases(cups_array_t *aliases) /* I - Array of aliases */ | |
514 | { | |
515 | cupsd_alias_t *a; /* Current alias */ | |
516 | ||
517 | ||
518 | for (a = (cupsd_alias_t *)cupsArrayFirst(aliases); | |
519 | a; | |
520 | a = (cupsd_alias_t *)cupsArrayNext(aliases)) | |
521 | free(a); | |
522 | ||
523 | cupsArrayDelete(aliases); | |
524 | } | |
525 | ||
526 | ||
ef416fc2 | 527 | /* |
528 | * 'cupsdReadConfiguration()' - Read the cupsd.conf file. | |
529 | */ | |
530 | ||
531 | int /* O - 1 on success, 0 otherwise */ | |
532 | cupsdReadConfiguration(void) | |
533 | { | |
534 | int i; /* Looping var */ | |
535 | cups_file_t *fp; /* Configuration file */ | |
536 | int status; /* Return status */ | |
537 | char temp[1024], /* Temporary buffer */ | |
dd1abb6b | 538 | mimedir[1024], /* MIME directory */ |
ef416fc2 | 539 | *slash; /* Directory separator */ |
ef416fc2 | 540 | cups_lang_t *language; /* Language */ |
541 | struct passwd *user; /* Default user */ | |
542 | struct group *group; /* Default group */ | |
543 | char *old_serverroot, /* Old ServerRoot */ | |
544 | *old_requestroot; /* Old RequestRoot */ | |
f11a948a | 545 | int old_remote_port; /* Old RemotePort */ |
b423cd4c | 546 | const char *tmpdir; /* TMPDIR environment variable */ |
547 | struct stat tmpinfo; /* Temporary directory info */ | |
2e4ff8af | 548 | cupsd_policy_t *p; /* Policy */ |
b423cd4c | 549 | |
ef416fc2 | 550 | |
ef416fc2 | 551 | /* |
552 | * Save the old root paths... | |
553 | */ | |
554 | ||
555 | old_serverroot = NULL; | |
556 | cupsdSetString(&old_serverroot, ServerRoot); | |
557 | old_requestroot = NULL; | |
558 | cupsdSetString(&old_requestroot, RequestRoot); | |
559 | ||
560 | /* | |
561 | * Reset the server configuration data... | |
562 | */ | |
563 | ||
564 | cupsdDeleteAllLocations(); | |
565 | ||
bd7854cb | 566 | cupsdDeleteAllListeners(); |
ef416fc2 | 567 | |
f11a948a MS |
568 | old_remote_port = RemotePort; |
569 | RemotePort = 0; | |
d1c13e16 | 570 | |
ef416fc2 | 571 | /* |
572 | * String options... | |
573 | */ | |
574 | ||
e07d4801 MS |
575 | cupsdFreeAliases(ServerAlias); |
576 | ServerAlias = NULL; | |
577 | ||
d1c13e16 MS |
578 | cupsdClearString(&ServerName); |
579 | cupsdClearString(&ServerAdmin); | |
ef416fc2 | 580 | cupsdSetString(&ServerBin, CUPS_SERVERBIN); |
581 | cupsdSetString(&RequestRoot, CUPS_REQUESTS); | |
582 | cupsdSetString(&CacheDir, CUPS_CACHEDIR); | |
583 | cupsdSetString(&DataDir, CUPS_DATADIR); | |
584 | cupsdSetString(&DocumentRoot, CUPS_DOCROOT); | |
585 | cupsdSetString(&AccessLog, CUPS_LOGDIR "/access_log"); | |
a4845881 | 586 | cupsdClearString(&ErrorLog); |
ef416fc2 | 587 | cupsdSetString(&PageLog, CUPS_LOGDIR "/page_log"); |
01ce6322 | 588 | cupsdSetString(&PageLogFormat, |
0268488e | 589 | "%p %u %j %T %P %C %{job-billing} " |
01ce6322 | 590 | "%{job-originating-host-name} %{job-name} %{media} %{sides}"); |
e53920b9 | 591 | cupsdSetString(&Printcap, CUPS_DEFAULT_PRINTCAP); |
ef416fc2 | 592 | cupsdSetString(&FontPath, CUPS_FONTPATH); |
593 | cupsdSetString(&RemoteRoot, "remroot"); | |
db8b865d | 594 | cupsdSetStringf(&ServerHeader, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR, |
771bd8cb | 595 | CUPS_VERSION_MINOR); |
ef416fc2 | 596 | cupsdSetString(&StateDir, CUPS_STATEDIR); |
597 | ||
ed486911 | 598 | if (!strcmp(CUPS_DEFAULT_PRINTCAP, "/etc/printers.conf")) |
599 | PrintcapFormat = PRINTCAP_SOLARIS; | |
0af14961 MS |
600 | else if (!strcmp(CUPS_DEFAULT_PRINTCAP, |
601 | "/Library/Preferences/org.cups.printers.plist")) | |
602 | PrintcapFormat = PRINTCAP_PLIST; | |
ed486911 | 603 | else |
604 | PrintcapFormat = PRINTCAP_BSD; | |
605 | ||
ef416fc2 | 606 | strlcpy(temp, ConfigurationFile, sizeof(temp)); |
607 | if ((slash = strrchr(temp, '/')) != NULL) | |
608 | *slash = '\0'; | |
609 | ||
610 | cupsdSetString(&ServerRoot, temp); | |
611 | ||
612 | cupsdClearString(&Classification); | |
613 | ClassifyOverride = 0; | |
614 | ||
615 | #ifdef HAVE_SSL | |
616 | # ifdef HAVE_CDSASSL | |
fa73b229 | 617 | cupsdSetString(&ServerCertificate, "/Library/Keychains/System.keychain"); |
ef416fc2 | 618 | # else |
619 | cupsdSetString(&ServerCertificate, "ssl/server.crt"); | |
620 | cupsdSetString(&ServerKey, "ssl/server.key"); | |
621 | # endif /* HAVE_CDSASSL */ | |
622 | #endif /* HAVE_SSL */ | |
623 | ||
624 | language = cupsLangDefault(); | |
625 | ||
626 | if (!strcmp(language->language, "C") || !strcmp(language->language, "POSIX")) | |
627 | cupsdSetString(&DefaultLanguage, "en"); | |
628 | else | |
629 | cupsdSetString(&DefaultLanguage, language->language); | |
630 | ||
c5571a1d MS |
631 | cupsdClearString(&DefaultPaperSize); |
632 | ||
eac3a0a0 | 633 | cupsdSetString(&RIPCache, "128m"); |
ef416fc2 | 634 | |
b423cd4c | 635 | cupsdSetString(&TempDir, NULL); |
ef416fc2 | 636 | |
dcb445bc MS |
637 | #ifdef HAVE_GSSAPI |
638 | cupsdSetString(&GSSServiceName, CUPS_DEFAULT_GSSSERVICENAME); | |
639 | ||
640 | if (HaveServerCreds) | |
641 | { | |
642 | OM_uint32 minor_status; /* Minor status code */ | |
643 | ||
644 | gss_release_cred(&minor_status, &ServerCreds); | |
645 | ||
646 | HaveServerCreds = 0; | |
647 | } | |
648 | ||
649 | ServerCreds = GSS_C_NO_CREDENTIAL; | |
650 | #endif /* HAVE_GSSAPI */ | |
651 | ||
ef416fc2 | 652 | /* |
653 | * Find the default user... | |
654 | */ | |
655 | ||
656 | if ((user = getpwnam(CUPS_DEFAULT_USER)) != NULL) | |
657 | User = user->pw_uid; | |
658 | else | |
659 | { | |
660 | /* | |
661 | * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos- | |
662 | * complement number...) | |
663 | */ | |
664 | ||
665 | User = 65534; | |
666 | } | |
667 | ||
668 | endpwent(); | |
669 | ||
670 | /* | |
d6ae789d | 671 | * Find the default group... |
ef416fc2 | 672 | */ |
673 | ||
d6ae789d | 674 | group = getgrnam(CUPS_DEFAULT_GROUP); |
ef416fc2 | 675 | endgrent(); |
676 | ||
d6ae789d | 677 | if (group) |
ef416fc2 | 678 | Group = group->gr_gid; |
679 | else | |
680 | { | |
681 | /* | |
d6ae789d | 682 | * Fallback to group "nobody"... |
ef416fc2 | 683 | */ |
684 | ||
d6ae789d | 685 | group = getgrnam("nobody"); |
686 | endgrent(); | |
687 | ||
688 | if (group) | |
689 | Group = group->gr_gid; | |
690 | else | |
691 | { | |
692 | /* | |
693 | * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos- | |
694 | * complement number...) | |
695 | */ | |
696 | ||
697 | Group = 65534; | |
698 | } | |
ef416fc2 | 699 | } |
700 | ||
701 | /* | |
702 | * Numeric options... | |
703 | */ | |
704 | ||
dfd5680b MS |
705 | AccessLogLevel = CUPSD_ACCESSLOG_ACTIONS; |
706 | ConfigFilePerm = CUPS_DEFAULT_CONFIG_FILE_PERM; | |
707 | FatalErrors = parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS); | |
6961465f | 708 | default_auth_type = CUPSD_AUTH_BASIC; |
4744bd90 | 709 | #ifdef HAVE_SSL |
dfd5680b MS |
710 | DefaultEncryption = HTTP_ENCRYPT_REQUIRED; |
711 | SSLOptions = CUPSD_SSL_NONE; | |
4744bd90 | 712 | #endif /* HAVE_SSL */ |
dfd5680b | 713 | DirtyCleanInterval = DEFAULT_KEEPALIVE; |
238c3832 | 714 | JobKillDelay = DEFAULT_TIMEOUT; |
dfd5680b MS |
715 | JobRetryLimit = 5; |
716 | JobRetryInterval = 300; | |
717 | FileDevice = FALSE; | |
718 | FilterLevel = 0; | |
719 | FilterLimit = 0; | |
720 | FilterNice = 0; | |
721 | HostNameLookups = FALSE; | |
dfd5680b MS |
722 | KeepAlive = TRUE; |
723 | KeepAliveTimeout = DEFAULT_KEEPALIVE; | |
724 | ListenBackLog = SOMAXCONN; | |
178cb736 | 725 | LogDebugHistory = 200; |
dfd5680b MS |
726 | LogFilePerm = CUPS_DEFAULT_LOG_FILE_PERM; |
727 | LogLevel = CUPSD_LOG_WARN; | |
728 | LogTimeFormat = CUPSD_TIME_STANDARD; | |
729 | MaxClients = 100; | |
730 | MaxClientsPerHost = 0; | |
731 | MaxLogSize = 1024 * 1024; | |
dfd5680b MS |
732 | MaxRequestSize = 0; |
733 | MultipleOperationTimeout = DEFAULT_TIMEOUT; | |
a29fd7dd | 734 | NumSystemGroups = 0; |
dfd5680b MS |
735 | ReloadTimeout = DEFAULT_KEEPALIVE; |
736 | RootCertDuration = 300; | |
a29fd7dd | 737 | StrictConformance = FALSE; |
8a259669 | 738 | SyncOnClose = FALSE; |
dfd5680b | 739 | Timeout = DEFAULT_TIMEOUT; |
229681c1 | 740 | WebInterface = CUPS_DEFAULT_WEBIF; |
dfd5680b | 741 | |
dfd5680b | 742 | BrowseLocalProtocols = parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS); |
dfd5680b MS |
743 | BrowseWebIF = FALSE; |
744 | Browsing = CUPS_DEFAULT_BROWSING; | |
745 | DefaultShared = CUPS_DEFAULT_DEFAULT_SHARED; | |
ef416fc2 | 746 | |
37e7e6e0 | 747 | #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) |
f3c17241 | 748 | cupsdSetString(&DNSSDSubTypes, "_cups,_print"); |
37e7e6e0 | 749 | #endif /* HAVE_DNSSD || HAVE_AVAHI */ |
84315f46 | 750 | |
2e4ff8af MS |
751 | cupsdSetString(&LPDConfigFile, CUPS_DEFAULT_LPD_CONFIG_FILE); |
752 | cupsdSetString(&SMBConfigFile, CUPS_DEFAULT_SMB_CONFIG_FILE); | |
753 | ||
323c5de1 | 754 | cupsdSetString(&ErrorPolicy, "stop-printer"); |
755 | ||
ef416fc2 | 756 | JobHistory = DEFAULT_HISTORY; |
757 | JobFiles = DEFAULT_FILES; | |
758 | JobAutoPurge = 0; | |
3e7fe0ca | 759 | MaxHoldTime = 0; |
ef416fc2 | 760 | MaxJobs = 500; |
761 | MaxActiveJobs = 0; | |
762 | MaxJobsPerUser = 0; | |
763 | MaxJobsPerPrinter = 0; | |
dcb445bc | 764 | MaxJobTime = 3 * 60 * 60; /* 3 hours */ |
f7deaa1a | 765 | MaxCopies = CUPS_DEFAULT_MAX_COPIES; |
ef416fc2 | 766 | |
767 | cupsdDeleteAllPolicies(); | |
768 | cupsdClearString(&DefaultPolicy); | |
769 | ||
f7deaa1a | 770 | #ifdef HAVE_AUTHORIZATION_H |
6961465f | 771 | cupsdSetString(&SystemGroupAuthKey, CUPS_DEFAULT_SYSTEM_AUTHKEY); |
f7deaa1a | 772 | #endif /* HAVE_AUTHORIZATION_H */ |
773 | ||
ef416fc2 | 774 | MaxSubscriptions = 100; |
775 | MaxSubscriptionsPerJob = 0; | |
776 | MaxSubscriptionsPerPrinter = 0; | |
777 | MaxSubscriptionsPerUser = 0; | |
778 | DefaultLeaseDuration = 86400; | |
779 | MaxLeaseDuration = 0; | |
780 | ||
a4d04587 | 781 | #ifdef HAVE_LAUNCHD |
dcb445bc | 782 | LaunchdTimeout = 10; |
a4d04587 | 783 | #endif /* HAVE_LAUNCHD */ |
784 | ||
0268488e MS |
785 | /* |
786 | * Setup environment variables... | |
787 | */ | |
788 | ||
789 | cupsdInitEnv(); | |
790 | ||
ef416fc2 | 791 | /* |
c41769ff MS |
792 | * Read the cups-files.conf file... |
793 | */ | |
794 | ||
795 | if ((fp = cupsFileOpen(CupsFilesFile, "r")) != NULL) | |
796 | { | |
797 | status = read_cups_files_conf(fp); | |
798 | ||
799 | cupsFileClose(fp); | |
800 | ||
801 | if (!status) | |
cb7f98ee MS |
802 | { |
803 | if (TestConfigFile) | |
804 | printf("\"%s\" contains errors.\n", CupsFilesFile); | |
805 | else | |
806 | syslog(LOG_LPR, "Unable to read \"%s\" due to errors.", | |
807 | CupsFilesFile); | |
808 | ||
c41769ff | 809 | return (0); |
cb7f98ee | 810 | } |
c41769ff MS |
811 | } |
812 | else if (errno == ENOENT) | |
813 | cupsdLogMessage(CUPSD_LOG_INFO, "No %s, using defaults.", CupsFilesFile); | |
814 | else | |
815 | { | |
cb7f98ee MS |
816 | syslog(LOG_LPR, "Unable to open \"%s\": %s", CupsFilesFile, |
817 | strerror(errno)); | |
c41769ff MS |
818 | return (0); |
819 | } | |
820 | ||
821 | if (!ErrorLog) | |
822 | cupsdSetString(&ErrorLog, CUPS_LOGDIR "/error_log"); | |
823 | ||
824 | /* | |
825 | * Read the cupsd.conf file... | |
ef416fc2 | 826 | */ |
827 | ||
828 | if ((fp = cupsFileOpen(ConfigurationFile, "r")) == NULL) | |
c41769ff | 829 | { |
cb7f98ee MS |
830 | syslog(LOG_LPR, "Unable to open \"%s\": %s", ConfigurationFile, |
831 | strerror(errno)); | |
ef416fc2 | 832 | return (0); |
c41769ff | 833 | } |
ef416fc2 | 834 | |
c41769ff | 835 | status = read_cupsd_conf(fp); |
ef416fc2 | 836 | |
837 | cupsFileClose(fp); | |
838 | ||
839 | if (!status) | |
cb7f98ee MS |
840 | { |
841 | if (TestConfigFile) | |
842 | printf("\"%s\" contains errors.\n", ConfigurationFile); | |
843 | else | |
844 | syslog(LOG_LPR, "Unable to read \"%s\" due to errors.", | |
845 | ConfigurationFile); | |
846 | ||
ef416fc2 | 847 | return (0); |
cb7f98ee | 848 | } |
ef416fc2 | 849 | |
4744bd90 | 850 | RunUser = getuid(); |
ef416fc2 | 851 | |
d1c13e16 | 852 | cupsdLogMessage(CUPSD_LOG_INFO, "Remote access is %s.", |
f11a948a | 853 | RemotePort ? "enabled" : "disabled"); |
d1c13e16 | 854 | |
5a6b583a MS |
855 | if (!RemotePort) |
856 | BrowseLocalProtocols = 0; /* Disable sharing - no remote access */ | |
857 | ||
8ca02f3c | 858 | /* |
859 | * See if the ServerName is an IP address... | |
860 | */ | |
861 | ||
f11a948a MS |
862 | if (ServerName) |
863 | { | |
864 | if (!ServerAlias) | |
865 | ServerAlias = cupsArrayNew(NULL, NULL); | |
866 | ||
867 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", ServerName); | |
868 | } | |
869 | else | |
d1c13e16 | 870 | { |
e07d4801 | 871 | if (gethostname(temp, sizeof(temp))) |
d1c13e16 MS |
872 | { |
873 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get hostname: %s", | |
874 | strerror(errno)); | |
875 | strlcpy(temp, "localhost", sizeof(temp)); | |
876 | } | |
877 | ||
878 | cupsdSetString(&ServerName, temp); | |
e07d4801 MS |
879 | |
880 | if (!ServerAlias) | |
881 | ServerAlias = cupsArrayNew(NULL, NULL); | |
882 | ||
883 | cupsdAddAlias(ServerAlias, temp); | |
884 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", temp); | |
885 | ||
f11a948a | 886 | if (HostNameLookups || RemotePort) |
e07d4801 MS |
887 | { |
888 | struct hostent *host; /* Host entry to get FQDN */ | |
889 | ||
890 | if ((host = gethostbyname(temp)) != NULL) | |
891 | { | |
88f9aafc | 892 | if (_cups_strcasecmp(temp, host->h_name)) |
e07d4801 MS |
893 | { |
894 | cupsdSetString(&ServerName, host->h_name); | |
895 | cupsdAddAlias(ServerAlias, host->h_name); | |
896 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", | |
897 | host->h_name); | |
898 | } | |
899 | ||
900 | if (host->h_aliases) | |
901 | { | |
902 | for (i = 0; host->h_aliases[i]; i ++) | |
88f9aafc | 903 | if (_cups_strcasecmp(temp, host->h_aliases[i])) |
e07d4801 MS |
904 | { |
905 | cupsdAddAlias(ServerAlias, host->h_aliases[i]); | |
906 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", | |
907 | host->h_aliases[i]); | |
908 | } | |
909 | } | |
910 | } | |
911 | } | |
912 | ||
913 | /* | |
914 | * Make sure we have the base hostname added as an alias, too! | |
915 | */ | |
916 | ||
917 | if ((slash = strchr(temp, '.')) != NULL) | |
918 | { | |
919 | *slash = '\0'; | |
920 | cupsdAddAlias(ServerAlias, temp); | |
921 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", temp); | |
922 | } | |
d1c13e16 MS |
923 | } |
924 | ||
8ca02f3c | 925 | for (slash = ServerName; isdigit(*slash & 255) || *slash == '.'; slash ++); |
926 | ||
927 | ServerNameIsIP = !*slash; | |
928 | ||
d1c13e16 MS |
929 | /* |
930 | * Make sure ServerAdmin is initialized... | |
931 | */ | |
932 | ||
933 | if (!ServerAdmin) | |
934 | cupsdSetStringf(&ServerAdmin, "root@%s", ServerName); | |
935 | ||
ef416fc2 | 936 | /* |
937 | * Use the default system group if none was supplied in cupsd.conf... | |
938 | */ | |
939 | ||
940 | if (NumSystemGroups == 0) | |
bd7854cb | 941 | { |
942 | if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS)) | |
943 | { | |
944 | /* | |
945 | * Find the group associated with GID 0... | |
946 | */ | |
947 | ||
948 | group = getgrgid(0); | |
949 | endgrent(); | |
950 | ||
951 | if (group != NULL) | |
952 | cupsdSetString(&SystemGroups[0], group->gr_name); | |
953 | else | |
954 | cupsdSetString(&SystemGroups[0], "unknown"); | |
955 | ||
956 | SystemGroupIDs[0] = 0; | |
957 | NumSystemGroups = 1; | |
958 | } | |
959 | } | |
ef416fc2 | 960 | |
cb7f98ee MS |
961 | /* |
962 | * Make sure ConfigFilePerm and LogFilePerm have sane values... | |
963 | */ | |
964 | ||
965 | ConfigFilePerm &= 0664; | |
966 | LogFilePerm &= 0664; | |
967 | ||
ef416fc2 | 968 | /* |
969 | * Open the system log for cupsd if necessary... | |
970 | */ | |
971 | ||
972 | #ifdef HAVE_VSYSLOG | |
973 | if (!strcmp(AccessLog, "syslog") || | |
974 | !strcmp(ErrorLog, "syslog") || | |
975 | !strcmp(PageLog, "syslog")) | |
976 | openlog("cupsd", LOG_PID | LOG_NOWAIT | LOG_NDELAY, LOG_LPR); | |
977 | #endif /* HAVE_VSYSLOG */ | |
978 | ||
22c9029b MS |
979 | /* |
980 | * Make sure each of the log files exists and gets rotated as necessary... | |
981 | */ | |
982 | ||
eac3a0a0 | 983 | if (strcmp(AccessLog, "syslog")) |
22c9029b MS |
984 | cupsdCheckLogFile(&AccessFile, AccessLog); |
985 | ||
eac3a0a0 | 986 | if (strcmp(ErrorLog, "syslog")) |
22c9029b MS |
987 | cupsdCheckLogFile(&ErrorFile, ErrorLog); |
988 | ||
eac3a0a0 | 989 | if (strcmp(PageLog, "syslog")) |
22c9029b MS |
990 | cupsdCheckLogFile(&PageFile, PageLog); |
991 | ||
ef416fc2 | 992 | /* |
993 | * Log the configuration file that was used... | |
994 | */ | |
995 | ||
996 | cupsdLogMessage(CUPSD_LOG_INFO, "Loaded configuration file \"%s\"", | |
997 | ConfigurationFile); | |
998 | ||
999 | /* | |
1000 | * Validate the Group and SystemGroup settings - they cannot be the same, | |
1001 | * otherwise the CGI programs will be able to authenticate as root without | |
1002 | * a password! | |
1003 | */ | |
1004 | ||
1005 | if (!RunUser) | |
1006 | { | |
1007 | for (i = 0; i < NumSystemGroups; i ++) | |
1008 | if (Group == SystemGroupIDs[i]) | |
1009 | break; | |
1010 | ||
1011 | if (i < NumSystemGroups) | |
1012 | { | |
1013 | /* | |
1014 | * Log the error and reset the group to a safe value... | |
1015 | */ | |
1016 | ||
1017 | cupsdLogMessage(CUPSD_LOG_NOTICE, | |
c8fef167 | 1018 | "Group and SystemGroup cannot use the same groups."); |
ef416fc2 | 1019 | cupsdLogMessage(CUPSD_LOG_INFO, "Resetting Group to \"nobody\"..."); |
1020 | ||
1021 | group = getgrnam("nobody"); | |
1022 | endgrent(); | |
1023 | ||
1024 | if (group != NULL) | |
1025 | Group = group->gr_gid; | |
1026 | else | |
1027 | { | |
1028 | /* | |
1029 | * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos- | |
1030 | * complement number...) | |
1031 | */ | |
1032 | ||
1033 | Group = 65534; | |
1034 | } | |
1035 | } | |
1036 | } | |
1037 | ||
1038 | /* | |
1039 | * Check that we have at least one listen/port line; if not, report this | |
1040 | * as an error and exit! | |
1041 | */ | |
1042 | ||
bd7854cb | 1043 | if (cupsArrayCount(Listeners) == 0) |
ef416fc2 | 1044 | { |
1045 | /* | |
1046 | * No listeners! | |
1047 | */ | |
1048 | ||
1049 | cupsdLogMessage(CUPSD_LOG_EMERG, | |
49d87452 | 1050 | "No valid Listen or Port lines were found in the " |
c8fef167 | 1051 | "configuration file."); |
ef416fc2 | 1052 | |
1053 | /* | |
1054 | * Commit suicide... | |
1055 | */ | |
1056 | ||
1057 | cupsdEndProcess(getpid(), 0); | |
1058 | } | |
1059 | ||
1060 | /* | |
1061 | * Set the default locale using the language and charset... | |
1062 | */ | |
1063 | ||
f8b3a85b | 1064 | cupsdSetStringf(&DefaultLocale, "%s.UTF-8", DefaultLanguage); |
ef416fc2 | 1065 | |
1066 | /* | |
1067 | * Update all relative filenames to include the full path from ServerRoot... | |
1068 | */ | |
1069 | ||
1070 | if (DocumentRoot[0] != '/') | |
1071 | cupsdSetStringf(&DocumentRoot, "%s/%s", ServerRoot, DocumentRoot); | |
1072 | ||
1073 | if (RequestRoot[0] != '/') | |
1074 | cupsdSetStringf(&RequestRoot, "%s/%s", ServerRoot, RequestRoot); | |
1075 | ||
1076 | if (ServerBin[0] != '/') | |
1077 | cupsdSetStringf(&ServerBin, "%s/%s", ServerRoot, ServerBin); | |
1078 | ||
1079 | if (StateDir[0] != '/') | |
1080 | cupsdSetStringf(&StateDir, "%s/%s", ServerRoot, StateDir); | |
1081 | ||
1082 | if (CacheDir[0] != '/') | |
1083 | cupsdSetStringf(&CacheDir, "%s/%s", ServerRoot, CacheDir); | |
1084 | ||
1085 | #ifdef HAVE_SSL | |
1086 | if (ServerCertificate[0] != '/') | |
1087 | cupsdSetStringf(&ServerCertificate, "%s/%s", ServerRoot, ServerCertificate); | |
1088 | ||
49d87452 MS |
1089 | if (!strncmp(ServerRoot, ServerCertificate, strlen(ServerRoot)) && |
1090 | cupsdCheckPermissions(ServerCertificate, NULL, 0600, RunUser, Group, | |
1091 | 0, 0) < 0 && | |
1092 | (FatalErrors & CUPSD_FATAL_PERMISSIONS)) | |
1093 | return (0); | |
ef416fc2 | 1094 | |
1095 | # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS) | |
1096 | if (ServerKey[0] != '/') | |
1097 | cupsdSetStringf(&ServerKey, "%s/%s", ServerRoot, ServerKey); | |
1098 | ||
49d87452 MS |
1099 | if (!strncmp(ServerRoot, ServerKey, strlen(ServerRoot)) && |
1100 | cupsdCheckPermissions(ServerKey, NULL, 0600, RunUser, Group, 0, 0) < 0 && | |
1101 | (FatalErrors & CUPSD_FATAL_PERMISSIONS)) | |
1102 | return (0); | |
ef416fc2 | 1103 | # endif /* HAVE_LIBSSL || HAVE_GNUTLS */ |
1104 | #endif /* HAVE_SSL */ | |
1105 | ||
1106 | /* | |
1107 | * Make sure that directories and config files are owned and | |
1108 | * writable by the user and group in the cupsd.conf file... | |
1109 | */ | |
1110 | ||
ae71f5de MS |
1111 | snprintf(temp, sizeof(temp), "%s/rss", CacheDir); |
1112 | ||
49d87452 MS |
1113 | if ((cupsdCheckPermissions(RequestRoot, NULL, 0710, RunUser, |
1114 | Group, 1, 1) < 0 || | |
1115 | cupsdCheckPermissions(CacheDir, NULL, 0775, RunUser, | |
1116 | Group, 1, 1) < 0 || | |
1117 | cupsdCheckPermissions(temp, NULL, 0775, RunUser, | |
1118 | Group, 1, 1) < 0 || | |
1119 | cupsdCheckPermissions(StateDir, NULL, 0755, RunUser, | |
1120 | Group, 1, 1) < 0 || | |
1121 | cupsdCheckPermissions(StateDir, "certs", RunUser ? 0711 : 0511, User, | |
1122 | SystemGroupIDs[0], 1, 1) < 0 || | |
ef55b745 | 1123 | cupsdCheckPermissions(ServerRoot, NULL, 0755, RunUser, |
49d87452 MS |
1124 | Group, 1, 0) < 0 || |
1125 | cupsdCheckPermissions(ServerRoot, "ppd", 0755, RunUser, | |
1126 | Group, 1, 1) < 0 || | |
1127 | cupsdCheckPermissions(ServerRoot, "ssl", 0700, RunUser, | |
1128 | Group, 1, 0) < 0 || | |
cb7f98ee MS |
1129 | cupsdCheckPermissions(ConfigurationFile, NULL, ConfigFilePerm, RunUser, |
1130 | Group, 0, 0) < 0 || | |
1131 | cupsdCheckPermissions(CupsFilesFile, NULL, ConfigFilePerm, RunUser, | |
49d87452 MS |
1132 | Group, 0, 0) < 0 || |
1133 | cupsdCheckPermissions(ServerRoot, "classes.conf", 0600, RunUser, | |
1134 | Group, 0, 0) < 0 || | |
1135 | cupsdCheckPermissions(ServerRoot, "printers.conf", 0600, RunUser, | |
1136 | Group, 0, 0) < 0 || | |
1137 | cupsdCheckPermissions(ServerRoot, "passwd.md5", 0600, User, | |
1138 | Group, 0, 0) < 0) && | |
1139 | (FatalErrors & CUPSD_FATAL_PERMISSIONS)) | |
d09495fa | 1140 | return (0); |
ef416fc2 | 1141 | |
b423cd4c | 1142 | /* |
1143 | * Update TempDir to the default if it hasn't been set already... | |
1144 | */ | |
1145 | ||
0fa6c7fa MS |
1146 | #ifdef __APPLE__ |
1147 | if (TempDir && !RunUser && | |
1148 | (!strncmp(TempDir, "/private/tmp", 12) || !strncmp(TempDir, "/tmp", 4))) | |
1149 | { | |
1150 | cupsdLogMessage(CUPSD_LOG_ERROR, "Cannot use %s for TempDir.", TempDir); | |
1151 | cupsdClearString(&TempDir); | |
1152 | } | |
1153 | #endif /* __APPLE__ */ | |
1154 | ||
b423cd4c | 1155 | if (!TempDir) |
1156 | { | |
9c80ffa2 MS |
1157 | #ifdef __APPLE__ |
1158 | if ((tmpdir = getenv("TMPDIR")) != NULL && | |
0fa6c7fa | 1159 | strncmp(tmpdir, "/private/tmp", 12) && strncmp(tmpdir, "/tmp", 4)) |
9c80ffa2 | 1160 | #else |
b423cd4c | 1161 | if ((tmpdir = getenv("TMPDIR")) != NULL) |
9c80ffa2 | 1162 | #endif /* __APPLE__ */ |
b423cd4c | 1163 | { |
1164 | /* | |
1165 | * TMPDIR is defined, see if it is OK for us to use... | |
1166 | */ | |
1167 | ||
1168 | if (stat(tmpdir, &tmpinfo)) | |
1169 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to access TMPDIR (%s): %s", | |
1170 | tmpdir, strerror(errno)); | |
1171 | else if (!S_ISDIR(tmpinfo.st_mode)) | |
c8fef167 | 1172 | cupsdLogMessage(CUPSD_LOG_ERROR, "TMPDIR (%s) is not a directory.", |
b423cd4c | 1173 | tmpdir); |
1174 | else if ((tmpinfo.st_uid != User || !(tmpinfo.st_mode & S_IWUSR)) && | |
1175 | (tmpinfo.st_gid != Group || !(tmpinfo.st_mode & S_IWGRP)) && | |
1176 | !(tmpinfo.st_mode & S_IWOTH)) | |
1177 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
c8fef167 | 1178 | "TMPDIR (%s) has the wrong permissions.", tmpdir); |
b423cd4c | 1179 | else |
1180 | cupsdSetString(&TempDir, tmpdir); | |
b423cd4c | 1181 | } |
0fa6c7fa | 1182 | } |
b423cd4c | 1183 | |
0fa6c7fa MS |
1184 | if (!TempDir) |
1185 | { | |
1186 | cupsdLogMessage(CUPSD_LOG_INFO, "Using default TempDir of %s/tmp...", | |
1187 | RequestRoot); | |
1188 | cupsdSetStringf(&TempDir, "%s/tmp", RequestRoot); | |
b423cd4c | 1189 | } |
1190 | ||
ef416fc2 | 1191 | /* |
b94498cf | 1192 | * Make sure the temporary directory has the right permissions... |
ef416fc2 | 1193 | */ |
1194 | ||
ef416fc2 | 1195 | if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)) || |
1196 | access(TempDir, 0)) | |
1197 | { | |
1198 | /* | |
1199 | * Update ownership and permissions if the CUPS temp directory | |
1200 | * is under the spool directory or does not exist... | |
1201 | */ | |
1202 | ||
49d87452 MS |
1203 | if (cupsdCheckPermissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0 && |
1204 | (FatalErrors & CUPSD_FATAL_PERMISSIONS)) | |
d09495fa | 1205 | return (0); |
ef416fc2 | 1206 | } |
1207 | ||
ef416fc2 | 1208 | /* |
0268488e | 1209 | * Update environment variables... |
ef416fc2 | 1210 | */ |
1211 | ||
0268488e | 1212 | cupsdUpdateEnv(); |
ef416fc2 | 1213 | |
c5571a1d MS |
1214 | /* |
1215 | * Update default paper size setting as needed... | |
1216 | */ | |
1217 | ||
1218 | if (!DefaultPaperSize) | |
1219 | { | |
1220 | #ifdef HAVE_LIBPAPER | |
1221 | char *paper_result; /* Paper size name from libpaper */ | |
1222 | ||
1223 | if ((paper_result = systempapername()) != NULL) | |
1224 | cupsdSetString(&DefaultPaperSize, paper_result); | |
1225 | else | |
1226 | #endif /* HAVE_LIBPAPER */ | |
1227 | if (!DefaultLanguage || | |
88f9aafc MS |
1228 | !_cups_strcasecmp(DefaultLanguage, "C") || |
1229 | !_cups_strcasecmp(DefaultLanguage, "POSIX") || | |
1230 | !_cups_strcasecmp(DefaultLanguage, "en") || | |
1231 | !_cups_strncasecmp(DefaultLanguage, "en.", 3) || | |
1232 | !_cups_strncasecmp(DefaultLanguage, "en_US", 5) || | |
1233 | !_cups_strncasecmp(DefaultLanguage, "en_CA", 5) || | |
1234 | !_cups_strncasecmp(DefaultLanguage, "fr_CA", 5)) | |
c5571a1d MS |
1235 | { |
1236 | /* | |
1237 | * These are the only locales that will default to "letter" size... | |
1238 | */ | |
1239 | ||
1240 | cupsdSetString(&DefaultPaperSize, "Letter"); | |
1241 | } | |
1242 | else | |
1243 | cupsdSetString(&DefaultPaperSize, "A4"); | |
1244 | } | |
1245 | ||
1246 | /* | |
1247 | * Update classification setting as needed... | |
1248 | */ | |
1249 | ||
88f9aafc | 1250 | if (Classification && !_cups_strcasecmp(Classification, "none")) |
c5571a1d MS |
1251 | cupsdClearString(&Classification); |
1252 | ||
1253 | if (Classification) | |
1254 | cupsdLogMessage(CUPSD_LOG_INFO, "Security set to \"%s\"", Classification); | |
1255 | ||
ef416fc2 | 1256 | /* |
1257 | * Check the MaxClients setting, and then allocate memory for it... | |
1258 | */ | |
1259 | ||
1260 | if (MaxClients > (MaxFDs / 3) || MaxClients <= 0) | |
1261 | { | |
1262 | if (MaxClients > 0) | |
49d87452 MS |
1263 | cupsdLogMessage(CUPSD_LOG_INFO, |
1264 | "MaxClients limited to 1/3 (%d) of the file descriptor " | |
1265 | "limit (%d)...", | |
1266 | MaxFDs / 3, MaxFDs); | |
ef416fc2 | 1267 | |
1268 | MaxClients = MaxFDs / 3; | |
1269 | } | |
1270 | ||
bd7854cb | 1271 | cupsdLogMessage(CUPSD_LOG_INFO, "Configured for up to %d clients.", |
1272 | MaxClients); | |
ef416fc2 | 1273 | |
1274 | /* | |
1275 | * Check the MaxActiveJobs setting; limit to 1/3 the available | |
1276 | * file descriptors, since we need a pipe for each job... | |
1277 | */ | |
1278 | ||
1279 | if (MaxActiveJobs > (MaxFDs / 3)) | |
1280 | MaxActiveJobs = MaxFDs / 3; | |
1281 | ||
ef416fc2 | 1282 | /* |
1283 | * Update the MaxClientsPerHost value, as needed... | |
1284 | */ | |
1285 | ||
1286 | if (MaxClientsPerHost <= 0) | |
1287 | MaxClientsPerHost = MaxClients; | |
1288 | ||
1289 | if (MaxClientsPerHost > MaxClients) | |
1290 | MaxClientsPerHost = MaxClients; | |
1291 | ||
1292 | cupsdLogMessage(CUPSD_LOG_INFO, | |
1293 | "Allowing up to %d client connections per host.", | |
1294 | MaxClientsPerHost); | |
1295 | ||
1296 | /* | |
1297 | * Update the default policy, as needed... | |
1298 | */ | |
1299 | ||
1300 | if (DefaultPolicy) | |
1301 | DefaultPolicyPtr = cupsdFindPolicy(DefaultPolicy); | |
1302 | else | |
1303 | DefaultPolicyPtr = NULL; | |
1304 | ||
1305 | if (!DefaultPolicyPtr) | |
1306 | { | |
ef416fc2 | 1307 | cupsd_location_t *po; /* New policy operation */ |
1308 | ||
1309 | ||
1310 | if (DefaultPolicy) | |
c8fef167 | 1311 | cupsdLogMessage(CUPSD_LOG_ERROR, "Default policy \"%s\" not found.", |
ef416fc2 | 1312 | DefaultPolicy); |
1313 | ||
e1d6a774 | 1314 | cupsdSetString(&DefaultPolicy, "default"); |
1315 | ||
ef416fc2 | 1316 | if ((DefaultPolicyPtr = cupsdFindPolicy("default")) != NULL) |
1317 | cupsdLogMessage(CUPSD_LOG_INFO, | |
c8fef167 | 1318 | "Using policy \"default\" as the default."); |
ef416fc2 | 1319 | else |
1320 | { | |
1321 | cupsdLogMessage(CUPSD_LOG_INFO, | |
1322 | "Creating CUPS default administrative policy:"); | |
1323 | ||
1324 | DefaultPolicyPtr = p = cupsdAddPolicy("default"); | |
1325 | ||
1326 | cupsdLogMessage(CUPSD_LOG_INFO, "<Policy default>"); | |
10d09e33 MS |
1327 | |
1328 | cupsdLogMessage(CUPSD_LOG_INFO, "JobPrivateAccess default"); | |
1329 | cupsdAddString(&(p->job_access), "@OWNER"); | |
1330 | cupsdAddString(&(p->job_access), "@SYSTEM"); | |
1331 | ||
1332 | cupsdLogMessage(CUPSD_LOG_INFO, "JobPrivateValues default"); | |
1333 | cupsdAddString(&(p->job_attrs), "job-name"); | |
1334 | cupsdAddString(&(p->job_attrs), "job-originating-host-name"); | |
1335 | cupsdAddString(&(p->job_attrs), "job-originating-user-name"); | |
1336 | ||
1337 | cupsdLogMessage(CUPSD_LOG_INFO, "SubscriptionPrivateAccess default"); | |
1338 | cupsdAddString(&(p->sub_access), "@OWNER"); | |
1339 | cupsdAddString(&(p->sub_access), "@SYSTEM"); | |
1340 | ||
1341 | cupsdLogMessage(CUPSD_LOG_INFO, "SubscriptionPrivateValues default"); | |
1342 | cupsdAddString(&(p->job_attrs), "notify-events"); | |
1343 | cupsdAddString(&(p->job_attrs), "notify-pull-method"); | |
1344 | cupsdAddString(&(p->job_attrs), "notify-recipient-uri"); | |
1345 | cupsdAddString(&(p->job_attrs), "notify-subscriber-user-name"); | |
1346 | cupsdAddString(&(p->job_attrs), "notify-user-data"); | |
1347 | ||
c7017ecc MS |
1348 | cupsdLogMessage(CUPSD_LOG_INFO, |
1349 | "<Limit Create-Job Print-Job Print-URI Validate-Job>"); | |
1350 | cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow"); | |
1351 | ||
1352 | po = cupsdAddPolicyOp(p, NULL, IPP_CREATE_JOB); | |
1353 | po->order_type = CUPSD_AUTH_ALLOW; | |
1354 | ||
1355 | cupsdAddPolicyOp(p, po, IPP_PRINT_JOB); | |
1356 | cupsdAddPolicyOp(p, po, IPP_PRINT_URI); | |
1357 | cupsdAddPolicyOp(p, po, IPP_VALIDATE_JOB); | |
1358 | ||
1359 | cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>"); | |
1360 | ||
ef416fc2 | 1361 | cupsdLogMessage(CUPSD_LOG_INFO, |
1362 | "<Limit Send-Document Send-URI Cancel-Job Hold-Job " | |
1363 | "Release-Job Restart-Job Purge-Jobs " | |
1364 | "Set-Job-Attributes Create-Job-Subscription " | |
1365 | "Renew-Subscription Cancel-Subscription " | |
1366 | "Get-Notifications Reprocess-Job Cancel-Current-Job " | |
10d09e33 | 1367 | "Suspend-Current-Job Resume-Job " |
aaf19ab0 | 1368 | "Cancel-My-Jobs Close-Job CUPS-Move-Job " |
2e4ff8af | 1369 | "CUPS-Authenticate-Job CUPS-Get-Document>"); |
ef416fc2 | 1370 | cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow"); |
1371 | ||
1372 | po = cupsdAddPolicyOp(p, NULL, IPP_SEND_DOCUMENT); | |
5bd77a73 MS |
1373 | po->order_type = CUPSD_AUTH_ALLOW; |
1374 | po->level = CUPSD_AUTH_USER; | |
ef416fc2 | 1375 | |
1376 | cupsdAddName(po, "@OWNER"); | |
1377 | cupsdAddName(po, "@SYSTEM"); | |
1378 | cupsdLogMessage(CUPSD_LOG_INFO, "Require user @OWNER @SYSTEM"); | |
1379 | ||
1380 | cupsdAddPolicyOp(p, po, IPP_SEND_URI); | |
1381 | cupsdAddPolicyOp(p, po, IPP_CANCEL_JOB); | |
1382 | cupsdAddPolicyOp(p, po, IPP_HOLD_JOB); | |
1383 | cupsdAddPolicyOp(p, po, IPP_RELEASE_JOB); | |
1384 | cupsdAddPolicyOp(p, po, IPP_RESTART_JOB); | |
1385 | cupsdAddPolicyOp(p, po, IPP_PURGE_JOBS); | |
1386 | cupsdAddPolicyOp(p, po, IPP_SET_JOB_ATTRIBUTES); | |
1387 | cupsdAddPolicyOp(p, po, IPP_CREATE_JOB_SUBSCRIPTION); | |
1388 | cupsdAddPolicyOp(p, po, IPP_RENEW_SUBSCRIPTION); | |
1389 | cupsdAddPolicyOp(p, po, IPP_CANCEL_SUBSCRIPTION); | |
1390 | cupsdAddPolicyOp(p, po, IPP_GET_NOTIFICATIONS); | |
1391 | cupsdAddPolicyOp(p, po, IPP_REPROCESS_JOB); | |
1392 | cupsdAddPolicyOp(p, po, IPP_CANCEL_CURRENT_JOB); | |
1393 | cupsdAddPolicyOp(p, po, IPP_SUSPEND_CURRENT_JOB); | |
1394 | cupsdAddPolicyOp(p, po, IPP_RESUME_JOB); | |
aaf19ab0 MS |
1395 | cupsdAddPolicyOp(p, po, IPP_CANCEL_MY_JOBS); |
1396 | cupsdAddPolicyOp(p, po, IPP_CLOSE_JOB); | |
ef416fc2 | 1397 | cupsdAddPolicyOp(p, po, CUPS_MOVE_JOB); |
1398 | cupsdAddPolicyOp(p, po, CUPS_AUTHENTICATE_JOB); | |
2e4ff8af | 1399 | cupsdAddPolicyOp(p, po, CUPS_GET_DOCUMENT); |
ef416fc2 | 1400 | |
1401 | cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>"); | |
1402 | ||
1403 | cupsdLogMessage(CUPSD_LOG_INFO, | |
1404 | "<Limit Pause-Printer Resume-Printer " | |
1405 | "Set-Printer-Attributes Enable-Printer " | |
1406 | "Disable-Printer Pause-Printer-After-Current-Job " | |
1407 | "Hold-New-Jobs Release-Held-New-Jobs " | |
1408 | "Deactivate-Printer Activate-Printer Restart-Printer " | |
1409 | "Shutdown-Printer Startup-Printer Promote-Job " | |
10d09e33 | 1410 | "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer " |
ef416fc2 | 1411 | "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class " |
1412 | "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>"); | |
1413 | cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow"); | |
bc44d920 | 1414 | cupsdLogMessage(CUPSD_LOG_INFO, "AuthType Default"); |
ef416fc2 | 1415 | |
1416 | po = cupsdAddPolicyOp(p, NULL, IPP_PAUSE_PRINTER); | |
5bd77a73 MS |
1417 | po->order_type = CUPSD_AUTH_ALLOW; |
1418 | po->type = CUPSD_AUTH_DEFAULT; | |
1419 | po->level = CUPSD_AUTH_USER; | |
ef416fc2 | 1420 | |
1421 | cupsdAddName(po, "@SYSTEM"); | |
1422 | cupsdLogMessage(CUPSD_LOG_INFO, "Require user @SYSTEM"); | |
1423 | ||
1424 | cupsdAddPolicyOp(p, po, IPP_RESUME_PRINTER); | |
1425 | cupsdAddPolicyOp(p, po, IPP_SET_PRINTER_ATTRIBUTES); | |
1426 | cupsdAddPolicyOp(p, po, IPP_ENABLE_PRINTER); | |
1427 | cupsdAddPolicyOp(p, po, IPP_DISABLE_PRINTER); | |
1428 | cupsdAddPolicyOp(p, po, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB); | |
1429 | cupsdAddPolicyOp(p, po, IPP_HOLD_NEW_JOBS); | |
1430 | cupsdAddPolicyOp(p, po, IPP_RELEASE_HELD_NEW_JOBS); | |
1431 | cupsdAddPolicyOp(p, po, IPP_DEACTIVATE_PRINTER); | |
1432 | cupsdAddPolicyOp(p, po, IPP_ACTIVATE_PRINTER); | |
1433 | cupsdAddPolicyOp(p, po, IPP_RESTART_PRINTER); | |
1434 | cupsdAddPolicyOp(p, po, IPP_SHUTDOWN_PRINTER); | |
1435 | cupsdAddPolicyOp(p, po, IPP_STARTUP_PRINTER); | |
1436 | cupsdAddPolicyOp(p, po, IPP_PROMOTE_JOB); | |
1437 | cupsdAddPolicyOp(p, po, IPP_SCHEDULE_JOB_AFTER); | |
10d09e33 | 1438 | cupsdAddPolicyOp(p, po, IPP_CANCEL_JOBS); |
ef416fc2 | 1439 | cupsdAddPolicyOp(p, po, CUPS_ADD_PRINTER); |
1440 | cupsdAddPolicyOp(p, po, CUPS_DELETE_PRINTER); | |
1441 | cupsdAddPolicyOp(p, po, CUPS_ADD_CLASS); | |
1442 | cupsdAddPolicyOp(p, po, CUPS_DELETE_CLASS); | |
1443 | cupsdAddPolicyOp(p, po, CUPS_ACCEPT_JOBS); | |
1444 | cupsdAddPolicyOp(p, po, CUPS_REJECT_JOBS); | |
1445 | cupsdAddPolicyOp(p, po, CUPS_SET_DEFAULT); | |
1446 | ||
1447 | cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>"); | |
1448 | ||
1449 | cupsdLogMessage(CUPSD_LOG_INFO, "<Limit All>"); | |
1450 | cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow"); | |
1451 | ||
1452 | po = cupsdAddPolicyOp(p, NULL, IPP_ANY_OPERATION); | |
5bd77a73 | 1453 | po->order_type = CUPSD_AUTH_ALLOW; |
ef416fc2 | 1454 | |
1455 | cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>"); | |
1456 | cupsdLogMessage(CUPSD_LOG_INFO, "</Policy>"); | |
1457 | } | |
1458 | } | |
1459 | ||
bd7854cb | 1460 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: NumPolicies=%d", |
2e4ff8af MS |
1461 | cupsArrayCount(Policies)); |
1462 | for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies); | |
1463 | p; | |
1464 | i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies)) | |
bd7854cb | 1465 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
2e4ff8af | 1466 | "cupsdReadConfiguration: Policies[%d]=\"%s\"", i, p->name); |
ef416fc2 | 1467 | |
1468 | /* | |
1469 | * If we are doing a full reload or the server root has changed, flush | |
1470 | * the jobs, printers, etc. and start from scratch... | |
1471 | */ | |
1472 | ||
1473 | if (NeedReload == RELOAD_ALL || | |
f11a948a | 1474 | old_remote_port != RemotePort || |
ef416fc2 | 1475 | !old_serverroot || !ServerRoot || strcmp(old_serverroot, ServerRoot) || |
1476 | !old_requestroot || !RequestRoot || strcmp(old_requestroot, RequestRoot)) | |
1477 | { | |
fa73b229 | 1478 | mime_type_t *type; /* Current type */ |
1479 | char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE]; | |
1480 | /* MIME type name */ | |
1481 | ||
1482 | ||
ef416fc2 | 1483 | cupsdLogMessage(CUPSD_LOG_INFO, "Full reload is required."); |
1484 | ||
1485 | /* | |
1486 | * Free all memory... | |
1487 | */ | |
1488 | ||
1489 | cupsdDeleteAllSubscriptions(); | |
1490 | cupsdFreeAllJobs(); | |
ef416fc2 | 1491 | cupsdDeleteAllPrinters(); |
1492 | ||
1493 | DefaultPrinter = NULL; | |
1494 | ||
1495 | if (MimeDatabase != NULL) | |
1496 | mimeDelete(MimeDatabase); | |
1497 | ||
1498 | if (NumMimeTypes) | |
1499 | { | |
1500 | for (i = 0; i < NumMimeTypes; i ++) | |
757d2cad | 1501 | _cupsStrFree(MimeTypes[i]); |
ef416fc2 | 1502 | |
1503 | free(MimeTypes); | |
1504 | } | |
1505 | ||
1506 | /* | |
1507 | * Read the MIME type and conversion database... | |
1508 | */ | |
1509 | ||
1510 | snprintf(temp, sizeof(temp), "%s/filter", ServerBin); | |
dd1abb6b | 1511 | snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir); |
ef416fc2 | 1512 | |
eac3a0a0 MS |
1513 | MimeDatabase = mimeNew(); |
1514 | mimeSetErrorCallback(MimeDatabase, mime_error_cb, NULL); | |
1515 | ||
1516 | MimeDatabase = mimeLoadTypes(MimeDatabase, mimedir); | |
75bd9771 MS |
1517 | MimeDatabase = mimeLoadTypes(MimeDatabase, ServerRoot); |
1518 | MimeDatabase = mimeLoadFilters(MimeDatabase, mimedir, temp); | |
1519 | MimeDatabase = mimeLoadFilters(MimeDatabase, ServerRoot, temp); | |
ef416fc2 | 1520 | |
1521 | if (!MimeDatabase) | |
1522 | { | |
1523 | cupsdLogMessage(CUPSD_LOG_EMERG, | |
c8fef167 | 1524 | "Unable to load MIME database from \"%s\" or \"%s\".", |
75bd9771 | 1525 | mimedir, ServerRoot); |
49d87452 MS |
1526 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
1527 | return (0); | |
ef416fc2 | 1528 | } |
1529 | ||
1530 | cupsdLogMessage(CUPSD_LOG_INFO, | |
75bd9771 MS |
1531 | "Loaded MIME database from \"%s\" and \"%s\": %d types, " |
1532 | "%d filters...", mimedir, ServerRoot, | |
1533 | mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase)); | |
ef416fc2 | 1534 | |
1535 | /* | |
1536 | * Create a list of MIME types for the document-format-supported | |
1537 | * attribute... | |
1538 | */ | |
1539 | ||
fa73b229 | 1540 | NumMimeTypes = mimeNumTypes(MimeDatabase); |
ef416fc2 | 1541 | if (!mimeType(MimeDatabase, "application", "octet-stream")) |
1542 | NumMimeTypes ++; | |
1543 | ||
91c84a35 | 1544 | if ((MimeTypes = calloc(NumMimeTypes, sizeof(const char *))) == NULL) |
ef416fc2 | 1545 | { |
91c84a35 | 1546 | cupsdLogMessage(CUPSD_LOG_ERROR, |
c8fef167 | 1547 | "Unable to allocate memory for %d MIME types.", |
91c84a35 MS |
1548 | NumMimeTypes); |
1549 | NumMimeTypes = 0; | |
ef416fc2 | 1550 | } |
91c84a35 MS |
1551 | else |
1552 | { | |
1553 | for (i = 0, type = mimeFirstType(MimeDatabase); | |
1554 | type; | |
1555 | i ++, type = mimeNextType(MimeDatabase)) | |
1556 | { | |
1557 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); | |
1558 | ||
1559 | MimeTypes[i] = _cupsStrAlloc(mimetype); | |
1560 | } | |
ef416fc2 | 1561 | |
91c84a35 MS |
1562 | if (i < NumMimeTypes) |
1563 | MimeTypes[i] = _cupsStrAlloc("application/octet-stream"); | |
1564 | } | |
bd7854cb | 1565 | |
1566 | if (LogLevel == CUPSD_LOG_DEBUG2) | |
1567 | { | |
1568 | mime_filter_t *filter; /* Current filter */ | |
1569 | ||
1570 | ||
1571 | for (type = mimeFirstType(MimeDatabase); | |
1572 | type; | |
1573 | type = mimeNextType(MimeDatabase)) | |
1574 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: type %s/%s", | |
1575 | type->super, type->type); | |
1576 | ||
1577 | for (filter = mimeFirstFilter(MimeDatabase); | |
1578 | filter; | |
1579 | filter = mimeNextFilter(MimeDatabase)) | |
1580 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
1581 | "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s", | |
1582 | filter->src->super, filter->src->type, | |
1583 | filter->dst->super, filter->dst->type, | |
1584 | filter->cost, filter->filter); | |
1585 | } | |
ef416fc2 | 1586 | |
1587 | /* | |
1588 | * Load banners... | |
1589 | */ | |
1590 | ||
1591 | snprintf(temp, sizeof(temp), "%s/banners", DataDir); | |
1592 | cupsdLoadBanners(temp); | |
1593 | ||
1594 | /* | |
1595 | * Load printers and classes... | |
1596 | */ | |
1597 | ||
1598 | cupsdLoadAllPrinters(); | |
1599 | cupsdLoadAllClasses(); | |
ef416fc2 | 1600 | |
1601 | cupsdCreateCommonData(); | |
1602 | ||
68b10830 MS |
1603 | /* |
1604 | * Update the printcap file as needed... | |
1605 | */ | |
1606 | ||
1607 | if (Printcap && *Printcap && access(Printcap, 0)) | |
1608 | cupsdWritePrintcap(); | |
1609 | ||
ef416fc2 | 1610 | /* |
1611 | * Load queued jobs... | |
1612 | */ | |
1613 | ||
1614 | cupsdLoadAllJobs(); | |
1615 | ||
1616 | /* | |
1617 | * Load subscriptions... | |
1618 | */ | |
1619 | ||
1620 | cupsdLoadAllSubscriptions(); | |
1621 | ||
1622 | cupsdLogMessage(CUPSD_LOG_INFO, "Full reload complete."); | |
1623 | } | |
1624 | else | |
1625 | { | |
1626 | /* | |
1627 | * Not a full reload, so recreate the common printer attributes... | |
1628 | */ | |
1629 | ||
1630 | cupsdCreateCommonData(); | |
1631 | ||
82cc1f9a MS |
1632 | /* |
1633 | * Update all jobs as needed... | |
1634 | */ | |
1635 | ||
1636 | cupsdUpdateJobs(); | |
1637 | ||
ef416fc2 | 1638 | /* |
1639 | * Update all printers as needed... | |
1640 | */ | |
1641 | ||
1642 | cupsdUpdatePrinters(); | |
3dfe78b3 | 1643 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); |
ef416fc2 | 1644 | |
1645 | cupsdLogMessage(CUPSD_LOG_INFO, "Partial reload complete."); | |
1646 | } | |
1647 | ||
1648 | /* | |
1649 | * Reset the reload state... | |
1650 | */ | |
1651 | ||
1652 | NeedReload = RELOAD_NONE; | |
1653 | ||
1654 | cupsdClearString(&old_serverroot); | |
1655 | cupsdClearString(&old_requestroot); | |
1656 | ||
ef416fc2 | 1657 | return (1); |
1658 | } | |
1659 | ||
1660 | ||
1661 | /* | |
1662 | * 'get_address()' - Get an address + port number from a line. | |
1663 | */ | |
1664 | ||
1665 | static http_addrlist_t * /* O - Pointer to list if address good, NULL if bad */ | |
1666 | get_address(const char *value, /* I - Value string */ | |
1667 | int defport) /* I - Default port */ | |
1668 | { | |
1669 | char buffer[1024], /* Hostname + port number buffer */ | |
1670 | defpname[255], /* Default port name */ | |
1671 | *hostname, /* Hostname or IP */ | |
1672 | *portname; /* Port number or name */ | |
1673 | http_addrlist_t *addrlist; /* Address list */ | |
1674 | ||
1675 | ||
1676 | /* | |
1677 | * Check for an empty value... | |
1678 | */ | |
1679 | ||
1680 | if (!*value) | |
1681 | { | |
c8fef167 | 1682 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad (empty) address."); |
ef416fc2 | 1683 | return (NULL); |
1684 | } | |
1685 | ||
1686 | /* | |
1687 | * Grab a hostname and port number; if there is no colon and the port name | |
1688 | * is only digits, then we have a port number by itself... | |
1689 | */ | |
1690 | ||
1691 | strlcpy(buffer, value, sizeof(buffer)); | |
1692 | ||
1693 | if ((portname = strrchr(buffer, ':')) != NULL && !strchr(portname, ']')) | |
1694 | { | |
1695 | *portname++ = '\0'; | |
1696 | hostname = buffer; | |
1697 | } | |
1698 | else | |
1699 | { | |
1700 | for (portname = buffer; isdigit(*portname & 255); portname ++); | |
1701 | ||
1702 | if (*portname) | |
1703 | { | |
1704 | /* | |
1705 | * Use the default port... | |
1706 | */ | |
1707 | ||
1708 | sprintf(defpname, "%d", defport); | |
1709 | portname = defpname; | |
1710 | hostname = buffer; | |
1711 | } | |
1712 | else | |
1713 | { | |
1714 | /* | |
1715 | * The buffer contains just a port number... | |
1716 | */ | |
1717 | ||
1718 | portname = buffer; | |
1719 | hostname = NULL; | |
1720 | } | |
1721 | } | |
1722 | ||
1723 | if (hostname && !strcmp(hostname, "*")) | |
1724 | hostname = NULL; | |
1725 | ||
1726 | /* | |
1727 | * Now lookup the address using httpAddrGetList()... | |
1728 | */ | |
1729 | ||
1730 | if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) == NULL) | |
c8fef167 | 1731 | cupsdLogMessage(CUPSD_LOG_ERROR, "Hostname lookup for \"%s\" failed.", |
ef416fc2 | 1732 | hostname ? hostname : "(nil)"); |
1733 | ||
1734 | return (addrlist); | |
1735 | } | |
1736 | ||
1737 | ||
1738 | /* | |
1739 | * 'get_addr_and_mask()' - Get an IP address and netmask. | |
1740 | */ | |
1741 | ||
1742 | static int /* O - 1 on success, 0 on failure */ | |
1743 | get_addr_and_mask(const char *value, /* I - String from config file */ | |
1744 | unsigned *ip, /* O - Address value */ | |
1745 | unsigned *mask) /* O - Mask value */ | |
1746 | { | |
1747 | int i, j, /* Looping vars */ | |
1748 | family, /* Address family */ | |
1749 | ipcount; /* Count of fields in address */ | |
1750 | unsigned ipval; /* Value */ | |
1751 | const char *maskval, /* Pointer to start of mask value */ | |
1752 | *ptr, /* Pointer into value */ | |
1753 | *ptr2; /* ... */ | |
ef416fc2 | 1754 | |
1755 | ||
1756 | /* | |
1757 | * Get the address... | |
1758 | */ | |
1759 | ||
b86bc4cf | 1760 | ip[0] = ip[1] = ip[2] = ip[3] = 0x00000000; |
ed486911 | 1761 | mask[0] = mask[1] = mask[2] = mask[3] = 0xffffffff; |
ef416fc2 | 1762 | |
1763 | if ((maskval = strchr(value, '/')) != NULL) | |
1764 | maskval ++; | |
1765 | else | |
1766 | maskval = value + strlen(value); | |
1767 | ||
1768 | #ifdef AF_INET6 | |
1769 | /* | |
1770 | * Check for an IPv6 address... | |
1771 | */ | |
1772 | ||
1773 | if (*value == '[') | |
1774 | { | |
1775 | /* | |
88f9aafc | 1776 | * Parse hexadecimal IPv6/IPv4 address... |
ef416fc2 | 1777 | */ |
1778 | ||
1779 | family = AF_INET6; | |
1780 | ||
1781 | for (i = 0, ptr = value + 1; *ptr && i < 8; i ++) | |
1782 | { | |
1783 | if (*ptr == ']') | |
1784 | break; | |
1785 | else if (!strncmp(ptr, "::", 2)) | |
1786 | { | |
1787 | for (ptr2 = strchr(ptr + 2, ':'), j = 0; | |
1788 | ptr2; | |
1789 | ptr2 = strchr(ptr2 + 1, ':'), j ++); | |
1790 | ||
88f9aafc MS |
1791 | i = 6 - j; |
1792 | ptr += 2; | |
1793 | } | |
1794 | else if (isdigit(*ptr & 255) && strchr(ptr + 1, '.') && i >= 6) | |
1795 | { | |
1796 | /* | |
1797 | * Read IPv4 dotted quad... | |
1798 | */ | |
1799 | ||
1800 | unsigned val[4] = { 0, 0, 0, 0 }; | |
1801 | /* IPv4 address values */ | |
1802 | ||
1803 | ipcount = sscanf(ptr, "%u.%u.%u.%u", val + 0, val + 1, val + 2, | |
1804 | val + 3); | |
1805 | ||
1806 | /* | |
1807 | * Range check the IP numbers... | |
1808 | */ | |
1809 | ||
1810 | for (i = 0; i < ipcount; i ++) | |
1811 | if (val[i] > 255) | |
1812 | return (0); | |
1813 | ||
1814 | /* | |
1815 | * Merge everything into a 32-bit IPv4 address in ip[3]... | |
1816 | */ | |
1817 | ||
1818 | ip[3] = (((((val[0] << 8) | val[1]) << 8) | val[2]) << 8) | val[3]; | |
1819 | ||
1820 | if (ipcount < 4) | |
1821 | mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff; | |
1822 | ||
1823 | /* | |
1824 | * If the leading words are all 0's then this is an IPv4 address... | |
1825 | */ | |
1826 | ||
1827 | if (!val[0] && !val[1] && !val[2]) | |
1828 | family = AF_INET; | |
1829 | ||
1830 | while (isdigit(*ptr & 255) || *ptr == '.') | |
1831 | ptr ++; | |
1832 | break; | |
ef416fc2 | 1833 | } |
1834 | else if (isxdigit(*ptr & 255)) | |
1835 | { | |
1836 | ipval = strtoul(ptr, (char **)&ptr, 16); | |
1837 | ||
88f9aafc MS |
1838 | if (*ptr == ':' && ptr[1] != ':') |
1839 | ptr ++; | |
1840 | ||
ef416fc2 | 1841 | if (ipval > 0xffff) |
1842 | return (0); | |
1843 | ||
1844 | if (i & 1) | |
ed486911 | 1845 | ip[i / 2] |= ipval; |
ef416fc2 | 1846 | else |
ed486911 | 1847 | ip[i / 2] |= ipval << 16; |
ef416fc2 | 1848 | } |
1849 | else | |
1850 | return (0); | |
ef416fc2 | 1851 | } |
1852 | ||
ed486911 | 1853 | if (*ptr != ']') |
1854 | return (0); | |
1855 | ||
1856 | ptr ++; | |
ef416fc2 | 1857 | |
1858 | if (*ptr && *ptr != '/') | |
1859 | return (0); | |
1860 | } | |
1861 | else | |
1862 | #endif /* AF_INET6 */ | |
1863 | { | |
1864 | /* | |
1865 | * Parse dotted-decimal IPv4 address... | |
1866 | */ | |
1867 | ||
88f9aafc | 1868 | unsigned val[4] = { 0, 0, 0, 0 }; /* IPv4 address values */ |
ef416fc2 | 1869 | |
ef416fc2 | 1870 | |
ed486911 | 1871 | family = AF_INET; |
1872 | ipcount = sscanf(value, "%u.%u.%u.%u", val + 0, val + 1, val + 2, val + 3); | |
1873 | ||
ef416fc2 | 1874 | /* |
ed486911 | 1875 | * Range check the IP numbers... |
ef416fc2 | 1876 | */ |
1877 | ||
ed486911 | 1878 | for (i = 0; i < ipcount; i ++) |
1879 | if (val[i] > 255) | |
1880 | return (0); | |
ef416fc2 | 1881 | |
ed486911 | 1882 | /* |
1883 | * Merge everything into a 32-bit IPv4 address in ip[3]... | |
1884 | */ | |
ef416fc2 | 1885 | |
ed486911 | 1886 | ip[3] = (((((val[0] << 8) | val[1]) << 8) | val[2]) << 8) | val[3]; |
ef416fc2 | 1887 | |
ed486911 | 1888 | if (ipcount < 4) |
1889 | mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff; | |
1890 | } | |
ef416fc2 | 1891 | |
ed486911 | 1892 | if (*maskval) |
1893 | { | |
1894 | /* | |
1895 | * Get the netmask value(s)... | |
1896 | */ | |
1897 | ||
1898 | memset(mask, 0, sizeof(unsigned) * 4); | |
ef416fc2 | 1899 | |
ef416fc2 | 1900 | if (strchr(maskval, '.')) |
1901 | { | |
1902 | /* | |
1903 | * Get dotted-decimal mask... | |
1904 | */ | |
1905 | ||
ed486911 | 1906 | if (family != AF_INET) |
1907 | return (0); | |
1908 | ||
88f9aafc MS |
1909 | if (sscanf(maskval, "%u.%u.%u.%u", mask + 0, mask + 1, mask + 2, |
1910 | mask + 3) != 4) | |
ef416fc2 | 1911 | return (0); |
1912 | ||
1913 | mask[3] |= ((((mask[0] << 8) | mask[1]) << 8) | mask[2]) << 8; | |
1914 | mask[0] = mask[1] = mask[2] = 0; | |
1915 | } | |
1916 | else | |
1917 | { | |
1918 | /* | |
1919 | * Get address/bits format... | |
1920 | */ | |
1921 | ||
1922 | i = atoi(maskval); | |
1923 | ||
1924 | #ifdef AF_INET6 | |
1925 | if (family == AF_INET6) | |
1926 | { | |
ed486911 | 1927 | if (i > 128) |
1928 | return (0); | |
1929 | ||
ef416fc2 | 1930 | i = 128 - i; |
1931 | ||
1932 | if (i <= 96) | |
1933 | mask[0] = 0xffffffff; | |
1934 | else | |
1935 | mask[0] = (0xffffffff << (i - 96)) & 0xffffffff; | |
1936 | ||
1937 | if (i <= 64) | |
1938 | mask[1] = 0xffffffff; | |
1939 | else if (i >= 96) | |
1940 | mask[1] = 0; | |
1941 | else | |
1942 | mask[1] = (0xffffffff << (i - 64)) & 0xffffffff; | |
1943 | ||
1944 | if (i <= 32) | |
1945 | mask[2] = 0xffffffff; | |
1946 | else if (i >= 64) | |
1947 | mask[2] = 0; | |
1948 | else | |
1949 | mask[2] = (0xffffffff << (i - 32)) & 0xffffffff; | |
1950 | ||
1951 | if (i == 0) | |
1952 | mask[3] = 0xffffffff; | |
1953 | else if (i >= 32) | |
1954 | mask[3] = 0; | |
1955 | else | |
1956 | mask[3] = (0xffffffff << i) & 0xffffffff; | |
1957 | } | |
1958 | else | |
1959 | #endif /* AF_INET6 */ | |
1960 | { | |
ed486911 | 1961 | if (i > 32) |
1962 | return (0); | |
ef416fc2 | 1963 | |
1964 | mask[0] = 0xffffffff; | |
1965 | mask[1] = 0xffffffff; | |
1966 | mask[2] = 0xffffffff; | |
1967 | ||
ed486911 | 1968 | if (i < 32) |
1969 | mask[3] = (0xffffffff << (32 - i)) & 0xffffffff; | |
ef416fc2 | 1970 | else |
1971 | mask[3] = 0xffffffff; | |
1972 | } | |
1973 | } | |
1974 | } | |
ef416fc2 | 1975 | |
1976 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
1977 | "get_addr_and_mask(value=\"%s\", " | |
b86bc4cf | 1978 | "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])", |
ef416fc2 | 1979 | value, ip[0], ip[1], ip[2], ip[3], mask[0], mask[1], mask[2], |
1980 | mask[3]); | |
1981 | ||
1982 | /* | |
1983 | * Check for a valid netmask; no fallback like in CUPS 1.1.x! | |
1984 | */ | |
1985 | ||
1986 | if ((ip[0] & ~mask[0]) != 0 || | |
1987 | (ip[1] & ~mask[1]) != 0 || | |
1988 | (ip[2] & ~mask[2]) != 0 || | |
1989 | (ip[3] & ~mask[3]) != 0) | |
1990 | return (0); | |
1991 | ||
1992 | return (1); | |
1993 | } | |
1994 | ||
1995 | ||
eac3a0a0 MS |
1996 | /* |
1997 | * 'mime_error_cb()' - Log a MIME error. | |
1998 | */ | |
1999 | ||
2000 | static void | |
2001 | mime_error_cb(void *ctx, /* I - Context pointer (unused) */ | |
2002 | const char *message) /* I - Message */ | |
2003 | { | |
321d8d57 MS |
2004 | (void)ctx; |
2005 | ||
eac3a0a0 MS |
2006 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s", message); |
2007 | } | |
2008 | ||
2009 | ||
ef416fc2 | 2010 | /* |
2011 | * 'parse_aaa()' - Parse authentication, authorization, and access control lines. | |
2012 | */ | |
2013 | ||
2014 | static int /* O - 1 on success, 0 on failure */ | |
2015 | parse_aaa(cupsd_location_t *loc, /* I - Location */ | |
2016 | char *line, /* I - Line from file */ | |
2017 | char *value, /* I - Start of value data */ | |
2018 | int linenum) /* I - Current line number */ | |
2019 | { | |
2020 | char *valptr; /* Pointer into value */ | |
2021 | unsigned ip[4], /* IP address components */ | |
2022 | mask[4]; /* IP netmask components */ | |
2023 | ||
2024 | ||
88f9aafc | 2025 | if (!_cups_strcasecmp(line, "Encryption")) |
ef416fc2 | 2026 | { |
2027 | /* | |
2028 | * "Encryption xxx" - set required encryption level... | |
2029 | */ | |
2030 | ||
88f9aafc | 2031 | if (!_cups_strcasecmp(value, "never")) |
ef416fc2 | 2032 | loc->encryption = HTTP_ENCRYPT_NEVER; |
88f9aafc | 2033 | else if (!_cups_strcasecmp(value, "always")) |
ef416fc2 | 2034 | { |
2035 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2036 | "Encryption value \"%s\" on line %d is invalid in this " | |
2037 | "context. Using \"required\" instead.", value, linenum); | |
2038 | ||
2039 | loc->encryption = HTTP_ENCRYPT_REQUIRED; | |
2040 | } | |
88f9aafc | 2041 | else if (!_cups_strcasecmp(value, "required")) |
ef416fc2 | 2042 | loc->encryption = HTTP_ENCRYPT_REQUIRED; |
88f9aafc | 2043 | else if (!_cups_strcasecmp(value, "ifrequested")) |
ef416fc2 | 2044 | loc->encryption = HTTP_ENCRYPT_IF_REQUESTED; |
2045 | else | |
2046 | { | |
2047 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2048 | "Unknown Encryption value %s on line %d.", value, linenum); | |
2049 | return (0); | |
2050 | } | |
2051 | } | |
88f9aafc | 2052 | else if (!_cups_strcasecmp(line, "Order")) |
ef416fc2 | 2053 | { |
2054 | /* | |
2055 | * "Order Deny,Allow" or "Order Allow,Deny"... | |
2056 | */ | |
2057 | ||
88f9aafc | 2058 | if (!_cups_strncasecmp(value, "deny", 4)) |
5bd77a73 | 2059 | loc->order_type = CUPSD_AUTH_ALLOW; |
88f9aafc | 2060 | else if (!_cups_strncasecmp(value, "allow", 5)) |
5bd77a73 | 2061 | loc->order_type = CUPSD_AUTH_DENY; |
ef416fc2 | 2062 | else |
2063 | { | |
2064 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown Order value %s on line %d.", | |
2065 | value, linenum); | |
2066 | return (0); | |
2067 | } | |
2068 | } | |
88f9aafc | 2069 | else if (!_cups_strcasecmp(line, "Allow") || !_cups_strcasecmp(line, "Deny")) |
ef416fc2 | 2070 | { |
2071 | /* | |
2072 | * Allow [From] host/ip... | |
2073 | * Deny [From] host/ip... | |
2074 | */ | |
2075 | ||
0af14961 | 2076 | while (*value) |
ef416fc2 | 2077 | { |
88f9aafc | 2078 | if (!_cups_strncasecmp(value, "from", 4)) |
0af14961 MS |
2079 | { |
2080 | /* | |
2081 | * Strip leading "from"... | |
2082 | */ | |
ef416fc2 | 2083 | |
0af14961 | 2084 | value += 4; |
ef416fc2 | 2085 | |
88f9aafc | 2086 | while (_cups_isspace(*value)) |
0af14961 | 2087 | value ++; |
ef416fc2 | 2088 | |
0af14961 MS |
2089 | if (!*value) |
2090 | break; | |
2091 | } | |
ef416fc2 | 2092 | |
ef416fc2 | 2093 | /* |
0af14961 | 2094 | * Find the end of the value... |
ef416fc2 | 2095 | */ |
2096 | ||
88f9aafc | 2097 | for (valptr = value; *valptr && !_cups_isspace(*valptr); valptr ++); |
0af14961 | 2098 | |
88f9aafc | 2099 | while (_cups_isspace(*valptr)) |
0af14961 MS |
2100 | *valptr++ = '\0'; |
2101 | ||
ef416fc2 | 2102 | /* |
0af14961 MS |
2103 | * Figure out what form the allow/deny address takes: |
2104 | * | |
2105 | * All | |
2106 | * None | |
2107 | * *.domain.com | |
2108 | * .domain.com | |
2109 | * host.domain.com | |
2110 | * nnn.* | |
2111 | * nnn.nnn.* | |
2112 | * nnn.nnn.nnn.* | |
2113 | * nnn.nnn.nnn.nnn | |
2114 | * nnn.nnn.nnn.nnn/mm | |
2115 | * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm | |
ef416fc2 | 2116 | */ |
2117 | ||
88f9aafc | 2118 | if (!_cups_strcasecmp(value, "all")) |
0af14961 MS |
2119 | { |
2120 | /* | |
2121 | * All hosts... | |
2122 | */ | |
2123 | ||
88f9aafc | 2124 | if (!_cups_strcasecmp(line, "Allow")) |
10d09e33 | 2125 | cupsdAddIPMask(&(loc->allow), zeros, zeros); |
0af14961 | 2126 | else |
10d09e33 | 2127 | cupsdAddIPMask(&(loc->deny), zeros, zeros); |
0af14961 | 2128 | } |
88f9aafc | 2129 | else if (!_cups_strcasecmp(value, "none")) |
0af14961 MS |
2130 | { |
2131 | /* | |
2132 | * No hosts... | |
2133 | */ | |
2134 | ||
88f9aafc | 2135 | if (!_cups_strcasecmp(line, "Allow")) |
10d09e33 | 2136 | cupsdAddIPMask(&(loc->allow), ones, zeros); |
0af14961 | 2137 | else |
10d09e33 | 2138 | cupsdAddIPMask(&(loc->deny), ones, zeros); |
0af14961 | 2139 | } |
ed486911 | 2140 | #ifdef AF_INET6 |
ef55b745 | 2141 | else if (value[0] == '*' || value[0] == '.' || |
0af14961 | 2142 | (!isdigit(value[0] & 255) && value[0] != '[')) |
ed486911 | 2143 | #else |
0af14961 | 2144 | else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255)) |
ed486911 | 2145 | #endif /* AF_INET6 */ |
0af14961 MS |
2146 | { |
2147 | /* | |
2148 | * Host or domain name... | |
2149 | */ | |
ef416fc2 | 2150 | |
0af14961 MS |
2151 | if (value[0] == '*') |
2152 | value ++; | |
ef416fc2 | 2153 | |
88f9aafc | 2154 | if (!_cups_strcasecmp(line, "Allow")) |
10d09e33 | 2155 | cupsdAddNameMask(&(loc->allow), value); |
0af14961 | 2156 | else |
10d09e33 | 2157 | cupsdAddNameMask(&(loc->deny), value); |
0af14961 | 2158 | } |
ef416fc2 | 2159 | else |
ef416fc2 | 2160 | { |
0af14961 MS |
2161 | /* |
2162 | * One of many IP address forms... | |
2163 | */ | |
2164 | ||
2165 | if (!get_addr_and_mask(value, ip, mask)) | |
2166 | { | |
2167 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.", | |
2168 | value, linenum); | |
2169 | return (0); | |
2170 | } | |
2171 | ||
88f9aafc | 2172 | if (!_cups_strcasecmp(line, "Allow")) |
10d09e33 | 2173 | cupsdAddIPMask(&(loc->allow), ip, mask); |
0af14961 | 2174 | else |
10d09e33 | 2175 | cupsdAddIPMask(&(loc->deny), ip, mask); |
ef416fc2 | 2176 | } |
2177 | ||
0af14961 MS |
2178 | /* |
2179 | * Advance to next value... | |
2180 | */ | |
2181 | ||
2182 | value = valptr; | |
ef416fc2 | 2183 | } |
2184 | } | |
88f9aafc | 2185 | else if (!_cups_strcasecmp(line, "AuthType")) |
ef416fc2 | 2186 | { |
2187 | /* | |
bc44d920 | 2188 | * AuthType {none,basic,digest,basicdigest,negotiate,default} |
ef416fc2 | 2189 | */ |
2190 | ||
88f9aafc | 2191 | if (!_cups_strcasecmp(value, "none")) |
ef416fc2 | 2192 | { |
5bd77a73 MS |
2193 | loc->type = CUPSD_AUTH_NONE; |
2194 | loc->level = CUPSD_AUTH_ANON; | |
ef416fc2 | 2195 | } |
88f9aafc | 2196 | else if (!_cups_strcasecmp(value, "basic")) |
ef416fc2 | 2197 | { |
5bd77a73 | 2198 | loc->type = CUPSD_AUTH_BASIC; |
ef416fc2 | 2199 | |
5bd77a73 MS |
2200 | if (loc->level == CUPSD_AUTH_ANON) |
2201 | loc->level = CUPSD_AUTH_USER; | |
ef416fc2 | 2202 | } |
88f9aafc | 2203 | else if (!_cups_strcasecmp(value, "digest")) |
ef416fc2 | 2204 | { |
5bd77a73 | 2205 | loc->type = CUPSD_AUTH_DIGEST; |
ef416fc2 | 2206 | |
5bd77a73 MS |
2207 | if (loc->level == CUPSD_AUTH_ANON) |
2208 | loc->level = CUPSD_AUTH_USER; | |
ef416fc2 | 2209 | } |
88f9aafc | 2210 | else if (!_cups_strcasecmp(value, "basicdigest")) |
ef416fc2 | 2211 | { |
5bd77a73 | 2212 | loc->type = CUPSD_AUTH_BASICDIGEST; |
ef416fc2 | 2213 | |
5bd77a73 MS |
2214 | if (loc->level == CUPSD_AUTH_ANON) |
2215 | loc->level = CUPSD_AUTH_USER; | |
bc44d920 | 2216 | } |
88f9aafc | 2217 | else if (!_cups_strcasecmp(value, "default")) |
bc44d920 | 2218 | { |
5bd77a73 | 2219 | loc->type = CUPSD_AUTH_DEFAULT; |
bc44d920 | 2220 | |
5bd77a73 MS |
2221 | if (loc->level == CUPSD_AUTH_ANON) |
2222 | loc->level = CUPSD_AUTH_USER; | |
ef416fc2 | 2223 | } |
f7deaa1a | 2224 | #ifdef HAVE_GSSAPI |
88f9aafc | 2225 | else if (!_cups_strcasecmp(value, "negotiate")) |
f7deaa1a | 2226 | { |
5bd77a73 | 2227 | loc->type = CUPSD_AUTH_NEGOTIATE; |
f7deaa1a | 2228 | |
5bd77a73 MS |
2229 | if (loc->level == CUPSD_AUTH_ANON) |
2230 | loc->level = CUPSD_AUTH_USER; | |
f7deaa1a | 2231 | } |
2232 | #endif /* HAVE_GSSAPI */ | |
ef416fc2 | 2233 | else |
2234 | { | |
2235 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2236 | "Unknown authorization type %s on line %d.", | |
2237 | value, linenum); | |
2238 | return (0); | |
2239 | } | |
2240 | } | |
88f9aafc | 2241 | else if (!_cups_strcasecmp(line, "AuthClass")) |
ef416fc2 | 2242 | { |
2243 | /* | |
2244 | * AuthClass anonymous, user, system, group | |
2245 | */ | |
2246 | ||
88f9aafc | 2247 | if (!_cups_strcasecmp(value, "anonymous")) |
ef416fc2 | 2248 | { |
5bd77a73 MS |
2249 | loc->type = CUPSD_AUTH_NONE; |
2250 | loc->level = CUPSD_AUTH_ANON; | |
ef416fc2 | 2251 | |
2252 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2253 | "\"AuthClass %s\" is deprecated; consider removing " | |
2254 | "it from line %d.", | |
2255 | value, linenum); | |
2256 | } | |
88f9aafc | 2257 | else if (!_cups_strcasecmp(value, "user")) |
ef416fc2 | 2258 | { |
5bd77a73 | 2259 | loc->level = CUPSD_AUTH_USER; |
ef416fc2 | 2260 | |
2261 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2262 | "\"AuthClass %s\" is deprecated; consider using " | |
2263 | "\"Require valid-user\" on line %d.", | |
2264 | value, linenum); | |
2265 | } | |
88f9aafc | 2266 | else if (!_cups_strcasecmp(value, "group")) |
ef416fc2 | 2267 | { |
5bd77a73 | 2268 | loc->level = CUPSD_AUTH_GROUP; |
ef416fc2 | 2269 | |
2270 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2271 | "\"AuthClass %s\" is deprecated; consider using " | |
09a101d6 | 2272 | "\"Require user @groupname\" on line %d.", |
ef416fc2 | 2273 | value, linenum); |
2274 | } | |
88f9aafc | 2275 | else if (!_cups_strcasecmp(value, "system")) |
ef416fc2 | 2276 | { |
5bd77a73 | 2277 | loc->level = CUPSD_AUTH_GROUP; |
ef416fc2 | 2278 | |
2279 | cupsdAddName(loc, "@SYSTEM"); | |
2280 | ||
2281 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2282 | "\"AuthClass %s\" is deprecated; consider using " | |
09a101d6 | 2283 | "\"Require user @SYSTEM\" on line %d.", |
ef416fc2 | 2284 | value, linenum); |
2285 | } | |
2286 | else | |
2287 | { | |
2288 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2289 | "Unknown authorization class %s on line %d.", | |
2290 | value, linenum); | |
2291 | return (0); | |
2292 | } | |
2293 | } | |
88f9aafc | 2294 | else if (!_cups_strcasecmp(line, "AuthGroupName")) |
ef416fc2 | 2295 | { |
2296 | cupsdAddName(loc, value); | |
2297 | ||
2298 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2299 | "\"AuthGroupName %s\" directive is deprecated; consider " | |
09a101d6 | 2300 | "using \"Require user @%s\" on line %d.", |
ef416fc2 | 2301 | value, value, linenum); |
2302 | } | |
88f9aafc | 2303 | else if (!_cups_strcasecmp(line, "Require")) |
ef416fc2 | 2304 | { |
2305 | /* | |
2306 | * Apache synonym for AuthClass and AuthGroupName... | |
2307 | * | |
2308 | * Get initial word: | |
2309 | * | |
2310 | * Require valid-user | |
2311 | * Require group names | |
2312 | * Require user names | |
2313 | */ | |
2314 | ||
88f9aafc | 2315 | for (valptr = value; !_cups_isspace(*valptr) && *valptr; valptr ++); |
ef416fc2 | 2316 | |
2317 | if (*valptr) | |
2318 | *valptr++ = '\0'; | |
2319 | ||
88f9aafc MS |
2320 | if (!_cups_strcasecmp(value, "valid-user") || |
2321 | !_cups_strcasecmp(value, "user")) | |
5bd77a73 | 2322 | loc->level = CUPSD_AUTH_USER; |
88f9aafc | 2323 | else if (!_cups_strcasecmp(value, "group")) |
5bd77a73 | 2324 | loc->level = CUPSD_AUTH_GROUP; |
ef416fc2 | 2325 | else |
2326 | { | |
2327 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Require type %s on line %d.", | |
2328 | value, linenum); | |
2329 | return (0); | |
2330 | } | |
2331 | ||
2332 | /* | |
2333 | * Get the list of names from the line... | |
2334 | */ | |
2335 | ||
2336 | for (value = valptr; *value;) | |
2337 | { | |
88f9aafc | 2338 | while (_cups_isspace(*value)) |
ef416fc2 | 2339 | value ++; |
2340 | ||
f7deaa1a | 2341 | #ifdef HAVE_AUTHORIZATION_H |
2342 | if (!strncmp(value, "@AUTHKEY(", 9)) | |
2343 | { | |
2344 | /* | |
2345 | * Grab "@AUTHKEY(name)" value... | |
2346 | */ | |
2347 | ||
2348 | for (valptr = value + 9; *valptr != ')' && *valptr; valptr ++); | |
2349 | ||
2350 | if (*valptr) | |
2351 | *valptr++ = '\0'; | |
2352 | } | |
2353 | else | |
2354 | #endif /* HAVE_AUTHORIZATION_H */ | |
ef416fc2 | 2355 | if (*value == '\"' || *value == '\'') |
2356 | { | |
2357 | /* | |
2358 | * Grab quoted name... | |
2359 | */ | |
2360 | ||
2361 | for (valptr = value + 1; *valptr != *value && *valptr; valptr ++); | |
2362 | ||
2363 | value ++; | |
2364 | } | |
2365 | else | |
2366 | { | |
2367 | /* | |
2368 | * Grab literal name. | |
2369 | */ | |
2370 | ||
88f9aafc | 2371 | for (valptr = value; !_cups_isspace(*valptr) && *valptr; valptr ++); |
ef416fc2 | 2372 | } |
2373 | ||
2374 | if (*valptr) | |
2375 | *valptr++ = '\0'; | |
2376 | ||
2377 | cupsdAddName(loc, value); | |
2378 | ||
88f9aafc | 2379 | for (value = valptr; _cups_isspace(*value); value ++); |
ef416fc2 | 2380 | } |
2381 | } | |
88f9aafc | 2382 | else if (!_cups_strcasecmp(line, "Satisfy")) |
ef416fc2 | 2383 | { |
88f9aafc | 2384 | if (!_cups_strcasecmp(value, "all")) |
5bd77a73 | 2385 | loc->satisfy = CUPSD_AUTH_SATISFY_ALL; |
88f9aafc | 2386 | else if (!_cups_strcasecmp(value, "any")) |
5bd77a73 | 2387 | loc->satisfy = CUPSD_AUTH_SATISFY_ANY; |
ef416fc2 | 2388 | else |
2389 | { | |
2390 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Satisfy value %s on line %d.", | |
2391 | value, linenum); | |
2392 | return (0); | |
2393 | } | |
2394 | } | |
2395 | else | |
2396 | return (0); | |
2397 | ||
2398 | return (1); | |
2399 | } | |
2400 | ||
2401 | ||
49d87452 MS |
2402 | /* |
2403 | * 'parse_fatal_errors()' - Parse FatalErrors values in a string. | |
2404 | */ | |
2405 | ||
2406 | static int /* O - FatalErrors bits */ | |
2407 | parse_fatal_errors(const char *s) /* I - FatalErrors string */ | |
2408 | { | |
2409 | int fatal; /* FatalErrors bits */ | |
2410 | char value[1024], /* Value string */ | |
2411 | *valstart, /* Pointer into value */ | |
2412 | *valend; /* End of value */ | |
2413 | ||
2414 | ||
2415 | /* | |
2416 | * Empty FatalErrors line yields NULL pointer... | |
2417 | */ | |
2418 | ||
2419 | if (!s) | |
2420 | return (CUPSD_FATAL_NONE); | |
2421 | ||
2422 | /* | |
2423 | * Loop through the value string,... | |
2424 | */ | |
2425 | ||
2426 | strlcpy(value, s, sizeof(value)); | |
2427 | ||
2428 | fatal = CUPSD_FATAL_NONE; | |
2429 | ||
2430 | for (valstart = value; *valstart;) | |
2431 | { | |
2432 | /* | |
2433 | * Get the current space/comma-delimited kind name... | |
2434 | */ | |
2435 | ||
2436 | for (valend = valstart; *valend; valend ++) | |
88f9aafc | 2437 | if (_cups_isspace(*valend) || *valend == ',') |
49d87452 MS |
2438 | break; |
2439 | ||
2440 | if (*valend) | |
2441 | *valend++ = '\0'; | |
2442 | ||
2443 | /* | |
2444 | * Add the error to the bitmask... | |
2445 | */ | |
2446 | ||
88f9aafc | 2447 | if (!_cups_strcasecmp(valstart, "all")) |
49d87452 | 2448 | fatal = CUPSD_FATAL_ALL; |
88f9aafc | 2449 | else if (!_cups_strcasecmp(valstart, "browse")) |
49d87452 | 2450 | fatal |= CUPSD_FATAL_BROWSE; |
88f9aafc | 2451 | else if (!_cups_strcasecmp(valstart, "-browse")) |
49d87452 | 2452 | fatal &= ~CUPSD_FATAL_BROWSE; |
88f9aafc | 2453 | else if (!_cups_strcasecmp(valstart, "config")) |
49d87452 | 2454 | fatal |= CUPSD_FATAL_CONFIG; |
88f9aafc | 2455 | else if (!_cups_strcasecmp(valstart, "-config")) |
49d87452 | 2456 | fatal &= ~CUPSD_FATAL_CONFIG; |
88f9aafc | 2457 | else if (!_cups_strcasecmp(valstart, "listen")) |
49d87452 | 2458 | fatal |= CUPSD_FATAL_LISTEN; |
88f9aafc | 2459 | else if (!_cups_strcasecmp(valstart, "-listen")) |
49d87452 | 2460 | fatal &= ~CUPSD_FATAL_LISTEN; |
88f9aafc | 2461 | else if (!_cups_strcasecmp(valstart, "log")) |
49d87452 | 2462 | fatal |= CUPSD_FATAL_LOG; |
88f9aafc | 2463 | else if (!_cups_strcasecmp(valstart, "-log")) |
49d87452 | 2464 | fatal &= ~CUPSD_FATAL_LOG; |
88f9aafc | 2465 | else if (!_cups_strcasecmp(valstart, "permissions")) |
49d87452 | 2466 | fatal |= CUPSD_FATAL_PERMISSIONS; |
88f9aafc | 2467 | else if (!_cups_strcasecmp(valstart, "-permissions")) |
49d87452 | 2468 | fatal &= ~CUPSD_FATAL_PERMISSIONS; |
88f9aafc | 2469 | else if (_cups_strcasecmp(valstart, "none")) |
49d87452 | 2470 | cupsdLogMessage(CUPSD_LOG_ERROR, |
c8fef167 | 2471 | "Unknown FatalErrors kind \"%s\" ignored.", valstart); |
49d87452 MS |
2472 | |
2473 | for (valstart = valend; *valstart; valstart ++) | |
88f9aafc | 2474 | if (!_cups_isspace(*valstart) || *valstart != ',') |
49d87452 MS |
2475 | break; |
2476 | } | |
2477 | ||
2478 | return (fatal); | |
2479 | } | |
2480 | ||
2481 | ||
bd7854cb | 2482 | /* |
2483 | * 'parse_groups()' - Parse system group names in a string. | |
2484 | */ | |
2485 | ||
2486 | static int /* O - 1 on success, 0 on failure */ | |
2487 | parse_groups(const char *s) /* I - Space-delimited groups */ | |
2488 | { | |
2489 | int status; /* Return status */ | |
2490 | char value[1024], /* Value string */ | |
2491 | *valstart, /* Pointer into value */ | |
2492 | *valend, /* End of value */ | |
2493 | quote; /* Quote character */ | |
2494 | struct group *group; /* Group */ | |
2495 | ||
2496 | ||
2497 | /* | |
2498 | * Make a copy of the string and parse out the groups... | |
2499 | */ | |
2500 | ||
2501 | strlcpy(value, s, sizeof(value)); | |
2502 | ||
2503 | status = 1; | |
2504 | valstart = value; | |
2505 | ||
2506 | while (*valstart && NumSystemGroups < MAX_SYSTEM_GROUPS) | |
2507 | { | |
2508 | if (*valstart == '\'' || *valstart == '\"') | |
2509 | { | |
2510 | /* | |
2511 | * Scan quoted name... | |
2512 | */ | |
2513 | ||
2514 | quote = *valstart++; | |
2515 | ||
2516 | for (valend = valstart; *valend; valend ++) | |
2517 | if (*valend == quote) | |
2518 | break; | |
2519 | } | |
2520 | else | |
2521 | { | |
2522 | /* | |
2523 | * Scan space or comma-delimited name... | |
2524 | */ | |
2525 | ||
2526 | for (valend = valstart; *valend; valend ++) | |
88f9aafc | 2527 | if (_cups_isspace(*valend) || *valend == ',') |
bd7854cb | 2528 | break; |
2529 | } | |
2530 | ||
2531 | if (*valend) | |
2532 | *valend++ = '\0'; | |
2533 | ||
2534 | group = getgrnam(valstart); | |
2535 | if (group) | |
2536 | { | |
2537 | cupsdSetString(SystemGroups + NumSystemGroups, valstart); | |
2538 | SystemGroupIDs[NumSystemGroups] = group->gr_gid; | |
2539 | ||
2540 | NumSystemGroups ++; | |
2541 | } | |
2542 | else | |
2543 | status = 0; | |
2544 | ||
2545 | endgrent(); | |
2546 | ||
2547 | valstart = valend; | |
2548 | ||
88f9aafc | 2549 | while (*valstart == ',' || _cups_isspace(*valstart)) |
bd7854cb | 2550 | valstart ++; |
2551 | } | |
2552 | ||
2553 | return (status); | |
2554 | } | |
2555 | ||
2556 | ||
2557 | /* | |
2558 | * 'parse_protocols()' - Parse browse protocols in a string. | |
2559 | */ | |
2560 | ||
2561 | static int /* O - Browse protocol bits */ | |
2562 | parse_protocols(const char *s) /* I - Space-delimited protocols */ | |
2563 | { | |
2564 | int protocols; /* Browse protocol bits */ | |
2565 | char value[1024], /* Value string */ | |
2566 | *valstart, /* Pointer into value */ | |
2567 | *valend; /* End of value */ | |
2568 | ||
2569 | ||
d09495fa | 2570 | /* |
2571 | * Empty protocol line yields NULL pointer... | |
2572 | */ | |
2573 | ||
2574 | if (!s) | |
2575 | return (0); | |
2576 | ||
bd7854cb | 2577 | /* |
2578 | * Loop through the value string,... | |
2579 | */ | |
2580 | ||
2581 | strlcpy(value, s, sizeof(value)); | |
2582 | ||
2583 | protocols = 0; | |
2584 | ||
2585 | for (valstart = value; *valstart;) | |
2586 | { | |
2587 | /* | |
2588 | * Get the current space/comma-delimited protocol name... | |
2589 | */ | |
2590 | ||
2591 | for (valend = valstart; *valend; valend ++) | |
88f9aafc | 2592 | if (_cups_isspace(*valend) || *valend == ',') |
bd7854cb | 2593 | break; |
2594 | ||
2595 | if (*valend) | |
2596 | *valend++ = '\0'; | |
2597 | ||
2598 | /* | |
2599 | * Add the protocol to the bitmask... | |
2600 | */ | |
2601 | ||
a2326b5b MS |
2602 | if (!_cups_strcasecmp(valstart, "dnssd") || |
2603 | !_cups_strcasecmp(valstart, "dns-sd") || | |
2604 | !_cups_strcasecmp(valstart, "bonjour")) | |
bd7854cb | 2605 | protocols |= BROWSE_DNSSD; |
88f9aafc | 2606 | else if (!_cups_strcasecmp(valstart, "all")) |
bd7854cb | 2607 | protocols |= BROWSE_ALL; |
88f9aafc | 2608 | else if (_cups_strcasecmp(valstart, "none")) |
a41f09e2 | 2609 | cupsdLogMessage(CUPSD_LOG_ERROR, |
c8fef167 | 2610 | "Unknown browse protocol \"%s\" ignored.", valstart); |
bd7854cb | 2611 | |
2612 | for (valstart = valend; *valstart; valstart ++) | |
88f9aafc | 2613 | if (!_cups_isspace(*valstart) || *valstart != ',') |
bd7854cb | 2614 | break; |
2615 | } | |
2616 | ||
2617 | return (protocols); | |
2618 | } | |
2619 | ||
2620 | ||
ef416fc2 | 2621 | /* |
c41769ff | 2622 | * 'parse_variable()' - Parse a variable line. |
ef416fc2 | 2623 | */ |
2624 | ||
2625 | static int /* O - 1 on success, 0 on failure */ | |
c41769ff MS |
2626 | parse_variable( |
2627 | const char *filename, /* I - Name of configuration file */ | |
2628 | int linenum, /* I - Line in configuration file */ | |
2629 | const char *line, /* I - Line from configuration file */ | |
2630 | const char *value, /* I - Value from configuration file */ | |
2631 | size_t num_vars, /* I - Number of variables */ | |
2632 | const cupsd_var_t *vars) /* I - Variables */ | |
2633 | { | |
2634 | size_t i; /* Looping var */ | |
2635 | const cupsd_var_t *var; /* Variables */ | |
2636 | char temp[1024]; /* Temporary string */ | |
2637 | ||
2638 | ||
2639 | for (i = num_vars, var = vars; i > 0; i --, var ++) | |
2640 | if (!_cups_strcasecmp(line, var->name)) | |
2641 | break; | |
2642 | ||
2643 | if (i == 0) | |
2644 | { | |
2645 | /* | |
2646 | * Unknown directive! Output an error message and continue... | |
2647 | */ | |
2648 | ||
2649 | if (!value) | |
2650 | cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value for %s on line %d of %s.", | |
2651 | line, linenum, filename); | |
2652 | else | |
2653 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown directive %s on line %d of %s.", | |
2654 | line, linenum, filename); | |
2655 | ||
2656 | return (0); | |
2657 | } | |
2658 | ||
2659 | switch (var->type) | |
2660 | { | |
2661 | case CUPSD_VARTYPE_INTEGER : | |
2662 | if (!value) | |
2663 | { | |
2664 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2665 | "Missing integer value for %s on line %d of %s.", | |
2666 | line, linenum, filename); | |
2667 | return (0); | |
2668 | } | |
2669 | else if (!isdigit(*value & 255)) | |
2670 | { | |
2671 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2672 | "Bad integer value for %s on line %d of %s.", | |
2673 | line, linenum, filename); | |
2674 | return (0); | |
2675 | } | |
2676 | else | |
2677 | { | |
2678 | int n; /* Number */ | |
2679 | char *units; /* Units */ | |
2680 | ||
2681 | n = strtol(value, &units, 0); | |
2682 | ||
2683 | if (units && *units) | |
2684 | { | |
2685 | if (tolower(units[0] & 255) == 'g') | |
2686 | n *= 1024 * 1024 * 1024; | |
2687 | else if (tolower(units[0] & 255) == 'm') | |
2688 | n *= 1024 * 1024; | |
2689 | else if (tolower(units[0] & 255) == 'k') | |
2690 | n *= 1024; | |
2691 | else if (tolower(units[0] & 255) == 't') | |
2692 | n *= 262144; | |
2693 | else | |
2694 | { | |
2695 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2696 | "Unknown integer value for %s on line %d of %s.", | |
2697 | line, linenum, filename); | |
2698 | return (0); | |
2699 | } | |
2700 | } | |
2701 | ||
2702 | if (n < 0) | |
2703 | { | |
2704 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2705 | "Bad negative integer value for %s on line %d of " | |
2706 | "%s.", line, linenum, filename); | |
2707 | return (0); | |
2708 | } | |
2709 | else | |
2710 | { | |
2711 | *((int *)var->ptr) = n; | |
2712 | } | |
2713 | } | |
2714 | break; | |
2715 | ||
2716 | case CUPSD_VARTYPE_TIME : | |
2717 | if (!value) | |
2718 | { | |
2719 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2720 | "Missing time interval value for %s on line %d of " | |
2721 | "%s.", line, linenum, filename); | |
2722 | return (0); | |
2723 | } | |
2724 | else if (!_cups_strncasecmp(line, "PreserveJob", 11) && | |
2725 | (!_cups_strcasecmp(value, "true") || | |
2726 | !_cups_strcasecmp(value, "on") || | |
2727 | !_cups_strcasecmp(value, "enabled") || | |
2728 | !_cups_strcasecmp(value, "yes"))) | |
2729 | { | |
2730 | *((int *)var->ptr) = INT_MAX; | |
2731 | } | |
2732 | else if (!_cups_strcasecmp(value, "false") || | |
2733 | !_cups_strcasecmp(value, "off") || | |
2734 | !_cups_strcasecmp(value, "disabled") || | |
2735 | !_cups_strcasecmp(value, "no")) | |
2736 | { | |
2737 | *((int *)var->ptr) = 0; | |
2738 | } | |
2739 | else if (!isdigit(*value & 255)) | |
2740 | { | |
2741 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2742 | "Unknown time interval value for %s on line %d of " | |
2743 | "%s.", line, linenum, filename); | |
2744 | return (0); | |
2745 | } | |
2746 | else | |
2747 | { | |
2748 | double n; /* Number */ | |
2749 | char *units; /* Units */ | |
2750 | ||
2751 | n = strtod(value, &units); | |
2752 | ||
2753 | if (units && *units) | |
2754 | { | |
2755 | if (tolower(units[0] & 255) == 'w') | |
2756 | n *= 7 * 24 * 60 * 60; | |
2757 | else if (tolower(units[0] & 255) == 'd') | |
2758 | n *= 24 * 60 * 60; | |
2759 | else if (tolower(units[0] & 255) == 'h') | |
2760 | n *= 60 * 60; | |
2761 | else if (tolower(units[0] & 255) == 'm') | |
2762 | n *= 60; | |
2763 | else | |
2764 | { | |
2765 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2766 | "Unknown time interval value for %s on line " | |
2767 | "%d of %s.", line, linenum, filename); | |
2768 | return (0); | |
2769 | } | |
2770 | } | |
2771 | ||
2772 | if (n < 0.0 || n > INT_MAX) | |
2773 | { | |
2774 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2775 | "Bad time value for %s on line %d of %s.", | |
2776 | line, linenum, filename); | |
2777 | return (0); | |
2778 | } | |
2779 | else | |
2780 | { | |
2781 | *((int *)var->ptr) = (int)n; | |
2782 | } | |
2783 | } | |
2784 | break; | |
2785 | ||
2786 | case CUPSD_VARTYPE_BOOLEAN : | |
2787 | if (!value) | |
2788 | { | |
2789 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2790 | "Missing boolean value for %s on line %d of %s.", | |
2791 | line, linenum, filename); | |
2792 | return (0); | |
2793 | } | |
2794 | else if (!_cups_strcasecmp(value, "true") || | |
2795 | !_cups_strcasecmp(value, "on") || | |
2796 | !_cups_strcasecmp(value, "enabled") || | |
2797 | !_cups_strcasecmp(value, "yes") || | |
2798 | atoi(value) != 0) | |
2799 | { | |
2800 | *((int *)var->ptr) = TRUE; | |
2801 | } | |
2802 | else if (!_cups_strcasecmp(value, "false") || | |
2803 | !_cups_strcasecmp(value, "off") || | |
2804 | !_cups_strcasecmp(value, "disabled") || | |
2805 | !_cups_strcasecmp(value, "no") || | |
2806 | !_cups_strcasecmp(value, "0")) | |
2807 | { | |
2808 | *((int *)var->ptr) = FALSE; | |
2809 | } | |
2810 | else | |
2811 | { | |
2812 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2813 | "Unknown boolean value %s on line %d of %s.", | |
2814 | value, linenum, filename); | |
2815 | return (0); | |
2816 | } | |
2817 | break; | |
2818 | ||
2819 | case CUPSD_VARTYPE_PATHNAME : | |
2820 | if (!value) | |
2821 | { | |
2822 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2823 | "Missing pathname value for %s on line %d of %s.", | |
2824 | line, linenum, filename); | |
2825 | return (0); | |
2826 | } | |
2827 | ||
2828 | if (value[0] == '/') | |
2829 | strlcpy(temp, value, sizeof(temp)); | |
2830 | else | |
2831 | snprintf(temp, sizeof(temp), "%s/%s", ServerRoot, value); | |
2832 | ||
2833 | if (access(temp, 0)) | |
2834 | { | |
2835 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2836 | "File or directory for \"%s %s\" on line %d of %s " | |
2837 | "does not exist.", line, value, linenum, filename); | |
2838 | return (0); | |
2839 | } | |
2840 | ||
2841 | cupsdSetString((char **)var->ptr, temp); | |
2842 | break; | |
2843 | ||
2844 | case CUPSD_VARTYPE_STRING : | |
2845 | cupsdSetString((char **)var->ptr, value); | |
2846 | break; | |
2847 | } | |
2848 | ||
2849 | return (1); | |
2850 | } | |
2851 | ||
2852 | ||
2853 | /* | |
2854 | * 'read_cupsd_conf()' - Read the cupsd.conf configuration file. | |
2855 | */ | |
2856 | ||
2857 | static int /* O - 1 on success, 0 on failure */ | |
2858 | read_cupsd_conf(cups_file_t *fp) /* I - File to read from */ | |
ef416fc2 | 2859 | { |
ef416fc2 | 2860 | int linenum; /* Current line number */ |
2861 | char line[HTTP_MAX_BUFFER], | |
2862 | /* Line from file */ | |
2863 | temp[HTTP_MAX_BUFFER], | |
2864 | /* Temporary buffer for value */ | |
ef416fc2 | 2865 | *value, /* Pointer to value */ |
bd7854cb | 2866 | *valueptr; /* Pointer into value */ |
ef416fc2 | 2867 | int valuelen; /* Length of value */ |
ef416fc2 | 2868 | http_addrlist_t *addrlist, /* Address list */ |
2869 | *addr; /* Current address */ | |
ef416fc2 | 2870 | cups_file_t *incfile; /* Include file */ |
2871 | char incname[1024]; /* Include filename */ | |
ef416fc2 | 2872 | |
2873 | ||
2874 | /* | |
2875 | * Loop through each line in the file... | |
2876 | */ | |
2877 | ||
2878 | linenum = 0; | |
2879 | ||
2880 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
2881 | { | |
2882 | /* | |
2883 | * Decode the directive... | |
2884 | */ | |
2885 | ||
88f9aafc | 2886 | if (!_cups_strcasecmp(line, "Include") && value) |
ef416fc2 | 2887 | { |
2888 | /* | |
2889 | * Include filename | |
2890 | */ | |
2891 | ||
2892 | if (value[0] == '/') | |
2893 | strlcpy(incname, value, sizeof(incname)); | |
2894 | else | |
2895 | snprintf(incname, sizeof(incname), "%s/%s", ServerRoot, value); | |
2896 | ||
2897 | if ((incfile = cupsFileOpen(incname, "rb")) == NULL) | |
2898 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2899 | "Unable to include config file \"%s\" - %s", | |
2900 | incname, strerror(errno)); | |
2901 | else | |
2902 | { | |
c41769ff | 2903 | read_cupsd_conf(incfile); |
ef416fc2 | 2904 | cupsFileClose(incfile); |
2905 | } | |
2906 | } | |
88f9aafc | 2907 | else if (!_cups_strcasecmp(line, "<Location") && value) |
ef416fc2 | 2908 | { |
2909 | /* | |
2910 | * <Location path> | |
2911 | */ | |
2912 | ||
c934a06c MS |
2913 | linenum = read_location(fp, value, linenum); |
2914 | if (linenum == 0) | |
2915 | return (0); | |
ef416fc2 | 2916 | } |
88f9aafc | 2917 | else if (!_cups_strcasecmp(line, "<Policy") && value) |
ef416fc2 | 2918 | { |
2919 | /* | |
2920 | * <Policy name> | |
2921 | */ | |
2922 | ||
c934a06c MS |
2923 | linenum = read_policy(fp, value, linenum); |
2924 | if (linenum == 0) | |
2925 | return (0); | |
ef416fc2 | 2926 | } |
88f9aafc | 2927 | else if (!_cups_strcasecmp(line, "FaxRetryInterval") && value) |
ef416fc2 | 2928 | { |
c934a06c MS |
2929 | JobRetryInterval = atoi(value); |
2930 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2931 | "FaxRetryInterval is deprecated; use " | |
2932 | "JobRetryInterval on line %d.", linenum); | |
ef416fc2 | 2933 | } |
88f9aafc | 2934 | else if (!_cups_strcasecmp(line, "FaxRetryLimit") && value) |
ef416fc2 | 2935 | { |
c934a06c MS |
2936 | JobRetryLimit = atoi(value); |
2937 | cupsdLogMessage(CUPSD_LOG_WARN, | |
2938 | "FaxRetryLimit is deprecated; use " | |
2939 | "JobRetryLimit on line %d.", linenum); | |
ef416fc2 | 2940 | } |
f99f3698 | 2941 | else if ((!_cups_strcasecmp(line, "Port") || !_cups_strcasecmp(line, "Listen") |
ef416fc2 | 2942 | #ifdef HAVE_SSL |
88f9aafc | 2943 | || !_cups_strcasecmp(line, "SSLPort") || !_cups_strcasecmp(line, "SSLListen") |
ef416fc2 | 2944 | #endif /* HAVE_SSL */ |
f99f3698 | 2945 | ) && value) |
ef416fc2 | 2946 | { |
2947 | /* | |
2948 | * Add listening address(es) to the list... | |
2949 | */ | |
2950 | ||
2951 | cupsd_listener_t *lis; /* New listeners array */ | |
2952 | ||
2953 | ||
2954 | /* | |
2955 | * Get the address list... | |
2956 | */ | |
2957 | ||
2958 | addrlist = get_address(value, IPP_PORT); | |
2959 | ||
2960 | if (!addrlist) | |
2961 | { | |
2962 | cupsdLogMessage(CUPSD_LOG_ERROR, "Bad %s address %s at line %d.", line, | |
2963 | value, linenum); | |
2964 | continue; | |
2965 | } | |
2966 | ||
2967 | /* | |
2968 | * Add each address... | |
2969 | */ | |
2970 | ||
2971 | for (addr = addrlist; addr; addr = addr->next) | |
2972 | { | |
49d87452 MS |
2973 | /* |
2974 | * See if this address is already present... | |
2975 | */ | |
2976 | ||
2977 | for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners); | |
2978 | lis; | |
2979 | lis = (cupsd_listener_t *)cupsArrayNext(Listeners)) | |
2980 | if (httpAddrEqual(&(addr->addr), &(lis->address)) && | |
a469f8a5 | 2981 | httpAddrPort(&(addr->addr)) == httpAddrPort(&(lis->address))) |
49d87452 MS |
2982 | break; |
2983 | ||
2984 | if (lis) | |
2985 | { | |
2986 | httpAddrString(&lis->address, temp, sizeof(temp)); | |
2987 | cupsdLogMessage(CUPSD_LOG_WARN, | |
c8fef167 | 2988 | "Duplicate listen address \"%s\" ignored.", temp); |
49d87452 MS |
2989 | continue; |
2990 | } | |
2991 | ||
ef416fc2 | 2992 | /* |
2993 | * Allocate another listener... | |
2994 | */ | |
2995 | ||
bd7854cb | 2996 | if (!Listeners) |
2997 | Listeners = cupsArrayNew(NULL, NULL); | |
ef416fc2 | 2998 | |
bd7854cb | 2999 | if (!Listeners) |
ef416fc2 | 3000 | { |
3001 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3002 | "Unable to allocate %s at line %d - %s.", | |
3003 | line, linenum, strerror(errno)); | |
3004 | break; | |
3005 | } | |
3006 | ||
bd7854cb | 3007 | if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL) |
3008 | { | |
3009 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3010 | "Unable to allocate %s at line %d - %s.", | |
3011 | line, linenum, strerror(errno)); | |
3012 | break; | |
3013 | } | |
3014 | ||
3015 | cupsArrayAdd(Listeners, lis); | |
ef416fc2 | 3016 | |
3017 | /* | |
3018 | * Copy the current address and log it... | |
3019 | */ | |
3020 | ||
ef416fc2 | 3021 | memcpy(&(lis->address), &(addr->addr), sizeof(lis->address)); |
a4d04587 | 3022 | lis->fd = -1; |
ef416fc2 | 3023 | |
3024 | #ifdef HAVE_SSL | |
88f9aafc | 3025 | if (!_cups_strcasecmp(line, "SSLPort") || !_cups_strcasecmp(line, "SSLListen")) |
ef416fc2 | 3026 | lis->encryption = HTTP_ENCRYPT_ALWAYS; |
3027 | #endif /* HAVE_SSL */ | |
3028 | ||
a4d04587 | 3029 | httpAddrString(&lis->address, temp, sizeof(temp)); |
3030 | ||
ef416fc2 | 3031 | #ifdef AF_LOCAL |
3032 | if (lis->address.addr.sa_family == AF_LOCAL) | |
3033 | cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s (Domain)", temp); | |
3034 | else | |
3035 | #endif /* AF_LOCAL */ | |
22c9029b | 3036 | cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv%d)", temp, |
a469f8a5 | 3037 | httpAddrPort(&(lis->address)), |
22c9029b | 3038 | _httpAddrFamily(&(lis->address)) == AF_INET ? 4 : 6); |
d1c13e16 MS |
3039 | |
3040 | if (!httpAddrLocalhost(&(lis->address))) | |
a469f8a5 | 3041 | RemotePort = httpAddrPort(&(lis->address)); |
ef416fc2 | 3042 | } |
3043 | ||
3044 | /* | |
3045 | * Free the list... | |
3046 | */ | |
3047 | ||
3048 | httpAddrFreeList(addrlist); | |
3049 | } | |
88f9aafc | 3050 | else if (!_cups_strcasecmp(line, "BrowseProtocols") || |
a2326b5b | 3051 | !_cups_strcasecmp(line, "BrowseLocalProtocols")) |
ef416fc2 | 3052 | { |
3053 | /* | |
bd7854cb | 3054 | * "BrowseProtocols name [... name]" |
3055 | * "BrowseLocalProtocols name [... name]" | |
ef416fc2 | 3056 | */ |
3057 | ||
bd7854cb | 3058 | int protocols = parse_protocols(value); |
ef416fc2 | 3059 | |
bd7854cb | 3060 | if (protocols < 0) |
ef416fc2 | 3061 | { |
bd7854cb | 3062 | cupsdLogMessage(CUPSD_LOG_ERROR, |
3063 | "Unknown browse protocol \"%s\" on line %d.", | |
3064 | value, linenum); | |
3065 | break; | |
ef416fc2 | 3066 | } |
bd7854cb | 3067 | |
a2326b5b | 3068 | BrowseLocalProtocols = protocols; |
ef416fc2 | 3069 | } |
c41769ff | 3070 | else if (!_cups_strcasecmp(line, "DefaultAuthType") && value) |
ef416fc2 | 3071 | { |
3072 | /* | |
c41769ff | 3073 | * DefaultAuthType {basic,digest,basicdigest,negotiate} |
ef416fc2 | 3074 | */ |
3075 | ||
88f9aafc | 3076 | if (!_cups_strcasecmp(value, "none")) |
dcb445bc | 3077 | default_auth_type = CUPSD_AUTH_NONE; |
88f9aafc | 3078 | else if (!_cups_strcasecmp(value, "basic")) |
dcb445bc | 3079 | default_auth_type = CUPSD_AUTH_BASIC; |
88f9aafc | 3080 | else if (!_cups_strcasecmp(value, "digest")) |
dcb445bc | 3081 | default_auth_type = CUPSD_AUTH_DIGEST; |
88f9aafc | 3082 | else if (!_cups_strcasecmp(value, "basicdigest")) |
dcb445bc | 3083 | default_auth_type = CUPSD_AUTH_BASICDIGEST; |
f7deaa1a | 3084 | #ifdef HAVE_GSSAPI |
88f9aafc | 3085 | else if (!_cups_strcasecmp(value, "negotiate")) |
dcb445bc | 3086 | default_auth_type = CUPSD_AUTH_NEGOTIATE; |
f7deaa1a | 3087 | #endif /* HAVE_GSSAPI */ |
dcb445bc MS |
3088 | else if (!_cups_strcasecmp(value, "auto")) |
3089 | default_auth_type = CUPSD_AUTH_AUTO; | |
ef416fc2 | 3090 | else |
3091 | { | |
3092 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3093 | "Unknown default authorization type %s on line %d.", | |
3094 | value, linenum); | |
49d87452 MS |
3095 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3096 | return (0); | |
ef416fc2 | 3097 | } |
3098 | } | |
4744bd90 | 3099 | #ifdef HAVE_SSL |
88f9aafc | 3100 | else if (!_cups_strcasecmp(line, "DefaultEncryption")) |
4744bd90 | 3101 | { |
3102 | /* | |
3103 | * DefaultEncryption {Never,IfRequested,Required} | |
3104 | */ | |
3105 | ||
88f9aafc | 3106 | if (!value || !_cups_strcasecmp(value, "never")) |
4744bd90 | 3107 | DefaultEncryption = HTTP_ENCRYPT_NEVER; |
88f9aafc | 3108 | else if (!_cups_strcasecmp(value, "required")) |
4744bd90 | 3109 | DefaultEncryption = HTTP_ENCRYPT_REQUIRED; |
88f9aafc | 3110 | else if (!_cups_strcasecmp(value, "ifrequested")) |
4744bd90 | 3111 | DefaultEncryption = HTTP_ENCRYPT_IF_REQUESTED; |
3112 | else | |
3113 | { | |
3114 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3115 | "Unknown default encryption %s on line %d.", | |
3116 | value, linenum); | |
49d87452 MS |
3117 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3118 | return (0); | |
4744bd90 | 3119 | } |
3120 | } | |
3121 | #endif /* HAVE_SSL */ | |
88f9aafc | 3122 | else if (!_cups_strcasecmp(line, "HostNameLookups") && value) |
ef416fc2 | 3123 | { |
3124 | /* | |
3125 | * Do hostname lookups? | |
3126 | */ | |
3127 | ||
88f9aafc MS |
3128 | if (!_cups_strcasecmp(value, "off") || !_cups_strcasecmp(value, "no") || |
3129 | !_cups_strcasecmp(value, "false")) | |
ef416fc2 | 3130 | HostNameLookups = 0; |
88f9aafc MS |
3131 | else if (!_cups_strcasecmp(value, "on") || !_cups_strcasecmp(value, "yes") || |
3132 | !_cups_strcasecmp(value, "true")) | |
ef416fc2 | 3133 | HostNameLookups = 1; |
88f9aafc | 3134 | else if (!_cups_strcasecmp(value, "double")) |
ef416fc2 | 3135 | HostNameLookups = 2; |
3136 | else | |
3137 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown HostNameLookups %s on line %d.", | |
3138 | value, linenum); | |
3139 | } | |
88f9aafc | 3140 | else if (!_cups_strcasecmp(line, "AccessLogLevel") && value) |
1f0275e3 MS |
3141 | { |
3142 | /* | |
3143 | * Amount of logging to do to access log... | |
3144 | */ | |
3145 | ||
88f9aafc | 3146 | if (!_cups_strcasecmp(value, "all")) |
1f0275e3 | 3147 | AccessLogLevel = CUPSD_ACCESSLOG_ALL; |
88f9aafc | 3148 | else if (!_cups_strcasecmp(value, "actions")) |
1f0275e3 | 3149 | AccessLogLevel = CUPSD_ACCESSLOG_ACTIONS; |
88f9aafc | 3150 | else if (!_cups_strcasecmp(value, "config")) |
1f0275e3 MS |
3151 | AccessLogLevel = CUPSD_ACCESSLOG_CONFIG; |
3152 | else | |
3153 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown AccessLogLevel %s on line %d.", | |
3154 | value, linenum); | |
3155 | } | |
88f9aafc | 3156 | else if (!_cups_strcasecmp(line, "LogLevel") && value) |
ef416fc2 | 3157 | { |
3158 | /* | |
1f0275e3 | 3159 | * Amount of logging to do to error log... |
ef416fc2 | 3160 | */ |
3161 | ||
88f9aafc | 3162 | if (!_cups_strcasecmp(value, "debug2")) |
ef416fc2 | 3163 | LogLevel = CUPSD_LOG_DEBUG2; |
88f9aafc | 3164 | else if (!_cups_strcasecmp(value, "debug")) |
ef416fc2 | 3165 | LogLevel = CUPSD_LOG_DEBUG; |
88f9aafc | 3166 | else if (!_cups_strcasecmp(value, "info")) |
ef416fc2 | 3167 | LogLevel = CUPSD_LOG_INFO; |
88f9aafc | 3168 | else if (!_cups_strcasecmp(value, "notice")) |
ef416fc2 | 3169 | LogLevel = CUPSD_LOG_NOTICE; |
88f9aafc | 3170 | else if (!_cups_strcasecmp(value, "warn")) |
ef416fc2 | 3171 | LogLevel = CUPSD_LOG_WARN; |
88f9aafc | 3172 | else if (!_cups_strcasecmp(value, "error")) |
ef416fc2 | 3173 | LogLevel = CUPSD_LOG_ERROR; |
88f9aafc | 3174 | else if (!_cups_strcasecmp(value, "crit")) |
ef416fc2 | 3175 | LogLevel = CUPSD_LOG_CRIT; |
88f9aafc | 3176 | else if (!_cups_strcasecmp(value, "alert")) |
ef416fc2 | 3177 | LogLevel = CUPSD_LOG_ALERT; |
88f9aafc | 3178 | else if (!_cups_strcasecmp(value, "emerg")) |
ef416fc2 | 3179 | LogLevel = CUPSD_LOG_EMERG; |
88f9aafc | 3180 | else if (!_cups_strcasecmp(value, "none")) |
ef416fc2 | 3181 | LogLevel = CUPSD_LOG_NONE; |
3182 | else | |
3183 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogLevel %s on line %d.", | |
3184 | value, linenum); | |
3185 | } | |
88f9aafc | 3186 | else if (!_cups_strcasecmp(line, "LogTimeFormat") && value) |
dfd5680b MS |
3187 | { |
3188 | /* | |
3189 | * Amount of logging to do to error log... | |
3190 | */ | |
3191 | ||
88f9aafc | 3192 | if (!_cups_strcasecmp(value, "standard")) |
dfd5680b | 3193 | LogTimeFormat = CUPSD_TIME_STANDARD; |
88f9aafc | 3194 | else if (!_cups_strcasecmp(value, "usecs")) |
dfd5680b MS |
3195 | LogTimeFormat = CUPSD_TIME_USECS; |
3196 | else | |
3197 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogTimeFormat %s on line %d.", | |
3198 | value, linenum); | |
3199 | } | |
88f9aafc | 3200 | else if (!_cups_strcasecmp(line, "ServerTokens") && value) |
ef416fc2 | 3201 | { |
3202 | /* | |
3203 | * Set the string used for the Server header... | |
3204 | */ | |
3205 | ||
3206 | struct utsname plat; /* Platform info */ | |
3207 | ||
3208 | ||
3209 | uname(&plat); | |
3210 | ||
88f9aafc | 3211 | if (!_cups_strcasecmp(value, "ProductOnly")) |
db8b865d | 3212 | cupsdSetString(&ServerHeader, "CUPS IPP"); |
88f9aafc | 3213 | else if (!_cups_strcasecmp(value, "Major")) |
db8b865d | 3214 | cupsdSetStringf(&ServerHeader, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR); |
88f9aafc | 3215 | else if (!_cups_strcasecmp(value, "Minor")) |
db8b865d | 3216 | cupsdSetStringf(&ServerHeader, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR, |
771bd8cb | 3217 | CUPS_VERSION_MINOR); |
88f9aafc | 3218 | else if (!_cups_strcasecmp(value, "Minimal")) |
db8b865d | 3219 | cupsdSetString(&ServerHeader, CUPS_MINIMAL " IPP/2.1"); |
88f9aafc | 3220 | else if (!_cups_strcasecmp(value, "OS")) |
db8b865d MS |
3221 | cupsdSetStringf(&ServerHeader, CUPS_MINIMAL " (%s %s) IPP/2.1", |
3222 | plat.sysname, plat.release); | |
88f9aafc | 3223 | else if (!_cups_strcasecmp(value, "Full")) |
db8b865d MS |
3224 | cupsdSetStringf(&ServerHeader, CUPS_MINIMAL " (%s %s; %s) IPP/2.1", |
3225 | plat.sysname, plat.release, plat.machine); | |
88f9aafc | 3226 | else if (!_cups_strcasecmp(value, "None")) |
ef416fc2 | 3227 | cupsdClearString(&ServerHeader); |
3228 | else | |
3229 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown ServerTokens %s on line %d.", | |
3230 | value, linenum); | |
3231 | } | |
88f9aafc | 3232 | else if (!_cups_strcasecmp(line, "PassEnv") && value) |
ef416fc2 | 3233 | { |
3234 | /* | |
3235 | * PassEnv variable [... variable] | |
3236 | */ | |
3237 | ||
3238 | for (; *value;) | |
3239 | { | |
3240 | for (valuelen = 0; value[valuelen]; valuelen ++) | |
88f9aafc | 3241 | if (_cups_isspace(value[valuelen]) || value[valuelen] == ',') |
ef416fc2 | 3242 | break; |
3243 | ||
3244 | if (value[valuelen]) | |
3245 | { | |
3246 | value[valuelen] = '\0'; | |
3247 | valuelen ++; | |
3248 | } | |
3249 | ||
3250 | cupsdSetEnv(value, NULL); | |
3251 | ||
3252 | for (value += valuelen; *value; value ++) | |
88f9aafc | 3253 | if (!_cups_isspace(*value) || *value != ',') |
ef416fc2 | 3254 | break; |
3255 | } | |
3256 | } | |
88f9aafc | 3257 | else if (!_cups_strcasecmp(line, "ServerAlias") && value) |
e07d4801 | 3258 | { |
88f9aafc MS |
3259 | /* |
3260 | * ServerAlias name [... name] | |
3261 | */ | |
3262 | ||
e07d4801 MS |
3263 | if (!ServerAlias) |
3264 | ServerAlias = cupsArrayNew(NULL, NULL); | |
3265 | ||
88f9aafc MS |
3266 | for (; *value;) |
3267 | { | |
3268 | for (valuelen = 0; value[valuelen]; valuelen ++) | |
3269 | if (_cups_isspace(value[valuelen]) || value[valuelen] == ',') | |
3270 | break; | |
3271 | ||
3272 | if (value[valuelen]) | |
3273 | { | |
3274 | value[valuelen] = '\0'; | |
3275 | valuelen ++; | |
3276 | } | |
3277 | ||
3278 | cupsdAddAlias(ServerAlias, value); | |
3279 | ||
3280 | for (value += valuelen; *value; value ++) | |
3281 | if (!_cups_isspace(*value) || *value != ',') | |
3282 | break; | |
3283 | } | |
e07d4801 | 3284 | } |
88f9aafc | 3285 | else if (!_cups_strcasecmp(line, "SetEnv") && value) |
ef416fc2 | 3286 | { |
3287 | /* | |
3288 | * SetEnv variable value | |
3289 | */ | |
3290 | ||
3291 | for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++); | |
3292 | ||
3293 | if (*valueptr) | |
3294 | { | |
3295 | /* | |
3296 | * Found a value... | |
3297 | */ | |
3298 | ||
3299 | while (isspace(*valueptr & 255)) | |
3300 | *valueptr++ = '\0'; | |
3301 | ||
3302 | cupsdSetEnv(value, valueptr); | |
3303 | } | |
3304 | else | |
3305 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3306 | "Missing value for SetEnv directive on line %d.", | |
3307 | linenum); | |
3308 | } | |
58dc1933 | 3309 | #ifdef HAVE_SSL |
88f9aafc | 3310 | else if (!_cups_strcasecmp(line, "SSLOptions")) |
b19ccc9e MS |
3311 | { |
3312 | /* | |
3313 | * SSLOptions options | |
3314 | */ | |
3315 | ||
88f9aafc | 3316 | if (!value || !_cups_strcasecmp(value, "none")) |
b19ccc9e | 3317 | SSLOptions = CUPSD_SSL_NONE; |
88f9aafc | 3318 | else if (!_cups_strcasecmp(value, "noemptyfragments")) |
b19ccc9e MS |
3319 | SSLOptions = CUPSD_SSL_NOEMPTY; |
3320 | else | |
3321 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3322 | "Unknown value \"%s\" for SSLOptions directive on " | |
3323 | "line %d.", value, linenum); | |
3324 | } | |
58dc1933 | 3325 | #endif /* HAVE_SSL */ |
cb7f98ee MS |
3326 | else if (!_cups_strcasecmp(line, "AccessLog") || |
3327 | !_cups_strcasecmp(line, "CacheDir") || | |
3328 | !_cups_strcasecmp(line, "ConfigFilePerm") || | |
3329 | !_cups_strcasecmp(line, "DataDir") || | |
3330 | !_cups_strcasecmp(line, "DocumentRoot") || | |
3331 | !_cups_strcasecmp(line, "ErrorLog") || | |
3332 | !_cups_strcasecmp(line, "FatalErrors") || | |
3333 | !_cups_strcasecmp(line, "FileDevice") || | |
3334 | !_cups_strcasecmp(line, "FontPath") || | |
3335 | !_cups_strcasecmp(line, "Group") || | |
3336 | !_cups_strcasecmp(line, "LogFilePerm") || | |
3337 | !_cups_strcasecmp(line, "LPDConfigFile") || | |
3338 | !_cups_strcasecmp(line, "PageLog") || | |
3339 | !_cups_strcasecmp(line, "Printcap") || | |
3340 | !_cups_strcasecmp(line, "PrintcapFormat") || | |
3341 | !_cups_strcasecmp(line, "RemoteRoot") || | |
3342 | !_cups_strcasecmp(line, "RequestRoot") || | |
3343 | !_cups_strcasecmp(line, "ServerBin") || | |
3344 | !_cups_strcasecmp(line, "ServerCertificate") || | |
3345 | !_cups_strcasecmp(line, "ServerKey") || | |
3346 | !_cups_strcasecmp(line, "ServerRoot") || | |
3347 | !_cups_strcasecmp(line, "SMBConfigFile") || | |
3348 | !_cups_strcasecmp(line, "StateDir") || | |
3349 | !_cups_strcasecmp(line, "SystemGroup") || | |
3350 | !_cups_strcasecmp(line, "SystemGroupAuthKey") || | |
3351 | !_cups_strcasecmp(line, "TempDir") || | |
3352 | !_cups_strcasecmp(line, "User")) | |
3353 | { | |
6961465f | 3354 | cupsdLogMessage(CUPSD_LOG_INFO, |
cb7f98ee MS |
3355 | "Please move \"%s%s%s\" on line %d of %s to the %s file; " |
3356 | "this will become an error in a future release.", | |
3357 | line, value ? " " : "", value ? value : "", linenum, | |
3358 | ConfigurationFile, CupsFilesFile); | |
3359 | } | |
ef416fc2 | 3360 | else |
c41769ff MS |
3361 | parse_variable(ConfigurationFile, linenum, line, value, |
3362 | sizeof(cupsd_vars) / sizeof(cupsd_vars[0]), cupsd_vars); | |
3363 | } | |
3364 | ||
3365 | return (1); | |
3366 | } | |
3367 | ||
3368 | ||
3369 | /* | |
3370 | * 'read_cups_files_conf()' - Read the cups-files.conf configuration file. | |
3371 | */ | |
3372 | ||
3373 | static int /* O - 1 on success, 0 on failure */ | |
3374 | read_cups_files_conf(cups_file_t *fp) /* I - File to read from */ | |
3375 | { | |
3376 | int linenum; /* Current line number */ | |
3377 | char line[HTTP_MAX_BUFFER], /* Line from file */ | |
3378 | *value; /* Value from line */ | |
3379 | struct group *group; /* Group */ | |
3380 | ||
3381 | ||
3382 | /* | |
3383 | * Loop through each line in the file... | |
3384 | */ | |
3385 | ||
3386 | linenum = 0; | |
3387 | ||
3388 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
3389 | { | |
3390 | if (!_cups_strcasecmp(line, "FatalErrors")) | |
3391 | FatalErrors = parse_fatal_errors(value); | |
3392 | else if (!_cups_strcasecmp(line, "Group") && value) | |
ef416fc2 | 3393 | { |
3394 | /* | |
c41769ff | 3395 | * Group ID to run as... |
ef416fc2 | 3396 | */ |
3397 | ||
c41769ff MS |
3398 | if (isdigit(value[0])) |
3399 | Group = atoi(value); | |
3400 | else | |
ef416fc2 | 3401 | { |
c41769ff MS |
3402 | endgrent(); |
3403 | group = getgrnam(value); | |
ef416fc2 | 3404 | |
c41769ff MS |
3405 | if (group != NULL) |
3406 | Group = group->gr_gid; | |
c934a06c | 3407 | else |
c41769ff MS |
3408 | { |
3409 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3410 | "Unknown Group \"%s\" on line %d of %s.", value, | |
3411 | linenum, CupsFilesFile); | |
3412 | if (FatalErrors & CUPSD_FATAL_CONFIG) | |
3413 | return (0); | |
3414 | } | |
ef416fc2 | 3415 | } |
c41769ff MS |
3416 | } |
3417 | else if (!_cups_strcasecmp(line, "PrintcapFormat") && value) | |
3418 | { | |
3419 | /* | |
3420 | * Format of printcap file? | |
3421 | */ | |
ef416fc2 | 3422 | |
c41769ff MS |
3423 | if (!_cups_strcasecmp(value, "bsd")) |
3424 | PrintcapFormat = PRINTCAP_BSD; | |
3425 | else if (!_cups_strcasecmp(value, "plist")) | |
3426 | PrintcapFormat = PRINTCAP_PLIST; | |
3427 | else if (!_cups_strcasecmp(value, "solaris")) | |
3428 | PrintcapFormat = PRINTCAP_SOLARIS; | |
3429 | else | |
ef416fc2 | 3430 | { |
c41769ff MS |
3431 | cupsdLogMessage(CUPSD_LOG_ERROR, |
3432 | "Unknown PrintcapFormat \"%s\" on line %d of %s.", | |
3433 | value, linenum, CupsFilesFile); | |
3434 | if (FatalErrors & CUPSD_FATAL_CONFIG) | |
3435 | return (0); | |
3436 | } | |
3437 | } | |
3438 | else if (!_cups_strcasecmp(line, "SystemGroup") && value) | |
3439 | { | |
3440 | /* | |
3441 | * SystemGroup (admin) group(s)... | |
3442 | */ | |
82cc1f9a | 3443 | |
c41769ff MS |
3444 | if (!parse_groups(value)) |
3445 | { | |
3446 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3447 | "Unknown SystemGroup \"%s\" on line %d of %s.", value, | |
3448 | linenum, CupsFilesFile); | |
3449 | if (FatalErrors & CUPSD_FATAL_CONFIG) | |
3450 | return (0); | |
3451 | } | |
3452 | } | |
3453 | else if (!_cups_strcasecmp(line, "User") && value) | |
3454 | { | |
3455 | /* | |
3456 | * User ID to run as... | |
3457 | */ | |
ef416fc2 | 3458 | |
c41769ff MS |
3459 | if (isdigit(value[0] & 255)) |
3460 | { | |
3461 | int uid = atoi(value); | |
c934a06c | 3462 | |
c41769ff MS |
3463 | if (!uid) |
3464 | { | |
3465 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3466 | "Will not use User 0 as specified on line %d of %s " | |
3467 | "for security reasons. You must use a non-" | |
3468 | "privileged account instead.", | |
3469 | linenum, CupsFilesFile); | |
3470 | if (FatalErrors & CUPSD_FATAL_CONFIG) | |
3471 | return (0); | |
3472 | } | |
3473 | else | |
3474 | User = atoi(value); | |
3475 | } | |
3476 | else | |
3477 | { | |
3478 | struct passwd *p; /* Password information */ | |
76cd9e37 | 3479 | |
c41769ff MS |
3480 | endpwent(); |
3481 | p = getpwnam(value); | |
76cd9e37 | 3482 | |
c41769ff MS |
3483 | if (p) |
3484 | { | |
3485 | if (!p->pw_uid) | |
3486 | { | |
3487 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3488 | "Will not use User %s (UID=0) as specified on line " | |
3489 | "%d of %s for security reasons. You must use a " | |
3490 | "non-privileged account instead.", | |
3491 | value, linenum, CupsFilesFile); | |
3492 | if (FatalErrors & CUPSD_FATAL_CONFIG) | |
3493 | return (0); | |
3494 | } | |
3495 | else | |
3496 | User = p->pw_uid; | |
3497 | } | |
3498 | else | |
3499 | { | |
3500 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3501 | "Unknown User \"%s\" on line %d of %s.", | |
3502 | value, linenum, CupsFilesFile); | |
3503 | if (FatalErrors & CUPSD_FATAL_CONFIG) | |
3504 | return (0); | |
3505 | } | |
ef416fc2 | 3506 | } |
3507 | } | |
c41769ff MS |
3508 | else if (!parse_variable(CupsFilesFile, linenum, line, value, |
3509 | sizeof(cupsfiles_vars) / sizeof(cupsfiles_vars[0]), | |
3510 | cupsfiles_vars) && | |
3511 | (FatalErrors & CUPSD_FATAL_CONFIG)) | |
3512 | return (0); | |
ef416fc2 | 3513 | } |
3514 | ||
3515 | return (1); | |
3516 | } | |
3517 | ||
3518 | ||
3519 | /* | |
3520 | * 'read_location()' - Read a <Location path> definition. | |
3521 | */ | |
3522 | ||
3523 | static int /* O - New line number or 0 on error */ | |
3524 | read_location(cups_file_t *fp, /* I - Configuration file */ | |
3525 | char *location, /* I - Location name/path */ | |
3526 | int linenum) /* I - Current line number */ | |
3527 | { | |
3528 | cupsd_location_t *loc, /* New location */ | |
3529 | *parent; /* Parent location */ | |
3530 | char line[HTTP_MAX_BUFFER], | |
3531 | /* Line buffer */ | |
3532 | *value, /* Value for directive */ | |
3533 | *valptr; /* Pointer into value */ | |
3534 | ||
3535 | ||
c8fef167 MS |
3536 | if ((parent = cupsdFindLocation(location)) != NULL) |
3537 | cupsdLogMessage(CUPSD_LOG_WARN, "Duplicate <Location %s> on line %d.", | |
3538 | location, linenum); | |
3539 | else if ((parent = cupsdNewLocation(location)) == NULL) | |
ef416fc2 | 3540 | return (0); |
c8fef167 MS |
3541 | else |
3542 | { | |
3543 | cupsdAddLocation(parent); | |
ef416fc2 | 3544 | |
c8fef167 MS |
3545 | parent->limit = CUPSD_AUTH_LIMIT_ALL; |
3546 | } | |
10d09e33 | 3547 | |
c8fef167 | 3548 | loc = parent; |
ef416fc2 | 3549 | |
3550 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
3551 | { | |
3552 | /* | |
3553 | * Decode the directive... | |
3554 | */ | |
3555 | ||
88f9aafc | 3556 | if (!_cups_strcasecmp(line, "</Location>")) |
ef416fc2 | 3557 | return (linenum); |
88f9aafc MS |
3558 | else if (!_cups_strcasecmp(line, "<Limit") || |
3559 | !_cups_strcasecmp(line, "<LimitExcept")) | |
ef416fc2 | 3560 | { |
3561 | if (!value) | |
3562 | { | |
3563 | cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum); | |
49d87452 MS |
3564 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3565 | return (0); | |
b19ccc9e MS |
3566 | else |
3567 | continue; | |
ef416fc2 | 3568 | } |
ef55b745 | 3569 | |
10d09e33 | 3570 | if ((loc = cupsdCopyLocation(parent)) == NULL) |
ef416fc2 | 3571 | return (0); |
3572 | ||
10d09e33 MS |
3573 | cupsdAddLocation(loc); |
3574 | ||
ef416fc2 | 3575 | loc->limit = 0; |
3576 | while (*value) | |
3577 | { | |
3578 | for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++); | |
3579 | ||
3580 | if (*valptr) | |
3581 | *valptr++ = '\0'; | |
3582 | ||
3583 | if (!strcmp(value, "ALL")) | |
5bd77a73 | 3584 | loc->limit = CUPSD_AUTH_LIMIT_ALL; |
ef416fc2 | 3585 | else if (!strcmp(value, "GET")) |
5bd77a73 | 3586 | loc->limit |= CUPSD_AUTH_LIMIT_GET; |
ef416fc2 | 3587 | else if (!strcmp(value, "HEAD")) |
5bd77a73 | 3588 | loc->limit |= CUPSD_AUTH_LIMIT_HEAD; |
ef416fc2 | 3589 | else if (!strcmp(value, "OPTIONS")) |
5bd77a73 | 3590 | loc->limit |= CUPSD_AUTH_LIMIT_OPTIONS; |
ef416fc2 | 3591 | else if (!strcmp(value, "POST")) |
5bd77a73 | 3592 | loc->limit |= CUPSD_AUTH_LIMIT_POST; |
ef416fc2 | 3593 | else if (!strcmp(value, "PUT")) |
5bd77a73 | 3594 | loc->limit |= CUPSD_AUTH_LIMIT_PUT; |
ef416fc2 | 3595 | else if (!strcmp(value, "TRACE")) |
5bd77a73 | 3596 | loc->limit |= CUPSD_AUTH_LIMIT_TRACE; |
ef416fc2 | 3597 | else |
c8fef167 | 3598 | cupsdLogMessage(CUPSD_LOG_WARN, "Unknown request type %s on line %d.", |
ef416fc2 | 3599 | value, linenum); |
3600 | ||
3601 | for (value = valptr; isspace(*value & 255); value ++); | |
3602 | } | |
3603 | ||
88f9aafc | 3604 | if (!_cups_strcasecmp(line, "<LimitExcept")) |
5bd77a73 | 3605 | loc->limit = CUPSD_AUTH_LIMIT_ALL ^ loc->limit; |
ef416fc2 | 3606 | |
3607 | parent->limit &= ~loc->limit; | |
3608 | } | |
88f9aafc MS |
3609 | else if (!_cups_strcasecmp(line, "</Limit>") || |
3610 | !_cups_strcasecmp(line, "</LimitExcept>")) | |
ef416fc2 | 3611 | loc = parent; |
f99f3698 MS |
3612 | else if (!value) |
3613 | { | |
3614 | cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value on line %d.", linenum); | |
3615 | if (FatalErrors & CUPSD_FATAL_CONFIG) | |
3616 | return (0); | |
3617 | } | |
ef416fc2 | 3618 | else if (!parse_aaa(loc, line, value, linenum)) |
3619 | { | |
3620 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3621 | "Unknown Location directive %s on line %d.", | |
3622 | line, linenum); | |
49d87452 MS |
3623 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3624 | return (0); | |
ef416fc2 | 3625 | } |
3626 | } | |
3627 | ||
3628 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
c8fef167 | 3629 | "Unexpected end-of-file at line %d while reading location.", |
ef416fc2 | 3630 | linenum); |
3631 | ||
49d87452 | 3632 | return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum); |
ef416fc2 | 3633 | } |
3634 | ||
3635 | ||
3636 | /* | |
3637 | * 'read_policy()' - Read a <Policy name> definition. | |
3638 | */ | |
3639 | ||
3640 | static int /* O - New line number or 0 on error */ | |
3641 | read_policy(cups_file_t *fp, /* I - Configuration file */ | |
3642 | char *policy, /* I - Location name/path */ | |
3643 | int linenum) /* I - Current line number */ | |
3644 | { | |
3645 | int i; /* Looping var */ | |
3646 | cupsd_policy_t *pol; /* Policy */ | |
3647 | cupsd_location_t *op; /* Policy operation */ | |
3648 | int num_ops; /* Number of IPP operations */ | |
3649 | ipp_op_t ops[100]; /* Operations */ | |
3650 | char line[HTTP_MAX_BUFFER], | |
3651 | /* Line buffer */ | |
3652 | *value, /* Value for directive */ | |
3653 | *valptr; /* Pointer into value */ | |
3654 | ||
3655 | ||
3656 | /* | |
3657 | * Create the policy... | |
3658 | */ | |
3659 | ||
c8fef167 MS |
3660 | if ((pol = cupsdFindPolicy(policy)) != NULL) |
3661 | cupsdLogMessage(CUPSD_LOG_WARN, "Duplicate <Policy %s> on line %d.", | |
3662 | policy, linenum); | |
3663 | else if ((pol = cupsdAddPolicy(policy)) == NULL) | |
ef416fc2 | 3664 | return (0); |
3665 | ||
3666 | /* | |
3667 | * Read from the file... | |
3668 | */ | |
3669 | ||
3670 | op = NULL; | |
3671 | num_ops = 0; | |
3672 | ||
3673 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
3674 | { | |
3675 | /* | |
3676 | * Decode the directive... | |
3677 | */ | |
3678 | ||
88f9aafc | 3679 | if (!_cups_strcasecmp(line, "</Policy>")) |
ef416fc2 | 3680 | { |
3681 | if (op) | |
3682 | cupsdLogMessage(CUPSD_LOG_WARN, | |
c8fef167 | 3683 | "Missing </Limit> before </Policy> on line %d.", |
ef416fc2 | 3684 | linenum); |
3685 | ||
10d09e33 | 3686 | set_policy_defaults(pol); |
2e4ff8af | 3687 | |
ef416fc2 | 3688 | return (linenum); |
3689 | } | |
88f9aafc | 3690 | else if (!_cups_strcasecmp(line, "<Limit") && !op) |
ef416fc2 | 3691 | { |
3692 | if (!value) | |
3693 | { | |
3694 | cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum); | |
49d87452 MS |
3695 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3696 | return (0); | |
b19ccc9e MS |
3697 | else |
3698 | continue; | |
ef416fc2 | 3699 | } |
ef55b745 | 3700 | |
ef416fc2 | 3701 | /* |
3702 | * Scan for IPP operation names... | |
3703 | */ | |
3704 | ||
3705 | num_ops = 0; | |
3706 | ||
3707 | while (*value) | |
3708 | { | |
3709 | for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++); | |
3710 | ||
3711 | if (*valptr) | |
3712 | *valptr++ = '\0'; | |
3713 | ||
3714 | if (num_ops < (int)(sizeof(ops) / sizeof(ops[0]))) | |
3715 | { | |
88f9aafc | 3716 | if (!_cups_strcasecmp(value, "All")) |
ef416fc2 | 3717 | ops[num_ops] = IPP_ANY_OPERATION; |
3718 | else if ((ops[num_ops] = ippOpValue(value)) == IPP_BAD_OPERATION) | |
3719 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
c8fef167 | 3720 | "Bad IPP operation name \"%s\" on line %d.", |
ef416fc2 | 3721 | value, linenum); |
3722 | else | |
3723 | num_ops ++; | |
3724 | } | |
3725 | else | |
3726 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
c8fef167 | 3727 | "Too many operations listed on line %d.", |
ef416fc2 | 3728 | linenum); |
3729 | ||
3730 | for (value = valptr; isspace(*value & 255); value ++); | |
3731 | } | |
3732 | ||
3733 | /* | |
3734 | * If none are specified, apply the policy to all operations... | |
3735 | */ | |
3736 | ||
3737 | if (num_ops == 0) | |
3738 | { | |
3739 | ops[0] = IPP_ANY_OPERATION; | |
3740 | num_ops = 1; | |
3741 | } | |
3742 | ||
3743 | /* | |
3744 | * Add a new policy for the first operation... | |
3745 | */ | |
3746 | ||
3747 | op = cupsdAddPolicyOp(pol, NULL, ops[0]); | |
3748 | } | |
88f9aafc | 3749 | else if (!_cups_strcasecmp(line, "</Limit>") && op) |
ef416fc2 | 3750 | { |
3751 | /* | |
3752 | * Finish the current operation limit... | |
3753 | */ | |
3754 | ||
3755 | if (num_ops > 1) | |
3756 | { | |
3757 | /* | |
3758 | * Copy the policy to the other operations... | |
3759 | */ | |
3760 | ||
3761 | for (i = 1; i < num_ops; i ++) | |
3762 | cupsdAddPolicyOp(pol, op, ops[i]); | |
3763 | } | |
3764 | ||
3765 | op = NULL; | |
3766 | } | |
f99f3698 MS |
3767 | else if (!value) |
3768 | { | |
3769 | cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value on line %d.", linenum); | |
3770 | if (FatalErrors & CUPSD_FATAL_CONFIG) | |
3771 | return (0); | |
3772 | } | |
88f9aafc MS |
3773 | else if (!_cups_strcasecmp(line, "JobPrivateAccess") || |
3774 | !_cups_strcasecmp(line, "JobPrivateValues") || | |
3775 | !_cups_strcasecmp(line, "SubscriptionPrivateAccess") || | |
3776 | !_cups_strcasecmp(line, "SubscriptionPrivateValues")) | |
10d09e33 MS |
3777 | { |
3778 | if (op) | |
3779 | { | |
3780 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3781 | "%s directive must appear outside <Limit>...</Limit> " | |
3782 | "on line %d.", line, linenum); | |
3783 | if (FatalErrors & CUPSD_FATAL_CONFIG) | |
3784 | return (0); | |
3785 | } | |
3786 | else | |
3787 | { | |
3788 | /* | |
3789 | * Pull out whitespace-delimited values... | |
3790 | */ | |
3791 | ||
3792 | while (*value) | |
3793 | { | |
3794 | /* | |
3795 | * Find the end of the current value... | |
3796 | */ | |
3797 | ||
3798 | for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++); | |
3799 | ||
3800 | if (*valptr) | |
3801 | *valptr++ = '\0'; | |
3802 | ||
3803 | /* | |
3804 | * Save it appropriately... | |
3805 | */ | |
3806 | ||
88f9aafc | 3807 | if (!_cups_strcasecmp(line, "JobPrivateAccess")) |
10d09e33 MS |
3808 | { |
3809 | /* | |
3810 | * JobPrivateAccess {all|default|user/group list|@@ACL} | |
3811 | */ | |
3812 | ||
88f9aafc | 3813 | if (!_cups_strcasecmp(value, "default")) |
10d09e33 MS |
3814 | { |
3815 | cupsdAddString(&(pol->job_access), "@OWNER"); | |
3816 | cupsdAddString(&(pol->job_access), "@SYSTEM"); | |
3817 | } | |
3818 | else | |
3819 | cupsdAddString(&(pol->job_access), value); | |
3820 | } | |
88f9aafc | 3821 | else if (!_cups_strcasecmp(line, "JobPrivateValues")) |
10d09e33 MS |
3822 | { |
3823 | /* | |
3824 | * JobPrivateValues {all|none|default|attribute list} | |
3825 | */ | |
3826 | ||
88f9aafc | 3827 | if (!_cups_strcasecmp(value, "default")) |
10d09e33 MS |
3828 | { |
3829 | cupsdAddString(&(pol->job_attrs), "job-name"); | |
3830 | cupsdAddString(&(pol->job_attrs), "job-originating-host-name"); | |
3831 | cupsdAddString(&(pol->job_attrs), "job-originating-user-name"); | |
82cc1f9a | 3832 | cupsdAddString(&(pol->job_attrs), "phone"); |
10d09e33 MS |
3833 | } |
3834 | else | |
3835 | cupsdAddString(&(pol->job_attrs), value); | |
3836 | } | |
88f9aafc | 3837 | else if (!_cups_strcasecmp(line, "SubscriptionPrivateAccess")) |
10d09e33 MS |
3838 | { |
3839 | /* | |
3840 | * SubscriptionPrivateAccess {all|default|user/group list|@@ACL} | |
3841 | */ | |
3842 | ||
88f9aafc | 3843 | if (!_cups_strcasecmp(value, "default")) |
10d09e33 MS |
3844 | { |
3845 | cupsdAddString(&(pol->sub_access), "@OWNER"); | |
3846 | cupsdAddString(&(pol->sub_access), "@SYSTEM"); | |
3847 | } | |
3848 | else | |
3849 | cupsdAddString(&(pol->sub_access), value); | |
3850 | } | |
88f9aafc | 3851 | else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */ |
10d09e33 MS |
3852 | { |
3853 | /* | |
3854 | * SubscriptionPrivateValues {all|none|default|attribute list} | |
3855 | */ | |
3856 | ||
88f9aafc | 3857 | if (!_cups_strcasecmp(value, "default")) |
10d09e33 MS |
3858 | { |
3859 | cupsdAddString(&(pol->sub_attrs), "notify-events"); | |
3860 | cupsdAddString(&(pol->sub_attrs), "notify-pull-method"); | |
3861 | cupsdAddString(&(pol->sub_attrs), "notify-recipient-uri"); | |
3862 | cupsdAddString(&(pol->sub_attrs), "notify-subscriber-user-name"); | |
3863 | cupsdAddString(&(pol->sub_attrs), "notify-user-data"); | |
3864 | } | |
3865 | else | |
3866 | cupsdAddString(&(pol->sub_attrs), value); | |
3867 | } | |
3868 | ||
3869 | /* | |
3870 | * Find the next string on the line... | |
3871 | */ | |
3872 | ||
3873 | for (value = valptr; isspace(*value & 255); value ++); | |
3874 | } | |
3875 | } | |
3876 | } | |
ef416fc2 | 3877 | else if (!op) |
3878 | { | |
3879 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
3880 | "Missing <Limit ops> directive before %s on line %d.", | |
3881 | line, linenum); | |
49d87452 MS |
3882 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3883 | return (0); | |
ef416fc2 | 3884 | } |
3885 | else if (!parse_aaa(op, line, value, linenum)) | |
3886 | { | |
321d8d57 MS |
3887 | cupsdLogMessage(CUPSD_LOG_ERROR, |
3888 | "Unknown Policy Limit directive %s on line %d.", | |
3889 | line, linenum); | |
ef416fc2 | 3890 | |
49d87452 MS |
3891 | if (FatalErrors & CUPSD_FATAL_CONFIG) |
3892 | return (0); | |
ef416fc2 | 3893 | } |
3894 | } | |
3895 | ||
3896 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
c8fef167 MS |
3897 | "Unexpected end-of-file at line %d while reading policy " |
3898 | "\"%s\".", linenum, policy); | |
ef416fc2 | 3899 | |
49d87452 | 3900 | return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum); |
ef416fc2 | 3901 | } |
3902 | ||
3903 | ||
3904 | /* | |
10d09e33 MS |
3905 | * 'set_policy_defaults()' - Set default policy values as needed. |
3906 | */ | |
3907 | ||
3908 | static void | |
3909 | set_policy_defaults(cupsd_policy_t *pol)/* I - Policy */ | |
3910 | { | |
3911 | cupsd_location_t *op; /* Policy operation */ | |
3912 | ||
3913 | ||
3914 | /* | |
3915 | * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs, | |
3916 | * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that | |
3917 | * upgrades do not introduce new security issues... | |
3918 | */ | |
3919 | ||
3920 | if ((op = cupsdFindPolicyOp(pol, IPP_VALIDATE_JOB)) == NULL || | |
3921 | op->op == IPP_ANY_OPERATION) | |
3922 | { | |
3923 | if ((op = cupsdFindPolicyOp(pol, IPP_PRINT_JOB)) != NULL && | |
3924 | op->op != IPP_ANY_OPERATION) | |
3925 | { | |
3926 | /* | |
3927 | * Add a new limit for Validate-Job using the Print-Job limit as a | |
3928 | * template... | |
3929 | */ | |
3930 | ||
3931 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3932 | "No limit for Validate-Job defined in policy %s " | |
3933 | "- using Print-Job's policy.", pol->name); | |
3934 | ||
3935 | cupsdAddPolicyOp(pol, op, IPP_VALIDATE_JOB); | |
3936 | } | |
3937 | else | |
3938 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3939 | "No limit for Validate-Job defined in policy %s " | |
3940 | "and no suitable template found.", pol->name); | |
3941 | } | |
3942 | ||
3943 | if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_JOBS)) == NULL || | |
3944 | op->op == IPP_ANY_OPERATION) | |
3945 | { | |
3946 | if ((op = cupsdFindPolicyOp(pol, IPP_PAUSE_PRINTER)) != NULL && | |
3947 | op->op != IPP_ANY_OPERATION) | |
3948 | { | |
3949 | /* | |
3950 | * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a | |
3951 | * template... | |
3952 | */ | |
3953 | ||
3954 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3955 | "No limit for Cancel-Jobs defined in policy %s " | |
3956 | "- using Pause-Printer's policy.", pol->name); | |
3957 | ||
3958 | cupsdAddPolicyOp(pol, op, IPP_CANCEL_JOBS); | |
3959 | } | |
3960 | else | |
3961 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3962 | "No limit for Cancel-Jobs defined in policy %s " | |
3963 | "and no suitable template found.", pol->name); | |
3964 | } | |
3965 | ||
3966 | if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_MY_JOBS)) == NULL || | |
3967 | op->op == IPP_ANY_OPERATION) | |
3968 | { | |
3969 | if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL && | |
3970 | op->op != IPP_ANY_OPERATION) | |
3971 | { | |
3972 | /* | |
3973 | * Add a new limit for Cancel-My-Jobs using the Send-Document limit as | |
3974 | * a template... | |
3975 | */ | |
3976 | ||
3977 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3978 | "No limit for Cancel-My-Jobs defined in policy %s " | |
3979 | "- using Send-Document's policy.", pol->name); | |
3980 | ||
3981 | cupsdAddPolicyOp(pol, op, IPP_CANCEL_MY_JOBS); | |
3982 | } | |
3983 | else | |
3984 | cupsdLogMessage(CUPSD_LOG_WARN, | |
3985 | "No limit for Cancel-My-Jobs defined in policy %s " | |
3986 | "and no suitable template found.", pol->name); | |
3987 | } | |
3988 | ||
3989 | if ((op = cupsdFindPolicyOp(pol, IPP_CLOSE_JOB)) == NULL || | |
3990 | op->op == IPP_ANY_OPERATION) | |
3991 | { | |
3992 | if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL && | |
3993 | op->op != IPP_ANY_OPERATION) | |
3994 | { | |
3995 | /* | |
3996 | * Add a new limit for Close-Job using the Send-Document limit as a | |
3997 | * template... | |
3998 | */ | |
3999 | ||
4000 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4001 | "No limit for Close-Job defined in policy %s " | |
4002 | "- using Send-Document's policy.", pol->name); | |
4003 | ||
4004 | cupsdAddPolicyOp(pol, op, IPP_CLOSE_JOB); | |
4005 | } | |
4006 | else | |
4007 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4008 | "No limit for Close-Job defined in policy %s " | |
4009 | "and no suitable template found.", pol->name); | |
4010 | } | |
4011 | ||
4012 | if ((op = cupsdFindPolicyOp(pol, CUPS_GET_DOCUMENT)) == NULL || | |
4013 | op->op == IPP_ANY_OPERATION) | |
4014 | { | |
4015 | if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL && | |
4016 | op->op != IPP_ANY_OPERATION) | |
4017 | { | |
4018 | /* | |
4019 | * Add a new limit for CUPS-Get-Document using the Send-Document | |
4020 | * limit as a template... | |
4021 | */ | |
4022 | ||
4023 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4024 | "No limit for CUPS-Get-Document defined in policy %s " | |
4025 | "- using Send-Document's policy.", pol->name); | |
4026 | ||
4027 | cupsdAddPolicyOp(pol, op, CUPS_GET_DOCUMENT); | |
4028 | } | |
4029 | else | |
4030 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4031 | "No limit for CUPS-Get-Document defined in policy %s " | |
4032 | "and no suitable template found.", pol->name); | |
4033 | } | |
4034 | ||
4035 | /* | |
4036 | * Verify we have JobPrivateAccess, JobPrivateValues, | |
4037 | * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy. | |
4038 | */ | |
4039 | ||
4040 | if (!pol->job_access) | |
4041 | { | |
4042 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4043 | "No JobPrivateAccess defined in policy %s " | |
4044 | "- using defaults.", pol->name); | |
4045 | cupsdAddString(&(pol->job_access), "@OWNER"); | |
4046 | cupsdAddString(&(pol->job_access), "@SYSTEM"); | |
4047 | } | |
4048 | ||
4049 | if (!pol->job_attrs) | |
4050 | { | |
4051 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4052 | "No JobPrivateValues defined in policy %s " | |
4053 | "- using defaults.", pol->name); | |
4054 | cupsdAddString(&(pol->job_attrs), "job-name"); | |
4055 | cupsdAddString(&(pol->job_attrs), "job-originating-host-name"); | |
4056 | cupsdAddString(&(pol->job_attrs), "job-originating-user-name"); | |
82cc1f9a | 4057 | cupsdAddString(&(pol->job_attrs), "phone"); |
10d09e33 MS |
4058 | } |
4059 | ||
4060 | if (!pol->sub_access) | |
4061 | { | |
4062 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4063 | "No SubscriptionPrivateAccess defined in policy %s " | |
4064 | "- using defaults.", pol->name); | |
4065 | cupsdAddString(&(pol->sub_access), "@OWNER"); | |
4066 | cupsdAddString(&(pol->sub_access), "@SYSTEM"); | |
4067 | } | |
4068 | ||
4069 | if (!pol->sub_attrs) | |
4070 | { | |
4071 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4072 | "No SubscriptionPrivateValues defined in policy %s " | |
4073 | "- using defaults.", pol->name); | |
4074 | cupsdAddString(&(pol->sub_attrs), "notify-events"); | |
4075 | cupsdAddString(&(pol->sub_attrs), "notify-pull-method"); | |
4076 | cupsdAddString(&(pol->sub_attrs), "notify-recipient-uri"); | |
4077 | cupsdAddString(&(pol->sub_attrs), "notify-subscriber-user-name"); | |
4078 | cupsdAddString(&(pol->sub_attrs), "notify-user-data"); | |
4079 | } | |
4080 | } | |
4081 | ||
4082 | ||
4083 | /* | |
f2d18633 | 4084 | * End of "$Id$". |
ef416fc2 | 4085 | */ |