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