2 * "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $"
4 * Configuration routines for the CUPS scheduler.
6 * Copyright 2007-2012 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 { "MaxHoldTime", &MaxHoldTime
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
147 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
148 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
149 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
150 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
151 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
152 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
153 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
154 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
155 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
156 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
157 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
158 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
159 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
160 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
162 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
163 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
164 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
165 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
166 #endif /* HAVE_SSL */
167 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
168 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
169 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
170 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
171 #ifdef HAVE_AUTHORIZATION_H
172 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
173 #endif /* HAVE_AUTHORIZATION_H */
174 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
175 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
176 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
178 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
181 static const unsigned ones
[4] =
183 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
185 static const unsigned zeros
[4] =
187 0x00000000, 0x00000000, 0x00000000, 0x00000000
195 static http_addrlist_t
*get_address(const char *value
, int defport
);
196 static int get_addr_and_mask(const char *value
, unsigned *ip
,
198 static void mime_error_cb(void *ctx
, const char *message
);
199 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
200 char *value
, int linenum
);
201 static int parse_fatal_errors(const char *s
);
202 static int parse_groups(const char *s
);
203 static int parse_protocols(const char *s
);
204 static int read_configuration(cups_file_t
*fp
);
205 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
206 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
207 static void set_policy_defaults(cupsd_policy_t
*pol
);
211 * 'cupsdAddAlias()' - Add a host alias.
215 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
216 const char *name
) /* I - Name to add */
218 cupsd_alias_t
*a
; /* New alias */
219 size_t namelen
; /* Length of name */
222 namelen
= strlen(name
);
224 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
227 a
->namelen
= namelen
;
228 strcpy(a
->name
, name
); /* OK since a->name is allocated */
230 cupsArrayAdd(aliases
, a
);
235 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
238 int /* O - 0 on success, -1 on error, 1 on warning */
239 cupsdCheckPermissions(
240 const char *filename
, /* I - File/directory name */
241 const char *suffix
, /* I - Additional file/directory name */
242 int mode
, /* I - Permissions */
243 int user
, /* I - Owner */
244 int group
, /* I - Group */
245 int is_dir
, /* I - 1 = directory, 0 = file */
246 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
248 int dir_created
= 0; /* Did we create a directory? */
249 char pathname
[1024]; /* File name with prefix */
250 struct stat fileinfo
; /* Stat buffer */
251 int is_symlink
; /* Is "filename" a symlink? */
255 * Prepend the given root to the filename before testing it...
260 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
265 * See if we can stat the file/directory...
268 if (lstat(filename
, &fileinfo
))
270 if (errno
== ENOENT
&& create_dir
)
273 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
276 if (mkdir(filename
, mode
))
279 cupsdLogMessage(CUPSD_LOG_ERROR
,
280 "Unable to create directory \"%s\" - %s", filename
,
283 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
290 fileinfo
.st_mode
= mode
| S_IFDIR
;
293 return (create_dir
? -1 : 1);
296 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
298 if (stat(filename
, &fileinfo
))
300 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
301 filename
, strerror(errno
));
307 * Make sure it's a regular file or a directory as needed...
310 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
312 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
316 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
319 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
321 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
327 * If the filename is a symlink, do not change permissions (STR #2937)...
334 * Fix owner, group, and mode as needed...
337 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
340 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
343 if (chown(filename
, user
, group
) && !getuid())
346 cupsdLogMessage(CUPSD_LOG_ERROR
,
347 "Unable to change ownership of \"%s\" - %s", filename
,
350 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
357 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
360 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
363 if (chmod(filename
, mode
))
366 cupsdLogMessage(CUPSD_LOG_ERROR
,
367 "Unable to change permissions of \"%s\" - %s", filename
,
370 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
378 * Everything is OK...
386 * 'cupsdDefaultAuthType()' - Get the default AuthType.
388 * When the default_auth_type is "auto", this function tries to get the GSS
389 * credentials for the server. If that succeeds we use Kerberos authentication,
390 * otherwise we do a fallback to Basic authentication against the local user
394 int /* O - Default AuthType value */
395 cupsdDefaultAuthType(void)
398 OM_uint32 major_status
, /* Major status code */
399 minor_status
; /* Minor status code */
400 gss_name_t server_name
; /* Server name */
401 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
402 /* Service name token */
403 char buf
[1024]; /* Service name buffer */
404 #endif /* HAVE_GSSAPI */
408 * If we have already determined the correct default AuthType, use it...
411 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
412 return (default_auth_type
);
417 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
421 if (gss_init_sec_context
== NULL
)
422 return (default_auth_type
= CUPSD_AUTH_BASIC
);
423 # endif /* __APPLE__ */
426 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
427 * that fails we must use Basic...
430 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
433 token
.length
= strlen(buf
);
434 server_name
= GSS_C_NO_NAME
;
435 major_status
= gss_import_name(&minor_status
, &token
,
436 GSS_C_NT_HOSTBASED_SERVICE
,
439 memset(&token
, 0, sizeof(token
));
441 if (GSS_ERROR(major_status
))
443 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
444 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
445 return (default_auth_type
= CUPSD_AUTH_BASIC
);
448 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
450 if (GSS_ERROR(major_status
))
452 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
453 "cupsdDefaultAuthType: gss_display_name(%s) failed",
455 return (default_auth_type
= CUPSD_AUTH_BASIC
);
458 cupsdLogMessage(CUPSD_LOG_DEBUG
,
459 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
460 "credentials for %s...", (char *)token
.value
);
462 ServerCreds
= GSS_C_NO_CREDENTIAL
;
463 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
464 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
465 &ServerCreds
, NULL
, NULL
);
466 if (GSS_ERROR(major_status
))
468 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
469 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
470 (char *)token
.value
);
471 gss_release_name(&minor_status
, &server_name
);
472 gss_release_buffer(&minor_status
, &token
);
473 return (default_auth_type
= CUPSD_AUTH_BASIC
);
476 cupsdLogMessage(CUPSD_LOG_DEBUG
,
477 "cupsdDefaultAuthType: Kerberos credentials acquired "
478 "successfully for %s.", (char *)token
.value
);
480 gss_release_name(&minor_status
, &server_name
);
481 gss_release_buffer(&minor_status
, &token
);
485 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
489 * No Kerberos support compiled in so just use Basic all the time...
492 return (default_auth_type
= CUPSD_AUTH_BASIC
);
493 #endif /* HAVE_GSSAPI */
498 * 'cupsdFreeAliases()' - Free all of the alias entries.
502 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
504 cupsd_alias_t
*a
; /* Current alias */
507 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
509 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
512 cupsArrayDelete(aliases
);
517 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
520 int /* O - 1 on success, 0 otherwise */
521 cupsdReadConfiguration(void)
523 int i
; /* Looping var */
524 cups_file_t
*fp
; /* Configuration file */
525 int status
; /* Return status */
526 char temp
[1024], /* Temporary buffer */
527 mimedir
[1024], /* MIME directory */
528 *slash
; /* Directory separator */
529 cups_lang_t
*language
; /* Language */
530 struct passwd
*user
; /* Default user */
531 struct group
*group
; /* Default group */
532 char *old_serverroot
, /* Old ServerRoot */
533 *old_requestroot
; /* Old RequestRoot */
534 int old_remote_port
; /* Old RemotePort */
535 const char *tmpdir
; /* TMPDIR environment variable */
536 struct stat tmpinfo
; /* Temporary directory info */
537 cupsd_policy_t
*p
; /* Policy */
541 * Save the old root paths...
544 old_serverroot
= NULL
;
545 cupsdSetString(&old_serverroot
, ServerRoot
);
546 old_requestroot
= NULL
;
547 cupsdSetString(&old_requestroot
, RequestRoot
);
550 * Reset the server configuration data...
553 cupsdDeleteAllLocations();
555 cupsdDeleteAllListeners();
557 old_remote_port
= RemotePort
;
564 cupsdFreeAliases(ServerAlias
);
567 cupsdClearString(&ServerName
);
568 cupsdClearString(&ServerAdmin
);
569 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
570 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
571 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
572 cupsdSetString(&DataDir
, CUPS_DATADIR
);
573 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
574 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
575 cupsdClearString(&ErrorLog
);
576 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
577 cupsdSetString(&PageLogFormat
,
578 "%p %u %j %T %P %C %{job-billing} "
579 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
580 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
581 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
582 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
583 cupsdSetString(&RemoteRoot
, "remroot");
584 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
586 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
588 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
589 PrintcapFormat
= PRINTCAP_SOLARIS
;
590 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
591 "/Library/Preferences/org.cups.printers.plist"))
592 PrintcapFormat
= PRINTCAP_PLIST
;
594 PrintcapFormat
= PRINTCAP_BSD
;
596 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
597 if ((slash
= strrchr(temp
, '/')) != NULL
)
600 cupsdSetString(&ServerRoot
, temp
);
602 cupsdClearString(&Classification
);
603 ClassifyOverride
= 0;
607 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
609 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
610 cupsdSetString(&ServerKey
, "ssl/server.key");
611 # endif /* HAVE_CDSASSL */
612 #endif /* HAVE_SSL */
614 language
= cupsLangDefault();
616 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
617 cupsdSetString(&DefaultLanguage
, "en");
619 cupsdSetString(&DefaultLanguage
, language
->language
);
621 cupsdClearString(&DefaultPaperSize
);
623 cupsdSetString(&RIPCache
, "128m");
625 cupsdSetString(&TempDir
, NULL
);
628 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
632 OM_uint32 minor_status
; /* Minor status code */
634 gss_release_cred(&minor_status
, &ServerCreds
);
639 ServerCreds
= GSS_C_NO_CREDENTIAL
;
640 #endif /* HAVE_GSSAPI */
643 * Find the default user...
646 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
651 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
652 * complement number...)
661 * Find the default group...
664 group
= getgrnam(CUPS_DEFAULT_GROUP
);
668 Group
= group
->gr_gid
;
672 * Fallback to group "nobody"...
675 group
= getgrnam("nobody");
679 Group
= group
->gr_gid
;
683 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
684 * complement number...)
695 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
696 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
697 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
698 default_auth_type
= CUPSD_AUTH_BASIC
;
700 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
701 SSLOptions
= CUPSD_SSL_NONE
;
702 #endif /* HAVE_SSL */
703 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
704 JobKillDelay
= DEFAULT_TIMEOUT
;
706 JobRetryInterval
= 300;
711 HostNameLookups
= FALSE
;
713 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
714 ListenBackLog
= SOMAXCONN
;
715 LogDebugHistory
= 200;
716 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
717 LogLevel
= CUPSD_LOG_WARN
;
718 LogTimeFormat
= CUPSD_TIME_STANDARD
;
720 MaxClientsPerHost
= 0;
721 MaxLogSize
= 1024 * 1024;
723 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
724 ReloadTimeout
= DEFAULT_KEEPALIVE
;
725 RootCertDuration
= 300;
726 Timeout
= DEFAULT_TIMEOUT
;
728 WebInterface
= CUPS_DEFAULT_WEBIF
;
730 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
732 Browsing
= CUPS_DEFAULT_BROWSING
;
733 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
736 cupsdSetString(&DNSSDRegType
, "_ipp._tcp,_cups");
737 #endif /* HAVE_DNSSD */
739 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
740 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
742 cupsdSetString(&ErrorPolicy
, "stop-printer");
744 JobHistory
= DEFAULT_HISTORY
;
745 JobFiles
= DEFAULT_FILES
;
751 MaxJobsPerPrinter
= 0;
752 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
753 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
755 cupsdDeleteAllPolicies();
756 cupsdClearString(&DefaultPolicy
);
758 #ifdef HAVE_AUTHORIZATION_H
759 cupsdClearString(&SystemGroupAuthKey
);
760 #endif /* HAVE_AUTHORIZATION_H */
762 MaxSubscriptions
= 100;
763 MaxSubscriptionsPerJob
= 0;
764 MaxSubscriptionsPerPrinter
= 0;
765 MaxSubscriptionsPerUser
= 0;
766 DefaultLeaseDuration
= 86400;
767 MaxLeaseDuration
= 0;
771 #endif /* HAVE_LAUNCHD */
774 * Setup environment variables...
780 * Read the configuration file...
783 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
786 status
= read_configuration(fp
);
794 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
798 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
799 RemotePort
? "enabled" : "disabled");
802 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
805 * See if the ServerName is an IP address...
811 ServerAlias
= cupsArrayNew(NULL
, NULL
);
813 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
817 if (gethostname(temp
, sizeof(temp
)))
819 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
821 strlcpy(temp
, "localhost", sizeof(temp
));
824 cupsdSetString(&ServerName
, temp
);
827 ServerAlias
= cupsArrayNew(NULL
, NULL
);
829 cupsdAddAlias(ServerAlias
, temp
);
830 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
832 if (HostNameLookups
|| RemotePort
)
834 struct hostent
*host
; /* Host entry to get FQDN */
836 if ((host
= gethostbyname(temp
)) != NULL
)
838 if (_cups_strcasecmp(temp
, host
->h_name
))
840 cupsdSetString(&ServerName
, host
->h_name
);
841 cupsdAddAlias(ServerAlias
, host
->h_name
);
842 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
848 for (i
= 0; host
->h_aliases
[i
]; i
++)
849 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
851 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
852 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
860 * Make sure we have the base hostname added as an alias, too!
863 if ((slash
= strchr(temp
, '.')) != NULL
)
866 cupsdAddAlias(ServerAlias
, temp
);
867 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
871 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
873 ServerNameIsIP
= !*slash
;
876 * Make sure ServerAdmin is initialized...
880 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
883 * Use the default system group if none was supplied in cupsd.conf...
886 if (NumSystemGroups
== 0)
888 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
891 * Find the group associated with GID 0...
898 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
900 cupsdSetString(&SystemGroups
[0], "unknown");
902 SystemGroupIDs
[0] = 0;
908 * Open the system log for cupsd if necessary...
912 if (!strcmp(AccessLog
, "syslog") ||
913 !strcmp(ErrorLog
, "syslog") ||
914 !strcmp(PageLog
, "syslog"))
915 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
916 #endif /* HAVE_VSYSLOG */
919 * Make sure each of the log files exists and gets rotated as necessary...
922 if (strcmp(AccessLog
, "syslog"))
923 cupsdCheckLogFile(&AccessFile
, AccessLog
);
925 if (strcmp(ErrorLog
, "syslog"))
926 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
928 if (strcmp(PageLog
, "syslog"))
929 cupsdCheckLogFile(&PageFile
, PageLog
);
932 * Log the configuration file that was used...
935 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
939 * Validate the Group and SystemGroup settings - they cannot be the same,
940 * otherwise the CGI programs will be able to authenticate as root without
946 for (i
= 0; i
< NumSystemGroups
; i
++)
947 if (Group
== SystemGroupIDs
[i
])
950 if (i
< NumSystemGroups
)
953 * Log the error and reset the group to a safe value...
956 cupsdLogMessage(CUPSD_LOG_NOTICE
,
957 "Group and SystemGroup cannot use the same groups.");
958 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
960 group
= getgrnam("nobody");
964 Group
= group
->gr_gid
;
968 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
969 * complement number...)
978 * Check that we have at least one listen/port line; if not, report this
979 * as an error and exit!
982 if (cupsArrayCount(Listeners
) == 0)
988 cupsdLogMessage(CUPSD_LOG_EMERG
,
989 "No valid Listen or Port lines were found in the "
990 "configuration file.");
996 cupsdEndProcess(getpid(), 0);
1000 * Set the default locale using the language and charset...
1003 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1006 * Update all relative filenames to include the full path from ServerRoot...
1009 if (DocumentRoot
[0] != '/')
1010 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1012 if (RequestRoot
[0] != '/')
1013 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1015 if (ServerBin
[0] != '/')
1016 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1018 if (StateDir
[0] != '/')
1019 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1021 if (CacheDir
[0] != '/')
1022 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1025 if (ServerCertificate
[0] != '/')
1026 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
1028 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
1029 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
1031 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1034 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
1035 if (ServerKey
[0] != '/')
1036 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
1038 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
1039 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
1040 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1042 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
1043 #endif /* HAVE_SSL */
1046 * Make sure that directories and config files are owned and
1047 * writable by the user and group in the cupsd.conf file...
1050 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1052 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1054 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
1056 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1058 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1060 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1061 SystemGroupIDs
[0], 1, 1) < 0 ||
1062 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1064 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1066 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1068 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
1070 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1072 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1074 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1075 Group
, 0, 0) < 0) &&
1076 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1080 * Update TempDir to the default if it hasn't been set already...
1086 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1087 strncmp(tmpdir
, "/private/tmp", 12))
1089 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1090 #endif /* __APPLE__ */
1093 * TMPDIR is defined, see if it is OK for us to use...
1096 if (stat(tmpdir
, &tmpinfo
))
1097 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1098 tmpdir
, strerror(errno
));
1099 else if (!S_ISDIR(tmpinfo
.st_mode
))
1100 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1102 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1103 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1104 !(tmpinfo
.st_mode
& S_IWOTH
))
1105 cupsdLogMessage(CUPSD_LOG_ERROR
,
1106 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1108 cupsdSetString(&TempDir
, tmpdir
);
1113 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1115 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1120 * Make sure the temporary directory has the right permissions...
1123 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1127 * Update ownership and permissions if the CUPS temp directory
1128 * is under the spool directory or does not exist...
1131 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1132 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1137 * Update environment variables...
1143 * Update default paper size setting as needed...
1146 if (!DefaultPaperSize
)
1148 #ifdef HAVE_LIBPAPER
1149 char *paper_result
; /* Paper size name from libpaper */
1151 if ((paper_result
= systempapername()) != NULL
)
1152 cupsdSetString(&DefaultPaperSize
, paper_result
);
1154 #endif /* HAVE_LIBPAPER */
1155 if (!DefaultLanguage
||
1156 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1157 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1158 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1159 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1160 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1161 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1162 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1165 * These are the only locales that will default to "letter" size...
1168 cupsdSetString(&DefaultPaperSize
, "Letter");
1171 cupsdSetString(&DefaultPaperSize
, "A4");
1175 * Update classification setting as needed...
1178 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1179 cupsdClearString(&Classification
);
1182 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1185 * Check the MaxClients setting, and then allocate memory for it...
1188 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1191 cupsdLogMessage(CUPSD_LOG_INFO
,
1192 "MaxClients limited to 1/3 (%d) of the file descriptor "
1194 MaxFDs
/ 3, MaxFDs
);
1196 MaxClients
= MaxFDs
/ 3;
1199 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1203 * Check the MaxActiveJobs setting; limit to 1/3 the available
1204 * file descriptors, since we need a pipe for each job...
1207 if (MaxActiveJobs
> (MaxFDs
/ 3))
1208 MaxActiveJobs
= MaxFDs
/ 3;
1211 * Update the MaxClientsPerHost value, as needed...
1214 if (MaxClientsPerHost
<= 0)
1215 MaxClientsPerHost
= MaxClients
;
1217 if (MaxClientsPerHost
> MaxClients
)
1218 MaxClientsPerHost
= MaxClients
;
1220 cupsdLogMessage(CUPSD_LOG_INFO
,
1221 "Allowing up to %d client connections per host.",
1225 * Update the default policy, as needed...
1229 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1231 DefaultPolicyPtr
= NULL
;
1233 if (!DefaultPolicyPtr
)
1235 cupsd_location_t
*po
; /* New policy operation */
1239 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1242 cupsdSetString(&DefaultPolicy
, "default");
1244 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1245 cupsdLogMessage(CUPSD_LOG_INFO
,
1246 "Using policy \"default\" as the default.");
1249 cupsdLogMessage(CUPSD_LOG_INFO
,
1250 "Creating CUPS default administrative policy:");
1252 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1254 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1256 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1257 cupsdAddString(&(p
->job_access
), "@OWNER");
1258 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1260 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1261 cupsdAddString(&(p
->job_attrs
), "job-name");
1262 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1263 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1265 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1266 cupsdAddString(&(p
->sub_access
), "@OWNER");
1267 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1269 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1270 cupsdAddString(&(p
->job_attrs
), "notify-events");
1271 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1272 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1273 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1274 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1276 cupsdLogMessage(CUPSD_LOG_INFO
,
1277 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1278 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1280 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1281 po
->order_type
= CUPSD_AUTH_ALLOW
;
1283 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1284 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1285 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1287 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1289 cupsdLogMessage(CUPSD_LOG_INFO
,
1290 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1291 "Release-Job Restart-Job Purge-Jobs "
1292 "Set-Job-Attributes Create-Job-Subscription "
1293 "Renew-Subscription Cancel-Subscription "
1294 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1295 "Suspend-Current-Job Resume-Job "
1296 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1297 "CUPS-Authenticate-Job CUPS-Get-Document>");
1298 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1300 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1301 po
->order_type
= CUPSD_AUTH_ALLOW
;
1302 po
->level
= CUPSD_AUTH_USER
;
1304 cupsdAddName(po
, "@OWNER");
1305 cupsdAddName(po
, "@SYSTEM");
1306 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1308 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1309 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1310 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1311 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1312 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1313 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1314 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1315 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1316 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1317 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1318 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1319 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1320 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1321 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1322 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1323 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1324 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1325 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1326 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1327 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1329 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1331 cupsdLogMessage(CUPSD_LOG_INFO
,
1332 "<Limit Pause-Printer Resume-Printer "
1333 "Set-Printer-Attributes Enable-Printer "
1334 "Disable-Printer Pause-Printer-After-Current-Job "
1335 "Hold-New-Jobs Release-Held-New-Jobs "
1336 "Deactivate-Printer Activate-Printer Restart-Printer "
1337 "Shutdown-Printer Startup-Printer Promote-Job "
1338 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1339 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1340 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1341 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1342 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1344 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1345 po
->order_type
= CUPSD_AUTH_ALLOW
;
1346 po
->type
= CUPSD_AUTH_DEFAULT
;
1347 po
->level
= CUPSD_AUTH_USER
;
1349 cupsdAddName(po
, "@SYSTEM");
1350 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1352 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1353 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1354 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1355 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1356 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1357 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1358 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1359 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1360 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1361 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1362 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1363 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1364 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1365 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1366 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1367 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1368 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1369 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1370 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1371 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1372 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1373 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1375 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1377 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1378 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1380 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1381 po
->order_type
= CUPSD_AUTH_ALLOW
;
1383 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1384 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1388 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1389 cupsArrayCount(Policies
));
1390 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1392 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1393 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1394 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1397 * If we are doing a full reload or the server root has changed, flush
1398 * the jobs, printers, etc. and start from scratch...
1401 if (NeedReload
== RELOAD_ALL
||
1402 old_remote_port
!= RemotePort
||
1403 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1404 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1406 mime_type_t
*type
; /* Current type */
1407 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1408 /* MIME type name */
1411 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1414 * Free all memory...
1417 cupsdDeleteAllSubscriptions();
1419 cupsdDeleteAllPrinters();
1421 DefaultPrinter
= NULL
;
1423 if (MimeDatabase
!= NULL
)
1424 mimeDelete(MimeDatabase
);
1428 for (i
= 0; i
< NumMimeTypes
; i
++)
1429 _cupsStrFree(MimeTypes
[i
]);
1435 * Read the MIME type and conversion database...
1438 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1439 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1441 MimeDatabase
= mimeNew();
1442 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1444 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1445 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1446 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1447 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1451 cupsdLogMessage(CUPSD_LOG_EMERG
,
1452 "Unable to load MIME database from \"%s\" or \"%s\".",
1453 mimedir
, ServerRoot
);
1454 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1458 cupsdLogMessage(CUPSD_LOG_INFO
,
1459 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1460 "%d filters...", mimedir
, ServerRoot
,
1461 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1464 * Create a list of MIME types for the document-format-supported
1468 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1469 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1472 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1474 cupsdLogMessage(CUPSD_LOG_ERROR
,
1475 "Unable to allocate memory for %d MIME types.",
1481 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1483 i
++, type
= mimeNextType(MimeDatabase
))
1485 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1487 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1490 if (i
< NumMimeTypes
)
1491 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1494 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1496 mime_filter_t
*filter
; /* Current filter */
1499 for (type
= mimeFirstType(MimeDatabase
);
1501 type
= mimeNextType(MimeDatabase
))
1502 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1503 type
->super
, type
->type
);
1505 for (filter
= mimeFirstFilter(MimeDatabase
);
1507 filter
= mimeNextFilter(MimeDatabase
))
1508 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1509 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1510 filter
->src
->super
, filter
->src
->type
,
1511 filter
->dst
->super
, filter
->dst
->type
,
1512 filter
->cost
, filter
->filter
);
1519 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1520 cupsdLoadBanners(temp
);
1523 * Load printers and classes...
1526 cupsdLoadAllPrinters();
1527 cupsdLoadAllClasses();
1529 cupsdCreateCommonData();
1532 * Update the printcap file as needed...
1535 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1536 cupsdWritePrintcap();
1539 * Load queued jobs...
1545 * Load subscriptions...
1548 cupsdLoadAllSubscriptions();
1550 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1555 * Not a full reload, so recreate the common printer attributes...
1558 cupsdCreateCommonData();
1561 * Update all printers as needed...
1564 cupsdUpdatePrinters();
1565 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1567 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1571 * Reset the reload state...
1574 NeedReload
= RELOAD_NONE
;
1576 cupsdClearString(&old_serverroot
);
1577 cupsdClearString(&old_requestroot
);
1584 * 'get_address()' - Get an address + port number from a line.
1587 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1588 get_address(const char *value
, /* I - Value string */
1589 int defport
) /* I - Default port */
1591 char buffer
[1024], /* Hostname + port number buffer */
1592 defpname
[255], /* Default port name */
1593 *hostname
, /* Hostname or IP */
1594 *portname
; /* Port number or name */
1595 http_addrlist_t
*addrlist
; /* Address list */
1599 * Check for an empty value...
1604 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1609 * Grab a hostname and port number; if there is no colon and the port name
1610 * is only digits, then we have a port number by itself...
1613 strlcpy(buffer
, value
, sizeof(buffer
));
1615 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1622 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1627 * Use the default port...
1630 sprintf(defpname
, "%d", defport
);
1631 portname
= defpname
;
1637 * The buffer contains just a port number...
1645 if (hostname
&& !strcmp(hostname
, "*"))
1649 * Now lookup the address using httpAddrGetList()...
1652 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1653 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1654 hostname
? hostname
: "(nil)");
1661 * 'get_addr_and_mask()' - Get an IP address and netmask.
1664 static int /* O - 1 on success, 0 on failure */
1665 get_addr_and_mask(const char *value
, /* I - String from config file */
1666 unsigned *ip
, /* O - Address value */
1667 unsigned *mask
) /* O - Mask value */
1669 int i
, j
, /* Looping vars */
1670 family
, /* Address family */
1671 ipcount
; /* Count of fields in address */
1672 unsigned ipval
; /* Value */
1673 const char *maskval
, /* Pointer to start of mask value */
1674 *ptr
, /* Pointer into value */
1679 * Get the address...
1682 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1683 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1685 if ((maskval
= strchr(value
, '/')) != NULL
)
1688 maskval
= value
+ strlen(value
);
1692 * Check for an IPv6 address...
1698 * Parse hexadecimal IPv6/IPv4 address...
1703 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1707 else if (!strncmp(ptr
, "::", 2))
1709 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1711 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1716 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1719 * Read IPv4 dotted quad...
1722 unsigned val
[4] = { 0, 0, 0, 0 };
1723 /* IPv4 address values */
1725 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1729 * Range check the IP numbers...
1732 for (i
= 0; i
< ipcount
; i
++)
1737 * Merge everything into a 32-bit IPv4 address in ip[3]...
1740 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1743 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1746 * If the leading words are all 0's then this is an IPv4 address...
1749 if (!val
[0] && !val
[1] && !val
[2])
1752 while (isdigit(*ptr
& 255) || *ptr
== '.')
1756 else if (isxdigit(*ptr
& 255))
1758 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1760 if (*ptr
== ':' && ptr
[1] != ':')
1769 ip
[i
/ 2] |= ipval
<< 16;
1780 if (*ptr
&& *ptr
!= '/')
1784 #endif /* AF_INET6 */
1787 * Parse dotted-decimal IPv4 address...
1790 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1794 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1797 * Range check the IP numbers...
1800 for (i
= 0; i
< ipcount
; i
++)
1805 * Merge everything into a 32-bit IPv4 address in ip[3]...
1808 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1811 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1817 * Get the netmask value(s)...
1820 memset(mask
, 0, sizeof(unsigned) * 4);
1822 if (strchr(maskval
, '.'))
1825 * Get dotted-decimal mask...
1828 if (family
!= AF_INET
)
1831 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1835 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1836 mask
[0] = mask
[1] = mask
[2] = 0;
1841 * Get address/bits format...
1847 if (family
== AF_INET6
)
1855 mask
[0] = 0xffffffff;
1857 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1860 mask
[1] = 0xffffffff;
1864 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1867 mask
[2] = 0xffffffff;
1871 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1874 mask
[3] = 0xffffffff;
1878 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1881 #endif /* AF_INET6 */
1886 mask
[0] = 0xffffffff;
1887 mask
[1] = 0xffffffff;
1888 mask
[2] = 0xffffffff;
1891 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1893 mask
[3] = 0xffffffff;
1898 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1899 "get_addr_and_mask(value=\"%s\", "
1900 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1901 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1905 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1908 if ((ip
[0] & ~mask
[0]) != 0 ||
1909 (ip
[1] & ~mask
[1]) != 0 ||
1910 (ip
[2] & ~mask
[2]) != 0 ||
1911 (ip
[3] & ~mask
[3]) != 0)
1919 * 'mime_error_cb()' - Log a MIME error.
1923 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
1924 const char *message
) /* I - Message */
1928 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
1933 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1936 static int /* O - 1 on success, 0 on failure */
1937 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1938 char *line
, /* I - Line from file */
1939 char *value
, /* I - Start of value data */
1940 int linenum
) /* I - Current line number */
1942 char *valptr
; /* Pointer into value */
1943 unsigned ip
[4], /* IP address components */
1944 mask
[4]; /* IP netmask components */
1947 if (!_cups_strcasecmp(line
, "Encryption"))
1950 * "Encryption xxx" - set required encryption level...
1953 if (!_cups_strcasecmp(value
, "never"))
1954 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1955 else if (!_cups_strcasecmp(value
, "always"))
1957 cupsdLogMessage(CUPSD_LOG_ERROR
,
1958 "Encryption value \"%s\" on line %d is invalid in this "
1959 "context. Using \"required\" instead.", value
, linenum
);
1961 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1963 else if (!_cups_strcasecmp(value
, "required"))
1964 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1965 else if (!_cups_strcasecmp(value
, "ifrequested"))
1966 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1969 cupsdLogMessage(CUPSD_LOG_ERROR
,
1970 "Unknown Encryption value %s on line %d.", value
, linenum
);
1974 else if (!_cups_strcasecmp(line
, "Order"))
1977 * "Order Deny,Allow" or "Order Allow,Deny"...
1980 if (!_cups_strncasecmp(value
, "deny", 4))
1981 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1982 else if (!_cups_strncasecmp(value
, "allow", 5))
1983 loc
->order_type
= CUPSD_AUTH_DENY
;
1986 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1991 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
1994 * Allow [From] host/ip...
1995 * Deny [From] host/ip...
2000 if (!_cups_strncasecmp(value
, "from", 4))
2003 * Strip leading "from"...
2008 while (_cups_isspace(*value
))
2016 * Find the end of the value...
2019 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2021 while (_cups_isspace(*valptr
))
2025 * Figure out what form the allow/deny address takes:
2036 * nnn.nnn.nnn.nnn/mm
2037 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2040 if (!_cups_strcasecmp(value
, "all"))
2046 if (!_cups_strcasecmp(line
, "Allow"))
2047 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2049 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2051 else if (!_cups_strcasecmp(value
, "none"))
2057 if (!_cups_strcasecmp(line
, "Allow"))
2058 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2060 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2063 else if (value
[0] == '*' || value
[0] == '.' ||
2064 (!isdigit(value
[0] & 255) && value
[0] != '['))
2066 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2067 #endif /* AF_INET6 */
2070 * Host or domain name...
2073 if (value
[0] == '*')
2076 if (!_cups_strcasecmp(line
, "Allow"))
2077 cupsdAddNameMask(&(loc
->allow
), value
);
2079 cupsdAddNameMask(&(loc
->deny
), value
);
2084 * One of many IP address forms...
2087 if (!get_addr_and_mask(value
, ip
, mask
))
2089 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2094 if (!_cups_strcasecmp(line
, "Allow"))
2095 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2097 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2101 * Advance to next value...
2107 else if (!_cups_strcasecmp(line
, "AuthType"))
2110 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2113 if (!_cups_strcasecmp(value
, "none"))
2115 loc
->type
= CUPSD_AUTH_NONE
;
2116 loc
->level
= CUPSD_AUTH_ANON
;
2118 else if (!_cups_strcasecmp(value
, "basic"))
2120 loc
->type
= CUPSD_AUTH_BASIC
;
2122 if (loc
->level
== CUPSD_AUTH_ANON
)
2123 loc
->level
= CUPSD_AUTH_USER
;
2125 else if (!_cups_strcasecmp(value
, "digest"))
2127 loc
->type
= CUPSD_AUTH_DIGEST
;
2129 if (loc
->level
== CUPSD_AUTH_ANON
)
2130 loc
->level
= CUPSD_AUTH_USER
;
2132 else if (!_cups_strcasecmp(value
, "basicdigest"))
2134 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
2136 if (loc
->level
== CUPSD_AUTH_ANON
)
2137 loc
->level
= CUPSD_AUTH_USER
;
2139 else if (!_cups_strcasecmp(value
, "default"))
2141 loc
->type
= CUPSD_AUTH_DEFAULT
;
2143 if (loc
->level
== CUPSD_AUTH_ANON
)
2144 loc
->level
= CUPSD_AUTH_USER
;
2147 else if (!_cups_strcasecmp(value
, "negotiate"))
2149 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2151 if (loc
->level
== CUPSD_AUTH_ANON
)
2152 loc
->level
= CUPSD_AUTH_USER
;
2154 #endif /* HAVE_GSSAPI */
2157 cupsdLogMessage(CUPSD_LOG_WARN
,
2158 "Unknown authorization type %s on line %d.",
2163 else if (!_cups_strcasecmp(line
, "AuthClass"))
2166 * AuthClass anonymous, user, system, group
2169 if (!_cups_strcasecmp(value
, "anonymous"))
2171 loc
->type
= CUPSD_AUTH_NONE
;
2172 loc
->level
= CUPSD_AUTH_ANON
;
2174 cupsdLogMessage(CUPSD_LOG_WARN
,
2175 "\"AuthClass %s\" is deprecated; consider removing "
2179 else if (!_cups_strcasecmp(value
, "user"))
2181 loc
->level
= CUPSD_AUTH_USER
;
2183 cupsdLogMessage(CUPSD_LOG_WARN
,
2184 "\"AuthClass %s\" is deprecated; consider using "
2185 "\"Require valid-user\" on line %d.",
2188 else if (!_cups_strcasecmp(value
, "group"))
2190 loc
->level
= CUPSD_AUTH_GROUP
;
2192 cupsdLogMessage(CUPSD_LOG_WARN
,
2193 "\"AuthClass %s\" is deprecated; consider using "
2194 "\"Require user @groupname\" on line %d.",
2197 else if (!_cups_strcasecmp(value
, "system"))
2199 loc
->level
= CUPSD_AUTH_GROUP
;
2201 cupsdAddName(loc
, "@SYSTEM");
2203 cupsdLogMessage(CUPSD_LOG_WARN
,
2204 "\"AuthClass %s\" is deprecated; consider using "
2205 "\"Require user @SYSTEM\" on line %d.",
2210 cupsdLogMessage(CUPSD_LOG_WARN
,
2211 "Unknown authorization class %s on line %d.",
2216 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2218 cupsdAddName(loc
, value
);
2220 cupsdLogMessage(CUPSD_LOG_WARN
,
2221 "\"AuthGroupName %s\" directive is deprecated; consider "
2222 "using \"Require user @%s\" on line %d.",
2223 value
, value
, linenum
);
2225 else if (!_cups_strcasecmp(line
, "Require"))
2228 * Apache synonym for AuthClass and AuthGroupName...
2232 * Require valid-user
2233 * Require group names
2234 * Require user names
2237 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2242 if (!_cups_strcasecmp(value
, "valid-user") ||
2243 !_cups_strcasecmp(value
, "user"))
2244 loc
->level
= CUPSD_AUTH_USER
;
2245 else if (!_cups_strcasecmp(value
, "group"))
2246 loc
->level
= CUPSD_AUTH_GROUP
;
2249 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2255 * Get the list of names from the line...
2258 for (value
= valptr
; *value
;)
2260 while (_cups_isspace(*value
))
2263 #ifdef HAVE_AUTHORIZATION_H
2264 if (!strncmp(value
, "@AUTHKEY(", 9))
2267 * Grab "@AUTHKEY(name)" value...
2270 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2276 #endif /* HAVE_AUTHORIZATION_H */
2277 if (*value
== '\"' || *value
== '\'')
2280 * Grab quoted name...
2283 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2290 * Grab literal name.
2293 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2299 cupsdAddName(loc
, value
);
2301 for (value
= valptr
; _cups_isspace(*value
); value
++);
2304 else if (!_cups_strcasecmp(line
, "Satisfy"))
2306 if (!_cups_strcasecmp(value
, "all"))
2307 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2308 else if (!_cups_strcasecmp(value
, "any"))
2309 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2312 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2325 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2328 static int /* O - FatalErrors bits */
2329 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2331 int fatal
; /* FatalErrors bits */
2332 char value
[1024], /* Value string */
2333 *valstart
, /* Pointer into value */
2334 *valend
; /* End of value */
2338 * Empty FatalErrors line yields NULL pointer...
2342 return (CUPSD_FATAL_NONE
);
2345 * Loop through the value string,...
2348 strlcpy(value
, s
, sizeof(value
));
2350 fatal
= CUPSD_FATAL_NONE
;
2352 for (valstart
= value
; *valstart
;)
2355 * Get the current space/comma-delimited kind name...
2358 for (valend
= valstart
; *valend
; valend
++)
2359 if (_cups_isspace(*valend
) || *valend
== ',')
2366 * Add the error to the bitmask...
2369 if (!_cups_strcasecmp(valstart
, "all"))
2370 fatal
= CUPSD_FATAL_ALL
;
2371 else if (!_cups_strcasecmp(valstart
, "browse"))
2372 fatal
|= CUPSD_FATAL_BROWSE
;
2373 else if (!_cups_strcasecmp(valstart
, "-browse"))
2374 fatal
&= ~CUPSD_FATAL_BROWSE
;
2375 else if (!_cups_strcasecmp(valstart
, "config"))
2376 fatal
|= CUPSD_FATAL_CONFIG
;
2377 else if (!_cups_strcasecmp(valstart
, "-config"))
2378 fatal
&= ~CUPSD_FATAL_CONFIG
;
2379 else if (!_cups_strcasecmp(valstart
, "listen"))
2380 fatal
|= CUPSD_FATAL_LISTEN
;
2381 else if (!_cups_strcasecmp(valstart
, "-listen"))
2382 fatal
&= ~CUPSD_FATAL_LISTEN
;
2383 else if (!_cups_strcasecmp(valstart
, "log"))
2384 fatal
|= CUPSD_FATAL_LOG
;
2385 else if (!_cups_strcasecmp(valstart
, "-log"))
2386 fatal
&= ~CUPSD_FATAL_LOG
;
2387 else if (!_cups_strcasecmp(valstart
, "permissions"))
2388 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2389 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2390 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2391 else if (_cups_strcasecmp(valstart
, "none"))
2392 cupsdLogMessage(CUPSD_LOG_ERROR
,
2393 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2395 for (valstart
= valend
; *valstart
; valstart
++)
2396 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2405 * 'parse_groups()' - Parse system group names in a string.
2408 static int /* O - 1 on success, 0 on failure */
2409 parse_groups(const char *s
) /* I - Space-delimited groups */
2411 int status
; /* Return status */
2412 char value
[1024], /* Value string */
2413 *valstart
, /* Pointer into value */
2414 *valend
, /* End of value */
2415 quote
; /* Quote character */
2416 struct group
*group
; /* Group */
2420 * Make a copy of the string and parse out the groups...
2423 strlcpy(value
, s
, sizeof(value
));
2428 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2430 if (*valstart
== '\'' || *valstart
== '\"')
2433 * Scan quoted name...
2436 quote
= *valstart
++;
2438 for (valend
= valstart
; *valend
; valend
++)
2439 if (*valend
== quote
)
2445 * Scan space or comma-delimited name...
2448 for (valend
= valstart
; *valend
; valend
++)
2449 if (_cups_isspace(*valend
) || *valend
== ',')
2456 group
= getgrnam(valstart
);
2459 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2460 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2471 while (*valstart
== ',' || _cups_isspace(*valstart
))
2480 * 'parse_protocols()' - Parse browse protocols in a string.
2483 static int /* O - Browse protocol bits */
2484 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2486 int protocols
; /* Browse protocol bits */
2487 char value
[1024], /* Value string */
2488 *valstart
, /* Pointer into value */
2489 *valend
; /* End of value */
2493 * Empty protocol line yields NULL pointer...
2500 * Loop through the value string,...
2503 strlcpy(value
, s
, sizeof(value
));
2507 for (valstart
= value
; *valstart
;)
2510 * Get the current space/comma-delimited protocol name...
2513 for (valend
= valstart
; *valend
; valend
++)
2514 if (_cups_isspace(*valend
) || *valend
== ',')
2521 * Add the protocol to the bitmask...
2524 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2525 !_cups_strcasecmp(valstart
, "dns-sd") ||
2526 !_cups_strcasecmp(valstart
, "bonjour"))
2527 protocols
|= BROWSE_DNSSD
;
2528 else if (!_cups_strcasecmp(valstart
, "all"))
2529 protocols
|= BROWSE_ALL
;
2530 else if (_cups_strcasecmp(valstart
, "none"))
2531 cupsdLogMessage(CUPSD_LOG_ERROR
,
2532 "Unknown browse protocol \"%s\" ignored.", valstart
);
2534 for (valstart
= valend
; *valstart
; valstart
++)
2535 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2544 * 'read_configuration()' - Read a configuration file.
2547 static int /* O - 1 on success, 0 on failure */
2548 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2550 int i
; /* Looping var */
2551 int linenum
; /* Current line number */
2552 char line
[HTTP_MAX_BUFFER
],
2553 /* Line from file */
2554 temp
[HTTP_MAX_BUFFER
],
2555 /* Temporary buffer for value */
2556 *value
, /* Pointer to value */
2557 *valueptr
; /* Pointer into value */
2558 int valuelen
; /* Length of value */
2559 cupsd_var_t
const *var
; /* Current variable */
2560 http_addrlist_t
*addrlist
, /* Address list */
2561 *addr
; /* Current address */
2562 cups_file_t
*incfile
; /* Include file */
2563 char incname
[1024]; /* Include filename */
2564 struct group
*group
; /* Group */
2568 * Loop through each line in the file...
2573 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2576 * Decode the directive...
2579 if (!_cups_strcasecmp(line
, "Include") && value
)
2585 if (value
[0] == '/')
2586 strlcpy(incname
, value
, sizeof(incname
));
2588 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2590 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2591 cupsdLogMessage(CUPSD_LOG_ERROR
,
2592 "Unable to include config file \"%s\" - %s",
2593 incname
, strerror(errno
));
2596 read_configuration(incfile
);
2597 cupsFileClose(incfile
);
2600 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2606 linenum
= read_location(fp
, value
, linenum
);
2610 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2616 linenum
= read_policy(fp
, value
, linenum
);
2620 else if (!_cups_strcasecmp(line
, "FatalErrors"))
2621 FatalErrors
= parse_fatal_errors(value
);
2622 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2624 JobRetryInterval
= atoi(value
);
2625 cupsdLogMessage(CUPSD_LOG_WARN
,
2626 "FaxRetryInterval is deprecated; use "
2627 "JobRetryInterval on line %d.", linenum
);
2629 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2631 JobRetryLimit
= atoi(value
);
2632 cupsdLogMessage(CUPSD_LOG_WARN
,
2633 "FaxRetryLimit is deprecated; use "
2634 "JobRetryLimit on line %d.", linenum
);
2636 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
2638 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
2639 #endif /* HAVE_SSL */
2643 * Add listening address(es) to the list...
2646 cupsd_listener_t
*lis
; /* New listeners array */
2650 * Get the address list...
2653 addrlist
= get_address(value
, IPP_PORT
);
2657 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2663 * Add each address...
2666 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2669 * See if this address is already present...
2672 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2674 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2675 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2676 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2681 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2682 cupsdLogMessage(CUPSD_LOG_WARN
,
2683 "Duplicate listen address \"%s\" ignored.", temp
);
2688 * Allocate another listener...
2692 Listeners
= cupsArrayNew(NULL
, NULL
);
2696 cupsdLogMessage(CUPSD_LOG_ERROR
,
2697 "Unable to allocate %s at line %d - %s.",
2698 line
, linenum
, strerror(errno
));
2702 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2704 cupsdLogMessage(CUPSD_LOG_ERROR
,
2705 "Unable to allocate %s at line %d - %s.",
2706 line
, linenum
, strerror(errno
));
2710 cupsArrayAdd(Listeners
, lis
);
2713 * Copy the current address and log it...
2716 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2720 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
2721 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2722 #endif /* HAVE_SSL */
2724 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2727 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2728 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2730 #endif /* AF_LOCAL */
2731 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
2732 _httpAddrPort(&(lis
->address
)),
2733 _httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
2735 if (!httpAddrLocalhost(&(lis
->address
)))
2736 RemotePort
= _httpAddrPort(&(lis
->address
));
2743 httpAddrFreeList(addrlist
);
2745 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
2746 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
2749 * "BrowseProtocols name [... name]"
2750 * "BrowseLocalProtocols name [... name]"
2753 int protocols
= parse_protocols(value
);
2757 cupsdLogMessage(CUPSD_LOG_ERROR
,
2758 "Unknown browse protocol \"%s\" on line %d.",
2763 BrowseLocalProtocols
= protocols
;
2765 else if (!_cups_strcasecmp(line
, "default_auth_type") && value
)
2768 * default_auth_type {basic,digest,basicdigest,negotiate}
2771 if (!_cups_strcasecmp(value
, "none"))
2772 default_auth_type
= CUPSD_AUTH_NONE
;
2773 else if (!_cups_strcasecmp(value
, "basic"))
2774 default_auth_type
= CUPSD_AUTH_BASIC
;
2775 else if (!_cups_strcasecmp(value
, "digest"))
2776 default_auth_type
= CUPSD_AUTH_DIGEST
;
2777 else if (!_cups_strcasecmp(value
, "basicdigest"))
2778 default_auth_type
= CUPSD_AUTH_BASICDIGEST
;
2780 else if (!_cups_strcasecmp(value
, "negotiate"))
2781 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
2782 #endif /* HAVE_GSSAPI */
2783 else if (!_cups_strcasecmp(value
, "auto"))
2784 default_auth_type
= CUPSD_AUTH_AUTO
;
2787 cupsdLogMessage(CUPSD_LOG_WARN
,
2788 "Unknown default authorization type %s on line %d.",
2790 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2795 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
2798 * DefaultEncryption {Never,IfRequested,Required}
2801 if (!value
|| !_cups_strcasecmp(value
, "never"))
2802 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2803 else if (!_cups_strcasecmp(value
, "required"))
2804 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2805 else if (!_cups_strcasecmp(value
, "ifrequested"))
2806 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2809 cupsdLogMessage(CUPSD_LOG_WARN
,
2810 "Unknown default encryption %s on line %d.",
2812 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2816 #endif /* HAVE_SSL */
2817 else if (!_cups_strcasecmp(line
, "User") && value
)
2820 * User ID to run as...
2823 if (isdigit(value
[0] & 255))
2825 int uid
= atoi(value
);
2828 cupsdLogMessage(CUPSD_LOG_ERROR
,
2829 "Will not use User 0 as specified on line %d "
2830 "for security reasons. You must use a non-"
2831 "privileged account instead.",
2838 struct passwd
*p
; /* Password information */
2841 p
= getpwnam(value
);
2846 cupsdLogMessage(CUPSD_LOG_ERROR
,
2847 "Will not use User %s (UID=0) as specified on line "
2848 "%d for security reasons. You must use a non-"
2849 "privileged account instead.",
2855 cupsdLogMessage(CUPSD_LOG_ERROR
,
2856 "Unknown User \"%s\" on line %d, ignoring.",
2860 else if (!_cups_strcasecmp(line
, "Group") && value
)
2863 * Group ID to run as...
2866 if (isdigit(value
[0]))
2867 Group
= atoi(value
);
2871 group
= getgrnam(value
);
2874 Group
= group
->gr_gid
;
2876 cupsdLogMessage(CUPSD_LOG_ERROR
,
2877 "Unknown Group \"%s\" on line %d, ignoring.",
2881 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
2884 * SystemGroup (admin) group(s)...
2887 if (!parse_groups(value
))
2888 cupsdLogMessage(CUPSD_LOG_ERROR
,
2889 "Unknown SystemGroup \"%s\" on line %d, ignoring.",
2892 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
2895 * Do hostname lookups?
2898 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
2899 !_cups_strcasecmp(value
, "false"))
2900 HostNameLookups
= 0;
2901 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
2902 !_cups_strcasecmp(value
, "true"))
2903 HostNameLookups
= 1;
2904 else if (!_cups_strcasecmp(value
, "double"))
2905 HostNameLookups
= 2;
2907 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2910 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
2913 * Amount of logging to do to access log...
2916 if (!_cups_strcasecmp(value
, "all"))
2917 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
2918 else if (!_cups_strcasecmp(value
, "actions"))
2919 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
2920 else if (!_cups_strcasecmp(value
, "config"))
2921 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
2923 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
2926 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
2929 * Amount of logging to do to error log...
2932 if (!_cups_strcasecmp(value
, "debug2"))
2933 LogLevel
= CUPSD_LOG_DEBUG2
;
2934 else if (!_cups_strcasecmp(value
, "debug"))
2935 LogLevel
= CUPSD_LOG_DEBUG
;
2936 else if (!_cups_strcasecmp(value
, "info"))
2937 LogLevel
= CUPSD_LOG_INFO
;
2938 else if (!_cups_strcasecmp(value
, "notice"))
2939 LogLevel
= CUPSD_LOG_NOTICE
;
2940 else if (!_cups_strcasecmp(value
, "warn"))
2941 LogLevel
= CUPSD_LOG_WARN
;
2942 else if (!_cups_strcasecmp(value
, "error"))
2943 LogLevel
= CUPSD_LOG_ERROR
;
2944 else if (!_cups_strcasecmp(value
, "crit"))
2945 LogLevel
= CUPSD_LOG_CRIT
;
2946 else if (!_cups_strcasecmp(value
, "alert"))
2947 LogLevel
= CUPSD_LOG_ALERT
;
2948 else if (!_cups_strcasecmp(value
, "emerg"))
2949 LogLevel
= CUPSD_LOG_EMERG
;
2950 else if (!_cups_strcasecmp(value
, "none"))
2951 LogLevel
= CUPSD_LOG_NONE
;
2953 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2956 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
2959 * Amount of logging to do to error log...
2962 if (!_cups_strcasecmp(value
, "standard"))
2963 LogTimeFormat
= CUPSD_TIME_STANDARD
;
2964 else if (!_cups_strcasecmp(value
, "usecs"))
2965 LogTimeFormat
= CUPSD_TIME_USECS
;
2967 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
2970 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
2973 * Format of printcap file?
2976 if (!_cups_strcasecmp(value
, "bsd"))
2977 PrintcapFormat
= PRINTCAP_BSD
;
2978 else if (!_cups_strcasecmp(value
, "plist"))
2979 PrintcapFormat
= PRINTCAP_PLIST
;
2980 else if (!_cups_strcasecmp(value
, "solaris"))
2981 PrintcapFormat
= PRINTCAP_SOLARIS
;
2983 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2986 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
2989 * Set the string used for the Server header...
2992 struct utsname plat
; /* Platform info */
2997 if (!_cups_strcasecmp(value
, "ProductOnly"))
2998 cupsdSetString(&ServerHeader
, "CUPS");
2999 else if (!_cups_strcasecmp(value
, "Major"))
3000 cupsdSetStringf(&ServerHeader
, "CUPS/%d", CUPS_VERSION_MAJOR
);
3001 else if (!_cups_strcasecmp(value
, "Minor"))
3002 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
3003 CUPS_VERSION_MINOR
);
3004 else if (!_cups_strcasecmp(value
, "Minimal"))
3005 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3006 else if (!_cups_strcasecmp(value
, "OS"))
3007 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3008 else if (!_cups_strcasecmp(value
, "Full"))
3009 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/2.1",
3011 else if (!_cups_strcasecmp(value
, "None"))
3012 cupsdClearString(&ServerHeader
);
3014 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3017 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3020 * PassEnv variable [... variable]
3025 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3026 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3029 if (value
[valuelen
])
3031 value
[valuelen
] = '\0';
3035 cupsdSetEnv(value
, NULL
);
3037 for (value
+= valuelen
; *value
; value
++)
3038 if (!_cups_isspace(*value
) || *value
!= ',')
3042 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3045 * ServerAlias name [... name]
3049 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3053 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3054 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3057 if (value
[valuelen
])
3059 value
[valuelen
] = '\0';
3063 cupsdAddAlias(ServerAlias
, value
);
3065 for (value
+= valuelen
; *value
; value
++)
3066 if (!_cups_isspace(*value
) || *value
!= ',')
3070 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3073 * SetEnv variable value
3076 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3084 while (isspace(*valueptr
& 255))
3087 cupsdSetEnv(value
, valueptr
);
3090 cupsdLogMessage(CUPSD_LOG_ERROR
,
3091 "Missing value for SetEnv directive on line %d.",
3095 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3098 * SSLOptions options
3101 if (!value
|| !_cups_strcasecmp(value
, "none"))
3102 SSLOptions
= CUPSD_SSL_NONE
;
3103 else if (!_cups_strcasecmp(value
, "noemptyfragments"))
3104 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3106 cupsdLogMessage(CUPSD_LOG_ERROR
,
3107 "Unknown value \"%s\" for SSLOptions directive on "
3108 "line %d.", value
, linenum
);
3110 #endif /* HAVE_SSL */
3114 * Find a simple variable in the list...
3117 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3118 if (!_cups_strcasecmp(line
, var
->name
))
3124 * Unknown directive! Output an error message and continue...
3128 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3131 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3138 case CUPSD_VARTYPE_INTEGER
:
3140 cupsdLogMessage(CUPSD_LOG_ERROR
,
3141 "Missing integer value for %s on line %d.",
3146 char *units
; /* Units */
3149 n
= strtol(value
, &units
, 0);
3151 if (units
&& *units
)
3153 if (tolower(units
[0] & 255) == 'g')
3154 n
*= 1024 * 1024 * 1024;
3155 else if (tolower(units
[0] & 255) == 'm')
3157 else if (tolower(units
[0] & 255) == 'k')
3159 else if (tolower(units
[0] & 255) == 't')
3164 cupsdLogMessage(CUPSD_LOG_ERROR
,
3165 "Bad negative integer value for %s on line %d.",
3168 *((int *)var
->ptr
) = n
;
3172 case CUPSD_VARTYPE_BOOLEAN
:
3174 cupsdLogMessage(CUPSD_LOG_ERROR
,
3175 "Missing boolean value for %s on line %d.",
3177 else if (!_cups_strcasecmp(value
, "true") ||
3178 !_cups_strcasecmp(value
, "on") ||
3179 !_cups_strcasecmp(value
, "enabled") ||
3180 !_cups_strcasecmp(value
, "yes") ||
3182 *((int *)var
->ptr
) = TRUE
;
3183 else if (!_cups_strcasecmp(value
, "false") ||
3184 !_cups_strcasecmp(value
, "off") ||
3185 !_cups_strcasecmp(value
, "disabled") ||
3186 !_cups_strcasecmp(value
, "no") ||
3187 !_cups_strcasecmp(value
, "0"))
3188 *((int *)var
->ptr
) = FALSE
;
3190 cupsdLogMessage(CUPSD_LOG_ERROR
,
3191 "Unknown boolean value %s on line %d.",
3195 case CUPSD_VARTYPE_PATHNAME
:
3198 cupsdLogMessage(CUPSD_LOG_ERROR
,
3199 "Missing pathname value for %s on line %d.",
3204 if (value
[0] == '/')
3205 strlcpy(temp
, value
, sizeof(temp
));
3207 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3209 if (access(temp
, 0))
3211 cupsdLogMessage(CUPSD_LOG_ERROR
,
3212 "File or directory for \"%s %s\" on line %d "
3213 "does not exist.", line
, value
, linenum
);
3217 case CUPSD_VARTYPE_STRING
:
3218 cupsdSetString((char **)var
->ptr
, value
);
3229 * 'read_location()' - Read a <Location path> definition.
3232 static int /* O - New line number or 0 on error */
3233 read_location(cups_file_t
*fp
, /* I - Configuration file */
3234 char *location
, /* I - Location name/path */
3235 int linenum
) /* I - Current line number */
3237 cupsd_location_t
*loc
, /* New location */
3238 *parent
; /* Parent location */
3239 char line
[HTTP_MAX_BUFFER
],
3241 *value
, /* Value for directive */
3242 *valptr
; /* Pointer into value */
3245 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3246 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d.",
3248 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3252 cupsdAddLocation(parent
);
3254 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3259 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3262 * Decode the directive...
3265 if (!_cups_strcasecmp(line
, "</Location>"))
3267 else if (!_cups_strcasecmp(line
, "<Limit") ||
3268 !_cups_strcasecmp(line
, "<LimitExcept"))
3272 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3273 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3279 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3282 cupsdAddLocation(loc
);
3287 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3292 if (!strcmp(value
, "ALL"))
3293 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3294 else if (!strcmp(value
, "GET"))
3295 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3296 else if (!strcmp(value
, "HEAD"))
3297 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3298 else if (!strcmp(value
, "OPTIONS"))
3299 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3300 else if (!strcmp(value
, "POST"))
3301 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3302 else if (!strcmp(value
, "PUT"))
3303 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3304 else if (!strcmp(value
, "TRACE"))
3305 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3307 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d.",
3310 for (value
= valptr
; isspace(*value
& 255); value
++);
3313 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3314 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3316 parent
->limit
&= ~loc
->limit
;
3318 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3319 !_cups_strcasecmp(line
, "</LimitExcept>"))
3323 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3324 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3327 else if (!parse_aaa(loc
, line
, value
, linenum
))
3329 cupsdLogMessage(CUPSD_LOG_ERROR
,
3330 "Unknown Location directive %s on line %d.",
3332 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3337 cupsdLogMessage(CUPSD_LOG_ERROR
,
3338 "Unexpected end-of-file at line %d while reading location.",
3341 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3346 * 'read_policy()' - Read a <Policy name> definition.
3349 static int /* O - New line number or 0 on error */
3350 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3351 char *policy
, /* I - Location name/path */
3352 int linenum
) /* I - Current line number */
3354 int i
; /* Looping var */
3355 cupsd_policy_t
*pol
; /* Policy */
3356 cupsd_location_t
*op
; /* Policy operation */
3357 int num_ops
; /* Number of IPP operations */
3358 ipp_op_t ops
[100]; /* Operations */
3359 char line
[HTTP_MAX_BUFFER
],
3361 *value
, /* Value for directive */
3362 *valptr
; /* Pointer into value */
3366 * Create the policy...
3369 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3370 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d.",
3372 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3376 * Read from the file...
3382 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3385 * Decode the directive...
3388 if (!_cups_strcasecmp(line
, "</Policy>"))
3391 cupsdLogMessage(CUPSD_LOG_WARN
,
3392 "Missing </Limit> before </Policy> on line %d.",
3395 set_policy_defaults(pol
);
3399 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3403 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3404 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3411 * Scan for IPP operation names...
3418 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3423 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3425 if (!_cups_strcasecmp(value
, "All"))
3426 ops
[num_ops
] = IPP_ANY_OPERATION
;
3427 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3428 cupsdLogMessage(CUPSD_LOG_ERROR
,
3429 "Bad IPP operation name \"%s\" on line %d.",
3435 cupsdLogMessage(CUPSD_LOG_ERROR
,
3436 "Too many operations listed on line %d.",
3439 for (value
= valptr
; isspace(*value
& 255); value
++);
3443 * If none are specified, apply the policy to all operations...
3448 ops
[0] = IPP_ANY_OPERATION
;
3453 * Add a new policy for the first operation...
3456 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3458 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3461 * Finish the current operation limit...
3467 * Copy the policy to the other operations...
3470 for (i
= 1; i
< num_ops
; i
++)
3471 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3478 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3479 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3482 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3483 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3484 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3485 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3489 cupsdLogMessage(CUPSD_LOG_ERROR
,
3490 "%s directive must appear outside <Limit>...</Limit> "
3491 "on line %d.", line
, linenum
);
3492 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3498 * Pull out whitespace-delimited values...
3504 * Find the end of the current value...
3507 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3513 * Save it appropriately...
3516 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3519 * JobPrivateAccess {all|default|user/group list|@@ACL}
3522 if (!_cups_strcasecmp(value
, "default"))
3524 cupsdAddString(&(pol
->job_access
), "@OWNER");
3525 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3528 cupsdAddString(&(pol
->job_access
), value
);
3530 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3533 * JobPrivateValues {all|none|default|attribute list}
3536 if (!_cups_strcasecmp(value
, "default"))
3538 cupsdAddString(&(pol
->job_attrs
), "job-name");
3539 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3540 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3543 cupsdAddString(&(pol
->job_attrs
), value
);
3545 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3548 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3551 if (!_cups_strcasecmp(value
, "default"))
3553 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3554 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3557 cupsdAddString(&(pol
->sub_access
), value
);
3559 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3562 * SubscriptionPrivateValues {all|none|default|attribute list}
3565 if (!_cups_strcasecmp(value
, "default"))
3567 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3568 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3569 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3570 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3571 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3574 cupsdAddString(&(pol
->sub_attrs
), value
);
3578 * Find the next string on the line...
3581 for (value
= valptr
; isspace(*value
& 255); value
++);
3587 cupsdLogMessage(CUPSD_LOG_ERROR
,
3588 "Missing <Limit ops> directive before %s on line %d.",
3590 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3593 else if (!parse_aaa(op
, line
, value
, linenum
))
3595 cupsdLogMessage(CUPSD_LOG_ERROR
,
3596 "Unknown Policy Limit directive %s on line %d.",
3599 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3604 cupsdLogMessage(CUPSD_LOG_ERROR
,
3605 "Unexpected end-of-file at line %d while reading policy "
3606 "\"%s\".", linenum
, policy
);
3608 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3613 * 'set_policy_defaults()' - Set default policy values as needed.
3617 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
3619 cupsd_location_t
*op
; /* Policy operation */
3623 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3624 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3625 * upgrades do not introduce new security issues...
3628 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
3629 op
->op
== IPP_ANY_OPERATION
)
3631 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
3632 op
->op
!= IPP_ANY_OPERATION
)
3635 * Add a new limit for Validate-Job using the Print-Job limit as a
3639 cupsdLogMessage(CUPSD_LOG_WARN
,
3640 "No limit for Validate-Job defined in policy %s "
3641 "- using Print-Job's policy.", pol
->name
);
3643 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
3646 cupsdLogMessage(CUPSD_LOG_WARN
,
3647 "No limit for Validate-Job defined in policy %s "
3648 "and no suitable template found.", pol
->name
);
3651 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
3652 op
->op
== IPP_ANY_OPERATION
)
3654 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
3655 op
->op
!= IPP_ANY_OPERATION
)
3658 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
3662 cupsdLogMessage(CUPSD_LOG_WARN
,
3663 "No limit for Cancel-Jobs defined in policy %s "
3664 "- using Pause-Printer's policy.", pol
->name
);
3666 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
3669 cupsdLogMessage(CUPSD_LOG_WARN
,
3670 "No limit for Cancel-Jobs defined in policy %s "
3671 "and no suitable template found.", pol
->name
);
3674 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
3675 op
->op
== IPP_ANY_OPERATION
)
3677 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3678 op
->op
!= IPP_ANY_OPERATION
)
3681 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3685 cupsdLogMessage(CUPSD_LOG_WARN
,
3686 "No limit for Cancel-My-Jobs defined in policy %s "
3687 "- using Send-Document's policy.", pol
->name
);
3689 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
3692 cupsdLogMessage(CUPSD_LOG_WARN
,
3693 "No limit for Cancel-My-Jobs defined in policy %s "
3694 "and no suitable template found.", pol
->name
);
3697 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
3698 op
->op
== IPP_ANY_OPERATION
)
3700 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3701 op
->op
!= IPP_ANY_OPERATION
)
3704 * Add a new limit for Close-Job using the Send-Document limit as a
3708 cupsdLogMessage(CUPSD_LOG_WARN
,
3709 "No limit for Close-Job defined in policy %s "
3710 "- using Send-Document's policy.", pol
->name
);
3712 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
3715 cupsdLogMessage(CUPSD_LOG_WARN
,
3716 "No limit for Close-Job defined in policy %s "
3717 "and no suitable template found.", pol
->name
);
3720 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3721 op
->op
== IPP_ANY_OPERATION
)
3723 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3724 op
->op
!= IPP_ANY_OPERATION
)
3727 * Add a new limit for CUPS-Get-Document using the Send-Document
3728 * limit as a template...
3731 cupsdLogMessage(CUPSD_LOG_WARN
,
3732 "No limit for CUPS-Get-Document defined in policy %s "
3733 "- using Send-Document's policy.", pol
->name
);
3735 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3738 cupsdLogMessage(CUPSD_LOG_WARN
,
3739 "No limit for CUPS-Get-Document defined in policy %s "
3740 "and no suitable template found.", pol
->name
);
3744 * Verify we have JobPrivateAccess, JobPrivateValues,
3745 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
3748 if (!pol
->job_access
)
3750 cupsdLogMessage(CUPSD_LOG_WARN
,
3751 "No JobPrivateAccess defined in policy %s "
3752 "- using defaults.", pol
->name
);
3753 cupsdAddString(&(pol
->job_access
), "@OWNER");
3754 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3757 if (!pol
->job_attrs
)
3759 cupsdLogMessage(CUPSD_LOG_WARN
,
3760 "No JobPrivateValues defined in policy %s "
3761 "- using defaults.", pol
->name
);
3762 cupsdAddString(&(pol
->job_attrs
), "job-name");
3763 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3764 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3767 if (!pol
->sub_access
)
3769 cupsdLogMessage(CUPSD_LOG_WARN
,
3770 "No SubscriptionPrivateAccess defined in policy %s "
3771 "- using defaults.", pol
->name
);
3772 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3773 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3776 if (!pol
->sub_attrs
)
3778 cupsdLogMessage(CUPSD_LOG_WARN
,
3779 "No SubscriptionPrivateValues defined in policy %s "
3780 "- using defaults.", pol
->name
);
3781 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3782 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3783 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3784 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3785 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3791 * End of "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $".