2 * Configuration routines for the CUPS scheduler.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
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/".
15 * Include necessary headers...
21 #include <sys/utsname.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 */
32 #endif /* HAVE_LIBPAPER */
36 * Possibly missing network definitions...
40 # define INADDR_NONE 0xffffffff
41 #endif /* !INADDR_NONE */
45 * Configuration variable structure...
50 CUPSD_VARTYPE_INTEGER
, /* Integer option */
51 CUPSD_VARTYPE_TIME
, /* Time interval option */
52 CUPSD_VARTYPE_STRING
, /* String option */
53 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
54 CUPSD_VARTYPE_PATHNAME
, /* File/directory name option */
55 CUPSD_VARTYPE_PERM
/* File/directory permissions */
60 const char *name
; /* Name of variable */
61 void *ptr
; /* Pointer to variable */
62 cupsd_vartype_t type
; /* Type (int, string, address) */
70 static const cupsd_var_t cupsd_vars
[] =
72 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
73 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
74 { "BrowseDNSSDSubTypes", &DNSSDSubTypes
, CUPSD_VARTYPE_STRING
},
75 #endif /* HAVE_DNSSD || HAVE_AVAHI */
76 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
77 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
78 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
79 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
80 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
81 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_TIME
},
82 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
83 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
84 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
85 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_TIME
},
86 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
87 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
88 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
90 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
91 #endif /* HAVE_GSSAPI */
93 { "IdleExitTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
94 #endif /* HAVE_ONDEMAND */
95 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_TIME
},
96 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
97 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_TIME
},
98 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_TIME
},
99 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
101 { "LaunchdTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
102 #endif /* HAVE_LAUNCHD */
103 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
104 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
105 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
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
},
111 { "MaxHoldTime", &MaxHoldTime
, CUPSD_VARTYPE_TIME
},
112 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
113 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
114 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
115 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_TIME
},
116 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_TIME
},
117 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
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
},
123 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_TIME
},
124 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
125 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_TIME
},
126 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_TIME
},
127 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_TIME
},
128 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
129 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_TIME
},
130 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
131 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
132 { "StrictConformance", &StrictConformance
, CUPSD_VARTYPE_BOOLEAN
},
133 { "Timeout", &Timeout
, CUPSD_VARTYPE_TIME
},
134 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
136 static const cupsd_var_t cupsfiles_vars
[] =
138 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
139 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
140 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_PERM
},
141 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
142 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
143 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
144 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
145 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
146 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_PERM
},
147 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
148 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
149 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
150 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
151 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
152 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
154 { "ServerKeychain", &ServerKeychain
, CUPSD_VARTYPE_PATHNAME
},
155 #endif /* HAVE_SSL */
156 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
157 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
158 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
159 { "SyncOnClose", &SyncOnClose
, CUPSD_VARTYPE_BOOLEAN
},
160 #ifdef HAVE_AUTHORIZATION_H
161 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
162 #endif /* HAVE_AUTHORIZATION_H */
163 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
}
166 static int default_auth_type
= CUPSD_AUTH_AUTO
;
167 /* Default AuthType, if not specified */
169 static const unsigned ones
[4] =
171 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
173 static const unsigned zeros
[4] =
175 0x00000000, 0x00000000, 0x00000000, 0x00000000
183 static http_addrlist_t
*get_address(const char *value
, int defport
);
184 static int get_addr_and_mask(const char *value
, unsigned *ip
,
186 static void mime_error_cb(void *ctx
, const char *message
);
187 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
188 char *value
, int linenum
);
189 static int parse_fatal_errors(const char *s
);
190 static int parse_groups(const char *s
);
191 static int parse_protocols(const char *s
);
192 static int parse_variable(const char *filename
, int linenum
,
193 const char *line
, const char *value
,
195 const cupsd_var_t
*vars
);
196 static int read_cupsd_conf(cups_file_t
*fp
);
197 static int read_cups_files_conf(cups_file_t
*fp
);
198 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
199 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
200 static void set_policy_defaults(cupsd_policy_t
*pol
);
204 * 'cupsdAddAlias()' - Add a host alias.
208 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
209 const char *name
) /* I - Name to add */
211 cupsd_alias_t
*a
; /* New alias */
212 size_t namelen
; /* Length of name */
215 namelen
= strlen(name
);
217 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
220 a
->namelen
= namelen
;
221 memcpy(a
->name
, name
, namelen
+ 1); /* OK since a->name is allocated */
223 cupsArrayAdd(aliases
, a
);
228 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
231 int /* O - 0 on success, -1 on error, 1 on warning */
232 cupsdCheckPermissions(
233 const char *filename
, /* I - File/directory name */
234 const char *suffix
, /* I - Additional file/directory name */
235 mode_t mode
, /* I - Permissions */
236 uid_t user
, /* I - Owner */
237 gid_t group
, /* I - Group */
238 int is_dir
, /* I - 1 = directory, 0 = file */
239 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
241 int dir_created
= 0; /* Did we create a directory? */
242 char pathname
[1024]; /* File name with prefix */
243 struct stat fileinfo
; /* Stat buffer */
244 int is_symlink
; /* Is "filename" a symlink? */
248 * Prepend the given root to the filename before testing it...
253 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
258 * See if we can stat the file/directory...
261 if (lstat(filename
, &fileinfo
))
263 if (errno
== ENOENT
&& create_dir
)
266 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
269 if (mkdir(filename
, mode
))
272 cupsdLogMessage(CUPSD_LOG_ERROR
,
273 "Unable to create directory \"%s\" - %s", filename
,
278 asl_object_t m
; /* Log message */
280 m
= asl_new(ASL_TYPE_MSG
);
281 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
282 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
285 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
286 sd_journal_print(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
288 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
289 #endif /* HAVE_ASL_H */
295 fileinfo
.st_mode
= mode
| S_IFDIR
;
298 return (create_dir
? -1 : 1);
301 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
303 if (stat(filename
, &fileinfo
))
305 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
306 filename
, strerror(errno
));
312 * Make sure it's a regular file or a directory as needed...
315 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
317 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
321 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
324 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
328 asl_object_t m
; /* Log message */
330 m
= asl_new(ASL_TYPE_MSG
);
331 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
332 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "\"%s\" is not a directory.", filename
);
335 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
336 sd_journal_print(LOG_ERR
, "\"%s\" is not a directory.", filename
);
338 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
339 #endif /* HAVE_ASL_H */
345 * If the filename is a symlink, do not change permissions (STR #2937)...
352 * Fix owner, group, and mode as needed...
355 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
358 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
361 if (chown(filename
, user
, group
) && !getuid())
364 cupsdLogMessage(CUPSD_LOG_ERROR
,
365 "Unable to change ownership of \"%s\" - %s", filename
,
370 asl_object_t m
; /* Log message */
372 m
= asl_new(ASL_TYPE_MSG
);
373 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
374 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
377 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
378 sd_journal_print(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
380 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
381 #endif /* HAVE_ASL_H */
387 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
390 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
393 if (chmod(filename
, mode
))
396 cupsdLogMessage(CUPSD_LOG_ERROR
,
397 "Unable to change permissions of \"%s\" - %s", filename
,
402 asl_object_t m
; /* Log message */
404 m
= asl_new(ASL_TYPE_MSG
);
405 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
406 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
409 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
410 sd_journal_print(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
412 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
413 #endif /* HAVE_ASL_H */
420 * Everything is OK...
428 * 'cupsdDefaultAuthType()' - Get the default AuthType.
430 * When the default_auth_type is "auto", this function tries to get the GSS
431 * credentials for the server. If that succeeds we use Kerberos authentication,
432 * otherwise we do a fallback to Basic authentication against the local user
436 int /* O - Default AuthType value */
437 cupsdDefaultAuthType(void)
440 OM_uint32 major_status
, /* Major status code */
441 minor_status
; /* Minor status code */
442 gss_name_t server_name
; /* Server name */
443 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
444 /* Service name token */
445 char buf
[1024]; /* Service name buffer */
446 #endif /* HAVE_GSSAPI */
450 * If we have already determined the correct default AuthType, use it...
453 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
454 return (default_auth_type
);
459 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
463 if (&gss_init_sec_context
== NULL
)
464 return (default_auth_type
= CUPSD_AUTH_BASIC
);
465 # endif /* __APPLE__ */
468 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
469 * that fails we must use Basic...
472 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
475 token
.length
= strlen(buf
);
476 server_name
= GSS_C_NO_NAME
;
477 major_status
= gss_import_name(&minor_status
, &token
,
478 GSS_C_NT_HOSTBASED_SERVICE
,
481 memset(&token
, 0, sizeof(token
));
483 if (GSS_ERROR(major_status
))
485 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
486 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
487 return (default_auth_type
= CUPSD_AUTH_BASIC
);
490 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
492 if (GSS_ERROR(major_status
))
494 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
495 "cupsdDefaultAuthType: gss_display_name(%s) failed",
497 return (default_auth_type
= CUPSD_AUTH_BASIC
);
500 cupsdLogMessage(CUPSD_LOG_DEBUG
,
501 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
502 "credentials for %s...", (char *)token
.value
);
504 ServerCreds
= GSS_C_NO_CREDENTIAL
;
505 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
506 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
507 &ServerCreds
, NULL
, NULL
);
508 if (GSS_ERROR(major_status
))
510 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
511 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
512 (char *)token
.value
);
513 gss_release_name(&minor_status
, &server_name
);
514 gss_release_buffer(&minor_status
, &token
);
515 return (default_auth_type
= CUPSD_AUTH_BASIC
);
518 cupsdLogMessage(CUPSD_LOG_DEBUG
,
519 "cupsdDefaultAuthType: Kerberos credentials acquired "
520 "successfully for %s.", (char *)token
.value
);
522 gss_release_name(&minor_status
, &server_name
);
523 gss_release_buffer(&minor_status
, &token
);
527 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
531 * No Kerberos support compiled in so just use Basic all the time...
534 return (default_auth_type
= CUPSD_AUTH_BASIC
);
535 #endif /* HAVE_GSSAPI */
540 * 'cupsdFreeAliases()' - Free all of the alias entries.
544 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
546 cupsd_alias_t
*a
; /* Current alias */
549 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
551 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
554 cupsArrayDelete(aliases
);
559 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
562 int /* O - 1 on success, 0 otherwise */
563 cupsdReadConfiguration(void)
565 int i
; /* Looping var */
566 cups_file_t
*fp
; /* Configuration file */
567 int status
; /* Return status */
568 char temp
[1024], /* Temporary buffer */
569 mimedir
[1024], /* MIME directory */
570 *slash
; /* Directory separator */
571 cups_lang_t
*language
; /* Language */
572 struct passwd
*user
; /* Default user */
573 struct group
*group
; /* Default group */
574 char *old_serverroot
, /* Old ServerRoot */
575 *old_requestroot
; /* Old RequestRoot */
576 int old_remote_port
; /* Old RemotePort */
577 const char *tmpdir
; /* TMPDIR environment variable */
578 struct stat tmpinfo
; /* Temporary directory info */
579 cupsd_policy_t
*p
; /* Policy */
583 * Save the old root paths...
586 old_serverroot
= NULL
;
587 cupsdSetString(&old_serverroot
, ServerRoot
);
588 old_requestroot
= NULL
;
589 cupsdSetString(&old_requestroot
, RequestRoot
);
592 * Reset the server configuration data...
595 cupsdDeleteAllLocations();
597 cupsdDeleteAllListeners();
599 old_remote_port
= RemotePort
;
606 cupsdFreeAliases(ServerAlias
);
609 cupsdClearString(&ServerName
);
610 cupsdClearString(&ServerAdmin
);
611 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
612 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
613 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
614 cupsdSetString(&DataDir
, CUPS_DATADIR
);
615 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
616 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
617 cupsdClearString(&ErrorLog
);
618 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
619 cupsdSetString(&PageLogFormat
,
620 "%p %u %j %T %P %C %{job-billing} "
621 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
622 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
623 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
624 cupsdSetString(&RemoteRoot
, "remroot");
625 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
627 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
629 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
630 PrintcapFormat
= PRINTCAP_SOLARIS
;
631 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
632 "/Library/Preferences/org.cups.printers.plist"))
633 PrintcapFormat
= PRINTCAP_PLIST
;
635 PrintcapFormat
= PRINTCAP_BSD
;
637 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
638 if ((slash
= strrchr(temp
, '/')) != NULL
)
641 cupsdSetString(&ServerRoot
, temp
);
643 cupsdClearString(&Classification
);
644 ClassifyOverride
= 0;
648 cupsdSetString(&ServerKeychain
, "ssl");
650 cupsdSetString(&ServerKeychain
, "/Library/Keychains/System.keychain");
651 # endif /* HAVE_GNUTLS */
653 _httpTLSSetOptions(0);
654 #endif /* HAVE_SSL */
656 language
= cupsLangDefault();
658 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
659 cupsdSetString(&DefaultLanguage
, "en");
661 cupsdSetString(&DefaultLanguage
, language
->language
);
663 cupsdClearString(&DefaultPaperSize
);
665 cupsdSetString(&RIPCache
, "128m");
667 cupsdSetString(&TempDir
, NULL
);
670 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
674 OM_uint32 minor_status
; /* Minor status code */
676 gss_release_cred(&minor_status
, &ServerCreds
);
681 ServerCreds
= GSS_C_NO_CREDENTIAL
;
682 #endif /* HAVE_GSSAPI */
685 * Find the default user...
688 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
693 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
694 * complement number...)
703 * Find the default group...
706 group
= getgrnam(CUPS_DEFAULT_GROUP
);
710 Group
= group
->gr_gid
;
714 * Fallback to group "nobody"...
717 group
= getgrnam("nobody");
721 Group
= group
->gr_gid
;
725 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
726 * complement number...)
737 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
738 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
739 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
740 default_auth_type
= CUPSD_AUTH_BASIC
;
742 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
743 #endif /* HAVE_SSL */
744 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
745 JobKillDelay
= DEFAULT_TIMEOUT
;
747 JobRetryInterval
= 300;
752 HostNameLookups
= FALSE
;
754 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
755 ListenBackLog
= SOMAXCONN
;
756 LogDebugHistory
= 200;
757 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
758 LogLevel
= CUPSD_LOG_WARN
;
759 LogTimeFormat
= CUPSD_TIME_STANDARD
;
761 MaxClientsPerHost
= 0;
762 MaxLogSize
= 1024 * 1024;
764 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
766 ReloadTimeout
= DEFAULT_KEEPALIVE
;
767 RootCertDuration
= 300;
768 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
769 StrictConformance
= FALSE
;
771 Timeout
= DEFAULT_TIMEOUT
;
772 WebInterface
= CUPS_DEFAULT_WEBIF
;
774 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
776 Browsing
= CUPS_DEFAULT_BROWSING
;
777 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
779 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
780 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
781 #endif /* HAVE_DNSSD || HAVE_AVAHI */
783 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
784 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
786 cupsdSetString(&ErrorPolicy
, "stop-printer");
788 JobHistory
= DEFAULT_HISTORY
;
789 JobFiles
= DEFAULT_FILES
;
795 MaxJobsPerPrinter
= 0;
796 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
797 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
799 cupsdDeleteAllPolicies();
800 cupsdClearString(&DefaultPolicy
);
802 #ifdef HAVE_AUTHORIZATION_H
803 cupsdSetString(&SystemGroupAuthKey
, CUPS_DEFAULT_SYSTEM_AUTHKEY
);
804 #endif /* HAVE_AUTHORIZATION_H */
806 MaxSubscriptions
= 100;
807 MaxSubscriptionsPerJob
= 0;
808 MaxSubscriptionsPerPrinter
= 0;
809 MaxSubscriptionsPerUser
= 0;
810 DefaultLeaseDuration
= 86400;
811 MaxLeaseDuration
= 0;
814 IdleExitTimeout
= 60;
815 #endif /* HAVE_ONDEMAND */
818 * Setup environment variables...
824 * Read the cups-files.conf file...
827 if ((fp
= cupsFileOpen(CupsFilesFile
, "r")) != NULL
)
829 status
= read_cups_files_conf(fp
);
836 printf("\"%s\" contains errors.\n", CupsFilesFile
);
840 asl_object_t m
; /* Log message */
842 m
= asl_new(ASL_TYPE_MSG
);
843 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
844 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
847 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
848 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
850 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
851 #endif /* HAVE_ASL_H */
856 else if (errno
== ENOENT
)
857 cupsdLogMessage(CUPSD_LOG_INFO
, "No %s, using defaults.", CupsFilesFile
);
861 asl_object_t m
; /* Log message */
863 m
= asl_new(ASL_TYPE_MSG
);
864 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
865 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
868 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
869 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
871 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
872 #endif /* HAVE_ASL_H */
878 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
881 * Read the cupsd.conf file...
884 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
887 asl_object_t m
; /* Log message */
889 m
= asl_new(ASL_TYPE_MSG
);
890 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
891 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
893 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
894 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
896 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
897 #endif /* HAVE_ASL_H */
902 status
= read_cupsd_conf(fp
);
909 printf("\"%s\" contains errors.\n", ConfigurationFile
);
913 asl_object_t m
; /* Log message */
915 m
= asl_new(ASL_TYPE_MSG
);
916 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
917 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
920 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
921 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
923 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
924 #endif /* HAVE_ASL_H */
931 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
932 RemotePort
? "enabled" : "disabled");
935 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
938 * See if the ServerName is an IP address...
944 ServerAlias
= cupsArrayNew(NULL
, NULL
);
946 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
950 if (gethostname(temp
, sizeof(temp
)))
952 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
954 strlcpy(temp
, "localhost", sizeof(temp
));
957 cupsdSetString(&ServerName
, temp
);
960 ServerAlias
= cupsArrayNew(NULL
, NULL
);
962 cupsdAddAlias(ServerAlias
, temp
);
963 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
965 if (HostNameLookups
|| RemotePort
)
967 struct hostent
*host
; /* Host entry to get FQDN */
969 if ((host
= gethostbyname(temp
)) != NULL
)
971 if (_cups_strcasecmp(temp
, host
->h_name
))
973 cupsdSetString(&ServerName
, host
->h_name
);
974 cupsdAddAlias(ServerAlias
, host
->h_name
);
975 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
981 for (i
= 0; host
->h_aliases
[i
]; i
++)
982 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
984 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
985 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
993 * Make sure we have the base hostname added as an alias, too!
996 if ((slash
= strchr(temp
, '.')) != NULL
)
999 cupsdAddAlias(ServerAlias
, temp
);
1000 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
1004 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
1006 ServerNameIsIP
= !*slash
;
1009 * Make sure ServerAdmin is initialized...
1013 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
1016 * Use the default system group if none was supplied in cupsd.conf...
1019 if (NumSystemGroups
== 0)
1021 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
1024 * Find the group associated with GID 0...
1027 group
= getgrgid(0);
1031 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
1033 cupsdSetString(&SystemGroups
[0], "unknown");
1035 SystemGroupIDs
[0] = 0;
1036 NumSystemGroups
= 1;
1041 * Make sure ConfigFilePerm and LogFilePerm have sane values...
1044 ConfigFilePerm
&= 0664;
1045 LogFilePerm
&= 0664;
1048 * Open the system log for cupsd if necessary...
1053 if (!strcmp(AccessLog
, "stderr"))
1054 cupsdSetString(&AccessLog
, "syslog");
1056 if (!strcmp(ErrorLog
, "stderr"))
1057 cupsdSetString(&ErrorLog
, "syslog");
1059 if (!strcmp(PageLog
, "stderr"))
1060 cupsdSetString(&PageLog
, "syslog");
1063 #if defined(HAVE_VSYSLOG) && !defined(HAVE_ASL_H) && !defined(HAVE_SYSTEMD_SD_JOURNAL_H)
1064 if (!strcmp(AccessLog
, "syslog") ||
1065 !strcmp(ErrorLog
, "syslog") ||
1066 !strcmp(PageLog
, "syslog"))
1067 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
1068 #endif /* HAVE_VSYSLOG && !HAVE_ASL_H && !HAVE_SYSTEMD_SD_JOURNAL_H */
1071 * Make sure each of the log files exists and gets rotated as necessary...
1074 if (strcmp(AccessLog
, "syslog"))
1075 cupsdCheckLogFile(&AccessFile
, AccessLog
);
1077 if (strcmp(ErrorLog
, "syslog"))
1078 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
1080 if (strcmp(PageLog
, "syslog"))
1081 cupsdCheckLogFile(&PageFile
, PageLog
);
1084 * Log the configuration file that was used...
1087 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
1091 * Validate the Group and SystemGroup settings - they cannot be the same,
1092 * otherwise the CGI programs will be able to authenticate as root without
1098 for (i
= 0; i
< NumSystemGroups
; i
++)
1099 if (Group
== SystemGroupIDs
[i
])
1102 if (i
< NumSystemGroups
)
1105 * Log the error and reset the group to a safe value...
1108 cupsdLogMessage(CUPSD_LOG_ERROR
,
1109 "Group and SystemGroup cannot use the same groups.");
1110 if (FatalErrors
& (CUPSD_FATAL_CONFIG
| CUPSD_FATAL_PERMISSIONS
))
1113 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
1115 group
= getgrnam("nobody");
1119 Group
= group
->gr_gid
;
1123 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
1124 * complement number...)
1133 * Check that we have at least one listen/port line; if not, report this
1134 * as an error and exit!
1137 if (cupsArrayCount(Listeners
) == 0)
1143 cupsdLogMessage(CUPSD_LOG_EMERG
,
1144 "No valid Listen or Port lines were found in the "
1145 "configuration file.");
1151 cupsdEndProcess(getpid(), 0);
1155 * Set the default locale using the language and charset...
1158 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1161 * Update all relative filenames to include the full path from ServerRoot...
1164 if (DocumentRoot
[0] != '/')
1165 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1167 if (RequestRoot
[0] != '/')
1168 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1170 if (ServerBin
[0] != '/')
1171 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1173 if (StateDir
[0] != '/')
1174 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1176 if (CacheDir
[0] != '/')
1177 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1180 if (ServerKeychain
[0] != '/')
1181 cupsdSetStringf(&ServerKeychain
, "%s/%s", ServerRoot
, ServerKeychain
);
1183 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Using keychain \"%s\" for server name \"%s\".", ServerKeychain
, ServerName
);
1184 cupsSetServerCredentials(ServerKeychain
, ServerName
, 1);
1185 #endif /* HAVE_SSL */
1188 * Make sure that directories and config files are owned and
1189 * writable by the user and group in the cupsd.conf file...
1192 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1194 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1196 cupsdCheckPermissions(CacheDir
, NULL
, 0770, RunUser
,
1198 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1200 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1202 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1203 SystemGroupIDs
[0], 1, 1) < 0 ||
1204 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1206 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1208 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1210 cupsdCheckPermissions(ConfigurationFile
, NULL
, ConfigFilePerm
, RunUser
,
1212 cupsdCheckPermissions(CupsFilesFile
, NULL
, ConfigFilePerm
, RunUser
,
1214 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1216 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1218 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1219 Group
, 0, 0) < 0) &&
1220 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1224 * Update TempDir to the default if it hasn't been set already...
1228 if (TempDir
&& !RunUser
&&
1229 (!strncmp(TempDir
, "/private/tmp", 12) || !strncmp(TempDir
, "/tmp", 4)))
1231 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot use %s for TempDir.", TempDir
);
1232 cupsdClearString(&TempDir
);
1234 #endif /* __APPLE__ */
1239 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1240 strncmp(tmpdir
, "/private/tmp", 12) && strncmp(tmpdir
, "/tmp", 4))
1242 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1243 #endif /* __APPLE__ */
1246 * TMPDIR is defined, see if it is OK for us to use...
1249 if (stat(tmpdir
, &tmpinfo
))
1250 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1251 tmpdir
, strerror(errno
));
1252 else if (!S_ISDIR(tmpinfo
.st_mode
))
1253 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1255 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1256 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1257 !(tmpinfo
.st_mode
& S_IWOTH
))
1258 cupsdLogMessage(CUPSD_LOG_ERROR
,
1259 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1261 cupsdSetString(&TempDir
, tmpdir
);
1267 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1269 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1272 setenv("TMPDIR", TempDir
, 1);
1275 * Make sure the temporary directory has the right permissions...
1278 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1282 * Update ownership and permissions if the CUPS temp directory
1283 * is under the spool directory or does not exist...
1286 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1287 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1292 * Update environment variables...
1298 * Validate the default error policy...
1301 if (strcmp(ErrorPolicy
, "retry-current-job") &&
1302 strcmp(ErrorPolicy
, "abort-job") &&
1303 strcmp(ErrorPolicy
, "retry-job") &&
1304 strcmp(ErrorPolicy
, "stop-printer"))
1306 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\", resetting to \"stop-printer\".", ErrorPolicy
);
1307 cupsdSetString(&ErrorPolicy
, "stop-printer");
1311 * Update default paper size setting as needed...
1314 if (!DefaultPaperSize
)
1316 #ifdef HAVE_LIBPAPER
1317 char *paper_result
; /* Paper size name from libpaper */
1319 if ((paper_result
= systempapername()) != NULL
)
1320 cupsdSetString(&DefaultPaperSize
, paper_result
);
1322 #endif /* HAVE_LIBPAPER */
1323 if (!DefaultLanguage
||
1324 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1325 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1326 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1327 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1328 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1329 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1330 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1333 * These are the only locales that will default to "letter" size...
1336 cupsdSetString(&DefaultPaperSize
, "Letter");
1339 cupsdSetString(&DefaultPaperSize
, "A4");
1343 * Update classification setting as needed...
1346 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1347 cupsdClearString(&Classification
);
1350 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1353 * Check the MaxClients setting, and then allocate memory for it...
1356 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1359 cupsdLogMessage(CUPSD_LOG_INFO
,
1360 "MaxClients limited to 1/3 (%d) of the file descriptor "
1362 MaxFDs
/ 3, MaxFDs
);
1364 MaxClients
= MaxFDs
/ 3;
1367 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1371 * Check the MaxActiveJobs setting; limit to 1/3 the available
1372 * file descriptors, since we need a pipe for each job...
1375 if (MaxActiveJobs
> (MaxFDs
/ 3))
1376 MaxActiveJobs
= MaxFDs
/ 3;
1379 * Update the MaxClientsPerHost value, as needed...
1382 if (MaxClientsPerHost
<= 0)
1383 MaxClientsPerHost
= MaxClients
;
1385 if (MaxClientsPerHost
> MaxClients
)
1386 MaxClientsPerHost
= MaxClients
;
1388 cupsdLogMessage(CUPSD_LOG_INFO
,
1389 "Allowing up to %d client connections per host.",
1393 * Update the default policy, as needed...
1397 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1399 DefaultPolicyPtr
= NULL
;
1401 if (!DefaultPolicyPtr
)
1403 cupsd_location_t
*po
; /* New policy operation */
1407 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1410 cupsdSetString(&DefaultPolicy
, "default");
1412 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1413 cupsdLogMessage(CUPSD_LOG_INFO
,
1414 "Using policy \"default\" as the default.");
1417 cupsdLogMessage(CUPSD_LOG_INFO
,
1418 "Creating CUPS default administrative policy:");
1420 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1422 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1424 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1425 cupsdAddString(&(p
->job_access
), "@OWNER");
1426 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1428 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1429 cupsdAddString(&(p
->job_attrs
), "job-name");
1430 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1431 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1432 cupsdAddString(&(p
->job_attrs
), "phone");
1434 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1435 cupsdAddString(&(p
->sub_access
), "@OWNER");
1436 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1438 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1439 cupsdAddString(&(p
->job_attrs
), "notify-events");
1440 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1441 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1442 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1443 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1445 cupsdLogMessage(CUPSD_LOG_INFO
,
1446 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1447 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1449 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1450 po
->order_type
= CUPSD_AUTH_ALLOW
;
1452 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1453 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1454 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1456 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1458 cupsdLogMessage(CUPSD_LOG_INFO
,
1459 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1460 "Release-Job Restart-Job Purge-Jobs "
1461 "Set-Job-Attributes Create-Job-Subscription "
1462 "Renew-Subscription Cancel-Subscription "
1463 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1464 "Suspend-Current-Job Resume-Job "
1465 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1466 "CUPS-Authenticate-Job CUPS-Get-Document>");
1467 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1469 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1470 po
->order_type
= CUPSD_AUTH_ALLOW
;
1471 po
->level
= CUPSD_AUTH_USER
;
1473 cupsdAddName(po
, "@OWNER");
1474 cupsdAddName(po
, "@SYSTEM");
1475 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1477 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1478 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1479 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1480 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1481 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1482 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1483 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1484 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1485 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1486 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1487 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1488 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1489 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1490 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1491 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1492 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1493 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1494 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1495 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1496 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1498 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1500 cupsdLogMessage(CUPSD_LOG_INFO
,
1501 "<Limit Pause-Printer Resume-Printer "
1502 "Set-Printer-Attributes Enable-Printer "
1503 "Disable-Printer Pause-Printer-After-Current-Job "
1504 "Hold-New-Jobs Release-Held-New-Jobs "
1505 "Deactivate-Printer Activate-Printer Restart-Printer "
1506 "Shutdown-Printer Startup-Printer Promote-Job "
1507 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1508 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1509 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1510 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1511 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1513 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1514 po
->order_type
= CUPSD_AUTH_ALLOW
;
1515 po
->type
= CUPSD_AUTH_DEFAULT
;
1516 po
->level
= CUPSD_AUTH_USER
;
1518 cupsdAddName(po
, "@SYSTEM");
1519 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1521 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1522 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1523 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1524 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1525 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1526 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1527 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1528 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1529 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1530 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1531 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1532 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1533 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1534 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1535 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1536 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1537 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1538 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1539 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1540 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1541 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1542 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1544 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1546 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1547 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1549 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1550 po
->order_type
= CUPSD_AUTH_ALLOW
;
1552 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1553 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1557 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1558 cupsArrayCount(Policies
));
1559 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1561 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1562 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1563 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1566 * If we are doing a full reload or the server root has changed, flush
1567 * the jobs, printers, etc. and start from scratch...
1570 if (NeedReload
== RELOAD_ALL
||
1571 old_remote_port
!= RemotePort
||
1572 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1573 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1575 mime_type_t
*type
; /* Current type */
1576 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1577 /* MIME type name */
1580 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1583 * Free all memory...
1586 cupsdDeleteAllSubscriptions();
1588 cupsdDeleteAllPrinters();
1590 DefaultPrinter
= NULL
;
1592 if (MimeDatabase
!= NULL
)
1593 mimeDelete(MimeDatabase
);
1597 for (i
= 0; i
< NumMimeTypes
; i
++)
1598 _cupsStrFree(MimeTypes
[i
]);
1604 * Read the MIME type and conversion database...
1607 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1608 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1610 MimeDatabase
= mimeNew();
1611 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1613 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1614 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1615 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1616 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1620 cupsdLogMessage(CUPSD_LOG_EMERG
,
1621 "Unable to load MIME database from \"%s\" or \"%s\".",
1622 mimedir
, ServerRoot
);
1623 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1627 cupsdLogMessage(CUPSD_LOG_INFO
,
1628 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1629 "%d filters...", mimedir
, ServerRoot
,
1630 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1633 * Create a list of MIME types for the document-format-supported
1637 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1638 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1641 if ((MimeTypes
= calloc((size_t)NumMimeTypes
, sizeof(const char *))) == NULL
)
1643 cupsdLogMessage(CUPSD_LOG_ERROR
,
1644 "Unable to allocate memory for %d MIME types.",
1650 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1652 i
++, type
= mimeNextType(MimeDatabase
))
1654 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1656 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1659 if (i
< NumMimeTypes
)
1660 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1663 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1665 mime_filter_t
*filter
; /* Current filter */
1668 for (type
= mimeFirstType(MimeDatabase
);
1670 type
= mimeNextType(MimeDatabase
))
1671 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1672 type
->super
, type
->type
);
1674 for (filter
= mimeFirstFilter(MimeDatabase
);
1676 filter
= mimeNextFilter(MimeDatabase
))
1677 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1678 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1679 filter
->src
->super
, filter
->src
->type
,
1680 filter
->dst
->super
, filter
->dst
->type
,
1681 filter
->cost
, filter
->filter
);
1688 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1689 cupsdLoadBanners(temp
);
1692 * Load printers and classes...
1695 cupsdLoadAllPrinters();
1696 cupsdLoadAllClasses();
1698 cupsdCreateCommonData();
1701 * Update the printcap file as needed...
1704 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1705 cupsdWritePrintcap();
1708 * Load queued jobs...
1714 * Load subscriptions...
1717 cupsdLoadAllSubscriptions();
1719 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1724 * Not a full reload, so recreate the common printer attributes...
1727 cupsdCreateCommonData();
1730 * Update all jobs as needed...
1736 * Update all printers as needed...
1739 cupsdUpdatePrinters();
1740 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1742 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1746 * Reset the reload state...
1749 NeedReload
= RELOAD_NONE
;
1751 cupsdClearString(&old_serverroot
);
1752 cupsdClearString(&old_requestroot
);
1759 * 'get_address()' - Get an address + port number from a line.
1762 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1763 get_address(const char *value
, /* I - Value string */
1764 int defport
) /* I - Default port */
1766 char buffer
[1024], /* Hostname + port number buffer */
1767 defpname
[255], /* Default port name */
1768 *hostname
, /* Hostname or IP */
1769 *portname
; /* Port number or name */
1770 http_addrlist_t
*addrlist
; /* Address list */
1774 * Check for an empty value...
1779 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1784 * Grab a hostname and port number; if there is no colon and the port name
1785 * is only digits, then we have a port number by itself...
1788 strlcpy(buffer
, value
, sizeof(buffer
));
1790 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1797 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1802 * Use the default port...
1805 sprintf(defpname
, "%d", defport
);
1806 portname
= defpname
;
1812 * The buffer contains just a port number...
1820 if (hostname
&& !strcmp(hostname
, "*"))
1824 * Now lookup the address using httpAddrGetList()...
1827 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1828 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1829 hostname
? hostname
: "(nil)");
1836 * 'get_addr_and_mask()' - Get an IP address and netmask.
1839 static int /* O - 1 on success, 0 on failure */
1840 get_addr_and_mask(const char *value
, /* I - String from config file */
1841 unsigned *ip
, /* O - Address value */
1842 unsigned *mask
) /* O - Mask value */
1844 int i
, j
, /* Looping vars */
1845 family
, /* Address family */
1846 ipcount
; /* Count of fields in address */
1847 unsigned ipval
; /* Value */
1848 const char *maskval
, /* Pointer to start of mask value */
1849 *ptr
, /* Pointer into value */
1854 * Get the address...
1857 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1858 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1860 if ((maskval
= strchr(value
, '/')) != NULL
)
1863 maskval
= value
+ strlen(value
);
1867 * Check for an IPv6 address...
1873 * Parse hexadecimal IPv6/IPv4 address...
1878 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1882 else if (!strncmp(ptr
, "::", 2))
1884 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1886 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1891 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1894 * Read IPv4 dotted quad...
1897 unsigned val
[4] = { 0, 0, 0, 0 };
1898 /* IPv4 address values */
1900 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1904 * Range check the IP numbers...
1907 for (i
= 0; i
< ipcount
; i
++)
1912 * Merge everything into a 32-bit IPv4 address in ip[3]...
1915 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1916 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1919 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1922 * If the leading words are all 0's then this is an IPv4 address...
1925 if (!val
[0] && !val
[1] && !val
[2])
1928 while (isdigit(*ptr
& 255) || *ptr
== '.')
1932 else if (isxdigit(*ptr
& 255))
1934 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1936 if (*ptr
== ':' && ptr
[1] != ':')
1945 ip
[i
/ 2] |= ipval
<< 16;
1956 if (*ptr
&& *ptr
!= '/')
1960 #endif /* AF_INET6 */
1963 * Parse dotted-decimal IPv4 address...
1966 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1970 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1973 * Range check the IP numbers...
1976 for (i
= 0; i
< ipcount
; i
++)
1981 * Merge everything into a 32-bit IPv4 address in ip[3]...
1984 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1985 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1988 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1994 * Get the netmask value(s)...
1997 memset(mask
, 0, sizeof(unsigned) * 4);
1999 if (strchr(maskval
, '.'))
2002 * Get dotted-decimal mask...
2005 if (family
!= AF_INET
)
2008 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
2012 mask
[3] |= (((((unsigned)mask
[0] << 8) | (unsigned)mask
[1]) << 8) |
2013 (unsigned)mask
[2]) << 8;
2014 mask
[0] = mask
[1] = mask
[2] = 0;
2019 * Get address/bits format...
2025 if (family
== AF_INET6
)
2033 mask
[0] = 0xffffffff;
2035 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
2038 mask
[1] = 0xffffffff;
2042 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
2045 mask
[2] = 0xffffffff;
2049 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
2052 mask
[3] = 0xffffffff;
2056 mask
[3] = (0xffffffff << i
) & 0xffffffff;
2059 #endif /* AF_INET6 */
2064 mask
[0] = 0xffffffff;
2065 mask
[1] = 0xffffffff;
2066 mask
[2] = 0xffffffff;
2069 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
2071 mask
[3] = 0xffffffff;
2076 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2077 "get_addr_and_mask(value=\"%s\", "
2078 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
2079 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
2083 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2086 if ((ip
[0] & ~mask
[0]) != 0 ||
2087 (ip
[1] & ~mask
[1]) != 0 ||
2088 (ip
[2] & ~mask
[2]) != 0 ||
2089 (ip
[3] & ~mask
[3]) != 0)
2097 * 'mime_error_cb()' - Log a MIME error.
2101 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
2102 const char *message
) /* I - Message */
2106 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
2111 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
2114 static int /* O - 1 on success, 0 on failure */
2115 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
2116 char *line
, /* I - Line from file */
2117 char *value
, /* I - Start of value data */
2118 int linenum
) /* I - Current line number */
2120 char *valptr
; /* Pointer into value */
2121 unsigned ip
[4], /* IP address components */
2122 mask
[4]; /* IP netmask components */
2125 if (!_cups_strcasecmp(line
, "Encryption"))
2128 * "Encryption xxx" - set required encryption level...
2131 if (!_cups_strcasecmp(value
, "never"))
2132 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
2133 else if (!_cups_strcasecmp(value
, "always"))
2135 cupsdLogMessage(CUPSD_LOG_ERROR
,
2136 "Encryption value \"%s\" on line %d of %s is invalid in this "
2137 "context. Using \"required\" instead.", value
, linenum
, ConfigurationFile
);
2139 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2141 else if (!_cups_strcasecmp(value
, "required"))
2142 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2143 else if (!_cups_strcasecmp(value
, "ifrequested"))
2144 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2147 cupsdLogMessage(CUPSD_LOG_ERROR
,
2148 "Unknown Encryption value %s on line %d of %s.", value
, linenum
, ConfigurationFile
);
2152 else if (!_cups_strcasecmp(line
, "Order"))
2155 * "Order Deny,Allow" or "Order Allow,Deny"...
2158 if (!_cups_strncasecmp(value
, "deny", 4))
2159 loc
->order_type
= CUPSD_AUTH_ALLOW
;
2160 else if (!_cups_strncasecmp(value
, "allow", 5))
2161 loc
->order_type
= CUPSD_AUTH_DENY
;
2164 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d of %s.",
2165 value
, linenum
, ConfigurationFile
);
2169 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2172 * Allow [From] host/ip...
2173 * Deny [From] host/ip...
2178 if (!_cups_strncasecmp(value
, "from", 4))
2181 * Strip leading "from"...
2186 while (_cups_isspace(*value
))
2194 * Find the end of the value...
2197 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2199 while (_cups_isspace(*valptr
))
2203 * Figure out what form the allow/deny address takes:
2214 * nnn.nnn.nnn.nnn/mm
2215 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2218 if (!_cups_strcasecmp(value
, "all"))
2224 if (!_cups_strcasecmp(line
, "Allow"))
2225 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2227 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2229 else if (!_cups_strcasecmp(value
, "none"))
2235 if (!_cups_strcasecmp(line
, "Allow"))
2236 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2238 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2241 else if (value
[0] == '*' || value
[0] == '.' ||
2242 (!isdigit(value
[0] & 255) && value
[0] != '['))
2244 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2245 #endif /* AF_INET6 */
2248 * Host or domain name...
2251 if (value
[0] == '*')
2254 if (!_cups_strcasecmp(line
, "Allow"))
2255 cupsdAddNameMask(&(loc
->allow
), value
);
2257 cupsdAddNameMask(&(loc
->deny
), value
);
2262 * One of many IP address forms...
2265 if (!get_addr_and_mask(value
, ip
, mask
))
2267 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d of %s.",
2268 value
, linenum
, ConfigurationFile
);
2272 if (!_cups_strcasecmp(line
, "Allow"))
2273 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2275 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2279 * Advance to next value...
2285 else if (!_cups_strcasecmp(line
, "AuthType"))
2288 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2291 if (!_cups_strcasecmp(value
, "none"))
2293 loc
->type
= CUPSD_AUTH_NONE
;
2294 loc
->level
= CUPSD_AUTH_ANON
;
2296 else if (!_cups_strcasecmp(value
, "basic"))
2298 loc
->type
= CUPSD_AUTH_BASIC
;
2300 if (loc
->level
== CUPSD_AUTH_ANON
)
2301 loc
->level
= CUPSD_AUTH_USER
;
2303 else if (!_cups_strcasecmp(value
, "default"))
2305 loc
->type
= CUPSD_AUTH_DEFAULT
;
2307 if (loc
->level
== CUPSD_AUTH_ANON
)
2308 loc
->level
= CUPSD_AUTH_USER
;
2311 else if (!_cups_strcasecmp(value
, "negotiate"))
2313 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2315 if (loc
->level
== CUPSD_AUTH_ANON
)
2316 loc
->level
= CUPSD_AUTH_USER
;
2318 #endif /* HAVE_GSSAPI */
2321 cupsdLogMessage(CUPSD_LOG_WARN
,
2322 "Unknown authorization type %s on line %d of %s.",
2323 value
, linenum
, ConfigurationFile
);
2327 else if (!_cups_strcasecmp(line
, "AuthClass"))
2330 * AuthClass anonymous, user, system, group
2333 if (!_cups_strcasecmp(value
, "anonymous"))
2335 loc
->type
= CUPSD_AUTH_NONE
;
2336 loc
->level
= CUPSD_AUTH_ANON
;
2338 cupsdLogMessage(CUPSD_LOG_WARN
,
2339 "\"AuthClass %s\" is deprecated; consider removing "
2343 else if (!_cups_strcasecmp(value
, "user"))
2345 loc
->level
= CUPSD_AUTH_USER
;
2347 cupsdLogMessage(CUPSD_LOG_WARN
,
2348 "\"AuthClass %s\" is deprecated; consider using "
2349 "\"Require valid-user\" on line %d of %s.",
2350 value
, linenum
, ConfigurationFile
);
2352 else if (!_cups_strcasecmp(value
, "group"))
2354 loc
->level
= CUPSD_AUTH_GROUP
;
2356 cupsdLogMessage(CUPSD_LOG_WARN
,
2357 "\"AuthClass %s\" is deprecated; consider using "
2358 "\"Require user @groupname\" on line %d of %s.",
2359 value
, linenum
, ConfigurationFile
);
2361 else if (!_cups_strcasecmp(value
, "system"))
2363 loc
->level
= CUPSD_AUTH_GROUP
;
2365 cupsdAddName(loc
, "@SYSTEM");
2367 cupsdLogMessage(CUPSD_LOG_WARN
,
2368 "\"AuthClass %s\" is deprecated; consider using "
2369 "\"Require user @SYSTEM\" on line %d of %s.",
2370 value
, linenum
, ConfigurationFile
);
2374 cupsdLogMessage(CUPSD_LOG_WARN
,
2375 "Unknown authorization class %s on line %d of %s.",
2376 value
, linenum
, ConfigurationFile
);
2380 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2382 cupsdAddName(loc
, value
);
2384 cupsdLogMessage(CUPSD_LOG_WARN
,
2385 "\"AuthGroupName %s\" directive is deprecated; consider "
2386 "using \"Require user @%s\" on line %d of %s.",
2387 value
, value
, linenum
, ConfigurationFile
);
2389 else if (!_cups_strcasecmp(line
, "Require"))
2392 * Apache synonym for AuthClass and AuthGroupName...
2396 * Require valid-user
2397 * Require group names
2398 * Require user names
2401 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2406 if (!_cups_strcasecmp(value
, "valid-user") ||
2407 !_cups_strcasecmp(value
, "user"))
2408 loc
->level
= CUPSD_AUTH_USER
;
2409 else if (!_cups_strcasecmp(value
, "group"))
2410 loc
->level
= CUPSD_AUTH_GROUP
;
2413 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d of %s.",
2414 value
, linenum
, ConfigurationFile
);
2419 * Get the list of names from the line...
2422 for (value
= valptr
; *value
;)
2424 while (_cups_isspace(*value
))
2427 #ifdef HAVE_AUTHORIZATION_H
2428 if (!strncmp(value
, "@AUTHKEY(", 9))
2431 * Grab "@AUTHKEY(name)" value...
2434 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2440 #endif /* HAVE_AUTHORIZATION_H */
2441 if (*value
== '\"' || *value
== '\'')
2444 * Grab quoted name...
2447 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2454 * Grab literal name.
2457 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2463 cupsdAddName(loc
, value
);
2465 for (value
= valptr
; _cups_isspace(*value
); value
++);
2468 else if (!_cups_strcasecmp(line
, "Satisfy"))
2470 if (!_cups_strcasecmp(value
, "all"))
2471 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2472 else if (!_cups_strcasecmp(value
, "any"))
2473 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2476 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d of %s.",
2477 value
, linenum
, ConfigurationFile
);
2489 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2492 static int /* O - FatalErrors bits */
2493 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2495 int fatal
; /* FatalErrors bits */
2496 char value
[1024], /* Value string */
2497 *valstart
, /* Pointer into value */
2498 *valend
; /* End of value */
2502 * Empty FatalErrors line yields NULL pointer...
2506 return (CUPSD_FATAL_NONE
);
2509 * Loop through the value string,...
2512 strlcpy(value
, s
, sizeof(value
));
2514 fatal
= CUPSD_FATAL_NONE
;
2516 for (valstart
= value
; *valstart
;)
2519 * Get the current space/comma-delimited kind name...
2522 for (valend
= valstart
; *valend
; valend
++)
2523 if (_cups_isspace(*valend
) || *valend
== ',')
2530 * Add the error to the bitmask...
2533 if (!_cups_strcasecmp(valstart
, "all"))
2534 fatal
= CUPSD_FATAL_ALL
;
2535 else if (!_cups_strcasecmp(valstart
, "browse"))
2536 fatal
|= CUPSD_FATAL_BROWSE
;
2537 else if (!_cups_strcasecmp(valstart
, "-browse"))
2538 fatal
&= ~CUPSD_FATAL_BROWSE
;
2539 else if (!_cups_strcasecmp(valstart
, "config"))
2540 fatal
|= CUPSD_FATAL_CONFIG
;
2541 else if (!_cups_strcasecmp(valstart
, "-config"))
2542 fatal
&= ~CUPSD_FATAL_CONFIG
;
2543 else if (!_cups_strcasecmp(valstart
, "listen"))
2544 fatal
|= CUPSD_FATAL_LISTEN
;
2545 else if (!_cups_strcasecmp(valstart
, "-listen"))
2546 fatal
&= ~CUPSD_FATAL_LISTEN
;
2547 else if (!_cups_strcasecmp(valstart
, "log"))
2548 fatal
|= CUPSD_FATAL_LOG
;
2549 else if (!_cups_strcasecmp(valstart
, "-log"))
2550 fatal
&= ~CUPSD_FATAL_LOG
;
2551 else if (!_cups_strcasecmp(valstart
, "permissions"))
2552 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2553 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2554 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2555 else if (_cups_strcasecmp(valstart
, "none"))
2556 cupsdLogMessage(CUPSD_LOG_ERROR
,
2557 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2559 for (valstart
= valend
; *valstart
; valstart
++)
2560 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2569 * 'parse_groups()' - Parse system group names in a string.
2572 static int /* O - 1 on success, 0 on failure */
2573 parse_groups(const char *s
) /* I - Space-delimited groups */
2575 int status
; /* Return status */
2576 char value
[1024], /* Value string */
2577 *valstart
, /* Pointer into value */
2578 *valend
, /* End of value */
2579 quote
; /* Quote character */
2580 struct group
*group
; /* Group */
2584 * Make a copy of the string and parse out the groups...
2587 strlcpy(value
, s
, sizeof(value
));
2592 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2594 if (*valstart
== '\'' || *valstart
== '\"')
2597 * Scan quoted name...
2600 quote
= *valstart
++;
2602 for (valend
= valstart
; *valend
; valend
++)
2603 if (*valend
== quote
)
2609 * Scan space or comma-delimited name...
2612 for (valend
= valstart
; *valend
; valend
++)
2613 if (_cups_isspace(*valend
) || *valend
== ',')
2620 group
= getgrnam(valstart
);
2623 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2624 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2635 while (*valstart
== ',' || _cups_isspace(*valstart
))
2644 * 'parse_protocols()' - Parse browse protocols in a string.
2647 static int /* O - Browse protocol bits */
2648 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2650 int protocols
; /* Browse protocol bits */
2651 char value
[1024], /* Value string */
2652 *valstart
, /* Pointer into value */
2653 *valend
; /* End of value */
2657 * Empty protocol line yields NULL pointer...
2664 * Loop through the value string,...
2667 strlcpy(value
, s
, sizeof(value
));
2671 for (valstart
= value
; *valstart
;)
2674 * Get the current space/comma-delimited protocol name...
2677 for (valend
= valstart
; *valend
; valend
++)
2678 if (_cups_isspace(*valend
) || *valend
== ',')
2685 * Add the protocol to the bitmask...
2688 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2689 !_cups_strcasecmp(valstart
, "dns-sd") ||
2690 !_cups_strcasecmp(valstart
, "bonjour"))
2691 protocols
|= BROWSE_DNSSD
;
2692 else if (!_cups_strcasecmp(valstart
, "all"))
2693 protocols
|= BROWSE_ALL
;
2694 else if (_cups_strcasecmp(valstart
, "none"))
2695 cupsdLogMessage(CUPSD_LOG_ERROR
,
2696 "Unknown browse protocol \"%s\" ignored.", valstart
);
2698 for (valstart
= valend
; *valstart
; valstart
++)
2699 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2708 * 'parse_variable()' - Parse a variable line.
2711 static int /* O - 1 on success, 0 on failure */
2713 const char *filename
, /* I - Name of configuration file */
2714 int linenum
, /* I - Line in configuration file */
2715 const char *line
, /* I - Line from configuration file */
2716 const char *value
, /* I - Value from configuration file */
2717 size_t num_vars
, /* I - Number of variables */
2718 const cupsd_var_t
*vars
) /* I - Variables */
2720 size_t i
; /* Looping var */
2721 const cupsd_var_t
*var
; /* Variables */
2722 char temp
[1024]; /* Temporary string */
2725 for (i
= num_vars
, var
= vars
; i
> 0; i
--, var
++)
2726 if (!_cups_strcasecmp(line
, var
->name
))
2732 * Unknown directive! Output an error message and continue...
2736 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d of %s.",
2737 line
, linenum
, filename
);
2739 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d of %s.",
2740 line
, linenum
, filename
);
2747 case CUPSD_VARTYPE_INTEGER
:
2750 cupsdLogMessage(CUPSD_LOG_ERROR
,
2751 "Missing integer value for %s on line %d of %s.",
2752 line
, linenum
, filename
);
2755 else if (!isdigit(*value
& 255))
2757 cupsdLogMessage(CUPSD_LOG_ERROR
,
2758 "Bad integer value for %s on line %d of %s.",
2759 line
, linenum
, filename
);
2765 char *units
; /* Units */
2767 n
= strtol(value
, &units
, 0);
2769 if (units
&& *units
)
2771 if (tolower(units
[0] & 255) == 'g')
2772 n
*= 1024 * 1024 * 1024;
2773 else if (tolower(units
[0] & 255) == 'm')
2775 else if (tolower(units
[0] & 255) == 'k')
2777 else if (tolower(units
[0] & 255) == 't')
2781 cupsdLogMessage(CUPSD_LOG_ERROR
,
2782 "Unknown integer value for %s on line %d of %s.",
2783 line
, linenum
, filename
);
2790 cupsdLogMessage(CUPSD_LOG_ERROR
,
2791 "Bad negative integer value for %s on line %d of "
2792 "%s.", line
, linenum
, filename
);
2797 *((int *)var
->ptr
) = n
;
2802 case CUPSD_VARTYPE_PERM
:
2805 cupsdLogMessage(CUPSD_LOG_ERROR
,
2806 "Missing permissions value for %s on line %d of %s.",
2807 line
, linenum
, filename
);
2810 else if (!isdigit(*value
& 255))
2812 /* TODO: Add chmod UGO syntax support */
2813 cupsdLogMessage(CUPSD_LOG_ERROR
,
2814 "Bad permissions value for %s on line %d of %s.",
2815 line
, linenum
, filename
);
2820 int n
= strtol(value
, NULL
, 8);
2821 /* Permissions value */
2825 cupsdLogMessage(CUPSD_LOG_ERROR
,
2826 "Bad negative permissions value for %s on line %d of "
2827 "%s.", line
, linenum
, filename
);
2832 *((mode_t
*)var
->ptr
) = (mode_t
)n
;
2837 case CUPSD_VARTYPE_TIME
:
2840 cupsdLogMessage(CUPSD_LOG_ERROR
,
2841 "Missing time interval value for %s on line %d of "
2842 "%s.", line
, linenum
, filename
);
2845 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
2846 (!_cups_strcasecmp(value
, "true") ||
2847 !_cups_strcasecmp(value
, "on") ||
2848 !_cups_strcasecmp(value
, "enabled") ||
2849 !_cups_strcasecmp(value
, "yes")))
2851 *((int *)var
->ptr
) = INT_MAX
;
2853 else if (!_cups_strcasecmp(value
, "false") ||
2854 !_cups_strcasecmp(value
, "off") ||
2855 !_cups_strcasecmp(value
, "disabled") ||
2856 !_cups_strcasecmp(value
, "no"))
2858 *((int *)var
->ptr
) = 0;
2860 else if (!isdigit(*value
& 255))
2862 cupsdLogMessage(CUPSD_LOG_ERROR
,
2863 "Unknown time interval value for %s on line %d of "
2864 "%s.", line
, linenum
, filename
);
2869 double n
; /* Number */
2870 char *units
; /* Units */
2872 n
= strtod(value
, &units
);
2874 if (units
&& *units
)
2876 if (tolower(units
[0] & 255) == 'w')
2877 n
*= 7 * 24 * 60 * 60;
2878 else if (tolower(units
[0] & 255) == 'd')
2880 else if (tolower(units
[0] & 255) == 'h')
2882 else if (tolower(units
[0] & 255) == 'm')
2886 cupsdLogMessage(CUPSD_LOG_ERROR
,
2887 "Unknown time interval value for %s on line "
2888 "%d of %s.", line
, linenum
, filename
);
2893 if (n
< 0.0 || n
> INT_MAX
)
2895 cupsdLogMessage(CUPSD_LOG_ERROR
,
2896 "Bad time value for %s on line %d of %s.",
2897 line
, linenum
, filename
);
2902 *((int *)var
->ptr
) = (int)n
;
2907 case CUPSD_VARTYPE_BOOLEAN
:
2910 cupsdLogMessage(CUPSD_LOG_ERROR
,
2911 "Missing boolean value for %s on line %d of %s.",
2912 line
, linenum
, filename
);
2915 else if (!_cups_strcasecmp(value
, "true") ||
2916 !_cups_strcasecmp(value
, "on") ||
2917 !_cups_strcasecmp(value
, "enabled") ||
2918 !_cups_strcasecmp(value
, "yes") ||
2921 *((int *)var
->ptr
) = TRUE
;
2923 else if (!_cups_strcasecmp(value
, "false") ||
2924 !_cups_strcasecmp(value
, "off") ||
2925 !_cups_strcasecmp(value
, "disabled") ||
2926 !_cups_strcasecmp(value
, "no") ||
2927 !_cups_strcasecmp(value
, "0"))
2929 *((int *)var
->ptr
) = FALSE
;
2933 cupsdLogMessage(CUPSD_LOG_ERROR
,
2934 "Unknown boolean value %s on line %d of %s.",
2935 value
, linenum
, filename
);
2940 case CUPSD_VARTYPE_PATHNAME
:
2943 cupsdLogMessage(CUPSD_LOG_ERROR
,
2944 "Missing pathname value for %s on line %d of %s.",
2945 line
, linenum
, filename
);
2949 if (value
[0] == '/')
2950 strlcpy(temp
, value
, sizeof(temp
));
2952 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
2954 if (access(temp
, 0))
2956 cupsdLogMessage(CUPSD_LOG_ERROR
,
2957 "File or directory for \"%s %s\" on line %d of %s "
2958 "does not exist.", line
, value
, linenum
, filename
);
2962 cupsdSetString((char **)var
->ptr
, temp
);
2965 case CUPSD_VARTYPE_STRING
:
2966 cupsdSetString((char **)var
->ptr
, value
);
2975 * 'read_cupsd_conf()' - Read the cupsd.conf configuration file.
2978 static int /* O - 1 on success, 0 on failure */
2979 read_cupsd_conf(cups_file_t
*fp
) /* I - File to read from */
2981 int linenum
; /* Current line number */
2982 char line
[HTTP_MAX_BUFFER
],
2983 /* Line from file */
2984 temp
[HTTP_MAX_BUFFER
],
2985 /* Temporary buffer for value */
2986 *value
, /* Pointer to value */
2987 *valueptr
; /* Pointer into value */
2988 int valuelen
; /* Length of value */
2989 http_addrlist_t
*addrlist
, /* Address list */
2990 *addr
; /* Current address */
2991 cups_file_t
*incfile
; /* Include file */
2992 char incname
[1024]; /* Include filename */
2996 * Loop through each line in the file...
3001 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3004 * Decode the directive...
3007 if (!_cups_strcasecmp(line
, "Include") && value
)
3013 if (value
[0] == '/')
3014 strlcpy(incname
, value
, sizeof(incname
));
3016 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
3018 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
3019 cupsdLogMessage(CUPSD_LOG_ERROR
,
3020 "Unable to include config file \"%s\" - %s",
3021 incname
, strerror(errno
));
3024 read_cupsd_conf(incfile
);
3025 cupsFileClose(incfile
);
3028 else if (!_cups_strcasecmp(line
, "<Location") && value
)
3034 linenum
= read_location(fp
, value
, linenum
);
3038 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
3044 linenum
= read_policy(fp
, value
, linenum
);
3048 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
3050 JobRetryInterval
= atoi(value
);
3051 cupsdLogMessage(CUPSD_LOG_WARN
,
3052 "FaxRetryInterval is deprecated; use "
3053 "JobRetryInterval on line %d of %s.", linenum
, ConfigurationFile
);
3055 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
3057 JobRetryLimit
= atoi(value
);
3058 cupsdLogMessage(CUPSD_LOG_WARN
,
3059 "FaxRetryLimit is deprecated; use "
3060 "JobRetryLimit on line %d of %s.", linenum
, ConfigurationFile
);
3063 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3066 * SSLOptions [AllowRC4] [AllowSSL3] [None]
3069 int options
= 0; /* SSL/TLS options */
3073 char *start
, /* Start of option */
3074 *end
; /* End of option */
3076 for (start
= value
; *start
; start
= end
)
3079 * Find end of keyword...
3083 while (*end
&& !_cups_isspace(*end
))
3093 if (!_cups_strcasecmp(start
, "AllowRC4"))
3094 options
|= _HTTP_TLS_ALLOW_RC4
;
3095 else if (!_cups_strcasecmp(start
, "AllowSSL3"))
3096 options
|= _HTTP_TLS_ALLOW_SSL3
;
3097 else if (!_cups_strcasecmp(start
, "None"))
3099 else if (_cups_strcasecmp(start
, "NoEmptyFragments"))
3100 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown SSL option %s at line %d.", start
, linenum
);
3104 _httpTLSSetOptions(options
);
3106 #endif /* HAVE_SSL */
3107 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
3109 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
3110 #endif /* HAVE_SSL */
3114 * Add listening address(es) to the list...
3117 cupsd_listener_t
*lis
; /* New listeners array */
3121 * Get the address list...
3124 addrlist
= get_address(value
, IPP_PORT
);
3128 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
3134 * Add each address...
3137 for (addr
= addrlist
; addr
; addr
= addr
->next
)
3140 * See if this address is already present...
3143 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
3145 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
3146 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
3147 httpAddrPort(&(addr
->addr
)) == httpAddrPort(&(lis
->address
)))
3152 #ifdef HAVE_ONDEMAND
3153 if (!lis
->on_demand
)
3154 #endif /* HAVE_ONDEMAND */
3156 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3157 cupsdLogMessage(CUPSD_LOG_WARN
,
3158 "Duplicate listen address \"%s\" ignored.", temp
);
3165 * Allocate another listener...
3169 Listeners
= cupsArrayNew(NULL
, NULL
);
3173 cupsdLogMessage(CUPSD_LOG_ERROR
,
3174 "Unable to allocate %s at line %d - %s.",
3175 line
, linenum
, strerror(errno
));
3179 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
3181 cupsdLogMessage(CUPSD_LOG_ERROR
,
3182 "Unable to allocate %s at line %d - %s.",
3183 line
, linenum
, strerror(errno
));
3187 cupsArrayAdd(Listeners
, lis
);
3190 * Copy the current address and log it...
3193 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
3197 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
3198 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
3199 #endif /* HAVE_SSL */
3201 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3204 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
3205 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
3207 #endif /* AF_LOCAL */
3208 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
3209 httpAddrPort(&(lis
->address
)),
3210 httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
3212 if (!httpAddrLocalhost(&(lis
->address
)))
3213 RemotePort
= httpAddrPort(&(lis
->address
));
3220 httpAddrFreeList(addrlist
);
3222 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
3223 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
3226 * "BrowseProtocols name [... name]"
3227 * "BrowseLocalProtocols name [... name]"
3230 int protocols
= parse_protocols(value
);
3234 cupsdLogMessage(CUPSD_LOG_ERROR
,
3235 "Unknown browse protocol \"%s\" on line %d of %s.",
3236 value
, linenum
, ConfigurationFile
);
3240 BrowseLocalProtocols
= protocols
;
3242 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
3245 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3248 if (!_cups_strcasecmp(value
, "none"))
3249 default_auth_type
= CUPSD_AUTH_NONE
;
3250 else if (!_cups_strcasecmp(value
, "basic"))
3251 default_auth_type
= CUPSD_AUTH_BASIC
;
3253 else if (!_cups_strcasecmp(value
, "negotiate"))
3254 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
3255 #endif /* HAVE_GSSAPI */
3256 else if (!_cups_strcasecmp(value
, "auto"))
3257 default_auth_type
= CUPSD_AUTH_AUTO
;
3260 cupsdLogMessage(CUPSD_LOG_WARN
,
3261 "Unknown default authorization type %s on line %d of %s.",
3262 value
, linenum
, ConfigurationFile
);
3263 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3268 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
3271 * DefaultEncryption {Never,IfRequested,Required}
3274 if (!value
|| !_cups_strcasecmp(value
, "never"))
3275 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3276 else if (!_cups_strcasecmp(value
, "required"))
3277 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3278 else if (!_cups_strcasecmp(value
, "ifrequested"))
3279 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3282 cupsdLogMessage(CUPSD_LOG_WARN
,
3283 "Unknown default encryption %s on line %d of %s.",
3284 value
, linenum
, ConfigurationFile
);
3285 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3289 #endif /* HAVE_SSL */
3290 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
3293 * Do hostname lookups?
3296 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
3297 !_cups_strcasecmp(value
, "false"))
3298 HostNameLookups
= 0;
3299 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
3300 !_cups_strcasecmp(value
, "true"))
3301 HostNameLookups
= 1;
3302 else if (!_cups_strcasecmp(value
, "double"))
3303 HostNameLookups
= 2;
3305 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d of %s.",
3306 value
, linenum
, ConfigurationFile
);
3308 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
3311 * Amount of logging to do to access log...
3314 if (!_cups_strcasecmp(value
, "all"))
3315 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3316 else if (!_cups_strcasecmp(value
, "actions"))
3317 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3318 else if (!_cups_strcasecmp(value
, "config"))
3319 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3320 else if (!_cups_strcasecmp(value
, "none"))
3321 AccessLogLevel
= CUPSD_ACCESSLOG_NONE
;
3323 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d of %s.",
3324 value
, linenum
, ConfigurationFile
);
3326 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
3329 * Amount of logging to do to error log...
3332 if (!_cups_strcasecmp(value
, "debug2"))
3333 LogLevel
= CUPSD_LOG_DEBUG2
;
3334 else if (!_cups_strcasecmp(value
, "debug"))
3335 LogLevel
= CUPSD_LOG_DEBUG
;
3336 else if (!_cups_strcasecmp(value
, "info"))
3337 LogLevel
= CUPSD_LOG_INFO
;
3338 else if (!_cups_strcasecmp(value
, "notice"))
3339 LogLevel
= CUPSD_LOG_NOTICE
;
3340 else if (!_cups_strcasecmp(value
, "warn"))
3341 LogLevel
= CUPSD_LOG_WARN
;
3342 else if (!_cups_strcasecmp(value
, "error"))
3343 LogLevel
= CUPSD_LOG_ERROR
;
3344 else if (!_cups_strcasecmp(value
, "crit"))
3345 LogLevel
= CUPSD_LOG_CRIT
;
3346 else if (!_cups_strcasecmp(value
, "alert"))
3347 LogLevel
= CUPSD_LOG_ALERT
;
3348 else if (!_cups_strcasecmp(value
, "emerg"))
3349 LogLevel
= CUPSD_LOG_EMERG
;
3350 else if (!_cups_strcasecmp(value
, "none"))
3351 LogLevel
= CUPSD_LOG_NONE
;
3353 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d of %s.",
3354 value
, linenum
, ConfigurationFile
);
3356 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
3359 * Amount of logging to do to error log...
3362 if (!_cups_strcasecmp(value
, "standard"))
3363 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3364 else if (!_cups_strcasecmp(value
, "usecs"))
3365 LogTimeFormat
= CUPSD_TIME_USECS
;
3367 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d of %s.",
3368 value
, linenum
, ConfigurationFile
);
3370 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
3373 * Set the string used for the Server header...
3376 struct utsname plat
; /* Platform info */
3381 if (!_cups_strcasecmp(value
, "ProductOnly"))
3382 cupsdSetString(&ServerHeader
, "CUPS IPP");
3383 else if (!_cups_strcasecmp(value
, "Major"))
3384 cupsdSetStringf(&ServerHeader
, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR
);
3385 else if (!_cups_strcasecmp(value
, "Minor"))
3386 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
3387 CUPS_VERSION_MINOR
);
3388 else if (!_cups_strcasecmp(value
, "Minimal"))
3389 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
" IPP/2.1");
3390 else if (!_cups_strcasecmp(value
, "OS"))
3391 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s) IPP/2.1",
3392 plat
.sysname
, plat
.release
);
3393 else if (!_cups_strcasecmp(value
, "Full"))
3394 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s; %s) IPP/2.1",
3395 plat
.sysname
, plat
.release
, plat
.machine
);
3396 else if (!_cups_strcasecmp(value
, "None"))
3397 cupsdClearString(&ServerHeader
);
3399 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d of %s.",
3400 value
, linenum
, ConfigurationFile
);
3402 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3405 * PassEnv variable [... variable]
3410 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3411 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3414 if (value
[valuelen
])
3416 value
[valuelen
] = '\0';
3420 cupsdSetEnv(value
, NULL
);
3422 for (value
+= valuelen
; *value
; value
++)
3423 if (!_cups_isspace(*value
) || *value
!= ',')
3427 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3430 * ServerAlias name [... name]
3434 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3438 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3439 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3442 if (value
[valuelen
])
3444 value
[valuelen
] = '\0';
3448 cupsdAddAlias(ServerAlias
, value
);
3450 for (value
+= valuelen
; *value
; value
++)
3451 if (!_cups_isspace(*value
) || *value
!= ',')
3455 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3458 * SetEnv variable value
3461 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3469 while (isspace(*valueptr
& 255))
3472 cupsdSetEnv(value
, valueptr
);
3475 cupsdLogMessage(CUPSD_LOG_ERROR
,
3476 "Missing value for SetEnv directive on line %d of %s.",
3477 linenum
, ConfigurationFile
);
3479 else if (!_cups_strcasecmp(line
, "AccessLog") ||
3480 !_cups_strcasecmp(line
, "CacheDir") ||
3481 !_cups_strcasecmp(line
, "ConfigFilePerm") ||
3482 !_cups_strcasecmp(line
, "DataDir") ||
3483 !_cups_strcasecmp(line
, "DocumentRoot") ||
3484 !_cups_strcasecmp(line
, "ErrorLog") ||
3485 !_cups_strcasecmp(line
, "FatalErrors") ||
3486 !_cups_strcasecmp(line
, "FileDevice") ||
3487 !_cups_strcasecmp(line
, "FontPath") ||
3488 !_cups_strcasecmp(line
, "Group") ||
3489 !_cups_strcasecmp(line
, "LogFilePerm") ||
3490 !_cups_strcasecmp(line
, "LPDConfigFile") ||
3491 !_cups_strcasecmp(line
, "PageLog") ||
3492 !_cups_strcasecmp(line
, "Printcap") ||
3493 !_cups_strcasecmp(line
, "PrintcapFormat") ||
3494 !_cups_strcasecmp(line
, "RemoteRoot") ||
3495 !_cups_strcasecmp(line
, "RequestRoot") ||
3496 !_cups_strcasecmp(line
, "ServerBin") ||
3497 !_cups_strcasecmp(line
, "ServerCertificate") ||
3498 !_cups_strcasecmp(line
, "ServerKey") ||
3499 !_cups_strcasecmp(line
, "ServerKeychain") ||
3500 !_cups_strcasecmp(line
, "ServerRoot") ||
3501 !_cups_strcasecmp(line
, "SMBConfigFile") ||
3502 !_cups_strcasecmp(line
, "StateDir") ||
3503 !_cups_strcasecmp(line
, "SystemGroup") ||
3504 !_cups_strcasecmp(line
, "SystemGroupAuthKey") ||
3505 !_cups_strcasecmp(line
, "TempDir") ||
3506 !_cups_strcasecmp(line
, "User"))
3508 cupsdLogMessage(CUPSD_LOG_INFO
,
3509 "Please move \"%s%s%s\" on line %d of %s to the %s file; "
3510 "this will become an error in a future release.",
3511 line
, value
? " " : "", value
? value
: "", linenum
,
3512 ConfigurationFile
, CupsFilesFile
);
3515 parse_variable(ConfigurationFile
, linenum
, line
, value
,
3516 sizeof(cupsd_vars
) / sizeof(cupsd_vars
[0]), cupsd_vars
);
3524 * 'read_cups_files_conf()' - Read the cups-files.conf configuration file.
3527 static int /* O - 1 on success, 0 on failure */
3528 read_cups_files_conf(cups_file_t
*fp
) /* I - File to read from */
3530 int linenum
; /* Current line number */
3531 char line
[HTTP_MAX_BUFFER
], /* Line from file */
3532 *value
; /* Value from line */
3533 struct group
*group
; /* Group */
3537 * Loop through each line in the file...
3542 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3544 if (!_cups_strcasecmp(line
, "FatalErrors"))
3545 FatalErrors
= parse_fatal_errors(value
);
3546 else if (!_cups_strcasecmp(line
, "Group") && value
)
3549 * Group ID to run as...
3552 if (isdigit(value
[0]))
3553 Group
= (gid_t
)atoi(value
);
3557 group
= getgrnam(value
);
3560 Group
= group
->gr_gid
;
3563 cupsdLogMessage(CUPSD_LOG_ERROR
,
3564 "Unknown Group \"%s\" on line %d of %s.", value
,
3565 linenum
, CupsFilesFile
);
3566 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3571 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
3574 * Format of printcap file?
3577 if (!_cups_strcasecmp(value
, "bsd"))
3578 PrintcapFormat
= PRINTCAP_BSD
;
3579 else if (!_cups_strcasecmp(value
, "plist"))
3580 PrintcapFormat
= PRINTCAP_PLIST
;
3581 else if (!_cups_strcasecmp(value
, "solaris"))
3582 PrintcapFormat
= PRINTCAP_SOLARIS
;
3585 cupsdLogMessage(CUPSD_LOG_ERROR
,
3586 "Unknown PrintcapFormat \"%s\" on line %d of %s.",
3587 value
, linenum
, CupsFilesFile
);
3588 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3592 else if (!_cups_strcasecmp(line
, "Sandboxing") && value
)
3595 * Level of sandboxing?
3598 if (!_cups_strcasecmp(value
, "off") && getuid())
3600 Sandboxing
= CUPSD_SANDBOXING_OFF
;
3601 cupsdLogMessage(CUPSD_LOG_WARN
, "Disabling sandboxing is not recommended (line %d of %s)", linenum
, CupsFilesFile
);
3603 else if (!_cups_strcasecmp(value
, "relaxed"))
3604 Sandboxing
= CUPSD_SANDBOXING_RELAXED
;
3605 else if (!_cups_strcasecmp(value
, "strict"))
3606 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
3609 cupsdLogMessage(CUPSD_LOG_ERROR
,
3610 "Unknown Sandboxing \"%s\" on line %d of %s.",
3611 value
, linenum
, CupsFilesFile
);
3612 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3616 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
3619 * SystemGroup (admin) group(s)...
3622 if (!parse_groups(value
))
3624 cupsdLogMessage(CUPSD_LOG_ERROR
,
3625 "Unknown SystemGroup \"%s\" on line %d of %s.", value
,
3626 linenum
, CupsFilesFile
);
3627 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3631 else if (!_cups_strcasecmp(line
, "User") && value
)
3634 * User ID to run as...
3637 if (isdigit(value
[0] & 255))
3639 int uid
= atoi(value
);
3643 cupsdLogMessage(CUPSD_LOG_ERROR
,
3644 "Will not use User 0 as specified on line %d of %s "
3645 "for security reasons. You must use a non-"
3646 "privileged account instead.",
3647 linenum
, CupsFilesFile
);
3648 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3652 User
= (uid_t
)atoi(value
);
3656 struct passwd
*p
; /* Password information */
3659 p
= getpwnam(value
);
3665 cupsdLogMessage(CUPSD_LOG_ERROR
,
3666 "Will not use User %s (UID=0) as specified on line "
3667 "%d of %s for security reasons. You must use a "
3668 "non-privileged account instead.",
3669 value
, linenum
, CupsFilesFile
);
3670 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3678 cupsdLogMessage(CUPSD_LOG_ERROR
,
3679 "Unknown User \"%s\" on line %d of %s.",
3680 value
, linenum
, CupsFilesFile
);
3681 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3686 else if (!_cups_strcasecmp(line
, "ServerCertificate") ||
3687 !_cups_strcasecmp(line
, "ServerKey"))
3689 cupsdLogMessage(CUPSD_LOG_INFO
,
3690 "The \"%s\" directive on line %d of %s is no longer "
3691 "supported; this will become an error in a future "
3693 line
, linenum
, CupsFilesFile
);
3695 else if (!parse_variable(CupsFilesFile
, linenum
, line
, value
,
3696 sizeof(cupsfiles_vars
) / sizeof(cupsfiles_vars
[0]),
3698 (FatalErrors
& CUPSD_FATAL_CONFIG
))
3707 * 'read_location()' - Read a <Location path> definition.
3710 static int /* O - New line number or 0 on error */
3711 read_location(cups_file_t
*fp
, /* I - Configuration file */
3712 char *location
, /* I - Location name/path */
3713 int linenum
) /* I - Current line number */
3715 cupsd_location_t
*loc
, /* New location */
3716 *parent
; /* Parent location */
3717 char line
[HTTP_MAX_BUFFER
],
3719 *value
, /* Value for directive */
3720 *valptr
; /* Pointer into value */
3723 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3724 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d of %s.",
3725 location
, linenum
, ConfigurationFile
);
3726 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3730 cupsdAddLocation(parent
);
3732 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3737 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3740 * Decode the directive...
3743 if (!_cups_strcasecmp(line
, "</Location>"))
3745 else if (!_cups_strcasecmp(line
, "<Limit") ||
3746 !_cups_strcasecmp(line
, "<LimitExcept"))
3750 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3751 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3757 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3760 cupsdAddLocation(loc
);
3765 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3770 if (!strcmp(value
, "ALL"))
3771 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3772 else if (!strcmp(value
, "GET"))
3773 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3774 else if (!strcmp(value
, "HEAD"))
3775 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3776 else if (!strcmp(value
, "OPTIONS"))
3777 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3778 else if (!strcmp(value
, "POST"))
3779 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3780 else if (!strcmp(value
, "PUT"))
3781 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3782 else if (!strcmp(value
, "TRACE"))
3783 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3785 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d of %s.",
3786 value
, linenum
, ConfigurationFile
);
3788 for (value
= valptr
; isspace(*value
& 255); value
++);
3791 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3792 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3794 parent
->limit
&= ~loc
->limit
;
3796 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3797 !_cups_strcasecmp(line
, "</LimitExcept>"))
3801 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3802 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3805 else if (!parse_aaa(loc
, line
, value
, linenum
))
3807 cupsdLogMessage(CUPSD_LOG_ERROR
,
3808 "Unknown Location directive %s on line %d of %s.",
3809 line
, linenum
, ConfigurationFile
);
3810 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3815 cupsdLogMessage(CUPSD_LOG_ERROR
,
3816 "Unexpected end-of-file at line %d while reading location.",
3819 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3824 * 'read_policy()' - Read a <Policy name> definition.
3827 static int /* O - New line number or 0 on error */
3828 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3829 char *policy
, /* I - Location name/path */
3830 int linenum
) /* I - Current line number */
3832 int i
; /* Looping var */
3833 cupsd_policy_t
*pol
; /* Policy */
3834 cupsd_location_t
*op
; /* Policy operation */
3835 int num_ops
; /* Number of IPP operations */
3836 ipp_op_t ops
[100]; /* Operations */
3837 char line
[HTTP_MAX_BUFFER
],
3839 *value
, /* Value for directive */
3840 *valptr
; /* Pointer into value */
3844 * Create the policy...
3847 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3848 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d of %s.",
3849 policy
, linenum
, ConfigurationFile
);
3850 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3854 * Read from the file...
3860 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3863 * Decode the directive...
3866 if (!_cups_strcasecmp(line
, "</Policy>"))
3869 cupsdLogMessage(CUPSD_LOG_WARN
,
3870 "Missing </Limit> before </Policy> on line %d of %s.",
3871 linenum
, ConfigurationFile
);
3873 set_policy_defaults(pol
);
3877 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3881 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3882 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3889 * Scan for IPP operation names...
3896 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3901 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3903 if (!_cups_strcasecmp(value
, "All"))
3904 ops
[num_ops
] = IPP_ANY_OPERATION
;
3905 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3906 cupsdLogMessage(CUPSD_LOG_ERROR
,
3907 "Bad IPP operation name \"%s\" on line %d of %s.",
3908 value
, linenum
, ConfigurationFile
);
3913 cupsdLogMessage(CUPSD_LOG_ERROR
,
3914 "Too many operations listed on line %d of %s.",
3915 linenum
, ConfigurationFile
);
3917 for (value
= valptr
; isspace(*value
& 255); value
++);
3921 * If none are specified, apply the policy to all operations...
3926 ops
[0] = IPP_ANY_OPERATION
;
3931 * Add a new policy for the first operation...
3934 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3936 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3939 * Finish the current operation limit...
3945 * Copy the policy to the other operations...
3948 for (i
= 1; i
< num_ops
; i
++)
3949 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3956 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3957 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3960 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3961 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3962 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3963 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3967 cupsdLogMessage(CUPSD_LOG_ERROR
,
3968 "%s directive must appear outside <Limit>...</Limit> "
3969 "on line %d of %s.", line
, linenum
, ConfigurationFile
);
3970 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3976 * Pull out whitespace-delimited values...
3982 * Find the end of the current value...
3985 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3991 * Save it appropriately...
3994 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3997 * JobPrivateAccess {all|default|user/group list|@@ACL}
4000 if (!_cups_strcasecmp(value
, "default"))
4002 cupsdAddString(&(pol
->job_access
), "@OWNER");
4003 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4006 cupsdAddString(&(pol
->job_access
), value
);
4008 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
4011 * JobPrivateValues {all|none|default|attribute list}
4014 if (!_cups_strcasecmp(value
, "default"))
4016 cupsdAddString(&(pol
->job_attrs
), "job-name");
4017 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4018 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4019 cupsdAddString(&(pol
->job_attrs
), "phone");
4022 cupsdAddString(&(pol
->job_attrs
), value
);
4024 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
4027 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
4030 if (!_cups_strcasecmp(value
, "default"))
4032 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4033 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4036 cupsdAddString(&(pol
->sub_access
), value
);
4038 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
4041 * SubscriptionPrivateValues {all|none|default|attribute list}
4044 if (!_cups_strcasecmp(value
, "default"))
4046 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4047 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4048 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4049 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4050 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
4053 cupsdAddString(&(pol
->sub_attrs
), value
);
4057 * Find the next string on the line...
4060 for (value
= valptr
; isspace(*value
& 255); value
++);
4066 cupsdLogMessage(CUPSD_LOG_ERROR
,
4067 "Missing <Limit ops> directive before %s on line %d of %s.",
4068 line
, linenum
, ConfigurationFile
);
4069 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4072 else if (!parse_aaa(op
, line
, value
, linenum
))
4074 cupsdLogMessage(CUPSD_LOG_ERROR
,
4075 "Unknown Policy Limit directive %s on line %d of %s.",
4076 line
, linenum
, ConfigurationFile
);
4078 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4083 cupsdLogMessage(CUPSD_LOG_ERROR
,
4084 "Unexpected end-of-file at line %d while reading policy "
4085 "\"%s\".", linenum
, policy
);
4087 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
4092 * 'set_policy_defaults()' - Set default policy values as needed.
4096 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
4098 cupsd_location_t
*op
; /* Policy operation */
4102 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
4103 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
4104 * upgrades do not introduce new security issues...
4106 * CUPS STR #4659: Allow a lone <Limit All> policy.
4109 if (cupsArrayCount(pol
->ops
) > 1)
4111 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
4112 op
->op
== IPP_ANY_OPERATION
)
4114 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
4115 op
->op
!= IPP_ANY_OPERATION
)
4118 * Add a new limit for Validate-Job using the Print-Job limit as a
4122 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s - using Print-Job's policy.", pol
->name
);
4124 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
4127 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s and no suitable template found.", pol
->name
);
4130 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
4131 op
->op
== IPP_ANY_OPERATION
)
4133 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
4134 op
->op
!= IPP_ANY_OPERATION
)
4137 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
4141 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s - using Pause-Printer's policy.", pol
->name
);
4143 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
4146 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s and no suitable template found.", pol
->name
);
4149 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
4150 op
->op
== IPP_ANY_OPERATION
)
4152 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4153 op
->op
!= IPP_ANY_OPERATION
)
4156 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
4160 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-My-Jobs defined in policy %s - using Send-Document's policy.", pol
->name
);
4162 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
4165 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-My-Jobs defined in policy %s and no suitable template found.", pol
->name
);
4168 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
4169 op
->op
== IPP_ANY_OPERATION
)
4171 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4172 op
->op
!= IPP_ANY_OPERATION
)
4175 * Add a new limit for Close-Job using the Send-Document limit as a
4179 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s - using Send-Document's policy.", pol
->name
);
4181 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
4184 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s and no suitable template found.", pol
->name
);
4187 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
4188 op
->op
== IPP_ANY_OPERATION
)
4190 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4191 op
->op
!= IPP_ANY_OPERATION
)
4194 * Add a new limit for CUPS-Get-Document using the Send-Document
4195 * limit as a template...
4198 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s - using Send-Document's policy.", pol
->name
);
4200 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
4203 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s and no suitable template found.", pol
->name
);
4208 * Verify we have JobPrivateAccess, JobPrivateValues,
4209 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4212 if (!pol
->job_access
)
4214 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4215 cupsdAddString(&(pol
->job_access
), "@OWNER");
4216 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4219 if (!pol
->job_attrs
)
4221 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateValues defined in policy %s - using defaults.", pol
->name
);
4222 cupsdAddString(&(pol
->job_attrs
), "job-name");
4223 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4224 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4225 cupsdAddString(&(pol
->job_attrs
), "phone");
4228 if (!pol
->sub_access
)
4230 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4231 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4232 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4235 if (!pol
->sub_attrs
)
4237 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateValues defined in policy %s - using defaults.", pol
->name
);
4238 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4239 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4240 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4241 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4242 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");