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