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