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