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