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