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