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_TIME
, /* Time interval option */
69 CUPSD_VARTYPE_STRING
, /* String option */
70 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
71 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
76 const char *name
; /* Name of variable */
77 void *ptr
; /* Pointer to variable */
78 cupsd_vartype_t type
; /* Type (int, string, address) */
86 static int default_auth_type
= CUPSD_AUTH_AUTO
;
87 /* Default AuthType, if not specified */
88 static const cupsd_var_t variables
[] =
90 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
91 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
93 { "BrowseDNSSDSubTypes", &DNSSDSubTypes
, CUPSD_VARTYPE_STRING
},
94 #endif /* HAVE_DNSSD */
95 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
96 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
97 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
98 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
99 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
100 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
101 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
102 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
103 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_TIME
},
104 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
105 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
106 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
107 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_TIME
},
108 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
109 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
110 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
111 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
112 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
113 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
114 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
116 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
117 #endif /* HAVE_GSSAPI */
118 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_TIME
},
119 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
120 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_TIME
},
121 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_TIME
},
122 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
124 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_TIME
},
125 #endif /* HAVE_LAUNCHD */
126 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
127 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
128 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
129 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
130 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
131 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxHoldTime", &MaxHoldTime
, CUPSD_VARTYPE_TIME
},
137 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_TIME
},
142 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
148 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_TIME
},
149 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
150 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
151 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_TIME
},
152 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_TIME
},
153 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
154 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
155 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_TIME
},
156 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
157 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
158 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
159 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_TIME
},
160 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
161 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
163 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
164 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
165 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
166 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
167 #endif /* HAVE_SSL */
168 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
169 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
170 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
171 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
172 { "StrictConformance", &StrictConformance
, CUPSD_VARTYPE_BOOLEAN
},
173 #ifdef HAVE_AUTHORIZATION_H
174 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
175 #endif /* HAVE_AUTHORIZATION_H */
176 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
177 { "Timeout", &Timeout
, CUPSD_VARTYPE_TIME
},
178 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
180 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
183 static const unsigned ones
[4] =
185 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
187 static const unsigned zeros
[4] =
189 0x00000000, 0x00000000, 0x00000000, 0x00000000
197 static http_addrlist_t
*get_address(const char *value
, int defport
);
198 static int get_addr_and_mask(const char *value
, unsigned *ip
,
200 static void mime_error_cb(void *ctx
, const char *message
);
201 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
202 char *value
, int linenum
);
203 static int parse_fatal_errors(const char *s
);
204 static int parse_groups(const char *s
);
205 static int parse_protocols(const char *s
);
206 static int read_configuration(cups_file_t
*fp
);
207 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
208 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
209 static void set_policy_defaults(cupsd_policy_t
*pol
);
213 * 'cupsdAddAlias()' - Add a host alias.
217 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
218 const char *name
) /* I - Name to add */
220 cupsd_alias_t
*a
; /* New alias */
221 size_t namelen
; /* Length of name */
224 namelen
= strlen(name
);
226 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
229 a
->namelen
= namelen
;
230 strcpy(a
->name
, name
); /* OK since a->name is allocated */
232 cupsArrayAdd(aliases
, a
);
237 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
240 int /* O - 0 on success, -1 on error, 1 on warning */
241 cupsdCheckPermissions(
242 const char *filename
, /* I - File/directory name */
243 const char *suffix
, /* I - Additional file/directory name */
244 int mode
, /* I - Permissions */
245 int user
, /* I - Owner */
246 int group
, /* I - Group */
247 int is_dir
, /* I - 1 = directory, 0 = file */
248 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
250 int dir_created
= 0; /* Did we create a directory? */
251 char pathname
[1024]; /* File name with prefix */
252 struct stat fileinfo
; /* Stat buffer */
253 int is_symlink
; /* Is "filename" a symlink? */
257 * Prepend the given root to the filename before testing it...
262 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
267 * See if we can stat the file/directory...
270 if (lstat(filename
, &fileinfo
))
272 if (errno
== ENOENT
&& create_dir
)
275 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
278 if (mkdir(filename
, mode
))
281 cupsdLogMessage(CUPSD_LOG_ERROR
,
282 "Unable to create directory \"%s\" - %s", filename
,
285 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
292 fileinfo
.st_mode
= mode
| S_IFDIR
;
295 return (create_dir
? -1 : 1);
298 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
300 if (stat(filename
, &fileinfo
))
302 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
303 filename
, strerror(errno
));
309 * Make sure it's a regular file or a directory as needed...
312 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
314 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
318 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
321 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
323 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
329 * If the filename is a symlink, do not change permissions (STR #2937)...
336 * Fix owner, group, and mode as needed...
339 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
342 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
345 if (chown(filename
, user
, group
) && !getuid())
348 cupsdLogMessage(CUPSD_LOG_ERROR
,
349 "Unable to change ownership of \"%s\" - %s", filename
,
352 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
359 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
362 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
365 if (chmod(filename
, mode
))
368 cupsdLogMessage(CUPSD_LOG_ERROR
,
369 "Unable to change permissions of \"%s\" - %s", filename
,
372 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
380 * Everything is OK...
388 * 'cupsdDefaultAuthType()' - Get the default AuthType.
390 * When the default_auth_type is "auto", this function tries to get the GSS
391 * credentials for the server. If that succeeds we use Kerberos authentication,
392 * otherwise we do a fallback to Basic authentication against the local user
396 int /* O - Default AuthType value */
397 cupsdDefaultAuthType(void)
400 OM_uint32 major_status
, /* Major status code */
401 minor_status
; /* Minor status code */
402 gss_name_t server_name
; /* Server name */
403 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
404 /* Service name token */
405 char buf
[1024]; /* Service name buffer */
406 #endif /* HAVE_GSSAPI */
410 * If we have already determined the correct default AuthType, use it...
413 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
414 return (default_auth_type
);
419 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
423 if (gss_init_sec_context
== NULL
)
424 return (default_auth_type
= CUPSD_AUTH_BASIC
);
425 # endif /* __APPLE__ */
428 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
429 * that fails we must use Basic...
432 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
435 token
.length
= strlen(buf
);
436 server_name
= GSS_C_NO_NAME
;
437 major_status
= gss_import_name(&minor_status
, &token
,
438 GSS_C_NT_HOSTBASED_SERVICE
,
441 memset(&token
, 0, sizeof(token
));
443 if (GSS_ERROR(major_status
))
445 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
446 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
447 return (default_auth_type
= CUPSD_AUTH_BASIC
);
450 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
452 if (GSS_ERROR(major_status
))
454 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
455 "cupsdDefaultAuthType: gss_display_name(%s) failed",
457 return (default_auth_type
= CUPSD_AUTH_BASIC
);
460 cupsdLogMessage(CUPSD_LOG_DEBUG
,
461 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
462 "credentials for %s...", (char *)token
.value
);
464 ServerCreds
= GSS_C_NO_CREDENTIAL
;
465 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
466 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
467 &ServerCreds
, NULL
, NULL
);
468 if (GSS_ERROR(major_status
))
470 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
471 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
472 (char *)token
.value
);
473 gss_release_name(&minor_status
, &server_name
);
474 gss_release_buffer(&minor_status
, &token
);
475 return (default_auth_type
= CUPSD_AUTH_BASIC
);
478 cupsdLogMessage(CUPSD_LOG_DEBUG
,
479 "cupsdDefaultAuthType: Kerberos credentials acquired "
480 "successfully for %s.", (char *)token
.value
);
482 gss_release_name(&minor_status
, &server_name
);
483 gss_release_buffer(&minor_status
, &token
);
487 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
491 * No Kerberos support compiled in so just use Basic all the time...
494 return (default_auth_type
= CUPSD_AUTH_BASIC
);
495 #endif /* HAVE_GSSAPI */
500 * 'cupsdFreeAliases()' - Free all of the alias entries.
504 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
506 cupsd_alias_t
*a
; /* Current alias */
509 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
511 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
514 cupsArrayDelete(aliases
);
519 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
522 int /* O - 1 on success, 0 otherwise */
523 cupsdReadConfiguration(void)
525 int i
; /* Looping var */
526 cups_file_t
*fp
; /* Configuration file */
527 int status
; /* Return status */
528 char temp
[1024], /* Temporary buffer */
529 mimedir
[1024], /* MIME directory */
530 *slash
; /* Directory separator */
531 cups_lang_t
*language
; /* Language */
532 struct passwd
*user
; /* Default user */
533 struct group
*group
; /* Default group */
534 char *old_serverroot
, /* Old ServerRoot */
535 *old_requestroot
; /* Old RequestRoot */
536 int old_remote_port
; /* Old RemotePort */
537 const char *tmpdir
; /* TMPDIR environment variable */
538 struct stat tmpinfo
; /* Temporary directory info */
539 cupsd_policy_t
*p
; /* Policy */
543 * Save the old root paths...
546 old_serverroot
= NULL
;
547 cupsdSetString(&old_serverroot
, ServerRoot
);
548 old_requestroot
= NULL
;
549 cupsdSetString(&old_requestroot
, RequestRoot
);
552 * Reset the server configuration data...
555 cupsdDeleteAllLocations();
557 cupsdDeleteAllListeners();
559 old_remote_port
= RemotePort
;
566 cupsdFreeAliases(ServerAlias
);
569 cupsdClearString(&ServerName
);
570 cupsdClearString(&ServerAdmin
);
571 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
572 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
573 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
574 cupsdSetString(&DataDir
, CUPS_DATADIR
);
575 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
576 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
577 cupsdClearString(&ErrorLog
);
578 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
579 cupsdSetString(&PageLogFormat
,
580 "%p %u %j %T %P %C %{job-billing} "
581 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
582 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
583 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
584 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
585 cupsdSetString(&RemoteRoot
, "remroot");
586 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
588 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
590 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
591 PrintcapFormat
= PRINTCAP_SOLARIS
;
592 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
593 "/Library/Preferences/org.cups.printers.plist"))
594 PrintcapFormat
= PRINTCAP_PLIST
;
596 PrintcapFormat
= PRINTCAP_BSD
;
598 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
599 if ((slash
= strrchr(temp
, '/')) != NULL
)
602 cupsdSetString(&ServerRoot
, temp
);
604 cupsdClearString(&Classification
);
605 ClassifyOverride
= 0;
609 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
611 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
612 cupsdSetString(&ServerKey
, "ssl/server.key");
613 # endif /* HAVE_CDSASSL */
614 #endif /* HAVE_SSL */
616 language
= cupsLangDefault();
618 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
619 cupsdSetString(&DefaultLanguage
, "en");
621 cupsdSetString(&DefaultLanguage
, language
->language
);
623 cupsdClearString(&DefaultPaperSize
);
625 cupsdSetString(&RIPCache
, "128m");
627 cupsdSetString(&TempDir
, NULL
);
630 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
634 OM_uint32 minor_status
; /* Minor status code */
636 gss_release_cred(&minor_status
, &ServerCreds
);
641 ServerCreds
= GSS_C_NO_CREDENTIAL
;
642 #endif /* HAVE_GSSAPI */
645 * Find the default user...
648 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
653 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
654 * complement number...)
663 * Find the default group...
666 group
= getgrnam(CUPS_DEFAULT_GROUP
);
670 Group
= group
->gr_gid
;
674 * Fallback to group "nobody"...
677 group
= getgrnam("nobody");
681 Group
= group
->gr_gid
;
685 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
686 * complement number...)
697 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
698 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
699 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
700 default_auth_type
= CUPSD_AUTH_BASIC
;
702 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
703 SSLOptions
= CUPSD_SSL_NONE
;
704 #endif /* HAVE_SSL */
705 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
706 JobKillDelay
= DEFAULT_TIMEOUT
;
708 JobRetryInterval
= 300;
713 HostNameLookups
= FALSE
;
715 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
716 ListenBackLog
= SOMAXCONN
;
717 LogDebugHistory
= 200;
718 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
719 LogLevel
= CUPSD_LOG_WARN
;
720 LogTimeFormat
= CUPSD_TIME_STANDARD
;
722 MaxClientsPerHost
= 0;
723 MaxLogSize
= 1024 * 1024;
725 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
727 ReloadTimeout
= DEFAULT_KEEPALIVE
;
728 RootCertDuration
= 300;
729 StrictConformance
= FALSE
;
730 Timeout
= DEFAULT_TIMEOUT
;
731 WebInterface
= CUPS_DEFAULT_WEBIF
;
733 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
735 Browsing
= CUPS_DEFAULT_BROWSING
;
736 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
739 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
740 #endif /* HAVE_DNSSD */
742 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
743 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
745 cupsdSetString(&ErrorPolicy
, "stop-printer");
747 JobHistory
= DEFAULT_HISTORY
;
748 JobFiles
= DEFAULT_FILES
;
754 MaxJobsPerPrinter
= 0;
755 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
756 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
758 cupsdDeleteAllPolicies();
759 cupsdClearString(&DefaultPolicy
);
761 #ifdef HAVE_AUTHORIZATION_H
762 cupsdClearString(&SystemGroupAuthKey
);
763 #endif /* HAVE_AUTHORIZATION_H */
765 MaxSubscriptions
= 100;
766 MaxSubscriptionsPerJob
= 0;
767 MaxSubscriptionsPerPrinter
= 0;
768 MaxSubscriptionsPerUser
= 0;
769 DefaultLeaseDuration
= 86400;
770 MaxLeaseDuration
= 0;
774 #endif /* HAVE_LAUNCHD */
777 * Setup environment variables...
783 * Read the configuration file...
786 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
789 status
= read_configuration(fp
);
797 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
801 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
802 RemotePort
? "enabled" : "disabled");
805 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
808 * See if the ServerName is an IP address...
814 ServerAlias
= cupsArrayNew(NULL
, NULL
);
816 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
820 if (gethostname(temp
, sizeof(temp
)))
822 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
824 strlcpy(temp
, "localhost", sizeof(temp
));
827 cupsdSetString(&ServerName
, temp
);
830 ServerAlias
= cupsArrayNew(NULL
, NULL
);
832 cupsdAddAlias(ServerAlias
, temp
);
833 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
835 if (HostNameLookups
|| RemotePort
)
837 struct hostent
*host
; /* Host entry to get FQDN */
839 if ((host
= gethostbyname(temp
)) != NULL
)
841 if (_cups_strcasecmp(temp
, host
->h_name
))
843 cupsdSetString(&ServerName
, host
->h_name
);
844 cupsdAddAlias(ServerAlias
, host
->h_name
);
845 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
851 for (i
= 0; host
->h_aliases
[i
]; i
++)
852 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
854 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
855 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
863 * Make sure we have the base hostname added as an alias, too!
866 if ((slash
= strchr(temp
, '.')) != NULL
)
869 cupsdAddAlias(ServerAlias
, temp
);
870 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
874 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
876 ServerNameIsIP
= !*slash
;
879 * Make sure ServerAdmin is initialized...
883 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
886 * Use the default system group if none was supplied in cupsd.conf...
889 if (NumSystemGroups
== 0)
891 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
894 * Find the group associated with GID 0...
901 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
903 cupsdSetString(&SystemGroups
[0], "unknown");
905 SystemGroupIDs
[0] = 0;
911 * Open the system log for cupsd if necessary...
915 if (!strcmp(AccessLog
, "syslog") ||
916 !strcmp(ErrorLog
, "syslog") ||
917 !strcmp(PageLog
, "syslog"))
918 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
919 #endif /* HAVE_VSYSLOG */
922 * Make sure each of the log files exists and gets rotated as necessary...
925 if (strcmp(AccessLog
, "syslog"))
926 cupsdCheckLogFile(&AccessFile
, AccessLog
);
928 if (strcmp(ErrorLog
, "syslog"))
929 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
931 if (strcmp(PageLog
, "syslog"))
932 cupsdCheckLogFile(&PageFile
, PageLog
);
935 * Log the configuration file that was used...
938 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
942 * Validate the Group and SystemGroup settings - they cannot be the same,
943 * otherwise the CGI programs will be able to authenticate as root without
949 for (i
= 0; i
< NumSystemGroups
; i
++)
950 if (Group
== SystemGroupIDs
[i
])
953 if (i
< NumSystemGroups
)
956 * Log the error and reset the group to a safe value...
959 cupsdLogMessage(CUPSD_LOG_NOTICE
,
960 "Group and SystemGroup cannot use the same groups.");
961 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
963 group
= getgrnam("nobody");
967 Group
= group
->gr_gid
;
971 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
972 * complement number...)
981 * Check that we have at least one listen/port line; if not, report this
982 * as an error and exit!
985 if (cupsArrayCount(Listeners
) == 0)
991 cupsdLogMessage(CUPSD_LOG_EMERG
,
992 "No valid Listen or Port lines were found in the "
993 "configuration file.");
999 cupsdEndProcess(getpid(), 0);
1003 * Set the default locale using the language and charset...
1006 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1009 * Update all relative filenames to include the full path from ServerRoot...
1012 if (DocumentRoot
[0] != '/')
1013 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1015 if (RequestRoot
[0] != '/')
1016 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1018 if (ServerBin
[0] != '/')
1019 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1021 if (StateDir
[0] != '/')
1022 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1024 if (CacheDir
[0] != '/')
1025 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1028 if (ServerCertificate
[0] != '/')
1029 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
1031 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
1032 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
1034 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1037 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
1038 if (ServerKey
[0] != '/')
1039 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
1041 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
1042 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
1043 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1045 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
1046 #endif /* HAVE_SSL */
1049 * Make sure that directories and config files are owned and
1050 * writable by the user and group in the cupsd.conf file...
1053 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1055 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1057 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
1059 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1061 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1063 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1064 SystemGroupIDs
[0], 1, 1) < 0 ||
1065 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1067 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1069 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1071 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
1073 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1075 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1077 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1078 Group
, 0, 0) < 0) &&
1079 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1083 * Update TempDir to the default if it hasn't been set already...
1089 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1090 strncmp(tmpdir
, "/private/tmp", 12))
1092 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1093 #endif /* __APPLE__ */
1096 * TMPDIR is defined, see if it is OK for us to use...
1099 if (stat(tmpdir
, &tmpinfo
))
1100 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1101 tmpdir
, strerror(errno
));
1102 else if (!S_ISDIR(tmpinfo
.st_mode
))
1103 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1105 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1106 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1107 !(tmpinfo
.st_mode
& S_IWOTH
))
1108 cupsdLogMessage(CUPSD_LOG_ERROR
,
1109 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1111 cupsdSetString(&TempDir
, tmpdir
);
1116 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1118 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1123 * Make sure the temporary directory has the right permissions...
1126 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1130 * Update ownership and permissions if the CUPS temp directory
1131 * is under the spool directory or does not exist...
1134 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1135 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1140 * Update environment variables...
1146 * Update default paper size setting as needed...
1149 if (!DefaultPaperSize
)
1151 #ifdef HAVE_LIBPAPER
1152 char *paper_result
; /* Paper size name from libpaper */
1154 if ((paper_result
= systempapername()) != NULL
)
1155 cupsdSetString(&DefaultPaperSize
, paper_result
);
1157 #endif /* HAVE_LIBPAPER */
1158 if (!DefaultLanguage
||
1159 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1160 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1161 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1162 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1163 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1164 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1165 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1168 * These are the only locales that will default to "letter" size...
1171 cupsdSetString(&DefaultPaperSize
, "Letter");
1174 cupsdSetString(&DefaultPaperSize
, "A4");
1178 * Update classification setting as needed...
1181 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1182 cupsdClearString(&Classification
);
1185 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1188 * Check the MaxClients setting, and then allocate memory for it...
1191 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1194 cupsdLogMessage(CUPSD_LOG_INFO
,
1195 "MaxClients limited to 1/3 (%d) of the file descriptor "
1197 MaxFDs
/ 3, MaxFDs
);
1199 MaxClients
= MaxFDs
/ 3;
1202 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1206 * Check the MaxActiveJobs setting; limit to 1/3 the available
1207 * file descriptors, since we need a pipe for each job...
1210 if (MaxActiveJobs
> (MaxFDs
/ 3))
1211 MaxActiveJobs
= MaxFDs
/ 3;
1214 * Update the MaxClientsPerHost value, as needed...
1217 if (MaxClientsPerHost
<= 0)
1218 MaxClientsPerHost
= MaxClients
;
1220 if (MaxClientsPerHost
> MaxClients
)
1221 MaxClientsPerHost
= MaxClients
;
1223 cupsdLogMessage(CUPSD_LOG_INFO
,
1224 "Allowing up to %d client connections per host.",
1228 * Update the default policy, as needed...
1232 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1234 DefaultPolicyPtr
= NULL
;
1236 if (!DefaultPolicyPtr
)
1238 cupsd_location_t
*po
; /* New policy operation */
1242 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1245 cupsdSetString(&DefaultPolicy
, "default");
1247 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1248 cupsdLogMessage(CUPSD_LOG_INFO
,
1249 "Using policy \"default\" as the default.");
1252 cupsdLogMessage(CUPSD_LOG_INFO
,
1253 "Creating CUPS default administrative policy:");
1255 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1257 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1259 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1260 cupsdAddString(&(p
->job_access
), "@OWNER");
1261 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1263 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1264 cupsdAddString(&(p
->job_attrs
), "job-name");
1265 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1266 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1268 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1269 cupsdAddString(&(p
->sub_access
), "@OWNER");
1270 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1272 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1273 cupsdAddString(&(p
->job_attrs
), "notify-events");
1274 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1275 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1276 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1277 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1279 cupsdLogMessage(CUPSD_LOG_INFO
,
1280 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1281 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1283 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1284 po
->order_type
= CUPSD_AUTH_ALLOW
;
1286 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1287 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1288 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1290 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1292 cupsdLogMessage(CUPSD_LOG_INFO
,
1293 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1294 "Release-Job Restart-Job Purge-Jobs "
1295 "Set-Job-Attributes Create-Job-Subscription "
1296 "Renew-Subscription Cancel-Subscription "
1297 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1298 "Suspend-Current-Job Resume-Job "
1299 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1300 "CUPS-Authenticate-Job CUPS-Get-Document>");
1301 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1303 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1304 po
->order_type
= CUPSD_AUTH_ALLOW
;
1305 po
->level
= CUPSD_AUTH_USER
;
1307 cupsdAddName(po
, "@OWNER");
1308 cupsdAddName(po
, "@SYSTEM");
1309 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1311 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1312 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1313 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1314 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1315 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1316 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1317 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1318 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1319 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1320 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1321 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1322 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1323 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1324 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1325 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1326 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1327 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1328 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1329 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1330 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1332 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1334 cupsdLogMessage(CUPSD_LOG_INFO
,
1335 "<Limit Pause-Printer Resume-Printer "
1336 "Set-Printer-Attributes Enable-Printer "
1337 "Disable-Printer Pause-Printer-After-Current-Job "
1338 "Hold-New-Jobs Release-Held-New-Jobs "
1339 "Deactivate-Printer Activate-Printer Restart-Printer "
1340 "Shutdown-Printer Startup-Printer Promote-Job "
1341 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1342 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1343 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1344 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1345 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1347 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1348 po
->order_type
= CUPSD_AUTH_ALLOW
;
1349 po
->type
= CUPSD_AUTH_DEFAULT
;
1350 po
->level
= CUPSD_AUTH_USER
;
1352 cupsdAddName(po
, "@SYSTEM");
1353 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1355 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1356 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1357 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1358 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1359 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1360 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1361 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1362 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1363 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1364 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1365 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1366 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1367 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1368 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1369 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1370 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1371 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1372 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1373 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1374 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1375 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1376 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1378 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1380 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1381 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1383 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1384 po
->order_type
= CUPSD_AUTH_ALLOW
;
1386 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1387 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1391 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1392 cupsArrayCount(Policies
));
1393 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1395 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1396 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1397 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1400 * If we are doing a full reload or the server root has changed, flush
1401 * the jobs, printers, etc. and start from scratch...
1404 if (NeedReload
== RELOAD_ALL
||
1405 old_remote_port
!= RemotePort
||
1406 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1407 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1409 mime_type_t
*type
; /* Current type */
1410 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1411 /* MIME type name */
1414 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1417 * Free all memory...
1420 cupsdDeleteAllSubscriptions();
1422 cupsdDeleteAllPrinters();
1424 DefaultPrinter
= NULL
;
1426 if (MimeDatabase
!= NULL
)
1427 mimeDelete(MimeDatabase
);
1431 for (i
= 0; i
< NumMimeTypes
; i
++)
1432 _cupsStrFree(MimeTypes
[i
]);
1438 * Read the MIME type and conversion database...
1441 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1442 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1444 MimeDatabase
= mimeNew();
1445 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1447 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1448 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1449 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1450 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1454 cupsdLogMessage(CUPSD_LOG_EMERG
,
1455 "Unable to load MIME database from \"%s\" or \"%s\".",
1456 mimedir
, ServerRoot
);
1457 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1461 cupsdLogMessage(CUPSD_LOG_INFO
,
1462 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1463 "%d filters...", mimedir
, ServerRoot
,
1464 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1467 * Create a list of MIME types for the document-format-supported
1471 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1472 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1475 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1477 cupsdLogMessage(CUPSD_LOG_ERROR
,
1478 "Unable to allocate memory for %d MIME types.",
1484 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1486 i
++, type
= mimeNextType(MimeDatabase
))
1488 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1490 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1493 if (i
< NumMimeTypes
)
1494 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1497 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1499 mime_filter_t
*filter
; /* Current filter */
1502 for (type
= mimeFirstType(MimeDatabase
);
1504 type
= mimeNextType(MimeDatabase
))
1505 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1506 type
->super
, type
->type
);
1508 for (filter
= mimeFirstFilter(MimeDatabase
);
1510 filter
= mimeNextFilter(MimeDatabase
))
1511 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1512 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1513 filter
->src
->super
, filter
->src
->type
,
1514 filter
->dst
->super
, filter
->dst
->type
,
1515 filter
->cost
, filter
->filter
);
1522 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1523 cupsdLoadBanners(temp
);
1526 * Load printers and classes...
1529 cupsdLoadAllPrinters();
1530 cupsdLoadAllClasses();
1532 cupsdCreateCommonData();
1535 * Update the printcap file as needed...
1538 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1539 cupsdWritePrintcap();
1542 * Load queued jobs...
1548 * Load subscriptions...
1551 cupsdLoadAllSubscriptions();
1553 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1558 * Not a full reload, so recreate the common printer attributes...
1561 cupsdCreateCommonData();
1564 * Update all jobs as needed...
1570 * Update all printers as needed...
1573 cupsdUpdatePrinters();
1574 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1576 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1580 * Reset the reload state...
1583 NeedReload
= RELOAD_NONE
;
1585 cupsdClearString(&old_serverroot
);
1586 cupsdClearString(&old_requestroot
);
1593 * 'get_address()' - Get an address + port number from a line.
1596 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1597 get_address(const char *value
, /* I - Value string */
1598 int defport
) /* I - Default port */
1600 char buffer
[1024], /* Hostname + port number buffer */
1601 defpname
[255], /* Default port name */
1602 *hostname
, /* Hostname or IP */
1603 *portname
; /* Port number or name */
1604 http_addrlist_t
*addrlist
; /* Address list */
1608 * Check for an empty value...
1613 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1618 * Grab a hostname and port number; if there is no colon and the port name
1619 * is only digits, then we have a port number by itself...
1622 strlcpy(buffer
, value
, sizeof(buffer
));
1624 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1631 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1636 * Use the default port...
1639 sprintf(defpname
, "%d", defport
);
1640 portname
= defpname
;
1646 * The buffer contains just a port number...
1654 if (hostname
&& !strcmp(hostname
, "*"))
1658 * Now lookup the address using httpAddrGetList()...
1661 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1662 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1663 hostname
? hostname
: "(nil)");
1670 * 'get_addr_and_mask()' - Get an IP address and netmask.
1673 static int /* O - 1 on success, 0 on failure */
1674 get_addr_and_mask(const char *value
, /* I - String from config file */
1675 unsigned *ip
, /* O - Address value */
1676 unsigned *mask
) /* O - Mask value */
1678 int i
, j
, /* Looping vars */
1679 family
, /* Address family */
1680 ipcount
; /* Count of fields in address */
1681 unsigned ipval
; /* Value */
1682 const char *maskval
, /* Pointer to start of mask value */
1683 *ptr
, /* Pointer into value */
1688 * Get the address...
1691 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1692 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1694 if ((maskval
= strchr(value
, '/')) != NULL
)
1697 maskval
= value
+ strlen(value
);
1701 * Check for an IPv6 address...
1707 * Parse hexadecimal IPv6/IPv4 address...
1712 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1716 else if (!strncmp(ptr
, "::", 2))
1718 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1720 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1725 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1728 * Read IPv4 dotted quad...
1731 unsigned val
[4] = { 0, 0, 0, 0 };
1732 /* IPv4 address values */
1734 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1738 * Range check the IP numbers...
1741 for (i
= 0; i
< ipcount
; i
++)
1746 * Merge everything into a 32-bit IPv4 address in ip[3]...
1749 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1752 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1755 * If the leading words are all 0's then this is an IPv4 address...
1758 if (!val
[0] && !val
[1] && !val
[2])
1761 while (isdigit(*ptr
& 255) || *ptr
== '.')
1765 else if (isxdigit(*ptr
& 255))
1767 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1769 if (*ptr
== ':' && ptr
[1] != ':')
1778 ip
[i
/ 2] |= ipval
<< 16;
1789 if (*ptr
&& *ptr
!= '/')
1793 #endif /* AF_INET6 */
1796 * Parse dotted-decimal IPv4 address...
1799 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1803 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1806 * Range check the IP numbers...
1809 for (i
= 0; i
< ipcount
; i
++)
1814 * Merge everything into a 32-bit IPv4 address in ip[3]...
1817 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1820 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1826 * Get the netmask value(s)...
1829 memset(mask
, 0, sizeof(unsigned) * 4);
1831 if (strchr(maskval
, '.'))
1834 * Get dotted-decimal mask...
1837 if (family
!= AF_INET
)
1840 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1844 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1845 mask
[0] = mask
[1] = mask
[2] = 0;
1850 * Get address/bits format...
1856 if (family
== AF_INET6
)
1864 mask
[0] = 0xffffffff;
1866 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1869 mask
[1] = 0xffffffff;
1873 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1876 mask
[2] = 0xffffffff;
1880 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1883 mask
[3] = 0xffffffff;
1887 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1890 #endif /* AF_INET6 */
1895 mask
[0] = 0xffffffff;
1896 mask
[1] = 0xffffffff;
1897 mask
[2] = 0xffffffff;
1900 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1902 mask
[3] = 0xffffffff;
1907 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1908 "get_addr_and_mask(value=\"%s\", "
1909 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1910 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1914 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1917 if ((ip
[0] & ~mask
[0]) != 0 ||
1918 (ip
[1] & ~mask
[1]) != 0 ||
1919 (ip
[2] & ~mask
[2]) != 0 ||
1920 (ip
[3] & ~mask
[3]) != 0)
1928 * 'mime_error_cb()' - Log a MIME error.
1932 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
1933 const char *message
) /* I - Message */
1937 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
1942 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1945 static int /* O - 1 on success, 0 on failure */
1946 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1947 char *line
, /* I - Line from file */
1948 char *value
, /* I - Start of value data */
1949 int linenum
) /* I - Current line number */
1951 char *valptr
; /* Pointer into value */
1952 unsigned ip
[4], /* IP address components */
1953 mask
[4]; /* IP netmask components */
1956 if (!_cups_strcasecmp(line
, "Encryption"))
1959 * "Encryption xxx" - set required encryption level...
1962 if (!_cups_strcasecmp(value
, "never"))
1963 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1964 else if (!_cups_strcasecmp(value
, "always"))
1966 cupsdLogMessage(CUPSD_LOG_ERROR
,
1967 "Encryption value \"%s\" on line %d is invalid in this "
1968 "context. Using \"required\" instead.", value
, linenum
);
1970 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1972 else if (!_cups_strcasecmp(value
, "required"))
1973 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1974 else if (!_cups_strcasecmp(value
, "ifrequested"))
1975 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1978 cupsdLogMessage(CUPSD_LOG_ERROR
,
1979 "Unknown Encryption value %s on line %d.", value
, linenum
);
1983 else if (!_cups_strcasecmp(line
, "Order"))
1986 * "Order Deny,Allow" or "Order Allow,Deny"...
1989 if (!_cups_strncasecmp(value
, "deny", 4))
1990 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1991 else if (!_cups_strncasecmp(value
, "allow", 5))
1992 loc
->order_type
= CUPSD_AUTH_DENY
;
1995 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
2000 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2003 * Allow [From] host/ip...
2004 * Deny [From] host/ip...
2009 if (!_cups_strncasecmp(value
, "from", 4))
2012 * Strip leading "from"...
2017 while (_cups_isspace(*value
))
2025 * Find the end of the value...
2028 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2030 while (_cups_isspace(*valptr
))
2034 * Figure out what form the allow/deny address takes:
2045 * nnn.nnn.nnn.nnn/mm
2046 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2049 if (!_cups_strcasecmp(value
, "all"))
2055 if (!_cups_strcasecmp(line
, "Allow"))
2056 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2058 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2060 else if (!_cups_strcasecmp(value
, "none"))
2066 if (!_cups_strcasecmp(line
, "Allow"))
2067 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2069 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2072 else if (value
[0] == '*' || value
[0] == '.' ||
2073 (!isdigit(value
[0] & 255) && value
[0] != '['))
2075 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2076 #endif /* AF_INET6 */
2079 * Host or domain name...
2082 if (value
[0] == '*')
2085 if (!_cups_strcasecmp(line
, "Allow"))
2086 cupsdAddNameMask(&(loc
->allow
), value
);
2088 cupsdAddNameMask(&(loc
->deny
), value
);
2093 * One of many IP address forms...
2096 if (!get_addr_and_mask(value
, ip
, mask
))
2098 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2103 if (!_cups_strcasecmp(line
, "Allow"))
2104 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2106 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2110 * Advance to next value...
2116 else if (!_cups_strcasecmp(line
, "AuthType"))
2119 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2122 if (!_cups_strcasecmp(value
, "none"))
2124 loc
->type
= CUPSD_AUTH_NONE
;
2125 loc
->level
= CUPSD_AUTH_ANON
;
2127 else if (!_cups_strcasecmp(value
, "basic"))
2129 loc
->type
= CUPSD_AUTH_BASIC
;
2131 if (loc
->level
== CUPSD_AUTH_ANON
)
2132 loc
->level
= CUPSD_AUTH_USER
;
2134 else if (!_cups_strcasecmp(value
, "digest"))
2136 loc
->type
= CUPSD_AUTH_DIGEST
;
2138 if (loc
->level
== CUPSD_AUTH_ANON
)
2139 loc
->level
= CUPSD_AUTH_USER
;
2141 else if (!_cups_strcasecmp(value
, "basicdigest"))
2143 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
2145 if (loc
->level
== CUPSD_AUTH_ANON
)
2146 loc
->level
= CUPSD_AUTH_USER
;
2148 else if (!_cups_strcasecmp(value
, "default"))
2150 loc
->type
= CUPSD_AUTH_DEFAULT
;
2152 if (loc
->level
== CUPSD_AUTH_ANON
)
2153 loc
->level
= CUPSD_AUTH_USER
;
2156 else if (!_cups_strcasecmp(value
, "negotiate"))
2158 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2160 if (loc
->level
== CUPSD_AUTH_ANON
)
2161 loc
->level
= CUPSD_AUTH_USER
;
2163 #endif /* HAVE_GSSAPI */
2166 cupsdLogMessage(CUPSD_LOG_WARN
,
2167 "Unknown authorization type %s on line %d.",
2172 else if (!_cups_strcasecmp(line
, "AuthClass"))
2175 * AuthClass anonymous, user, system, group
2178 if (!_cups_strcasecmp(value
, "anonymous"))
2180 loc
->type
= CUPSD_AUTH_NONE
;
2181 loc
->level
= CUPSD_AUTH_ANON
;
2183 cupsdLogMessage(CUPSD_LOG_WARN
,
2184 "\"AuthClass %s\" is deprecated; consider removing "
2188 else if (!_cups_strcasecmp(value
, "user"))
2190 loc
->level
= CUPSD_AUTH_USER
;
2192 cupsdLogMessage(CUPSD_LOG_WARN
,
2193 "\"AuthClass %s\" is deprecated; consider using "
2194 "\"Require valid-user\" on line %d.",
2197 else if (!_cups_strcasecmp(value
, "group"))
2199 loc
->level
= CUPSD_AUTH_GROUP
;
2201 cupsdLogMessage(CUPSD_LOG_WARN
,
2202 "\"AuthClass %s\" is deprecated; consider using "
2203 "\"Require user @groupname\" on line %d.",
2206 else if (!_cups_strcasecmp(value
, "system"))
2208 loc
->level
= CUPSD_AUTH_GROUP
;
2210 cupsdAddName(loc
, "@SYSTEM");
2212 cupsdLogMessage(CUPSD_LOG_WARN
,
2213 "\"AuthClass %s\" is deprecated; consider using "
2214 "\"Require user @SYSTEM\" on line %d.",
2219 cupsdLogMessage(CUPSD_LOG_WARN
,
2220 "Unknown authorization class %s on line %d.",
2225 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2227 cupsdAddName(loc
, value
);
2229 cupsdLogMessage(CUPSD_LOG_WARN
,
2230 "\"AuthGroupName %s\" directive is deprecated; consider "
2231 "using \"Require user @%s\" on line %d.",
2232 value
, value
, linenum
);
2234 else if (!_cups_strcasecmp(line
, "Require"))
2237 * Apache synonym for AuthClass and AuthGroupName...
2241 * Require valid-user
2242 * Require group names
2243 * Require user names
2246 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2251 if (!_cups_strcasecmp(value
, "valid-user") ||
2252 !_cups_strcasecmp(value
, "user"))
2253 loc
->level
= CUPSD_AUTH_USER
;
2254 else if (!_cups_strcasecmp(value
, "group"))
2255 loc
->level
= CUPSD_AUTH_GROUP
;
2258 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2264 * Get the list of names from the line...
2267 for (value
= valptr
; *value
;)
2269 while (_cups_isspace(*value
))
2272 #ifdef HAVE_AUTHORIZATION_H
2273 if (!strncmp(value
, "@AUTHKEY(", 9))
2276 * Grab "@AUTHKEY(name)" value...
2279 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2285 #endif /* HAVE_AUTHORIZATION_H */
2286 if (*value
== '\"' || *value
== '\'')
2289 * Grab quoted name...
2292 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2299 * Grab literal name.
2302 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2308 cupsdAddName(loc
, value
);
2310 for (value
= valptr
; _cups_isspace(*value
); value
++);
2313 else if (!_cups_strcasecmp(line
, "Satisfy"))
2315 if (!_cups_strcasecmp(value
, "all"))
2316 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2317 else if (!_cups_strcasecmp(value
, "any"))
2318 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2321 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2334 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2337 static int /* O - FatalErrors bits */
2338 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2340 int fatal
; /* FatalErrors bits */
2341 char value
[1024], /* Value string */
2342 *valstart
, /* Pointer into value */
2343 *valend
; /* End of value */
2347 * Empty FatalErrors line yields NULL pointer...
2351 return (CUPSD_FATAL_NONE
);
2354 * Loop through the value string,...
2357 strlcpy(value
, s
, sizeof(value
));
2359 fatal
= CUPSD_FATAL_NONE
;
2361 for (valstart
= value
; *valstart
;)
2364 * Get the current space/comma-delimited kind name...
2367 for (valend
= valstart
; *valend
; valend
++)
2368 if (_cups_isspace(*valend
) || *valend
== ',')
2375 * Add the error to the bitmask...
2378 if (!_cups_strcasecmp(valstart
, "all"))
2379 fatal
= CUPSD_FATAL_ALL
;
2380 else if (!_cups_strcasecmp(valstart
, "browse"))
2381 fatal
|= CUPSD_FATAL_BROWSE
;
2382 else if (!_cups_strcasecmp(valstart
, "-browse"))
2383 fatal
&= ~CUPSD_FATAL_BROWSE
;
2384 else if (!_cups_strcasecmp(valstart
, "config"))
2385 fatal
|= CUPSD_FATAL_CONFIG
;
2386 else if (!_cups_strcasecmp(valstart
, "-config"))
2387 fatal
&= ~CUPSD_FATAL_CONFIG
;
2388 else if (!_cups_strcasecmp(valstart
, "listen"))
2389 fatal
|= CUPSD_FATAL_LISTEN
;
2390 else if (!_cups_strcasecmp(valstart
, "-listen"))
2391 fatal
&= ~CUPSD_FATAL_LISTEN
;
2392 else if (!_cups_strcasecmp(valstart
, "log"))
2393 fatal
|= CUPSD_FATAL_LOG
;
2394 else if (!_cups_strcasecmp(valstart
, "-log"))
2395 fatal
&= ~CUPSD_FATAL_LOG
;
2396 else if (!_cups_strcasecmp(valstart
, "permissions"))
2397 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2398 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2399 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2400 else if (_cups_strcasecmp(valstart
, "none"))
2401 cupsdLogMessage(CUPSD_LOG_ERROR
,
2402 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2404 for (valstart
= valend
; *valstart
; valstart
++)
2405 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2414 * 'parse_groups()' - Parse system group names in a string.
2417 static int /* O - 1 on success, 0 on failure */
2418 parse_groups(const char *s
) /* I - Space-delimited groups */
2420 int status
; /* Return status */
2421 char value
[1024], /* Value string */
2422 *valstart
, /* Pointer into value */
2423 *valend
, /* End of value */
2424 quote
; /* Quote character */
2425 struct group
*group
; /* Group */
2429 * Make a copy of the string and parse out the groups...
2432 strlcpy(value
, s
, sizeof(value
));
2437 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2439 if (*valstart
== '\'' || *valstart
== '\"')
2442 * Scan quoted name...
2445 quote
= *valstart
++;
2447 for (valend
= valstart
; *valend
; valend
++)
2448 if (*valend
== quote
)
2454 * Scan space or comma-delimited name...
2457 for (valend
= valstart
; *valend
; valend
++)
2458 if (_cups_isspace(*valend
) || *valend
== ',')
2465 group
= getgrnam(valstart
);
2468 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2469 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2480 while (*valstart
== ',' || _cups_isspace(*valstart
))
2489 * 'parse_protocols()' - Parse browse protocols in a string.
2492 static int /* O - Browse protocol bits */
2493 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2495 int protocols
; /* Browse protocol bits */
2496 char value
[1024], /* Value string */
2497 *valstart
, /* Pointer into value */
2498 *valend
; /* End of value */
2502 * Empty protocol line yields NULL pointer...
2509 * Loop through the value string,...
2512 strlcpy(value
, s
, sizeof(value
));
2516 for (valstart
= value
; *valstart
;)
2519 * Get the current space/comma-delimited protocol name...
2522 for (valend
= valstart
; *valend
; valend
++)
2523 if (_cups_isspace(*valend
) || *valend
== ',')
2530 * Add the protocol to the bitmask...
2533 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2534 !_cups_strcasecmp(valstart
, "dns-sd") ||
2535 !_cups_strcasecmp(valstart
, "bonjour"))
2536 protocols
|= BROWSE_DNSSD
;
2537 else if (!_cups_strcasecmp(valstart
, "all"))
2538 protocols
|= BROWSE_ALL
;
2539 else if (_cups_strcasecmp(valstart
, "none"))
2540 cupsdLogMessage(CUPSD_LOG_ERROR
,
2541 "Unknown browse protocol \"%s\" ignored.", valstart
);
2543 for (valstart
= valend
; *valstart
; valstart
++)
2544 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2553 * 'read_configuration()' - Read a configuration file.
2556 static int /* O - 1 on success, 0 on failure */
2557 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2559 int i
; /* Looping var */
2560 int linenum
; /* Current line number */
2561 char line
[HTTP_MAX_BUFFER
],
2562 /* Line from file */
2563 temp
[HTTP_MAX_BUFFER
],
2564 /* Temporary buffer for value */
2565 *value
, /* Pointer to value */
2566 *valueptr
; /* Pointer into value */
2567 int valuelen
; /* Length of value */
2568 cupsd_var_t
const *var
; /* Current variable */
2569 http_addrlist_t
*addrlist
, /* Address list */
2570 *addr
; /* Current address */
2571 cups_file_t
*incfile
; /* Include file */
2572 char incname
[1024]; /* Include filename */
2573 struct group
*group
; /* Group */
2577 * Loop through each line in the file...
2582 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2585 * Decode the directive...
2588 if (!_cups_strcasecmp(line
, "Include") && value
)
2594 if (value
[0] == '/')
2595 strlcpy(incname
, value
, sizeof(incname
));
2597 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2599 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2600 cupsdLogMessage(CUPSD_LOG_ERROR
,
2601 "Unable to include config file \"%s\" - %s",
2602 incname
, strerror(errno
));
2605 read_configuration(incfile
);
2606 cupsFileClose(incfile
);
2609 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2615 linenum
= read_location(fp
, value
, linenum
);
2619 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2625 linenum
= read_policy(fp
, value
, linenum
);
2629 else if (!_cups_strcasecmp(line
, "FatalErrors"))
2630 FatalErrors
= parse_fatal_errors(value
);
2631 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2633 JobRetryInterval
= atoi(value
);
2634 cupsdLogMessage(CUPSD_LOG_WARN
,
2635 "FaxRetryInterval is deprecated; use "
2636 "JobRetryInterval on line %d.", linenum
);
2638 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2640 JobRetryLimit
= atoi(value
);
2641 cupsdLogMessage(CUPSD_LOG_WARN
,
2642 "FaxRetryLimit is deprecated; use "
2643 "JobRetryLimit on line %d.", linenum
);
2645 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
2647 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
2648 #endif /* HAVE_SSL */
2652 * Add listening address(es) to the list...
2655 cupsd_listener_t
*lis
; /* New listeners array */
2659 * Get the address list...
2662 addrlist
= get_address(value
, IPP_PORT
);
2666 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2672 * Add each address...
2675 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2678 * See if this address is already present...
2681 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2683 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2684 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2685 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2690 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2691 cupsdLogMessage(CUPSD_LOG_WARN
,
2692 "Duplicate listen address \"%s\" ignored.", temp
);
2697 * Allocate another listener...
2701 Listeners
= cupsArrayNew(NULL
, NULL
);
2705 cupsdLogMessage(CUPSD_LOG_ERROR
,
2706 "Unable to allocate %s at line %d - %s.",
2707 line
, linenum
, strerror(errno
));
2711 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2713 cupsdLogMessage(CUPSD_LOG_ERROR
,
2714 "Unable to allocate %s at line %d - %s.",
2715 line
, linenum
, strerror(errno
));
2719 cupsArrayAdd(Listeners
, lis
);
2722 * Copy the current address and log it...
2725 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2729 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
2730 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2731 #endif /* HAVE_SSL */
2733 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2736 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2737 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2739 #endif /* AF_LOCAL */
2740 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
2741 _httpAddrPort(&(lis
->address
)),
2742 _httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
2744 if (!httpAddrLocalhost(&(lis
->address
)))
2745 RemotePort
= _httpAddrPort(&(lis
->address
));
2752 httpAddrFreeList(addrlist
);
2754 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
2755 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
2758 * "BrowseProtocols name [... name]"
2759 * "BrowseLocalProtocols name [... name]"
2762 int protocols
= parse_protocols(value
);
2766 cupsdLogMessage(CUPSD_LOG_ERROR
,
2767 "Unknown browse protocol \"%s\" on line %d.",
2772 BrowseLocalProtocols
= protocols
;
2774 else if (!_cups_strcasecmp(line
, "default_auth_type") && value
)
2777 * default_auth_type {basic,digest,basicdigest,negotiate}
2780 if (!_cups_strcasecmp(value
, "none"))
2781 default_auth_type
= CUPSD_AUTH_NONE
;
2782 else if (!_cups_strcasecmp(value
, "basic"))
2783 default_auth_type
= CUPSD_AUTH_BASIC
;
2784 else if (!_cups_strcasecmp(value
, "digest"))
2785 default_auth_type
= CUPSD_AUTH_DIGEST
;
2786 else if (!_cups_strcasecmp(value
, "basicdigest"))
2787 default_auth_type
= CUPSD_AUTH_BASICDIGEST
;
2789 else if (!_cups_strcasecmp(value
, "negotiate"))
2790 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
2791 #endif /* HAVE_GSSAPI */
2792 else if (!_cups_strcasecmp(value
, "auto"))
2793 default_auth_type
= CUPSD_AUTH_AUTO
;
2796 cupsdLogMessage(CUPSD_LOG_WARN
,
2797 "Unknown default authorization type %s on line %d.",
2799 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2804 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
2807 * DefaultEncryption {Never,IfRequested,Required}
2810 if (!value
|| !_cups_strcasecmp(value
, "never"))
2811 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2812 else if (!_cups_strcasecmp(value
, "required"))
2813 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2814 else if (!_cups_strcasecmp(value
, "ifrequested"))
2815 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2818 cupsdLogMessage(CUPSD_LOG_WARN
,
2819 "Unknown default encryption %s on line %d.",
2821 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2825 #endif /* HAVE_SSL */
2826 else if (!_cups_strcasecmp(line
, "User") && value
)
2829 * User ID to run as...
2832 if (isdigit(value
[0] & 255))
2834 int uid
= atoi(value
);
2837 cupsdLogMessage(CUPSD_LOG_ERROR
,
2838 "Will not use User 0 as specified on line %d "
2839 "for security reasons. You must use a non-"
2840 "privileged account instead.",
2847 struct passwd
*p
; /* Password information */
2850 p
= getpwnam(value
);
2855 cupsdLogMessage(CUPSD_LOG_ERROR
,
2856 "Will not use User %s (UID=0) as specified on line "
2857 "%d for security reasons. You must use a non-"
2858 "privileged account instead.",
2864 cupsdLogMessage(CUPSD_LOG_ERROR
,
2865 "Unknown User \"%s\" on line %d, ignoring.",
2869 else if (!_cups_strcasecmp(line
, "Group") && value
)
2872 * Group ID to run as...
2875 if (isdigit(value
[0]))
2876 Group
= atoi(value
);
2880 group
= getgrnam(value
);
2883 Group
= group
->gr_gid
;
2885 cupsdLogMessage(CUPSD_LOG_ERROR
,
2886 "Unknown Group \"%s\" on line %d, ignoring.",
2890 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
2893 * SystemGroup (admin) group(s)...
2896 if (!parse_groups(value
))
2897 cupsdLogMessage(CUPSD_LOG_ERROR
,
2898 "Unknown SystemGroup \"%s\" on line %d, ignoring.",
2901 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
2904 * Do hostname lookups?
2907 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
2908 !_cups_strcasecmp(value
, "false"))
2909 HostNameLookups
= 0;
2910 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
2911 !_cups_strcasecmp(value
, "true"))
2912 HostNameLookups
= 1;
2913 else if (!_cups_strcasecmp(value
, "double"))
2914 HostNameLookups
= 2;
2916 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2919 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
2922 * Amount of logging to do to access log...
2925 if (!_cups_strcasecmp(value
, "all"))
2926 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
2927 else if (!_cups_strcasecmp(value
, "actions"))
2928 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
2929 else if (!_cups_strcasecmp(value
, "config"))
2930 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
2932 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
2935 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
2938 * Amount of logging to do to error log...
2941 if (!_cups_strcasecmp(value
, "debug2"))
2942 LogLevel
= CUPSD_LOG_DEBUG2
;
2943 else if (!_cups_strcasecmp(value
, "debug"))
2944 LogLevel
= CUPSD_LOG_DEBUG
;
2945 else if (!_cups_strcasecmp(value
, "info"))
2946 LogLevel
= CUPSD_LOG_INFO
;
2947 else if (!_cups_strcasecmp(value
, "notice"))
2948 LogLevel
= CUPSD_LOG_NOTICE
;
2949 else if (!_cups_strcasecmp(value
, "warn"))
2950 LogLevel
= CUPSD_LOG_WARN
;
2951 else if (!_cups_strcasecmp(value
, "error"))
2952 LogLevel
= CUPSD_LOG_ERROR
;
2953 else if (!_cups_strcasecmp(value
, "crit"))
2954 LogLevel
= CUPSD_LOG_CRIT
;
2955 else if (!_cups_strcasecmp(value
, "alert"))
2956 LogLevel
= CUPSD_LOG_ALERT
;
2957 else if (!_cups_strcasecmp(value
, "emerg"))
2958 LogLevel
= CUPSD_LOG_EMERG
;
2959 else if (!_cups_strcasecmp(value
, "none"))
2960 LogLevel
= CUPSD_LOG_NONE
;
2962 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2965 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
2968 * Amount of logging to do to error log...
2971 if (!_cups_strcasecmp(value
, "standard"))
2972 LogTimeFormat
= CUPSD_TIME_STANDARD
;
2973 else if (!_cups_strcasecmp(value
, "usecs"))
2974 LogTimeFormat
= CUPSD_TIME_USECS
;
2976 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
2979 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
2982 * Format of printcap file?
2985 if (!_cups_strcasecmp(value
, "bsd"))
2986 PrintcapFormat
= PRINTCAP_BSD
;
2987 else if (!_cups_strcasecmp(value
, "plist"))
2988 PrintcapFormat
= PRINTCAP_PLIST
;
2989 else if (!_cups_strcasecmp(value
, "solaris"))
2990 PrintcapFormat
= PRINTCAP_SOLARIS
;
2992 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2995 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
2998 * Set the string used for the Server header...
3001 struct utsname plat
; /* Platform info */
3006 if (!_cups_strcasecmp(value
, "ProductOnly"))
3007 cupsdSetString(&ServerHeader
, "CUPS");
3008 else if (!_cups_strcasecmp(value
, "Major"))
3009 cupsdSetStringf(&ServerHeader
, "CUPS/%d", CUPS_VERSION_MAJOR
);
3010 else if (!_cups_strcasecmp(value
, "Minor"))
3011 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
3012 CUPS_VERSION_MINOR
);
3013 else if (!_cups_strcasecmp(value
, "Minimal"))
3014 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3015 else if (!_cups_strcasecmp(value
, "OS"))
3016 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3017 else if (!_cups_strcasecmp(value
, "Full"))
3018 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/2.1",
3020 else if (!_cups_strcasecmp(value
, "None"))
3021 cupsdClearString(&ServerHeader
);
3023 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3026 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3029 * PassEnv variable [... variable]
3034 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3035 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3038 if (value
[valuelen
])
3040 value
[valuelen
] = '\0';
3044 cupsdSetEnv(value
, NULL
);
3046 for (value
+= valuelen
; *value
; value
++)
3047 if (!_cups_isspace(*value
) || *value
!= ',')
3051 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3054 * ServerAlias name [... name]
3058 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3062 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3063 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3066 if (value
[valuelen
])
3068 value
[valuelen
] = '\0';
3072 cupsdAddAlias(ServerAlias
, value
);
3074 for (value
+= valuelen
; *value
; value
++)
3075 if (!_cups_isspace(*value
) || *value
!= ',')
3079 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3082 * SetEnv variable value
3085 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3093 while (isspace(*valueptr
& 255))
3096 cupsdSetEnv(value
, valueptr
);
3099 cupsdLogMessage(CUPSD_LOG_ERROR
,
3100 "Missing value for SetEnv directive on line %d.",
3104 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3107 * SSLOptions options
3110 if (!value
|| !_cups_strcasecmp(value
, "none"))
3111 SSLOptions
= CUPSD_SSL_NONE
;
3112 else if (!_cups_strcasecmp(value
, "noemptyfragments"))
3113 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3115 cupsdLogMessage(CUPSD_LOG_ERROR
,
3116 "Unknown value \"%s\" for SSLOptions directive on "
3117 "line %d.", value
, linenum
);
3119 #endif /* HAVE_SSL */
3123 * Find a simple variable in the list...
3126 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3127 if (!_cups_strcasecmp(line
, var
->name
))
3133 * Unknown directive! Output an error message and continue...
3137 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3140 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3147 case CUPSD_VARTYPE_INTEGER
:
3149 cupsdLogMessage(CUPSD_LOG_ERROR
,
3150 "Missing integer value for %s on line %d.",
3152 else if (!isdigit(*value
& 255))
3153 cupsdLogMessage(CUPSD_LOG_ERROR
,
3154 "Bad integer value for %s on line %d.",
3159 char *units
; /* Units */
3161 n
= strtol(value
, &units
, 0);
3163 if (units
&& *units
)
3165 if (tolower(units
[0] & 255) == 'g')
3166 n
*= 1024 * 1024 * 1024;
3167 else if (tolower(units
[0] & 255) == 'm')
3169 else if (tolower(units
[0] & 255) == 'k')
3171 else if (tolower(units
[0] & 255) == 't')
3175 cupsdLogMessage(CUPSD_LOG_ERROR
,
3176 "Unknown integer value for %s on line %d.",
3183 cupsdLogMessage(CUPSD_LOG_ERROR
,
3184 "Bad negative integer value for %s on line %d.",
3187 *((int *)var
->ptr
) = n
;
3191 case CUPSD_VARTYPE_TIME
:
3193 cupsdLogMessage(CUPSD_LOG_ERROR
,
3194 "Missing time interval value for %s on line %d.",
3196 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
3197 (!_cups_strcasecmp(value
, "true") ||
3198 !_cups_strcasecmp(value
, "on") ||
3199 !_cups_strcasecmp(value
, "enabled") ||
3200 !_cups_strcasecmp(value
, "yes")))
3201 *((int *)var
->ptr
) = INT_MAX
;
3202 else if (!_cups_strcasecmp(value
, "false") ||
3203 !_cups_strcasecmp(value
, "off") ||
3204 !_cups_strcasecmp(value
, "disabled") ||
3205 !_cups_strcasecmp(value
, "no"))
3206 *((int *)var
->ptr
) = 0;
3207 else if (!isdigit(*value
& 255))
3208 cupsdLogMessage(CUPSD_LOG_ERROR
,
3209 "Unknown time interval value for %s on line %d.",
3213 double n
; /* Number */
3214 char *units
; /* Units */
3216 n
= strtod(value
, &units
);
3218 if (units
&& *units
)
3220 if (tolower(units
[0] & 255) == 'w')
3221 n
*= 7 * 24 * 60 * 60;
3222 else if (tolower(units
[0] & 255) == 'd')
3224 else if (tolower(units
[0] & 255) == 'h')
3226 else if (tolower(units
[0] & 255) == 'm')
3230 cupsdLogMessage(CUPSD_LOG_ERROR
,
3231 "Unknown time interval value for %s on line "
3232 "%d.", line
, linenum
);
3237 if (n
< 0.0 || n
> INT_MAX
)
3238 cupsdLogMessage(CUPSD_LOG_ERROR
,
3239 "Bad time value for %s on line %d.",
3242 *((int *)var
->ptr
) = (int)n
;
3246 case CUPSD_VARTYPE_BOOLEAN
:
3248 cupsdLogMessage(CUPSD_LOG_ERROR
,
3249 "Missing boolean value for %s on line %d.",
3251 else if (!_cups_strcasecmp(value
, "true") ||
3252 !_cups_strcasecmp(value
, "on") ||
3253 !_cups_strcasecmp(value
, "enabled") ||
3254 !_cups_strcasecmp(value
, "yes") ||
3256 *((int *)var
->ptr
) = TRUE
;
3257 else if (!_cups_strcasecmp(value
, "false") ||
3258 !_cups_strcasecmp(value
, "off") ||
3259 !_cups_strcasecmp(value
, "disabled") ||
3260 !_cups_strcasecmp(value
, "no") ||
3261 !_cups_strcasecmp(value
, "0"))
3262 *((int *)var
->ptr
) = FALSE
;
3264 cupsdLogMessage(CUPSD_LOG_ERROR
,
3265 "Unknown boolean value %s on line %d.",
3269 case CUPSD_VARTYPE_PATHNAME
:
3272 cupsdLogMessage(CUPSD_LOG_ERROR
,
3273 "Missing pathname value for %s on line %d.",
3278 if (value
[0] == '/')
3279 strlcpy(temp
, value
, sizeof(temp
));
3281 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3283 if (access(temp
, 0))
3285 cupsdLogMessage(CUPSD_LOG_ERROR
,
3286 "File or directory for \"%s %s\" on line %d "
3287 "does not exist.", line
, value
, linenum
);
3291 case CUPSD_VARTYPE_STRING
:
3292 cupsdSetString((char **)var
->ptr
, value
);
3303 * 'read_location()' - Read a <Location path> definition.
3306 static int /* O - New line number or 0 on error */
3307 read_location(cups_file_t
*fp
, /* I - Configuration file */
3308 char *location
, /* I - Location name/path */
3309 int linenum
) /* I - Current line number */
3311 cupsd_location_t
*loc
, /* New location */
3312 *parent
; /* Parent location */
3313 char line
[HTTP_MAX_BUFFER
],
3315 *value
, /* Value for directive */
3316 *valptr
; /* Pointer into value */
3319 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3320 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d.",
3322 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3326 cupsdAddLocation(parent
);
3328 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3333 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3336 * Decode the directive...
3339 if (!_cups_strcasecmp(line
, "</Location>"))
3341 else if (!_cups_strcasecmp(line
, "<Limit") ||
3342 !_cups_strcasecmp(line
, "<LimitExcept"))
3346 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3347 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3353 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3356 cupsdAddLocation(loc
);
3361 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3366 if (!strcmp(value
, "ALL"))
3367 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3368 else if (!strcmp(value
, "GET"))
3369 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3370 else if (!strcmp(value
, "HEAD"))
3371 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3372 else if (!strcmp(value
, "OPTIONS"))
3373 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3374 else if (!strcmp(value
, "POST"))
3375 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3376 else if (!strcmp(value
, "PUT"))
3377 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3378 else if (!strcmp(value
, "TRACE"))
3379 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3381 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d.",
3384 for (value
= valptr
; isspace(*value
& 255); value
++);
3387 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3388 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3390 parent
->limit
&= ~loc
->limit
;
3392 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3393 !_cups_strcasecmp(line
, "</LimitExcept>"))
3397 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3398 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3401 else if (!parse_aaa(loc
, line
, value
, linenum
))
3403 cupsdLogMessage(CUPSD_LOG_ERROR
,
3404 "Unknown Location directive %s on line %d.",
3406 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3411 cupsdLogMessage(CUPSD_LOG_ERROR
,
3412 "Unexpected end-of-file at line %d while reading location.",
3415 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3420 * 'read_policy()' - Read a <Policy name> definition.
3423 static int /* O - New line number or 0 on error */
3424 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3425 char *policy
, /* I - Location name/path */
3426 int linenum
) /* I - Current line number */
3428 int i
; /* Looping var */
3429 cupsd_policy_t
*pol
; /* Policy */
3430 cupsd_location_t
*op
; /* Policy operation */
3431 int num_ops
; /* Number of IPP operations */
3432 ipp_op_t ops
[100]; /* Operations */
3433 char line
[HTTP_MAX_BUFFER
],
3435 *value
, /* Value for directive */
3436 *valptr
; /* Pointer into value */
3440 * Create the policy...
3443 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3444 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d.",
3446 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3450 * Read from the file...
3456 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3459 * Decode the directive...
3462 if (!_cups_strcasecmp(line
, "</Policy>"))
3465 cupsdLogMessage(CUPSD_LOG_WARN
,
3466 "Missing </Limit> before </Policy> on line %d.",
3469 set_policy_defaults(pol
);
3473 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3477 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3478 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3485 * Scan for IPP operation names...
3492 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3497 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3499 if (!_cups_strcasecmp(value
, "All"))
3500 ops
[num_ops
] = IPP_ANY_OPERATION
;
3501 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3502 cupsdLogMessage(CUPSD_LOG_ERROR
,
3503 "Bad IPP operation name \"%s\" on line %d.",
3509 cupsdLogMessage(CUPSD_LOG_ERROR
,
3510 "Too many operations listed on line %d.",
3513 for (value
= valptr
; isspace(*value
& 255); value
++);
3517 * If none are specified, apply the policy to all operations...
3522 ops
[0] = IPP_ANY_OPERATION
;
3527 * Add a new policy for the first operation...
3530 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3532 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3535 * Finish the current operation limit...
3541 * Copy the policy to the other operations...
3544 for (i
= 1; i
< num_ops
; i
++)
3545 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3552 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3553 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3556 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3557 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3558 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3559 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3563 cupsdLogMessage(CUPSD_LOG_ERROR
,
3564 "%s directive must appear outside <Limit>...</Limit> "
3565 "on line %d.", line
, linenum
);
3566 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3572 * Pull out whitespace-delimited values...
3578 * Find the end of the current value...
3581 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3587 * Save it appropriately...
3590 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3593 * JobPrivateAccess {all|default|user/group list|@@ACL}
3596 if (!_cups_strcasecmp(value
, "default"))
3598 cupsdAddString(&(pol
->job_access
), "@OWNER");
3599 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3602 cupsdAddString(&(pol
->job_access
), value
);
3604 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3607 * JobPrivateValues {all|none|default|attribute list}
3610 if (!_cups_strcasecmp(value
, "default"))
3612 cupsdAddString(&(pol
->job_attrs
), "job-name");
3613 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3614 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3615 cupsdAddString(&(pol
->job_attrs
), "phone");
3618 cupsdAddString(&(pol
->job_attrs
), value
);
3620 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3623 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3626 if (!_cups_strcasecmp(value
, "default"))
3628 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3629 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3632 cupsdAddString(&(pol
->sub_access
), value
);
3634 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3637 * SubscriptionPrivateValues {all|none|default|attribute list}
3640 if (!_cups_strcasecmp(value
, "default"))
3642 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3643 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3644 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3645 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3646 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3649 cupsdAddString(&(pol
->sub_attrs
), value
);
3653 * Find the next string on the line...
3656 for (value
= valptr
; isspace(*value
& 255); value
++);
3662 cupsdLogMessage(CUPSD_LOG_ERROR
,
3663 "Missing <Limit ops> directive before %s on line %d.",
3665 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3668 else if (!parse_aaa(op
, line
, value
, linenum
))
3670 cupsdLogMessage(CUPSD_LOG_ERROR
,
3671 "Unknown Policy Limit directive %s on line %d.",
3674 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3679 cupsdLogMessage(CUPSD_LOG_ERROR
,
3680 "Unexpected end-of-file at line %d while reading policy "
3681 "\"%s\".", linenum
, policy
);
3683 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3688 * 'set_policy_defaults()' - Set default policy values as needed.
3692 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
3694 cupsd_location_t
*op
; /* Policy operation */
3698 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3699 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3700 * upgrades do not introduce new security issues...
3703 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
3704 op
->op
== IPP_ANY_OPERATION
)
3706 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
3707 op
->op
!= IPP_ANY_OPERATION
)
3710 * Add a new limit for Validate-Job using the Print-Job limit as a
3714 cupsdLogMessage(CUPSD_LOG_WARN
,
3715 "No limit for Validate-Job defined in policy %s "
3716 "- using Print-Job's policy.", pol
->name
);
3718 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
3721 cupsdLogMessage(CUPSD_LOG_WARN
,
3722 "No limit for Validate-Job defined in policy %s "
3723 "and no suitable template found.", pol
->name
);
3726 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
3727 op
->op
== IPP_ANY_OPERATION
)
3729 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
3730 op
->op
!= IPP_ANY_OPERATION
)
3733 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
3737 cupsdLogMessage(CUPSD_LOG_WARN
,
3738 "No limit for Cancel-Jobs defined in policy %s "
3739 "- using Pause-Printer's policy.", pol
->name
);
3741 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
3744 cupsdLogMessage(CUPSD_LOG_WARN
,
3745 "No limit for Cancel-Jobs defined in policy %s "
3746 "and no suitable template found.", pol
->name
);
3749 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
3750 op
->op
== IPP_ANY_OPERATION
)
3752 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3753 op
->op
!= IPP_ANY_OPERATION
)
3756 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3760 cupsdLogMessage(CUPSD_LOG_WARN
,
3761 "No limit for Cancel-My-Jobs defined in policy %s "
3762 "- using Send-Document's policy.", pol
->name
);
3764 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
3767 cupsdLogMessage(CUPSD_LOG_WARN
,
3768 "No limit for Cancel-My-Jobs defined in policy %s "
3769 "and no suitable template found.", pol
->name
);
3772 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
3773 op
->op
== IPP_ANY_OPERATION
)
3775 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3776 op
->op
!= IPP_ANY_OPERATION
)
3779 * Add a new limit for Close-Job using the Send-Document limit as a
3783 cupsdLogMessage(CUPSD_LOG_WARN
,
3784 "No limit for Close-Job defined in policy %s "
3785 "- using Send-Document's policy.", pol
->name
);
3787 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
3790 cupsdLogMessage(CUPSD_LOG_WARN
,
3791 "No limit for Close-Job defined in policy %s "
3792 "and no suitable template found.", pol
->name
);
3795 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3796 op
->op
== IPP_ANY_OPERATION
)
3798 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3799 op
->op
!= IPP_ANY_OPERATION
)
3802 * Add a new limit for CUPS-Get-Document using the Send-Document
3803 * limit as a template...
3806 cupsdLogMessage(CUPSD_LOG_WARN
,
3807 "No limit for CUPS-Get-Document defined in policy %s "
3808 "- using Send-Document's policy.", pol
->name
);
3810 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3813 cupsdLogMessage(CUPSD_LOG_WARN
,
3814 "No limit for CUPS-Get-Document defined in policy %s "
3815 "and no suitable template found.", pol
->name
);
3819 * Verify we have JobPrivateAccess, JobPrivateValues,
3820 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
3823 if (!pol
->job_access
)
3825 cupsdLogMessage(CUPSD_LOG_WARN
,
3826 "No JobPrivateAccess defined in policy %s "
3827 "- using defaults.", pol
->name
);
3828 cupsdAddString(&(pol
->job_access
), "@OWNER");
3829 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3832 if (!pol
->job_attrs
)
3834 cupsdLogMessage(CUPSD_LOG_WARN
,
3835 "No JobPrivateValues defined in policy %s "
3836 "- using defaults.", pol
->name
);
3837 cupsdAddString(&(pol
->job_attrs
), "job-name");
3838 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3839 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3840 cupsdAddString(&(pol
->job_attrs
), "phone");
3843 if (!pol
->sub_access
)
3845 cupsdLogMessage(CUPSD_LOG_WARN
,
3846 "No SubscriptionPrivateAccess defined in policy %s "
3847 "- using defaults.", pol
->name
);
3848 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3849 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3852 if (!pol
->sub_attrs
)
3854 cupsdLogMessage(CUPSD_LOG_WARN
,
3855 "No SubscriptionPrivateValues defined in policy %s "
3856 "- using defaults.", pol
->name
);
3857 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3858 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3859 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3860 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3861 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3867 * End of "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $".