2 * "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $"
4 * Configuration routines for the CUPS scheduler.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddAlias() - Add a host alias.
18 * cupsdCheckPermissions() - Fix the mode and ownership of a file or
20 * cupsdDefaultAuthType() - Get the default AuthType.
21 * cupsdFreeAliases() - Free all of the alias entries.
22 * cupsdReadConfiguration() - Read the cupsd.conf file.
23 * get_address() - Get an address + port number from a line.
24 * get_addr_and_mask() - Get an IP address and netmask.
25 * mime_error_cb() - Log a MIME error.
26 * parse_aaa() - Parse authentication, authorization, and access
28 * parse_fatal_errors() - Parse FatalErrors values in a string.
29 * parse_groups() - Parse system group names in a string.
30 * parse_protocols() - Parse browse protocols in a string.
31 * read_configuration() - Read a configuration file.
32 * read_location() - Read a <Location path> definition.
33 * read_policy() - Read a <Policy name> definition.
34 * set_policy_defaults() - Set default policy values as needed.
38 * Include necessary headers...
44 #include <sys/utsname.h>
49 #endif /* HAVE_LIBPAPER */
53 * Possibly missing network definitions...
57 # define INADDR_NONE 0xffffffff
58 #endif /* !INADDR_NONE */
62 * Configuration variable structure...
67 CUPSD_VARTYPE_INTEGER
, /* Integer option */
68 CUPSD_VARTYPE_STRING
, /* String option */
69 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
70 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
75 const char *name
; /* Name of variable */
76 void *ptr
; /* Pointer to variable */
77 cupsd_vartype_t type
; /* Type (int, string, address) */
85 static int default_auth_type
= CUPSD_AUTH_AUTO
;
86 /* Default AuthType, if not specified */
87 static const cupsd_var_t variables
[] =
89 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
90 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
92 { "BrowseDNSSDRegType", &DNSSDRegType
, CUPSD_VARTYPE_STRING
},
93 #endif /* HAVE_DNSSD */
94 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
95 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
96 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
97 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
98 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
99 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
100 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
101 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
102 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
103 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
104 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
105 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
106 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
107 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
108 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
109 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
110 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
111 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
112 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
113 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
115 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
116 #endif /* HAVE_GSSAPI */
117 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_INTEGER
},
118 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
119 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
120 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
121 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
123 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
124 #endif /* HAVE_LAUNCHD */
125 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
126 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
127 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
128 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
129 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
130 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
146 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
147 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
148 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
149 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
150 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
151 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
152 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
153 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
154 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
155 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
156 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
157 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
158 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
159 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
161 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
162 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
163 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
164 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
165 #endif /* HAVE_SSL */
166 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
167 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
168 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
169 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
170 #ifdef HAVE_AUTHORIZATION_H
171 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
172 #endif /* HAVE_AUTHORIZATION_H */
173 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
174 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
175 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
177 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
180 static const unsigned ones
[4] =
182 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
184 static const unsigned zeros
[4] =
186 0x00000000, 0x00000000, 0x00000000, 0x00000000
194 static http_addrlist_t
*get_address(const char *value
, int defport
);
195 static int get_addr_and_mask(const char *value
, unsigned *ip
,
197 static void mime_error_cb(void *ctx
, const char *message
);
198 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
199 char *value
, int linenum
);
200 static int parse_fatal_errors(const char *s
);
201 static int parse_groups(const char *s
);
202 static int parse_protocols(const char *s
);
203 static int read_configuration(cups_file_t
*fp
);
204 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
205 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
206 static void set_policy_defaults(cupsd_policy_t
*pol
);
210 * 'cupsdAddAlias()' - Add a host alias.
214 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
215 const char *name
) /* I - Name to add */
217 cupsd_alias_t
*a
; /* New alias */
218 size_t namelen
; /* Length of name */
221 namelen
= strlen(name
);
223 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
226 a
->namelen
= namelen
;
227 strcpy(a
->name
, name
); /* OK since a->name is allocated */
229 cupsArrayAdd(aliases
, a
);
234 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
237 int /* O - 0 on success, -1 on error, 1 on warning */
238 cupsdCheckPermissions(
239 const char *filename
, /* I - File/directory name */
240 const char *suffix
, /* I - Additional file/directory name */
241 int mode
, /* I - Permissions */
242 int user
, /* I - Owner */
243 int group
, /* I - Group */
244 int is_dir
, /* I - 1 = directory, 0 = file */
245 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
247 int dir_created
= 0; /* Did we create a directory? */
248 char pathname
[1024]; /* File name with prefix */
249 struct stat fileinfo
; /* Stat buffer */
250 int is_symlink
; /* Is "filename" a symlink? */
254 * Prepend the given root to the filename before testing it...
259 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
264 * See if we can stat the file/directory...
267 if (lstat(filename
, &fileinfo
))
269 if (errno
== ENOENT
&& create_dir
)
272 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
275 if (mkdir(filename
, mode
))
278 cupsdLogMessage(CUPSD_LOG_ERROR
,
279 "Unable to create directory \"%s\" - %s", filename
,
282 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
289 fileinfo
.st_mode
= mode
| S_IFDIR
;
292 return (create_dir
? -1 : 1);
295 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
297 if (stat(filename
, &fileinfo
))
299 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
300 filename
, strerror(errno
));
306 * Make sure it's a regular file or a directory as needed...
309 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
311 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
315 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
318 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
320 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
326 * If the filename is a symlink, do not change permissions (STR #2937)...
333 * Fix owner, group, and mode as needed...
336 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
339 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
342 if (chown(filename
, user
, group
) && !getuid())
345 cupsdLogMessage(CUPSD_LOG_ERROR
,
346 "Unable to change ownership of \"%s\" - %s", filename
,
349 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
356 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
359 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
362 if (chmod(filename
, mode
))
365 cupsdLogMessage(CUPSD_LOG_ERROR
,
366 "Unable to change permissions of \"%s\" - %s", filename
,
369 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
377 * Everything is OK...
385 * 'cupsdDefaultAuthType()' - Get the default AuthType.
387 * When the default_auth_type is "auto", this function tries to get the GSS
388 * credentials for the server. If that succeeds we use Kerberos authentication,
389 * otherwise we do a fallback to Basic authentication against the local user
393 int /* O - Default AuthType value */
394 cupsdDefaultAuthType(void)
397 OM_uint32 major_status
, /* Major status code */
398 minor_status
; /* Minor status code */
399 gss_name_t server_name
; /* Server name */
400 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
401 /* Service name token */
402 char buf
[1024]; /* Service name buffer */
403 #endif /* HAVE_GSSAPI */
407 * If we have already determined the correct default AuthType, use it...
410 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
411 return (default_auth_type
);
416 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
420 if (gss_init_sec_context
== NULL
)
421 return (default_auth_type
= CUPSD_AUTH_BASIC
);
422 # endif /* __APPLE__ */
425 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
426 * that fails we must use Basic...
429 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
432 token
.length
= strlen(buf
);
433 server_name
= GSS_C_NO_NAME
;
434 major_status
= gss_import_name(&minor_status
, &token
,
435 GSS_C_NT_HOSTBASED_SERVICE
,
438 memset(&token
, 0, sizeof(token
));
440 if (GSS_ERROR(major_status
))
442 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
443 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
444 return (default_auth_type
= CUPSD_AUTH_BASIC
);
447 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
449 if (GSS_ERROR(major_status
))
451 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
452 "cupsdDefaultAuthType: gss_display_name(%s) failed",
454 return (default_auth_type
= CUPSD_AUTH_BASIC
);
457 cupsdLogMessage(CUPSD_LOG_DEBUG
,
458 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
459 "credentials for %s...", (char *)token
.value
);
461 ServerCreds
= GSS_C_NO_CREDENTIAL
;
462 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
463 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
464 &ServerCreds
, NULL
, NULL
);
465 if (GSS_ERROR(major_status
))
467 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
468 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
469 (char *)token
.value
);
470 gss_release_name(&minor_status
, &server_name
);
471 gss_release_buffer(&minor_status
, &token
);
472 return (default_auth_type
= CUPSD_AUTH_BASIC
);
475 cupsdLogMessage(CUPSD_LOG_DEBUG
,
476 "cupsdDefaultAuthType: Kerberos credentials acquired "
477 "successfully for %s.", (char *)token
.value
);
479 gss_release_name(&minor_status
, &server_name
);
480 gss_release_buffer(&minor_status
, &token
);
484 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
488 * No Kerberos support compiled in so just use Basic all the time...
491 return (default_auth_type
= CUPSD_AUTH_BASIC
);
492 #endif /* HAVE_GSSAPI */
497 * 'cupsdFreeAliases()' - Free all of the alias entries.
501 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
503 cupsd_alias_t
*a
; /* Current alias */
506 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
508 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
511 cupsArrayDelete(aliases
);
516 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
519 int /* O - 1 on success, 0 otherwise */
520 cupsdReadConfiguration(void)
522 int i
; /* Looping var */
523 cups_file_t
*fp
; /* Configuration file */
524 int status
; /* Return status */
525 char temp
[1024], /* Temporary buffer */
526 mimedir
[1024], /* MIME directory */
527 *slash
; /* Directory separator */
528 cups_lang_t
*language
; /* Language */
529 struct passwd
*user
; /* Default user */
530 struct group
*group
; /* Default group */
531 char *old_serverroot
, /* Old ServerRoot */
532 *old_requestroot
; /* Old RequestRoot */
533 int old_remote_port
; /* Old RemotePort */
534 const char *tmpdir
; /* TMPDIR environment variable */
535 struct stat tmpinfo
; /* Temporary directory info */
536 cupsd_policy_t
*p
; /* Policy */
540 * Save the old root paths...
543 old_serverroot
= NULL
;
544 cupsdSetString(&old_serverroot
, ServerRoot
);
545 old_requestroot
= NULL
;
546 cupsdSetString(&old_requestroot
, RequestRoot
);
549 * Reset the server configuration data...
552 cupsdDeleteAllLocations();
554 cupsdDeleteAllListeners();
556 old_remote_port
= RemotePort
;
563 cupsdFreeAliases(ServerAlias
);
566 cupsdClearString(&ServerName
);
567 cupsdClearString(&ServerAdmin
);
568 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
569 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
570 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
571 cupsdSetString(&DataDir
, CUPS_DATADIR
);
572 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
573 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
574 cupsdClearString(&ErrorLog
);
575 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
576 cupsdSetString(&PageLogFormat
,
577 "%p %u %j %T %P %C %{job-billing} "
578 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
579 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
580 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
581 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
582 cupsdSetString(&RemoteRoot
, "remroot");
583 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
585 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
587 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
588 PrintcapFormat
= PRINTCAP_SOLARIS
;
589 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
590 "/Library/Preferences/org.cups.printers.plist"))
591 PrintcapFormat
= PRINTCAP_PLIST
;
593 PrintcapFormat
= PRINTCAP_BSD
;
595 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
596 if ((slash
= strrchr(temp
, '/')) != NULL
)
599 cupsdSetString(&ServerRoot
, temp
);
601 cupsdClearString(&Classification
);
602 ClassifyOverride
= 0;
606 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
608 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
609 cupsdSetString(&ServerKey
, "ssl/server.key");
610 # endif /* HAVE_CDSASSL */
611 #endif /* HAVE_SSL */
613 language
= cupsLangDefault();
615 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
616 cupsdSetString(&DefaultLanguage
, "en");
618 cupsdSetString(&DefaultLanguage
, language
->language
);
620 cupsdClearString(&DefaultPaperSize
);
622 cupsdSetString(&RIPCache
, "128m");
624 cupsdSetString(&TempDir
, NULL
);
627 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
631 OM_uint32 minor_status
; /* Minor status code */
633 gss_release_cred(&minor_status
, &ServerCreds
);
638 ServerCreds
= GSS_C_NO_CREDENTIAL
;
639 #endif /* HAVE_GSSAPI */
642 * Find the default user...
645 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
650 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
651 * complement number...)
660 * Find the default group...
663 group
= getgrnam(CUPS_DEFAULT_GROUP
);
667 Group
= group
->gr_gid
;
671 * Fallback to group "nobody"...
674 group
= getgrnam("nobody");
678 Group
= group
->gr_gid
;
682 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
683 * complement number...)
694 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
695 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
696 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
697 default_auth_type
= CUPSD_AUTH_BASIC
;
699 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
700 SSLOptions
= CUPSD_SSL_NONE
;
701 #endif /* HAVE_SSL */
702 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
703 JobKillDelay
= DEFAULT_TIMEOUT
;
705 JobRetryInterval
= 300;
710 HostNameLookups
= FALSE
;
712 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
713 ListenBackLog
= SOMAXCONN
;
714 LogDebugHistory
= 200;
715 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
716 LogLevel
= CUPSD_LOG_WARN
;
717 LogTimeFormat
= CUPSD_TIME_STANDARD
;
719 MaxClientsPerHost
= 0;
720 MaxLogSize
= 1024 * 1024;
722 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
723 ReloadTimeout
= DEFAULT_KEEPALIVE
;
724 RootCertDuration
= 300;
725 Timeout
= DEFAULT_TIMEOUT
;
727 WebInterface
= CUPS_DEFAULT_WEBIF
;
729 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
731 Browsing
= CUPS_DEFAULT_BROWSING
;
732 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
735 cupsdSetString(&DNSSDRegType
, "_ipp._tcp,_cups");
736 #endif /* HAVE_DNSSD */
738 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
739 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
741 cupsdSetString(&ErrorPolicy
, "stop-printer");
743 JobHistory
= DEFAULT_HISTORY
;
744 JobFiles
= DEFAULT_FILES
;
749 MaxJobsPerPrinter
= 0;
750 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
751 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
753 cupsdDeleteAllPolicies();
754 cupsdClearString(&DefaultPolicy
);
756 #ifdef HAVE_AUTHORIZATION_H
757 cupsdClearString(&SystemGroupAuthKey
);
758 #endif /* HAVE_AUTHORIZATION_H */
760 MaxSubscriptions
= 100;
761 MaxSubscriptionsPerJob
= 0;
762 MaxSubscriptionsPerPrinter
= 0;
763 MaxSubscriptionsPerUser
= 0;
764 DefaultLeaseDuration
= 86400;
765 MaxLeaseDuration
= 0;
769 #endif /* HAVE_LAUNCHD */
772 * Setup environment variables...
778 * Read the configuration file...
781 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
784 status
= read_configuration(fp
);
792 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
796 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
797 RemotePort
? "enabled" : "disabled");
800 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
803 * See if the ServerName is an IP address...
809 ServerAlias
= cupsArrayNew(NULL
, NULL
);
811 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
815 if (gethostname(temp
, sizeof(temp
)))
817 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
819 strlcpy(temp
, "localhost", sizeof(temp
));
822 cupsdSetString(&ServerName
, temp
);
825 ServerAlias
= cupsArrayNew(NULL
, NULL
);
827 cupsdAddAlias(ServerAlias
, temp
);
828 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
830 if (HostNameLookups
|| RemotePort
)
832 struct hostent
*host
; /* Host entry to get FQDN */
834 if ((host
= gethostbyname(temp
)) != NULL
)
836 if (_cups_strcasecmp(temp
, host
->h_name
))
838 cupsdSetString(&ServerName
, host
->h_name
);
839 cupsdAddAlias(ServerAlias
, host
->h_name
);
840 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
846 for (i
= 0; host
->h_aliases
[i
]; i
++)
847 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
849 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
850 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
858 * Make sure we have the base hostname added as an alias, too!
861 if ((slash
= strchr(temp
, '.')) != NULL
)
864 cupsdAddAlias(ServerAlias
, temp
);
865 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
869 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
871 ServerNameIsIP
= !*slash
;
874 * Make sure ServerAdmin is initialized...
878 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
881 * Use the default system group if none was supplied in cupsd.conf...
884 if (NumSystemGroups
== 0)
886 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
889 * Find the group associated with GID 0...
896 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
898 cupsdSetString(&SystemGroups
[0], "unknown");
900 SystemGroupIDs
[0] = 0;
906 * Open the system log for cupsd if necessary...
910 if (!strcmp(AccessLog
, "syslog") ||
911 !strcmp(ErrorLog
, "syslog") ||
912 !strcmp(PageLog
, "syslog"))
913 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
914 #endif /* HAVE_VSYSLOG */
917 * Make sure each of the log files exists and gets rotated as necessary...
920 if (strcmp(AccessLog
, "syslog"))
921 cupsdCheckLogFile(&AccessFile
, AccessLog
);
923 if (strcmp(ErrorLog
, "syslog"))
924 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
926 if (strcmp(PageLog
, "syslog"))
927 cupsdCheckLogFile(&PageFile
, PageLog
);
930 * Log the configuration file that was used...
933 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
937 * Validate the Group and SystemGroup settings - they cannot be the same,
938 * otherwise the CGI programs will be able to authenticate as root without
944 for (i
= 0; i
< NumSystemGroups
; i
++)
945 if (Group
== SystemGroupIDs
[i
])
948 if (i
< NumSystemGroups
)
951 * Log the error and reset the group to a safe value...
954 cupsdLogMessage(CUPSD_LOG_NOTICE
,
955 "Group and SystemGroup cannot use the same groups.");
956 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
958 group
= getgrnam("nobody");
962 Group
= group
->gr_gid
;
966 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
967 * complement number...)
976 * Check that we have at least one listen/port line; if not, report this
977 * as an error and exit!
980 if (cupsArrayCount(Listeners
) == 0)
986 cupsdLogMessage(CUPSD_LOG_EMERG
,
987 "No valid Listen or Port lines were found in the "
988 "configuration file.");
994 cupsdEndProcess(getpid(), 0);
998 * Set the default locale using the language and charset...
1001 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1004 * Update all relative filenames to include the full path from ServerRoot...
1007 if (DocumentRoot
[0] != '/')
1008 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1010 if (RequestRoot
[0] != '/')
1011 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1013 if (ServerBin
[0] != '/')
1014 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1016 if (StateDir
[0] != '/')
1017 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1019 if (CacheDir
[0] != '/')
1020 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1023 if (ServerCertificate
[0] != '/')
1024 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
1026 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
1027 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
1029 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1032 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
1033 if (ServerKey
[0] != '/')
1034 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
1036 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
1037 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
1038 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1040 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
1041 #endif /* HAVE_SSL */
1044 * Make sure that directories and config files are owned and
1045 * writable by the user and group in the cupsd.conf file...
1048 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1050 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1052 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
1054 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1056 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1058 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1059 SystemGroupIDs
[0], 1, 1) < 0 ||
1060 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1062 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1064 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1066 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
1068 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1070 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1072 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1073 Group
, 0, 0) < 0) &&
1074 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1078 * Update TempDir to the default if it hasn't been set already...
1084 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1085 strncmp(tmpdir
, "/private/tmp", 12))
1087 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1088 #endif /* __APPLE__ */
1091 * TMPDIR is defined, see if it is OK for us to use...
1094 if (stat(tmpdir
, &tmpinfo
))
1095 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1096 tmpdir
, strerror(errno
));
1097 else if (!S_ISDIR(tmpinfo
.st_mode
))
1098 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1100 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1101 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1102 !(tmpinfo
.st_mode
& S_IWOTH
))
1103 cupsdLogMessage(CUPSD_LOG_ERROR
,
1104 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1106 cupsdSetString(&TempDir
, tmpdir
);
1111 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1113 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1118 * Make sure the temporary directory has the right permissions...
1121 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1125 * Update ownership and permissions if the CUPS temp directory
1126 * is under the spool directory or does not exist...
1129 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1130 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1135 * Update environment variables...
1141 * Update default paper size setting as needed...
1144 if (!DefaultPaperSize
)
1146 #ifdef HAVE_LIBPAPER
1147 char *paper_result
; /* Paper size name from libpaper */
1149 if ((paper_result
= systempapername()) != NULL
)
1150 cupsdSetString(&DefaultPaperSize
, paper_result
);
1152 #endif /* HAVE_LIBPAPER */
1153 if (!DefaultLanguage
||
1154 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1155 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1156 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1157 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1158 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1159 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1160 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1163 * These are the only locales that will default to "letter" size...
1166 cupsdSetString(&DefaultPaperSize
, "Letter");
1169 cupsdSetString(&DefaultPaperSize
, "A4");
1173 * Update classification setting as needed...
1176 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1177 cupsdClearString(&Classification
);
1180 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1183 * Check the MaxClients setting, and then allocate memory for it...
1186 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1189 cupsdLogMessage(CUPSD_LOG_INFO
,
1190 "MaxClients limited to 1/3 (%d) of the file descriptor "
1192 MaxFDs
/ 3, MaxFDs
);
1194 MaxClients
= MaxFDs
/ 3;
1197 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1201 * Check the MaxActiveJobs setting; limit to 1/3 the available
1202 * file descriptors, since we need a pipe for each job...
1205 if (MaxActiveJobs
> (MaxFDs
/ 3))
1206 MaxActiveJobs
= MaxFDs
/ 3;
1209 * Update the MaxClientsPerHost value, as needed...
1212 if (MaxClientsPerHost
<= 0)
1213 MaxClientsPerHost
= MaxClients
;
1215 if (MaxClientsPerHost
> MaxClients
)
1216 MaxClientsPerHost
= MaxClients
;
1218 cupsdLogMessage(CUPSD_LOG_INFO
,
1219 "Allowing up to %d client connections per host.",
1223 * Update the default policy, as needed...
1227 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1229 DefaultPolicyPtr
= NULL
;
1231 if (!DefaultPolicyPtr
)
1233 cupsd_location_t
*po
; /* New policy operation */
1237 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1240 cupsdSetString(&DefaultPolicy
, "default");
1242 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1243 cupsdLogMessage(CUPSD_LOG_INFO
,
1244 "Using policy \"default\" as the default.");
1247 cupsdLogMessage(CUPSD_LOG_INFO
,
1248 "Creating CUPS default administrative policy:");
1250 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1252 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1254 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1255 cupsdAddString(&(p
->job_access
), "@OWNER");
1256 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1258 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1259 cupsdAddString(&(p
->job_attrs
), "job-name");
1260 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1261 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1263 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1264 cupsdAddString(&(p
->sub_access
), "@OWNER");
1265 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1267 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1268 cupsdAddString(&(p
->job_attrs
), "notify-events");
1269 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1270 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1271 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1272 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1274 cupsdLogMessage(CUPSD_LOG_INFO
,
1275 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1276 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1278 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1279 po
->order_type
= CUPSD_AUTH_ALLOW
;
1281 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1282 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1283 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1285 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1287 cupsdLogMessage(CUPSD_LOG_INFO
,
1288 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1289 "Release-Job Restart-Job Purge-Jobs "
1290 "Set-Job-Attributes Create-Job-Subscription "
1291 "Renew-Subscription Cancel-Subscription "
1292 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1293 "Suspend-Current-Job Resume-Job "
1294 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1295 "CUPS-Authenticate-Job CUPS-Get-Document>");
1296 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1298 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1299 po
->order_type
= CUPSD_AUTH_ALLOW
;
1300 po
->level
= CUPSD_AUTH_USER
;
1302 cupsdAddName(po
, "@OWNER");
1303 cupsdAddName(po
, "@SYSTEM");
1304 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1306 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1307 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1308 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1309 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1310 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1311 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1312 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1313 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1314 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1315 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1316 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1317 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1318 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1319 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1320 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1321 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1322 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1323 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1324 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1325 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1327 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1329 cupsdLogMessage(CUPSD_LOG_INFO
,
1330 "<Limit Pause-Printer Resume-Printer "
1331 "Set-Printer-Attributes Enable-Printer "
1332 "Disable-Printer Pause-Printer-After-Current-Job "
1333 "Hold-New-Jobs Release-Held-New-Jobs "
1334 "Deactivate-Printer Activate-Printer Restart-Printer "
1335 "Shutdown-Printer Startup-Printer Promote-Job "
1336 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1337 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1338 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1339 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1340 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1342 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1343 po
->order_type
= CUPSD_AUTH_ALLOW
;
1344 po
->type
= CUPSD_AUTH_DEFAULT
;
1345 po
->level
= CUPSD_AUTH_USER
;
1347 cupsdAddName(po
, "@SYSTEM");
1348 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1350 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1351 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1352 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1353 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1354 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1355 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1356 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1357 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1358 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1359 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1360 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1361 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1362 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1363 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1364 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1365 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1366 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1367 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1368 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1369 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1370 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1371 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1373 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1375 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1376 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1378 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1379 po
->order_type
= CUPSD_AUTH_ALLOW
;
1381 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1382 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1386 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1387 cupsArrayCount(Policies
));
1388 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1390 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1391 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1392 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1395 * If we are doing a full reload or the server root has changed, flush
1396 * the jobs, printers, etc. and start from scratch...
1399 if (NeedReload
== RELOAD_ALL
||
1400 old_remote_port
!= RemotePort
||
1401 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1402 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1404 mime_type_t
*type
; /* Current type */
1405 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1406 /* MIME type name */
1409 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1412 * Free all memory...
1415 cupsdDeleteAllSubscriptions();
1417 cupsdDeleteAllPrinters();
1419 DefaultPrinter
= NULL
;
1421 if (MimeDatabase
!= NULL
)
1422 mimeDelete(MimeDatabase
);
1426 for (i
= 0; i
< NumMimeTypes
; i
++)
1427 _cupsStrFree(MimeTypes
[i
]);
1433 * Read the MIME type and conversion database...
1436 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1437 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1439 MimeDatabase
= mimeNew();
1440 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1442 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1443 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1444 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1445 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1449 cupsdLogMessage(CUPSD_LOG_EMERG
,
1450 "Unable to load MIME database from \"%s\" or \"%s\".",
1451 mimedir
, ServerRoot
);
1452 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1456 cupsdLogMessage(CUPSD_LOG_INFO
,
1457 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1458 "%d filters...", mimedir
, ServerRoot
,
1459 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1462 * Create a list of MIME types for the document-format-supported
1466 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1467 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1470 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1472 cupsdLogMessage(CUPSD_LOG_ERROR
,
1473 "Unable to allocate memory for %d MIME types.",
1479 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1481 i
++, type
= mimeNextType(MimeDatabase
))
1483 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1485 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1488 if (i
< NumMimeTypes
)
1489 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1492 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1494 mime_filter_t
*filter
; /* Current filter */
1497 for (type
= mimeFirstType(MimeDatabase
);
1499 type
= mimeNextType(MimeDatabase
))
1500 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1501 type
->super
, type
->type
);
1503 for (filter
= mimeFirstFilter(MimeDatabase
);
1505 filter
= mimeNextFilter(MimeDatabase
))
1506 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1507 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1508 filter
->src
->super
, filter
->src
->type
,
1509 filter
->dst
->super
, filter
->dst
->type
,
1510 filter
->cost
, filter
->filter
);
1517 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1518 cupsdLoadBanners(temp
);
1521 * Load printers and classes...
1524 cupsdLoadAllPrinters();
1525 cupsdLoadAllClasses();
1527 cupsdCreateCommonData();
1530 * Update the printcap file as needed...
1533 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1534 cupsdWritePrintcap();
1537 * Load queued jobs...
1543 * Load subscriptions...
1546 cupsdLoadAllSubscriptions();
1548 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1553 * Not a full reload, so recreate the common printer attributes...
1556 cupsdCreateCommonData();
1559 * Update all printers as needed...
1562 cupsdUpdatePrinters();
1563 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1565 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1569 * Reset the reload state...
1572 NeedReload
= RELOAD_NONE
;
1574 cupsdClearString(&old_serverroot
);
1575 cupsdClearString(&old_requestroot
);
1582 * 'get_address()' - Get an address + port number from a line.
1585 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1586 get_address(const char *value
, /* I - Value string */
1587 int defport
) /* I - Default port */
1589 char buffer
[1024], /* Hostname + port number buffer */
1590 defpname
[255], /* Default port name */
1591 *hostname
, /* Hostname or IP */
1592 *portname
; /* Port number or name */
1593 http_addrlist_t
*addrlist
; /* Address list */
1597 * Check for an empty value...
1602 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1607 * Grab a hostname and port number; if there is no colon and the port name
1608 * is only digits, then we have a port number by itself...
1611 strlcpy(buffer
, value
, sizeof(buffer
));
1613 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1620 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1625 * Use the default port...
1628 sprintf(defpname
, "%d", defport
);
1629 portname
= defpname
;
1635 * The buffer contains just a port number...
1643 if (hostname
&& !strcmp(hostname
, "*"))
1647 * Now lookup the address using httpAddrGetList()...
1650 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1651 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1652 hostname
? hostname
: "(nil)");
1659 * 'get_addr_and_mask()' - Get an IP address and netmask.
1662 static int /* O - 1 on success, 0 on failure */
1663 get_addr_and_mask(const char *value
, /* I - String from config file */
1664 unsigned *ip
, /* O - Address value */
1665 unsigned *mask
) /* O - Mask value */
1667 int i
, j
, /* Looping vars */
1668 family
, /* Address family */
1669 ipcount
; /* Count of fields in address */
1670 unsigned ipval
; /* Value */
1671 const char *maskval
, /* Pointer to start of mask value */
1672 *ptr
, /* Pointer into value */
1677 * Get the address...
1680 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1681 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1683 if ((maskval
= strchr(value
, '/')) != NULL
)
1686 maskval
= value
+ strlen(value
);
1690 * Check for an IPv6 address...
1696 * Parse hexadecimal IPv6/IPv4 address...
1701 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1705 else if (!strncmp(ptr
, "::", 2))
1707 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1709 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1714 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1717 * Read IPv4 dotted quad...
1720 unsigned val
[4] = { 0, 0, 0, 0 };
1721 /* IPv4 address values */
1723 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1727 * Range check the IP numbers...
1730 for (i
= 0; i
< ipcount
; i
++)
1735 * Merge everything into a 32-bit IPv4 address in ip[3]...
1738 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1741 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1744 * If the leading words are all 0's then this is an IPv4 address...
1747 if (!val
[0] && !val
[1] && !val
[2])
1750 while (isdigit(*ptr
& 255) || *ptr
== '.')
1754 else if (isxdigit(*ptr
& 255))
1756 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1758 if (*ptr
== ':' && ptr
[1] != ':')
1767 ip
[i
/ 2] |= ipval
<< 16;
1778 if (*ptr
&& *ptr
!= '/')
1782 #endif /* AF_INET6 */
1785 * Parse dotted-decimal IPv4 address...
1788 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1792 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1795 * Range check the IP numbers...
1798 for (i
= 0; i
< ipcount
; i
++)
1803 * Merge everything into a 32-bit IPv4 address in ip[3]...
1806 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1809 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1815 * Get the netmask value(s)...
1818 memset(mask
, 0, sizeof(unsigned) * 4);
1820 if (strchr(maskval
, '.'))
1823 * Get dotted-decimal mask...
1826 if (family
!= AF_INET
)
1829 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1833 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1834 mask
[0] = mask
[1] = mask
[2] = 0;
1839 * Get address/bits format...
1845 if (family
== AF_INET6
)
1853 mask
[0] = 0xffffffff;
1855 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1858 mask
[1] = 0xffffffff;
1862 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1865 mask
[2] = 0xffffffff;
1869 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1872 mask
[3] = 0xffffffff;
1876 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1879 #endif /* AF_INET6 */
1884 mask
[0] = 0xffffffff;
1885 mask
[1] = 0xffffffff;
1886 mask
[2] = 0xffffffff;
1889 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1891 mask
[3] = 0xffffffff;
1896 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1897 "get_addr_and_mask(value=\"%s\", "
1898 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1899 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1903 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1906 if ((ip
[0] & ~mask
[0]) != 0 ||
1907 (ip
[1] & ~mask
[1]) != 0 ||
1908 (ip
[2] & ~mask
[2]) != 0 ||
1909 (ip
[3] & ~mask
[3]) != 0)
1917 * 'mime_error_cb()' - Log a MIME error.
1921 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
1922 const char *message
) /* I - Message */
1926 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
1931 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1934 static int /* O - 1 on success, 0 on failure */
1935 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1936 char *line
, /* I - Line from file */
1937 char *value
, /* I - Start of value data */
1938 int linenum
) /* I - Current line number */
1940 char *valptr
; /* Pointer into value */
1941 unsigned ip
[4], /* IP address components */
1942 mask
[4]; /* IP netmask components */
1945 if (!_cups_strcasecmp(line
, "Encryption"))
1948 * "Encryption xxx" - set required encryption level...
1951 if (!_cups_strcasecmp(value
, "never"))
1952 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1953 else if (!_cups_strcasecmp(value
, "always"))
1955 cupsdLogMessage(CUPSD_LOG_ERROR
,
1956 "Encryption value \"%s\" on line %d is invalid in this "
1957 "context. Using \"required\" instead.", value
, linenum
);
1959 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1961 else if (!_cups_strcasecmp(value
, "required"))
1962 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1963 else if (!_cups_strcasecmp(value
, "ifrequested"))
1964 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1967 cupsdLogMessage(CUPSD_LOG_ERROR
,
1968 "Unknown Encryption value %s on line %d.", value
, linenum
);
1972 else if (!_cups_strcasecmp(line
, "Order"))
1975 * "Order Deny,Allow" or "Order Allow,Deny"...
1978 if (!_cups_strncasecmp(value
, "deny", 4))
1979 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1980 else if (!_cups_strncasecmp(value
, "allow", 5))
1981 loc
->order_type
= CUPSD_AUTH_DENY
;
1984 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1989 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
1992 * Allow [From] host/ip...
1993 * Deny [From] host/ip...
1998 if (!_cups_strncasecmp(value
, "from", 4))
2001 * Strip leading "from"...
2006 while (_cups_isspace(*value
))
2014 * Find the end of the value...
2017 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2019 while (_cups_isspace(*valptr
))
2023 * Figure out what form the allow/deny address takes:
2034 * nnn.nnn.nnn.nnn/mm
2035 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2038 if (!_cups_strcasecmp(value
, "all"))
2044 if (!_cups_strcasecmp(line
, "Allow"))
2045 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2047 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2049 else if (!_cups_strcasecmp(value
, "none"))
2055 if (!_cups_strcasecmp(line
, "Allow"))
2056 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2058 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2061 else if (value
[0] == '*' || value
[0] == '.' ||
2062 (!isdigit(value
[0] & 255) && value
[0] != '['))
2064 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2065 #endif /* AF_INET6 */
2068 * Host or domain name...
2071 if (value
[0] == '*')
2074 if (!_cups_strcasecmp(line
, "Allow"))
2075 cupsdAddNameMask(&(loc
->allow
), value
);
2077 cupsdAddNameMask(&(loc
->deny
), value
);
2082 * One of many IP address forms...
2085 if (!get_addr_and_mask(value
, ip
, mask
))
2087 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2092 if (!_cups_strcasecmp(line
, "Allow"))
2093 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2095 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2099 * Advance to next value...
2105 else if (!_cups_strcasecmp(line
, "AuthType"))
2108 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2111 if (!_cups_strcasecmp(value
, "none"))
2113 loc
->type
= CUPSD_AUTH_NONE
;
2114 loc
->level
= CUPSD_AUTH_ANON
;
2116 else if (!_cups_strcasecmp(value
, "basic"))
2118 loc
->type
= CUPSD_AUTH_BASIC
;
2120 if (loc
->level
== CUPSD_AUTH_ANON
)
2121 loc
->level
= CUPSD_AUTH_USER
;
2123 else if (!_cups_strcasecmp(value
, "digest"))
2125 loc
->type
= CUPSD_AUTH_DIGEST
;
2127 if (loc
->level
== CUPSD_AUTH_ANON
)
2128 loc
->level
= CUPSD_AUTH_USER
;
2130 else if (!_cups_strcasecmp(value
, "basicdigest"))
2132 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
2134 if (loc
->level
== CUPSD_AUTH_ANON
)
2135 loc
->level
= CUPSD_AUTH_USER
;
2137 else if (!_cups_strcasecmp(value
, "default"))
2139 loc
->type
= CUPSD_AUTH_DEFAULT
;
2141 if (loc
->level
== CUPSD_AUTH_ANON
)
2142 loc
->level
= CUPSD_AUTH_USER
;
2145 else if (!_cups_strcasecmp(value
, "negotiate"))
2147 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2149 if (loc
->level
== CUPSD_AUTH_ANON
)
2150 loc
->level
= CUPSD_AUTH_USER
;
2152 #endif /* HAVE_GSSAPI */
2155 cupsdLogMessage(CUPSD_LOG_WARN
,
2156 "Unknown authorization type %s on line %d.",
2161 else if (!_cups_strcasecmp(line
, "AuthClass"))
2164 * AuthClass anonymous, user, system, group
2167 if (!_cups_strcasecmp(value
, "anonymous"))
2169 loc
->type
= CUPSD_AUTH_NONE
;
2170 loc
->level
= CUPSD_AUTH_ANON
;
2172 cupsdLogMessage(CUPSD_LOG_WARN
,
2173 "\"AuthClass %s\" is deprecated; consider removing "
2177 else if (!_cups_strcasecmp(value
, "user"))
2179 loc
->level
= CUPSD_AUTH_USER
;
2181 cupsdLogMessage(CUPSD_LOG_WARN
,
2182 "\"AuthClass %s\" is deprecated; consider using "
2183 "\"Require valid-user\" on line %d.",
2186 else if (!_cups_strcasecmp(value
, "group"))
2188 loc
->level
= CUPSD_AUTH_GROUP
;
2190 cupsdLogMessage(CUPSD_LOG_WARN
,
2191 "\"AuthClass %s\" is deprecated; consider using "
2192 "\"Require user @groupname\" on line %d.",
2195 else if (!_cups_strcasecmp(value
, "system"))
2197 loc
->level
= CUPSD_AUTH_GROUP
;
2199 cupsdAddName(loc
, "@SYSTEM");
2201 cupsdLogMessage(CUPSD_LOG_WARN
,
2202 "\"AuthClass %s\" is deprecated; consider using "
2203 "\"Require user @SYSTEM\" on line %d.",
2208 cupsdLogMessage(CUPSD_LOG_WARN
,
2209 "Unknown authorization class %s on line %d.",
2214 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2216 cupsdAddName(loc
, value
);
2218 cupsdLogMessage(CUPSD_LOG_WARN
,
2219 "\"AuthGroupName %s\" directive is deprecated; consider "
2220 "using \"Require user @%s\" on line %d.",
2221 value
, value
, linenum
);
2223 else if (!_cups_strcasecmp(line
, "Require"))
2226 * Apache synonym for AuthClass and AuthGroupName...
2230 * Require valid-user
2231 * Require group names
2232 * Require user names
2235 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2240 if (!_cups_strcasecmp(value
, "valid-user") ||
2241 !_cups_strcasecmp(value
, "user"))
2242 loc
->level
= CUPSD_AUTH_USER
;
2243 else if (!_cups_strcasecmp(value
, "group"))
2244 loc
->level
= CUPSD_AUTH_GROUP
;
2247 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2253 * Get the list of names from the line...
2256 for (value
= valptr
; *value
;)
2258 while (_cups_isspace(*value
))
2261 #ifdef HAVE_AUTHORIZATION_H
2262 if (!strncmp(value
, "@AUTHKEY(", 9))
2265 * Grab "@AUTHKEY(name)" value...
2268 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2274 #endif /* HAVE_AUTHORIZATION_H */
2275 if (*value
== '\"' || *value
== '\'')
2278 * Grab quoted name...
2281 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2288 * Grab literal name.
2291 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2297 cupsdAddName(loc
, value
);
2299 for (value
= valptr
; _cups_isspace(*value
); value
++);
2302 else if (!_cups_strcasecmp(line
, "Satisfy"))
2304 if (!_cups_strcasecmp(value
, "all"))
2305 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2306 else if (!_cups_strcasecmp(value
, "any"))
2307 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2310 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2323 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2326 static int /* O - FatalErrors bits */
2327 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2329 int fatal
; /* FatalErrors bits */
2330 char value
[1024], /* Value string */
2331 *valstart
, /* Pointer into value */
2332 *valend
; /* End of value */
2336 * Empty FatalErrors line yields NULL pointer...
2340 return (CUPSD_FATAL_NONE
);
2343 * Loop through the value string,...
2346 strlcpy(value
, s
, sizeof(value
));
2348 fatal
= CUPSD_FATAL_NONE
;
2350 for (valstart
= value
; *valstart
;)
2353 * Get the current space/comma-delimited kind name...
2356 for (valend
= valstart
; *valend
; valend
++)
2357 if (_cups_isspace(*valend
) || *valend
== ',')
2364 * Add the error to the bitmask...
2367 if (!_cups_strcasecmp(valstart
, "all"))
2368 fatal
= CUPSD_FATAL_ALL
;
2369 else if (!_cups_strcasecmp(valstart
, "browse"))
2370 fatal
|= CUPSD_FATAL_BROWSE
;
2371 else if (!_cups_strcasecmp(valstart
, "-browse"))
2372 fatal
&= ~CUPSD_FATAL_BROWSE
;
2373 else if (!_cups_strcasecmp(valstart
, "config"))
2374 fatal
|= CUPSD_FATAL_CONFIG
;
2375 else if (!_cups_strcasecmp(valstart
, "-config"))
2376 fatal
&= ~CUPSD_FATAL_CONFIG
;
2377 else if (!_cups_strcasecmp(valstart
, "listen"))
2378 fatal
|= CUPSD_FATAL_LISTEN
;
2379 else if (!_cups_strcasecmp(valstart
, "-listen"))
2380 fatal
&= ~CUPSD_FATAL_LISTEN
;
2381 else if (!_cups_strcasecmp(valstart
, "log"))
2382 fatal
|= CUPSD_FATAL_LOG
;
2383 else if (!_cups_strcasecmp(valstart
, "-log"))
2384 fatal
&= ~CUPSD_FATAL_LOG
;
2385 else if (!_cups_strcasecmp(valstart
, "permissions"))
2386 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2387 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2388 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2389 else if (_cups_strcasecmp(valstart
, "none"))
2390 cupsdLogMessage(CUPSD_LOG_ERROR
,
2391 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2393 for (valstart
= valend
; *valstart
; valstart
++)
2394 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2403 * 'parse_groups()' - Parse system group names in a string.
2406 static int /* O - 1 on success, 0 on failure */
2407 parse_groups(const char *s
) /* I - Space-delimited groups */
2409 int status
; /* Return status */
2410 char value
[1024], /* Value string */
2411 *valstart
, /* Pointer into value */
2412 *valend
, /* End of value */
2413 quote
; /* Quote character */
2414 struct group
*group
; /* Group */
2418 * Make a copy of the string and parse out the groups...
2421 strlcpy(value
, s
, sizeof(value
));
2426 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2428 if (*valstart
== '\'' || *valstart
== '\"')
2431 * Scan quoted name...
2434 quote
= *valstart
++;
2436 for (valend
= valstart
; *valend
; valend
++)
2437 if (*valend
== quote
)
2443 * Scan space or comma-delimited name...
2446 for (valend
= valstart
; *valend
; valend
++)
2447 if (_cups_isspace(*valend
) || *valend
== ',')
2454 group
= getgrnam(valstart
);
2457 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2458 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2469 while (*valstart
== ',' || _cups_isspace(*valstart
))
2478 * 'parse_protocols()' - Parse browse protocols in a string.
2481 static int /* O - Browse protocol bits */
2482 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2484 int protocols
; /* Browse protocol bits */
2485 char value
[1024], /* Value string */
2486 *valstart
, /* Pointer into value */
2487 *valend
; /* End of value */
2491 * Empty protocol line yields NULL pointer...
2498 * Loop through the value string,...
2501 strlcpy(value
, s
, sizeof(value
));
2505 for (valstart
= value
; *valstart
;)
2508 * Get the current space/comma-delimited protocol name...
2511 for (valend
= valstart
; *valend
; valend
++)
2512 if (_cups_isspace(*valend
) || *valend
== ',')
2519 * Add the protocol to the bitmask...
2522 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2523 !_cups_strcasecmp(valstart
, "dns-sd") ||
2524 !_cups_strcasecmp(valstart
, "bonjour"))
2525 protocols
|= BROWSE_DNSSD
;
2526 else if (!_cups_strcasecmp(valstart
, "all"))
2527 protocols
|= BROWSE_ALL
;
2528 else if (_cups_strcasecmp(valstart
, "none"))
2529 cupsdLogMessage(CUPSD_LOG_ERROR
,
2530 "Unknown browse protocol \"%s\" ignored.", valstart
);
2532 for (valstart
= valend
; *valstart
; valstart
++)
2533 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2542 * 'read_configuration()' - Read a configuration file.
2545 static int /* O - 1 on success, 0 on failure */
2546 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2548 int i
; /* Looping var */
2549 int linenum
; /* Current line number */
2550 char line
[HTTP_MAX_BUFFER
],
2551 /* Line from file */
2552 temp
[HTTP_MAX_BUFFER
],
2553 /* Temporary buffer for value */
2554 *value
, /* Pointer to value */
2555 *valueptr
; /* Pointer into value */
2556 int valuelen
; /* Length of value */
2557 cupsd_var_t
const *var
; /* Current variable */
2558 http_addrlist_t
*addrlist
, /* Address list */
2559 *addr
; /* Current address */
2560 cups_file_t
*incfile
; /* Include file */
2561 char incname
[1024]; /* Include filename */
2562 struct group
*group
; /* Group */
2566 * Loop through each line in the file...
2571 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2574 * Decode the directive...
2577 if (!_cups_strcasecmp(line
, "Include") && value
)
2583 if (value
[0] == '/')
2584 strlcpy(incname
, value
, sizeof(incname
));
2586 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2588 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2589 cupsdLogMessage(CUPSD_LOG_ERROR
,
2590 "Unable to include config file \"%s\" - %s",
2591 incname
, strerror(errno
));
2594 read_configuration(incfile
);
2595 cupsFileClose(incfile
);
2598 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2604 linenum
= read_location(fp
, value
, linenum
);
2608 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2614 linenum
= read_policy(fp
, value
, linenum
);
2618 else if (!_cups_strcasecmp(line
, "FatalErrors"))
2619 FatalErrors
= parse_fatal_errors(value
);
2620 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2622 JobRetryInterval
= atoi(value
);
2623 cupsdLogMessage(CUPSD_LOG_WARN
,
2624 "FaxRetryInterval is deprecated; use "
2625 "JobRetryInterval on line %d.", linenum
);
2627 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2629 JobRetryLimit
= atoi(value
);
2630 cupsdLogMessage(CUPSD_LOG_WARN
,
2631 "FaxRetryLimit is deprecated; use "
2632 "JobRetryLimit on line %d.", linenum
);
2634 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
2636 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
2637 #endif /* HAVE_SSL */
2641 * Add listening address(es) to the list...
2644 cupsd_listener_t
*lis
; /* New listeners array */
2648 * Get the address list...
2651 addrlist
= get_address(value
, IPP_PORT
);
2655 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2661 * Add each address...
2664 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2667 * See if this address is already present...
2670 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2672 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2673 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2674 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2679 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2680 cupsdLogMessage(CUPSD_LOG_WARN
,
2681 "Duplicate listen address \"%s\" ignored.", temp
);
2686 * Allocate another listener...
2690 Listeners
= cupsArrayNew(NULL
, NULL
);
2694 cupsdLogMessage(CUPSD_LOG_ERROR
,
2695 "Unable to allocate %s at line %d - %s.",
2696 line
, linenum
, strerror(errno
));
2700 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2702 cupsdLogMessage(CUPSD_LOG_ERROR
,
2703 "Unable to allocate %s at line %d - %s.",
2704 line
, linenum
, strerror(errno
));
2708 cupsArrayAdd(Listeners
, lis
);
2711 * Copy the current address and log it...
2714 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2718 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
2719 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2720 #endif /* HAVE_SSL */
2722 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2725 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2726 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2728 #endif /* AF_LOCAL */
2729 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
2730 _httpAddrPort(&(lis
->address
)),
2731 _httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
2733 if (!httpAddrLocalhost(&(lis
->address
)))
2734 RemotePort
= _httpAddrPort(&(lis
->address
));
2741 httpAddrFreeList(addrlist
);
2743 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
2744 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
2747 * "BrowseProtocols name [... name]"
2748 * "BrowseLocalProtocols name [... name]"
2751 int protocols
= parse_protocols(value
);
2755 cupsdLogMessage(CUPSD_LOG_ERROR
,
2756 "Unknown browse protocol \"%s\" on line %d.",
2761 BrowseLocalProtocols
= protocols
;
2763 else if (!_cups_strcasecmp(line
, "default_auth_type") && value
)
2766 * default_auth_type {basic,digest,basicdigest,negotiate}
2769 if (!_cups_strcasecmp(value
, "none"))
2770 default_auth_type
= CUPSD_AUTH_NONE
;
2771 else if (!_cups_strcasecmp(value
, "basic"))
2772 default_auth_type
= CUPSD_AUTH_BASIC
;
2773 else if (!_cups_strcasecmp(value
, "digest"))
2774 default_auth_type
= CUPSD_AUTH_DIGEST
;
2775 else if (!_cups_strcasecmp(value
, "basicdigest"))
2776 default_auth_type
= CUPSD_AUTH_BASICDIGEST
;
2778 else if (!_cups_strcasecmp(value
, "negotiate"))
2779 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
2780 #endif /* HAVE_GSSAPI */
2781 else if (!_cups_strcasecmp(value
, "auto"))
2782 default_auth_type
= CUPSD_AUTH_AUTO
;
2785 cupsdLogMessage(CUPSD_LOG_WARN
,
2786 "Unknown default authorization type %s on line %d.",
2788 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2793 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
2796 * DefaultEncryption {Never,IfRequested,Required}
2799 if (!value
|| !_cups_strcasecmp(value
, "never"))
2800 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2801 else if (!_cups_strcasecmp(value
, "required"))
2802 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2803 else if (!_cups_strcasecmp(value
, "ifrequested"))
2804 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2807 cupsdLogMessage(CUPSD_LOG_WARN
,
2808 "Unknown default encryption %s on line %d.",
2810 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2814 #endif /* HAVE_SSL */
2815 else if (!_cups_strcasecmp(line
, "User") && value
)
2818 * User ID to run as...
2821 if (isdigit(value
[0] & 255))
2823 int uid
= atoi(value
);
2826 cupsdLogMessage(CUPSD_LOG_ERROR
,
2827 "Will not use User 0 as specified on line %d "
2828 "for security reasons. You must use a non-"
2829 "privileged account instead.",
2836 struct passwd
*p
; /* Password information */
2839 p
= getpwnam(value
);
2844 cupsdLogMessage(CUPSD_LOG_ERROR
,
2845 "Will not use User %s (UID=0) as specified on line "
2846 "%d for security reasons. You must use a non-"
2847 "privileged account instead.",
2853 cupsdLogMessage(CUPSD_LOG_ERROR
,
2854 "Unknown User \"%s\" on line %d, ignoring.",
2858 else if (!_cups_strcasecmp(line
, "Group") && value
)
2861 * Group ID to run as...
2864 if (isdigit(value
[0]))
2865 Group
= atoi(value
);
2869 group
= getgrnam(value
);
2872 Group
= group
->gr_gid
;
2874 cupsdLogMessage(CUPSD_LOG_ERROR
,
2875 "Unknown Group \"%s\" on line %d, ignoring.",
2879 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
2882 * SystemGroup (admin) group(s)...
2885 if (!parse_groups(value
))
2886 cupsdLogMessage(CUPSD_LOG_ERROR
,
2887 "Unknown SystemGroup \"%s\" on line %d, ignoring.",
2890 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
2893 * Do hostname lookups?
2896 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
2897 !_cups_strcasecmp(value
, "false"))
2898 HostNameLookups
= 0;
2899 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
2900 !_cups_strcasecmp(value
, "true"))
2901 HostNameLookups
= 1;
2902 else if (!_cups_strcasecmp(value
, "double"))
2903 HostNameLookups
= 2;
2905 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2908 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
2911 * Amount of logging to do to access log...
2914 if (!_cups_strcasecmp(value
, "all"))
2915 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
2916 else if (!_cups_strcasecmp(value
, "actions"))
2917 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
2918 else if (!_cups_strcasecmp(value
, "config"))
2919 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
2921 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
2924 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
2927 * Amount of logging to do to error log...
2930 if (!_cups_strcasecmp(value
, "debug2"))
2931 LogLevel
= CUPSD_LOG_DEBUG2
;
2932 else if (!_cups_strcasecmp(value
, "debug"))
2933 LogLevel
= CUPSD_LOG_DEBUG
;
2934 else if (!_cups_strcasecmp(value
, "info"))
2935 LogLevel
= CUPSD_LOG_INFO
;
2936 else if (!_cups_strcasecmp(value
, "notice"))
2937 LogLevel
= CUPSD_LOG_NOTICE
;
2938 else if (!_cups_strcasecmp(value
, "warn"))
2939 LogLevel
= CUPSD_LOG_WARN
;
2940 else if (!_cups_strcasecmp(value
, "error"))
2941 LogLevel
= CUPSD_LOG_ERROR
;
2942 else if (!_cups_strcasecmp(value
, "crit"))
2943 LogLevel
= CUPSD_LOG_CRIT
;
2944 else if (!_cups_strcasecmp(value
, "alert"))
2945 LogLevel
= CUPSD_LOG_ALERT
;
2946 else if (!_cups_strcasecmp(value
, "emerg"))
2947 LogLevel
= CUPSD_LOG_EMERG
;
2948 else if (!_cups_strcasecmp(value
, "none"))
2949 LogLevel
= CUPSD_LOG_NONE
;
2951 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2954 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
2957 * Amount of logging to do to error log...
2960 if (!_cups_strcasecmp(value
, "standard"))
2961 LogTimeFormat
= CUPSD_TIME_STANDARD
;
2962 else if (!_cups_strcasecmp(value
, "usecs"))
2963 LogTimeFormat
= CUPSD_TIME_USECS
;
2965 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
2968 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
2971 * Format of printcap file?
2974 if (!_cups_strcasecmp(value
, "bsd"))
2975 PrintcapFormat
= PRINTCAP_BSD
;
2976 else if (!_cups_strcasecmp(value
, "plist"))
2977 PrintcapFormat
= PRINTCAP_PLIST
;
2978 else if (!_cups_strcasecmp(value
, "solaris"))
2979 PrintcapFormat
= PRINTCAP_SOLARIS
;
2981 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2984 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
2987 * Set the string used for the Server header...
2990 struct utsname plat
; /* Platform info */
2995 if (!_cups_strcasecmp(value
, "ProductOnly"))
2996 cupsdSetString(&ServerHeader
, "CUPS");
2997 else if (!_cups_strcasecmp(value
, "Major"))
2998 cupsdSetStringf(&ServerHeader
, "CUPS/%d", CUPS_VERSION_MAJOR
);
2999 else if (!_cups_strcasecmp(value
, "Minor"))
3000 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
3001 CUPS_VERSION_MINOR
);
3002 else if (!_cups_strcasecmp(value
, "Minimal"))
3003 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3004 else if (!_cups_strcasecmp(value
, "OS"))
3005 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3006 else if (!_cups_strcasecmp(value
, "Full"))
3007 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/2.1",
3009 else if (!_cups_strcasecmp(value
, "None"))
3010 cupsdClearString(&ServerHeader
);
3012 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3015 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3018 * PassEnv variable [... variable]
3023 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3024 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3027 if (value
[valuelen
])
3029 value
[valuelen
] = '\0';
3033 cupsdSetEnv(value
, NULL
);
3035 for (value
+= valuelen
; *value
; value
++)
3036 if (!_cups_isspace(*value
) || *value
!= ',')
3040 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3043 * ServerAlias name [... name]
3047 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3051 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3052 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3055 if (value
[valuelen
])
3057 value
[valuelen
] = '\0';
3061 cupsdAddAlias(ServerAlias
, value
);
3063 for (value
+= valuelen
; *value
; value
++)
3064 if (!_cups_isspace(*value
) || *value
!= ',')
3068 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3071 * SetEnv variable value
3074 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3082 while (isspace(*valueptr
& 255))
3085 cupsdSetEnv(value
, valueptr
);
3088 cupsdLogMessage(CUPSD_LOG_ERROR
,
3089 "Missing value for SetEnv directive on line %d.",
3093 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3096 * SSLOptions options
3099 if (!value
|| !_cups_strcasecmp(value
, "none"))
3100 SSLOptions
= CUPSD_SSL_NONE
;
3101 else if (!_cups_strcasecmp(value
, "noemptyfragments"))
3102 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3104 cupsdLogMessage(CUPSD_LOG_ERROR
,
3105 "Unknown value \"%s\" for SSLOptions directive on "
3106 "line %d.", value
, linenum
);
3108 #endif /* HAVE_SSL */
3112 * Find a simple variable in the list...
3115 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3116 if (!_cups_strcasecmp(line
, var
->name
))
3122 * Unknown directive! Output an error message and continue...
3126 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3129 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3136 case CUPSD_VARTYPE_INTEGER
:
3138 cupsdLogMessage(CUPSD_LOG_ERROR
,
3139 "Missing integer value for %s on line %d.",
3144 char *units
; /* Units */
3147 n
= strtol(value
, &units
, 0);
3149 if (units
&& *units
)
3151 if (tolower(units
[0] & 255) == 'g')
3152 n
*= 1024 * 1024 * 1024;
3153 else if (tolower(units
[0] & 255) == 'm')
3155 else if (tolower(units
[0] & 255) == 'k')
3157 else if (tolower(units
[0] & 255) == 't')
3162 cupsdLogMessage(CUPSD_LOG_ERROR
,
3163 "Bad negative integer value for %s on line %d.",
3166 *((int *)var
->ptr
) = n
;
3170 case CUPSD_VARTYPE_BOOLEAN
:
3172 cupsdLogMessage(CUPSD_LOG_ERROR
,
3173 "Missing boolean value for %s on line %d.",
3175 else if (!_cups_strcasecmp(value
, "true") ||
3176 !_cups_strcasecmp(value
, "on") ||
3177 !_cups_strcasecmp(value
, "enabled") ||
3178 !_cups_strcasecmp(value
, "yes") ||
3180 *((int *)var
->ptr
) = TRUE
;
3181 else if (!_cups_strcasecmp(value
, "false") ||
3182 !_cups_strcasecmp(value
, "off") ||
3183 !_cups_strcasecmp(value
, "disabled") ||
3184 !_cups_strcasecmp(value
, "no") ||
3185 !_cups_strcasecmp(value
, "0"))
3186 *((int *)var
->ptr
) = FALSE
;
3188 cupsdLogMessage(CUPSD_LOG_ERROR
,
3189 "Unknown boolean value %s on line %d.",
3193 case CUPSD_VARTYPE_PATHNAME
:
3196 cupsdLogMessage(CUPSD_LOG_ERROR
,
3197 "Missing pathname value for %s on line %d.",
3202 if (value
[0] == '/')
3203 strlcpy(temp
, value
, sizeof(temp
));
3205 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3207 if (access(temp
, 0))
3209 cupsdLogMessage(CUPSD_LOG_ERROR
,
3210 "File or directory for \"%s %s\" on line %d "
3211 "does not exist.", line
, value
, linenum
);
3215 case CUPSD_VARTYPE_STRING
:
3216 cupsdSetString((char **)var
->ptr
, value
);
3227 * 'read_location()' - Read a <Location path> definition.
3230 static int /* O - New line number or 0 on error */
3231 read_location(cups_file_t
*fp
, /* I - Configuration file */
3232 char *location
, /* I - Location name/path */
3233 int linenum
) /* I - Current line number */
3235 cupsd_location_t
*loc
, /* New location */
3236 *parent
; /* Parent location */
3237 char line
[HTTP_MAX_BUFFER
],
3239 *value
, /* Value for directive */
3240 *valptr
; /* Pointer into value */
3243 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3244 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d.",
3246 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3250 cupsdAddLocation(parent
);
3252 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3257 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3260 * Decode the directive...
3263 if (!_cups_strcasecmp(line
, "</Location>"))
3265 else if (!_cups_strcasecmp(line
, "<Limit") ||
3266 !_cups_strcasecmp(line
, "<LimitExcept"))
3270 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3271 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3277 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3280 cupsdAddLocation(loc
);
3285 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3290 if (!strcmp(value
, "ALL"))
3291 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3292 else if (!strcmp(value
, "GET"))
3293 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3294 else if (!strcmp(value
, "HEAD"))
3295 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3296 else if (!strcmp(value
, "OPTIONS"))
3297 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3298 else if (!strcmp(value
, "POST"))
3299 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3300 else if (!strcmp(value
, "PUT"))
3301 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3302 else if (!strcmp(value
, "TRACE"))
3303 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3305 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d.",
3308 for (value
= valptr
; isspace(*value
& 255); value
++);
3311 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3312 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3314 parent
->limit
&= ~loc
->limit
;
3316 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3317 !_cups_strcasecmp(line
, "</LimitExcept>"))
3321 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3322 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3325 else if (!parse_aaa(loc
, line
, value
, linenum
))
3327 cupsdLogMessage(CUPSD_LOG_ERROR
,
3328 "Unknown Location directive %s on line %d.",
3330 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3335 cupsdLogMessage(CUPSD_LOG_ERROR
,
3336 "Unexpected end-of-file at line %d while reading location.",
3339 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3344 * 'read_policy()' - Read a <Policy name> definition.
3347 static int /* O - New line number or 0 on error */
3348 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3349 char *policy
, /* I - Location name/path */
3350 int linenum
) /* I - Current line number */
3352 int i
; /* Looping var */
3353 cupsd_policy_t
*pol
; /* Policy */
3354 cupsd_location_t
*op
; /* Policy operation */
3355 int num_ops
; /* Number of IPP operations */
3356 ipp_op_t ops
[100]; /* Operations */
3357 char line
[HTTP_MAX_BUFFER
],
3359 *value
, /* Value for directive */
3360 *valptr
; /* Pointer into value */
3364 * Create the policy...
3367 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3368 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d.",
3370 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3374 * Read from the file...
3380 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3383 * Decode the directive...
3386 if (!_cups_strcasecmp(line
, "</Policy>"))
3389 cupsdLogMessage(CUPSD_LOG_WARN
,
3390 "Missing </Limit> before </Policy> on line %d.",
3393 set_policy_defaults(pol
);
3397 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3401 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3402 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3409 * Scan for IPP operation names...
3416 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3421 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3423 if (!_cups_strcasecmp(value
, "All"))
3424 ops
[num_ops
] = IPP_ANY_OPERATION
;
3425 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3426 cupsdLogMessage(CUPSD_LOG_ERROR
,
3427 "Bad IPP operation name \"%s\" on line %d.",
3433 cupsdLogMessage(CUPSD_LOG_ERROR
,
3434 "Too many operations listed on line %d.",
3437 for (value
= valptr
; isspace(*value
& 255); value
++);
3441 * If none are specified, apply the policy to all operations...
3446 ops
[0] = IPP_ANY_OPERATION
;
3451 * Add a new policy for the first operation...
3454 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3456 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3459 * Finish the current operation limit...
3465 * Copy the policy to the other operations...
3468 for (i
= 1; i
< num_ops
; i
++)
3469 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3476 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3477 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3480 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3481 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3482 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3483 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3487 cupsdLogMessage(CUPSD_LOG_ERROR
,
3488 "%s directive must appear outside <Limit>...</Limit> "
3489 "on line %d.", line
, linenum
);
3490 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3496 * Pull out whitespace-delimited values...
3502 * Find the end of the current value...
3505 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3511 * Save it appropriately...
3514 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3517 * JobPrivateAccess {all|default|user/group list|@@ACL}
3520 if (!_cups_strcasecmp(value
, "default"))
3522 cupsdAddString(&(pol
->job_access
), "@OWNER");
3523 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3526 cupsdAddString(&(pol
->job_access
), value
);
3528 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3531 * JobPrivateValues {all|none|default|attribute list}
3534 if (!_cups_strcasecmp(value
, "default"))
3536 cupsdAddString(&(pol
->job_attrs
), "job-name");
3537 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3538 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3541 cupsdAddString(&(pol
->job_attrs
), value
);
3543 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3546 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3549 if (!_cups_strcasecmp(value
, "default"))
3551 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3552 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3555 cupsdAddString(&(pol
->sub_access
), value
);
3557 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3560 * SubscriptionPrivateValues {all|none|default|attribute list}
3563 if (!_cups_strcasecmp(value
, "default"))
3565 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3566 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3567 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3568 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3569 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3572 cupsdAddString(&(pol
->sub_attrs
), value
);
3576 * Find the next string on the line...
3579 for (value
= valptr
; isspace(*value
& 255); value
++);
3585 cupsdLogMessage(CUPSD_LOG_ERROR
,
3586 "Missing <Limit ops> directive before %s on line %d.",
3588 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3591 else if (!parse_aaa(op
, line
, value
, linenum
))
3593 cupsdLogMessage(CUPSD_LOG_ERROR
,
3594 "Unknown Policy Limit directive %s on line %d.",
3597 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3602 cupsdLogMessage(CUPSD_LOG_ERROR
,
3603 "Unexpected end-of-file at line %d while reading policy "
3604 "\"%s\".", linenum
, policy
);
3606 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3611 * 'set_policy_defaults()' - Set default policy values as needed.
3615 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
3617 cupsd_location_t
*op
; /* Policy operation */
3621 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3622 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3623 * upgrades do not introduce new security issues...
3626 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
3627 op
->op
== IPP_ANY_OPERATION
)
3629 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
3630 op
->op
!= IPP_ANY_OPERATION
)
3633 * Add a new limit for Validate-Job using the Print-Job limit as a
3637 cupsdLogMessage(CUPSD_LOG_WARN
,
3638 "No limit for Validate-Job defined in policy %s "
3639 "- using Print-Job's policy.", pol
->name
);
3641 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
3644 cupsdLogMessage(CUPSD_LOG_WARN
,
3645 "No limit for Validate-Job defined in policy %s "
3646 "and no suitable template found.", pol
->name
);
3649 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
3650 op
->op
== IPP_ANY_OPERATION
)
3652 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
3653 op
->op
!= IPP_ANY_OPERATION
)
3656 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
3660 cupsdLogMessage(CUPSD_LOG_WARN
,
3661 "No limit for Cancel-Jobs defined in policy %s "
3662 "- using Pause-Printer's policy.", pol
->name
);
3664 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
3667 cupsdLogMessage(CUPSD_LOG_WARN
,
3668 "No limit for Cancel-Jobs defined in policy %s "
3669 "and no suitable template found.", pol
->name
);
3672 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
3673 op
->op
== IPP_ANY_OPERATION
)
3675 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3676 op
->op
!= IPP_ANY_OPERATION
)
3679 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3683 cupsdLogMessage(CUPSD_LOG_WARN
,
3684 "No limit for Cancel-My-Jobs defined in policy %s "
3685 "- using Send-Document's policy.", pol
->name
);
3687 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
3690 cupsdLogMessage(CUPSD_LOG_WARN
,
3691 "No limit for Cancel-My-Jobs defined in policy %s "
3692 "and no suitable template found.", pol
->name
);
3695 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
3696 op
->op
== IPP_ANY_OPERATION
)
3698 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3699 op
->op
!= IPP_ANY_OPERATION
)
3702 * Add a new limit for Close-Job using the Send-Document limit as a
3706 cupsdLogMessage(CUPSD_LOG_WARN
,
3707 "No limit for Close-Job defined in policy %s "
3708 "- using Send-Document's policy.", pol
->name
);
3710 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
3713 cupsdLogMessage(CUPSD_LOG_WARN
,
3714 "No limit for Close-Job defined in policy %s "
3715 "and no suitable template found.", pol
->name
);
3718 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3719 op
->op
== IPP_ANY_OPERATION
)
3721 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3722 op
->op
!= IPP_ANY_OPERATION
)
3725 * Add a new limit for CUPS-Get-Document using the Send-Document
3726 * limit as a template...
3729 cupsdLogMessage(CUPSD_LOG_WARN
,
3730 "No limit for CUPS-Get-Document defined in policy %s "
3731 "- using Send-Document's policy.", pol
->name
);
3733 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3736 cupsdLogMessage(CUPSD_LOG_WARN
,
3737 "No limit for CUPS-Get-Document defined in policy %s "
3738 "and no suitable template found.", pol
->name
);
3742 * Verify we have JobPrivateAccess, JobPrivateValues,
3743 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
3746 if (!pol
->job_access
)
3748 cupsdLogMessage(CUPSD_LOG_WARN
,
3749 "No JobPrivateAccess defined in policy %s "
3750 "- using defaults.", pol
->name
);
3751 cupsdAddString(&(pol
->job_access
), "@OWNER");
3752 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3755 if (!pol
->job_attrs
)
3757 cupsdLogMessage(CUPSD_LOG_WARN
,
3758 "No JobPrivateValues defined in policy %s "
3759 "- using defaults.", pol
->name
);
3760 cupsdAddString(&(pol
->job_attrs
), "job-name");
3761 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3762 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3765 if (!pol
->sub_access
)
3767 cupsdLogMessage(CUPSD_LOG_WARN
,
3768 "No SubscriptionPrivateAccess defined in policy %s "
3769 "- using defaults.", pol
->name
);
3770 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3771 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3774 if (!pol
->sub_attrs
)
3776 cupsdLogMessage(CUPSD_LOG_WARN
,
3777 "No SubscriptionPrivateValues defined in policy %s "
3778 "- using defaults.", pol
->name
);
3779 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3780 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3781 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3782 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3783 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3789 * End of "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $".