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 #ifdef HAVE_AUTHORIZATION_H
173 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
174 #endif /* HAVE_AUTHORIZATION_H */
175 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
176 { "Timeout", &Timeout
, CUPSD_VARTYPE_TIME
},
177 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
179 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
182 static const unsigned ones
[4] =
184 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
186 static const unsigned zeros
[4] =
188 0x00000000, 0x00000000, 0x00000000, 0x00000000
196 static http_addrlist_t
*get_address(const char *value
, int defport
);
197 static int get_addr_and_mask(const char *value
, unsigned *ip
,
199 static void mime_error_cb(void *ctx
, const char *message
);
200 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
201 char *value
, int linenum
);
202 static int parse_fatal_errors(const char *s
);
203 static int parse_groups(const char *s
);
204 static int parse_protocols(const char *s
);
205 static int read_configuration(cups_file_t
*fp
);
206 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
207 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
208 static void set_policy_defaults(cupsd_policy_t
*pol
);
212 * 'cupsdAddAlias()' - Add a host alias.
216 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
217 const char *name
) /* I - Name to add */
219 cupsd_alias_t
*a
; /* New alias */
220 size_t namelen
; /* Length of name */
223 namelen
= strlen(name
);
225 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
228 a
->namelen
= namelen
;
229 strcpy(a
->name
, name
); /* OK since a->name is allocated */
231 cupsArrayAdd(aliases
, a
);
236 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
239 int /* O - 0 on success, -1 on error, 1 on warning */
240 cupsdCheckPermissions(
241 const char *filename
, /* I - File/directory name */
242 const char *suffix
, /* I - Additional file/directory name */
243 int mode
, /* I - Permissions */
244 int user
, /* I - Owner */
245 int group
, /* I - Group */
246 int is_dir
, /* I - 1 = directory, 0 = file */
247 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
249 int dir_created
= 0; /* Did we create a directory? */
250 char pathname
[1024]; /* File name with prefix */
251 struct stat fileinfo
; /* Stat buffer */
252 int is_symlink
; /* Is "filename" a symlink? */
256 * Prepend the given root to the filename before testing it...
261 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
266 * See if we can stat the file/directory...
269 if (lstat(filename
, &fileinfo
))
271 if (errno
== ENOENT
&& create_dir
)
274 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
277 if (mkdir(filename
, mode
))
280 cupsdLogMessage(CUPSD_LOG_ERROR
,
281 "Unable to create directory \"%s\" - %s", filename
,
284 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
291 fileinfo
.st_mode
= mode
| S_IFDIR
;
294 return (create_dir
? -1 : 1);
297 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
299 if (stat(filename
, &fileinfo
))
301 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
302 filename
, strerror(errno
));
308 * Make sure it's a regular file or a directory as needed...
311 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
313 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
317 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
320 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
322 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
328 * If the filename is a symlink, do not change permissions (STR #2937)...
335 * Fix owner, group, and mode as needed...
338 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
341 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
344 if (chown(filename
, user
, group
) && !getuid())
347 cupsdLogMessage(CUPSD_LOG_ERROR
,
348 "Unable to change ownership of \"%s\" - %s", filename
,
351 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
358 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
361 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
364 if (chmod(filename
, mode
))
367 cupsdLogMessage(CUPSD_LOG_ERROR
,
368 "Unable to change permissions of \"%s\" - %s", filename
,
371 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
379 * Everything is OK...
387 * 'cupsdDefaultAuthType()' - Get the default AuthType.
389 * When the default_auth_type is "auto", this function tries to get the GSS
390 * credentials for the server. If that succeeds we use Kerberos authentication,
391 * otherwise we do a fallback to Basic authentication against the local user
395 int /* O - Default AuthType value */
396 cupsdDefaultAuthType(void)
399 OM_uint32 major_status
, /* Major status code */
400 minor_status
; /* Minor status code */
401 gss_name_t server_name
; /* Server name */
402 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
403 /* Service name token */
404 char buf
[1024]; /* Service name buffer */
405 #endif /* HAVE_GSSAPI */
409 * If we have already determined the correct default AuthType, use it...
412 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
413 return (default_auth_type
);
418 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
422 if (gss_init_sec_context
== NULL
)
423 return (default_auth_type
= CUPSD_AUTH_BASIC
);
424 # endif /* __APPLE__ */
427 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
428 * that fails we must use Basic...
431 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
434 token
.length
= strlen(buf
);
435 server_name
= GSS_C_NO_NAME
;
436 major_status
= gss_import_name(&minor_status
, &token
,
437 GSS_C_NT_HOSTBASED_SERVICE
,
440 memset(&token
, 0, sizeof(token
));
442 if (GSS_ERROR(major_status
))
444 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
445 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
446 return (default_auth_type
= CUPSD_AUTH_BASIC
);
449 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
451 if (GSS_ERROR(major_status
))
453 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
454 "cupsdDefaultAuthType: gss_display_name(%s) failed",
456 return (default_auth_type
= CUPSD_AUTH_BASIC
);
459 cupsdLogMessage(CUPSD_LOG_DEBUG
,
460 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
461 "credentials for %s...", (char *)token
.value
);
463 ServerCreds
= GSS_C_NO_CREDENTIAL
;
464 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
465 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
466 &ServerCreds
, NULL
, NULL
);
467 if (GSS_ERROR(major_status
))
469 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
470 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
471 (char *)token
.value
);
472 gss_release_name(&minor_status
, &server_name
);
473 gss_release_buffer(&minor_status
, &token
);
474 return (default_auth_type
= CUPSD_AUTH_BASIC
);
477 cupsdLogMessage(CUPSD_LOG_DEBUG
,
478 "cupsdDefaultAuthType: Kerberos credentials acquired "
479 "successfully for %s.", (char *)token
.value
);
481 gss_release_name(&minor_status
, &server_name
);
482 gss_release_buffer(&minor_status
, &token
);
486 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
490 * No Kerberos support compiled in so just use Basic all the time...
493 return (default_auth_type
= CUPSD_AUTH_BASIC
);
494 #endif /* HAVE_GSSAPI */
499 * 'cupsdFreeAliases()' - Free all of the alias entries.
503 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
505 cupsd_alias_t
*a
; /* Current alias */
508 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
510 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
513 cupsArrayDelete(aliases
);
518 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
521 int /* O - 1 on success, 0 otherwise */
522 cupsdReadConfiguration(void)
524 int i
; /* Looping var */
525 cups_file_t
*fp
; /* Configuration file */
526 int status
; /* Return status */
527 char temp
[1024], /* Temporary buffer */
528 mimedir
[1024], /* MIME directory */
529 *slash
; /* Directory separator */
530 cups_lang_t
*language
; /* Language */
531 struct passwd
*user
; /* Default user */
532 struct group
*group
; /* Default group */
533 char *old_serverroot
, /* Old ServerRoot */
534 *old_requestroot
; /* Old RequestRoot */
535 int old_remote_port
; /* Old RemotePort */
536 const char *tmpdir
; /* TMPDIR environment variable */
537 struct stat tmpinfo
; /* Temporary directory info */
538 cupsd_policy_t
*p
; /* Policy */
542 * Save the old root paths...
545 old_serverroot
= NULL
;
546 cupsdSetString(&old_serverroot
, ServerRoot
);
547 old_requestroot
= NULL
;
548 cupsdSetString(&old_requestroot
, RequestRoot
);
551 * Reset the server configuration data...
554 cupsdDeleteAllLocations();
556 cupsdDeleteAllListeners();
558 old_remote_port
= RemotePort
;
565 cupsdFreeAliases(ServerAlias
);
568 cupsdClearString(&ServerName
);
569 cupsdClearString(&ServerAdmin
);
570 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
571 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
572 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
573 cupsdSetString(&DataDir
, CUPS_DATADIR
);
574 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
575 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
576 cupsdClearString(&ErrorLog
);
577 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
578 cupsdSetString(&PageLogFormat
,
579 "%p %u %j %T %P %C %{job-billing} "
580 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
581 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
582 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
583 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
584 cupsdSetString(&RemoteRoot
, "remroot");
585 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
587 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
589 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
590 PrintcapFormat
= PRINTCAP_SOLARIS
;
591 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
592 "/Library/Preferences/org.cups.printers.plist"))
593 PrintcapFormat
= PRINTCAP_PLIST
;
595 PrintcapFormat
= PRINTCAP_BSD
;
597 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
598 if ((slash
= strrchr(temp
, '/')) != NULL
)
601 cupsdSetString(&ServerRoot
, temp
);
603 cupsdClearString(&Classification
);
604 ClassifyOverride
= 0;
608 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
610 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
611 cupsdSetString(&ServerKey
, "ssl/server.key");
612 # endif /* HAVE_CDSASSL */
613 #endif /* HAVE_SSL */
615 language
= cupsLangDefault();
617 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
618 cupsdSetString(&DefaultLanguage
, "en");
620 cupsdSetString(&DefaultLanguage
, language
->language
);
622 cupsdClearString(&DefaultPaperSize
);
624 cupsdSetString(&RIPCache
, "128m");
626 cupsdSetString(&TempDir
, NULL
);
629 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
633 OM_uint32 minor_status
; /* Minor status code */
635 gss_release_cred(&minor_status
, &ServerCreds
);
640 ServerCreds
= GSS_C_NO_CREDENTIAL
;
641 #endif /* HAVE_GSSAPI */
644 * Find the default user...
647 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
652 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
653 * complement number...)
662 * Find the default group...
665 group
= getgrnam(CUPS_DEFAULT_GROUP
);
669 Group
= group
->gr_gid
;
673 * Fallback to group "nobody"...
676 group
= getgrnam("nobody");
680 Group
= group
->gr_gid
;
684 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
685 * complement number...)
696 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
697 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
698 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
699 default_auth_type
= CUPSD_AUTH_BASIC
;
701 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
702 SSLOptions
= CUPSD_SSL_NONE
;
703 #endif /* HAVE_SSL */
704 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
705 JobKillDelay
= DEFAULT_TIMEOUT
;
707 JobRetryInterval
= 300;
712 HostNameLookups
= FALSE
;
714 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
715 ListenBackLog
= SOMAXCONN
;
716 LogDebugHistory
= 200;
717 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
718 LogLevel
= CUPSD_LOG_WARN
;
719 LogTimeFormat
= CUPSD_TIME_STANDARD
;
721 MaxClientsPerHost
= 0;
722 MaxLogSize
= 1024 * 1024;
724 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
725 ReloadTimeout
= DEFAULT_KEEPALIVE
;
726 RootCertDuration
= 300;
727 Timeout
= DEFAULT_TIMEOUT
;
729 WebInterface
= CUPS_DEFAULT_WEBIF
;
731 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
733 Browsing
= CUPS_DEFAULT_BROWSING
;
734 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
737 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
738 #endif /* HAVE_DNSSD */
740 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
741 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
743 cupsdSetString(&ErrorPolicy
, "stop-printer");
745 JobHistory
= DEFAULT_HISTORY
;
746 JobFiles
= DEFAULT_FILES
;
752 MaxJobsPerPrinter
= 0;
753 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
754 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
756 cupsdDeleteAllPolicies();
757 cupsdClearString(&DefaultPolicy
);
759 #ifdef HAVE_AUTHORIZATION_H
760 cupsdClearString(&SystemGroupAuthKey
);
761 #endif /* HAVE_AUTHORIZATION_H */
763 MaxSubscriptions
= 100;
764 MaxSubscriptionsPerJob
= 0;
765 MaxSubscriptionsPerPrinter
= 0;
766 MaxSubscriptionsPerUser
= 0;
767 DefaultLeaseDuration
= 86400;
768 MaxLeaseDuration
= 0;
772 #endif /* HAVE_LAUNCHD */
775 * Setup environment variables...
781 * Read the configuration file...
784 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
787 status
= read_configuration(fp
);
795 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
799 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
800 RemotePort
? "enabled" : "disabled");
803 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
806 * See if the ServerName is an IP address...
812 ServerAlias
= cupsArrayNew(NULL
, NULL
);
814 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
818 if (gethostname(temp
, sizeof(temp
)))
820 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
822 strlcpy(temp
, "localhost", sizeof(temp
));
825 cupsdSetString(&ServerName
, temp
);
828 ServerAlias
= cupsArrayNew(NULL
, NULL
);
830 cupsdAddAlias(ServerAlias
, temp
);
831 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
833 if (HostNameLookups
|| RemotePort
)
835 struct hostent
*host
; /* Host entry to get FQDN */
837 if ((host
= gethostbyname(temp
)) != NULL
)
839 if (_cups_strcasecmp(temp
, host
->h_name
))
841 cupsdSetString(&ServerName
, host
->h_name
);
842 cupsdAddAlias(ServerAlias
, host
->h_name
);
843 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
849 for (i
= 0; host
->h_aliases
[i
]; i
++)
850 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
852 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
853 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
861 * Make sure we have the base hostname added as an alias, too!
864 if ((slash
= strchr(temp
, '.')) != NULL
)
867 cupsdAddAlias(ServerAlias
, temp
);
868 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
872 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
874 ServerNameIsIP
= !*slash
;
877 * Make sure ServerAdmin is initialized...
881 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
884 * Use the default system group if none was supplied in cupsd.conf...
887 if (NumSystemGroups
== 0)
889 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
892 * Find the group associated with GID 0...
899 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
901 cupsdSetString(&SystemGroups
[0], "unknown");
903 SystemGroupIDs
[0] = 0;
909 * Open the system log for cupsd if necessary...
913 if (!strcmp(AccessLog
, "syslog") ||
914 !strcmp(ErrorLog
, "syslog") ||
915 !strcmp(PageLog
, "syslog"))
916 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
917 #endif /* HAVE_VSYSLOG */
920 * Make sure each of the log files exists and gets rotated as necessary...
923 if (strcmp(AccessLog
, "syslog"))
924 cupsdCheckLogFile(&AccessFile
, AccessLog
);
926 if (strcmp(ErrorLog
, "syslog"))
927 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
929 if (strcmp(PageLog
, "syslog"))
930 cupsdCheckLogFile(&PageFile
, PageLog
);
933 * Log the configuration file that was used...
936 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
940 * Validate the Group and SystemGroup settings - they cannot be the same,
941 * otherwise the CGI programs will be able to authenticate as root without
947 for (i
= 0; i
< NumSystemGroups
; i
++)
948 if (Group
== SystemGroupIDs
[i
])
951 if (i
< NumSystemGroups
)
954 * Log the error and reset the group to a safe value...
957 cupsdLogMessage(CUPSD_LOG_NOTICE
,
958 "Group and SystemGroup cannot use the same groups.");
959 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
961 group
= getgrnam("nobody");
965 Group
= group
->gr_gid
;
969 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
970 * complement number...)
979 * Check that we have at least one listen/port line; if not, report this
980 * as an error and exit!
983 if (cupsArrayCount(Listeners
) == 0)
989 cupsdLogMessage(CUPSD_LOG_EMERG
,
990 "No valid Listen or Port lines were found in the "
991 "configuration file.");
997 cupsdEndProcess(getpid(), 0);
1001 * Set the default locale using the language and charset...
1004 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1007 * Update all relative filenames to include the full path from ServerRoot...
1010 if (DocumentRoot
[0] != '/')
1011 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1013 if (RequestRoot
[0] != '/')
1014 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1016 if (ServerBin
[0] != '/')
1017 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1019 if (StateDir
[0] != '/')
1020 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1022 if (CacheDir
[0] != '/')
1023 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1026 if (ServerCertificate
[0] != '/')
1027 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
1029 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
1030 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
1032 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1035 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
1036 if (ServerKey
[0] != '/')
1037 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
1039 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
1040 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
1041 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1043 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
1044 #endif /* HAVE_SSL */
1047 * Make sure that directories and config files are owned and
1048 * writable by the user and group in the cupsd.conf file...
1051 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1053 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1055 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
1057 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1059 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1061 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1062 SystemGroupIDs
[0], 1, 1) < 0 ||
1063 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1065 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1067 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1069 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
1071 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1073 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1075 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1076 Group
, 0, 0) < 0) &&
1077 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1081 * Update TempDir to the default if it hasn't been set already...
1087 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1088 strncmp(tmpdir
, "/private/tmp", 12))
1090 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1091 #endif /* __APPLE__ */
1094 * TMPDIR is defined, see if it is OK for us to use...
1097 if (stat(tmpdir
, &tmpinfo
))
1098 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1099 tmpdir
, strerror(errno
));
1100 else if (!S_ISDIR(tmpinfo
.st_mode
))
1101 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1103 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1104 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1105 !(tmpinfo
.st_mode
& S_IWOTH
))
1106 cupsdLogMessage(CUPSD_LOG_ERROR
,
1107 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1109 cupsdSetString(&TempDir
, tmpdir
);
1114 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1116 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1121 * Make sure the temporary directory has the right permissions...
1124 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1128 * Update ownership and permissions if the CUPS temp directory
1129 * is under the spool directory or does not exist...
1132 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1133 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1138 * Update environment variables...
1144 * Update default paper size setting as needed...
1147 if (!DefaultPaperSize
)
1149 #ifdef HAVE_LIBPAPER
1150 char *paper_result
; /* Paper size name from libpaper */
1152 if ((paper_result
= systempapername()) != NULL
)
1153 cupsdSetString(&DefaultPaperSize
, paper_result
);
1155 #endif /* HAVE_LIBPAPER */
1156 if (!DefaultLanguage
||
1157 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1158 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1159 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1160 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1161 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1162 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1163 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1166 * These are the only locales that will default to "letter" size...
1169 cupsdSetString(&DefaultPaperSize
, "Letter");
1172 cupsdSetString(&DefaultPaperSize
, "A4");
1176 * Update classification setting as needed...
1179 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1180 cupsdClearString(&Classification
);
1183 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1186 * Check the MaxClients setting, and then allocate memory for it...
1189 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1192 cupsdLogMessage(CUPSD_LOG_INFO
,
1193 "MaxClients limited to 1/3 (%d) of the file descriptor "
1195 MaxFDs
/ 3, MaxFDs
);
1197 MaxClients
= MaxFDs
/ 3;
1200 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1204 * Check the MaxActiveJobs setting; limit to 1/3 the available
1205 * file descriptors, since we need a pipe for each job...
1208 if (MaxActiveJobs
> (MaxFDs
/ 3))
1209 MaxActiveJobs
= MaxFDs
/ 3;
1212 * Update the MaxClientsPerHost value, as needed...
1215 if (MaxClientsPerHost
<= 0)
1216 MaxClientsPerHost
= MaxClients
;
1218 if (MaxClientsPerHost
> MaxClients
)
1219 MaxClientsPerHost
= MaxClients
;
1221 cupsdLogMessage(CUPSD_LOG_INFO
,
1222 "Allowing up to %d client connections per host.",
1226 * Update the default policy, as needed...
1230 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1232 DefaultPolicyPtr
= NULL
;
1234 if (!DefaultPolicyPtr
)
1236 cupsd_location_t
*po
; /* New policy operation */
1240 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1243 cupsdSetString(&DefaultPolicy
, "default");
1245 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1246 cupsdLogMessage(CUPSD_LOG_INFO
,
1247 "Using policy \"default\" as the default.");
1250 cupsdLogMessage(CUPSD_LOG_INFO
,
1251 "Creating CUPS default administrative policy:");
1253 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1255 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1257 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1258 cupsdAddString(&(p
->job_access
), "@OWNER");
1259 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1261 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1262 cupsdAddString(&(p
->job_attrs
), "job-name");
1263 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1264 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1266 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1267 cupsdAddString(&(p
->sub_access
), "@OWNER");
1268 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1270 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1271 cupsdAddString(&(p
->job_attrs
), "notify-events");
1272 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1273 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1274 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1275 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1277 cupsdLogMessage(CUPSD_LOG_INFO
,
1278 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1279 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1281 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1282 po
->order_type
= CUPSD_AUTH_ALLOW
;
1284 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1285 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1286 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1288 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1290 cupsdLogMessage(CUPSD_LOG_INFO
,
1291 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1292 "Release-Job Restart-Job Purge-Jobs "
1293 "Set-Job-Attributes Create-Job-Subscription "
1294 "Renew-Subscription Cancel-Subscription "
1295 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1296 "Suspend-Current-Job Resume-Job "
1297 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1298 "CUPS-Authenticate-Job CUPS-Get-Document>");
1299 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1301 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1302 po
->order_type
= CUPSD_AUTH_ALLOW
;
1303 po
->level
= CUPSD_AUTH_USER
;
1305 cupsdAddName(po
, "@OWNER");
1306 cupsdAddName(po
, "@SYSTEM");
1307 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1309 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1310 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1311 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1312 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1313 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1314 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1315 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1316 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1317 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1318 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1319 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1320 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1321 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1322 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1323 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1324 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1325 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1326 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1327 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1328 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1330 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1332 cupsdLogMessage(CUPSD_LOG_INFO
,
1333 "<Limit Pause-Printer Resume-Printer "
1334 "Set-Printer-Attributes Enable-Printer "
1335 "Disable-Printer Pause-Printer-After-Current-Job "
1336 "Hold-New-Jobs Release-Held-New-Jobs "
1337 "Deactivate-Printer Activate-Printer Restart-Printer "
1338 "Shutdown-Printer Startup-Printer Promote-Job "
1339 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1340 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1341 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1342 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1343 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1345 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1346 po
->order_type
= CUPSD_AUTH_ALLOW
;
1347 po
->type
= CUPSD_AUTH_DEFAULT
;
1348 po
->level
= CUPSD_AUTH_USER
;
1350 cupsdAddName(po
, "@SYSTEM");
1351 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1353 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1354 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1355 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1356 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1357 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1358 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1359 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1360 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1361 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1362 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1363 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1364 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1365 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1366 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1367 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1368 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1369 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1370 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1371 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1372 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1373 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1374 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1376 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1378 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1379 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1381 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1382 po
->order_type
= CUPSD_AUTH_ALLOW
;
1384 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1385 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1389 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1390 cupsArrayCount(Policies
));
1391 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1393 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1394 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1395 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1398 * If we are doing a full reload or the server root has changed, flush
1399 * the jobs, printers, etc. and start from scratch...
1402 if (NeedReload
== RELOAD_ALL
||
1403 old_remote_port
!= RemotePort
||
1404 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1405 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1407 mime_type_t
*type
; /* Current type */
1408 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1409 /* MIME type name */
1412 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1415 * Free all memory...
1418 cupsdDeleteAllSubscriptions();
1420 cupsdDeleteAllPrinters();
1422 DefaultPrinter
= NULL
;
1424 if (MimeDatabase
!= NULL
)
1425 mimeDelete(MimeDatabase
);
1429 for (i
= 0; i
< NumMimeTypes
; i
++)
1430 _cupsStrFree(MimeTypes
[i
]);
1436 * Read the MIME type and conversion database...
1439 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1440 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1442 MimeDatabase
= mimeNew();
1443 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1445 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1446 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1447 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1448 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1452 cupsdLogMessage(CUPSD_LOG_EMERG
,
1453 "Unable to load MIME database from \"%s\" or \"%s\".",
1454 mimedir
, ServerRoot
);
1455 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1459 cupsdLogMessage(CUPSD_LOG_INFO
,
1460 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1461 "%d filters...", mimedir
, ServerRoot
,
1462 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1465 * Create a list of MIME types for the document-format-supported
1469 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1470 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1473 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1475 cupsdLogMessage(CUPSD_LOG_ERROR
,
1476 "Unable to allocate memory for %d MIME types.",
1482 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1484 i
++, type
= mimeNextType(MimeDatabase
))
1486 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1488 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1491 if (i
< NumMimeTypes
)
1492 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1495 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1497 mime_filter_t
*filter
; /* Current filter */
1500 for (type
= mimeFirstType(MimeDatabase
);
1502 type
= mimeNextType(MimeDatabase
))
1503 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1504 type
->super
, type
->type
);
1506 for (filter
= mimeFirstFilter(MimeDatabase
);
1508 filter
= mimeNextFilter(MimeDatabase
))
1509 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1510 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1511 filter
->src
->super
, filter
->src
->type
,
1512 filter
->dst
->super
, filter
->dst
->type
,
1513 filter
->cost
, filter
->filter
);
1520 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1521 cupsdLoadBanners(temp
);
1524 * Load printers and classes...
1527 cupsdLoadAllPrinters();
1528 cupsdLoadAllClasses();
1530 cupsdCreateCommonData();
1533 * Update the printcap file as needed...
1536 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1537 cupsdWritePrintcap();
1540 * Load queued jobs...
1546 * Load subscriptions...
1549 cupsdLoadAllSubscriptions();
1551 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1556 * Not a full reload, so recreate the common printer attributes...
1559 cupsdCreateCommonData();
1562 * Update all jobs as needed...
1568 * Update all printers as needed...
1571 cupsdUpdatePrinters();
1572 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1574 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1578 * Reset the reload state...
1581 NeedReload
= RELOAD_NONE
;
1583 cupsdClearString(&old_serverroot
);
1584 cupsdClearString(&old_requestroot
);
1591 * 'get_address()' - Get an address + port number from a line.
1594 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1595 get_address(const char *value
, /* I - Value string */
1596 int defport
) /* I - Default port */
1598 char buffer
[1024], /* Hostname + port number buffer */
1599 defpname
[255], /* Default port name */
1600 *hostname
, /* Hostname or IP */
1601 *portname
; /* Port number or name */
1602 http_addrlist_t
*addrlist
; /* Address list */
1606 * Check for an empty value...
1611 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1616 * Grab a hostname and port number; if there is no colon and the port name
1617 * is only digits, then we have a port number by itself...
1620 strlcpy(buffer
, value
, sizeof(buffer
));
1622 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1629 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1634 * Use the default port...
1637 sprintf(defpname
, "%d", defport
);
1638 portname
= defpname
;
1644 * The buffer contains just a port number...
1652 if (hostname
&& !strcmp(hostname
, "*"))
1656 * Now lookup the address using httpAddrGetList()...
1659 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1660 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1661 hostname
? hostname
: "(nil)");
1668 * 'get_addr_and_mask()' - Get an IP address and netmask.
1671 static int /* O - 1 on success, 0 on failure */
1672 get_addr_and_mask(const char *value
, /* I - String from config file */
1673 unsigned *ip
, /* O - Address value */
1674 unsigned *mask
) /* O - Mask value */
1676 int i
, j
, /* Looping vars */
1677 family
, /* Address family */
1678 ipcount
; /* Count of fields in address */
1679 unsigned ipval
; /* Value */
1680 const char *maskval
, /* Pointer to start of mask value */
1681 *ptr
, /* Pointer into value */
1686 * Get the address...
1689 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1690 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1692 if ((maskval
= strchr(value
, '/')) != NULL
)
1695 maskval
= value
+ strlen(value
);
1699 * Check for an IPv6 address...
1705 * Parse hexadecimal IPv6/IPv4 address...
1710 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1714 else if (!strncmp(ptr
, "::", 2))
1716 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1718 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1723 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1726 * Read IPv4 dotted quad...
1729 unsigned val
[4] = { 0, 0, 0, 0 };
1730 /* IPv4 address values */
1732 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1736 * Range check the IP numbers...
1739 for (i
= 0; i
< ipcount
; i
++)
1744 * Merge everything into a 32-bit IPv4 address in ip[3]...
1747 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1750 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1753 * If the leading words are all 0's then this is an IPv4 address...
1756 if (!val
[0] && !val
[1] && !val
[2])
1759 while (isdigit(*ptr
& 255) || *ptr
== '.')
1763 else if (isxdigit(*ptr
& 255))
1765 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1767 if (*ptr
== ':' && ptr
[1] != ':')
1776 ip
[i
/ 2] |= ipval
<< 16;
1787 if (*ptr
&& *ptr
!= '/')
1791 #endif /* AF_INET6 */
1794 * Parse dotted-decimal IPv4 address...
1797 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1801 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1804 * Range check the IP numbers...
1807 for (i
= 0; i
< ipcount
; i
++)
1812 * Merge everything into a 32-bit IPv4 address in ip[3]...
1815 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1818 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1824 * Get the netmask value(s)...
1827 memset(mask
, 0, sizeof(unsigned) * 4);
1829 if (strchr(maskval
, '.'))
1832 * Get dotted-decimal mask...
1835 if (family
!= AF_INET
)
1838 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1842 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1843 mask
[0] = mask
[1] = mask
[2] = 0;
1848 * Get address/bits format...
1854 if (family
== AF_INET6
)
1862 mask
[0] = 0xffffffff;
1864 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1867 mask
[1] = 0xffffffff;
1871 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1874 mask
[2] = 0xffffffff;
1878 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1881 mask
[3] = 0xffffffff;
1885 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1888 #endif /* AF_INET6 */
1893 mask
[0] = 0xffffffff;
1894 mask
[1] = 0xffffffff;
1895 mask
[2] = 0xffffffff;
1898 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1900 mask
[3] = 0xffffffff;
1905 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1906 "get_addr_and_mask(value=\"%s\", "
1907 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1908 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1912 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1915 if ((ip
[0] & ~mask
[0]) != 0 ||
1916 (ip
[1] & ~mask
[1]) != 0 ||
1917 (ip
[2] & ~mask
[2]) != 0 ||
1918 (ip
[3] & ~mask
[3]) != 0)
1926 * 'mime_error_cb()' - Log a MIME error.
1930 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
1931 const char *message
) /* I - Message */
1935 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
1940 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1943 static int /* O - 1 on success, 0 on failure */
1944 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1945 char *line
, /* I - Line from file */
1946 char *value
, /* I - Start of value data */
1947 int linenum
) /* I - Current line number */
1949 char *valptr
; /* Pointer into value */
1950 unsigned ip
[4], /* IP address components */
1951 mask
[4]; /* IP netmask components */
1954 if (!_cups_strcasecmp(line
, "Encryption"))
1957 * "Encryption xxx" - set required encryption level...
1960 if (!_cups_strcasecmp(value
, "never"))
1961 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1962 else if (!_cups_strcasecmp(value
, "always"))
1964 cupsdLogMessage(CUPSD_LOG_ERROR
,
1965 "Encryption value \"%s\" on line %d is invalid in this "
1966 "context. Using \"required\" instead.", value
, linenum
);
1968 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1970 else if (!_cups_strcasecmp(value
, "required"))
1971 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1972 else if (!_cups_strcasecmp(value
, "ifrequested"))
1973 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1976 cupsdLogMessage(CUPSD_LOG_ERROR
,
1977 "Unknown Encryption value %s on line %d.", value
, linenum
);
1981 else if (!_cups_strcasecmp(line
, "Order"))
1984 * "Order Deny,Allow" or "Order Allow,Deny"...
1987 if (!_cups_strncasecmp(value
, "deny", 4))
1988 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1989 else if (!_cups_strncasecmp(value
, "allow", 5))
1990 loc
->order_type
= CUPSD_AUTH_DENY
;
1993 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1998 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2001 * Allow [From] host/ip...
2002 * Deny [From] host/ip...
2007 if (!_cups_strncasecmp(value
, "from", 4))
2010 * Strip leading "from"...
2015 while (_cups_isspace(*value
))
2023 * Find the end of the value...
2026 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2028 while (_cups_isspace(*valptr
))
2032 * Figure out what form the allow/deny address takes:
2043 * nnn.nnn.nnn.nnn/mm
2044 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2047 if (!_cups_strcasecmp(value
, "all"))
2053 if (!_cups_strcasecmp(line
, "Allow"))
2054 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2056 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2058 else if (!_cups_strcasecmp(value
, "none"))
2064 if (!_cups_strcasecmp(line
, "Allow"))
2065 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2067 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2070 else if (value
[0] == '*' || value
[0] == '.' ||
2071 (!isdigit(value
[0] & 255) && value
[0] != '['))
2073 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2074 #endif /* AF_INET6 */
2077 * Host or domain name...
2080 if (value
[0] == '*')
2083 if (!_cups_strcasecmp(line
, "Allow"))
2084 cupsdAddNameMask(&(loc
->allow
), value
);
2086 cupsdAddNameMask(&(loc
->deny
), value
);
2091 * One of many IP address forms...
2094 if (!get_addr_and_mask(value
, ip
, mask
))
2096 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2101 if (!_cups_strcasecmp(line
, "Allow"))
2102 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2104 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2108 * Advance to next value...
2114 else if (!_cups_strcasecmp(line
, "AuthType"))
2117 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2120 if (!_cups_strcasecmp(value
, "none"))
2122 loc
->type
= CUPSD_AUTH_NONE
;
2123 loc
->level
= CUPSD_AUTH_ANON
;
2125 else if (!_cups_strcasecmp(value
, "basic"))
2127 loc
->type
= CUPSD_AUTH_BASIC
;
2129 if (loc
->level
== CUPSD_AUTH_ANON
)
2130 loc
->level
= CUPSD_AUTH_USER
;
2132 else if (!_cups_strcasecmp(value
, "digest"))
2134 loc
->type
= CUPSD_AUTH_DIGEST
;
2136 if (loc
->level
== CUPSD_AUTH_ANON
)
2137 loc
->level
= CUPSD_AUTH_USER
;
2139 else if (!_cups_strcasecmp(value
, "basicdigest"))
2141 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
2143 if (loc
->level
== CUPSD_AUTH_ANON
)
2144 loc
->level
= CUPSD_AUTH_USER
;
2146 else if (!_cups_strcasecmp(value
, "default"))
2148 loc
->type
= CUPSD_AUTH_DEFAULT
;
2150 if (loc
->level
== CUPSD_AUTH_ANON
)
2151 loc
->level
= CUPSD_AUTH_USER
;
2154 else if (!_cups_strcasecmp(value
, "negotiate"))
2156 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2158 if (loc
->level
== CUPSD_AUTH_ANON
)
2159 loc
->level
= CUPSD_AUTH_USER
;
2161 #endif /* HAVE_GSSAPI */
2164 cupsdLogMessage(CUPSD_LOG_WARN
,
2165 "Unknown authorization type %s on line %d.",
2170 else if (!_cups_strcasecmp(line
, "AuthClass"))
2173 * AuthClass anonymous, user, system, group
2176 if (!_cups_strcasecmp(value
, "anonymous"))
2178 loc
->type
= CUPSD_AUTH_NONE
;
2179 loc
->level
= CUPSD_AUTH_ANON
;
2181 cupsdLogMessage(CUPSD_LOG_WARN
,
2182 "\"AuthClass %s\" is deprecated; consider removing "
2186 else if (!_cups_strcasecmp(value
, "user"))
2188 loc
->level
= CUPSD_AUTH_USER
;
2190 cupsdLogMessage(CUPSD_LOG_WARN
,
2191 "\"AuthClass %s\" is deprecated; consider using "
2192 "\"Require valid-user\" on line %d.",
2195 else if (!_cups_strcasecmp(value
, "group"))
2197 loc
->level
= CUPSD_AUTH_GROUP
;
2199 cupsdLogMessage(CUPSD_LOG_WARN
,
2200 "\"AuthClass %s\" is deprecated; consider using "
2201 "\"Require user @groupname\" on line %d.",
2204 else if (!_cups_strcasecmp(value
, "system"))
2206 loc
->level
= CUPSD_AUTH_GROUP
;
2208 cupsdAddName(loc
, "@SYSTEM");
2210 cupsdLogMessage(CUPSD_LOG_WARN
,
2211 "\"AuthClass %s\" is deprecated; consider using "
2212 "\"Require user @SYSTEM\" on line %d.",
2217 cupsdLogMessage(CUPSD_LOG_WARN
,
2218 "Unknown authorization class %s on line %d.",
2223 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2225 cupsdAddName(loc
, value
);
2227 cupsdLogMessage(CUPSD_LOG_WARN
,
2228 "\"AuthGroupName %s\" directive is deprecated; consider "
2229 "using \"Require user @%s\" on line %d.",
2230 value
, value
, linenum
);
2232 else if (!_cups_strcasecmp(line
, "Require"))
2235 * Apache synonym for AuthClass and AuthGroupName...
2239 * Require valid-user
2240 * Require group names
2241 * Require user names
2244 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2249 if (!_cups_strcasecmp(value
, "valid-user") ||
2250 !_cups_strcasecmp(value
, "user"))
2251 loc
->level
= CUPSD_AUTH_USER
;
2252 else if (!_cups_strcasecmp(value
, "group"))
2253 loc
->level
= CUPSD_AUTH_GROUP
;
2256 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2262 * Get the list of names from the line...
2265 for (value
= valptr
; *value
;)
2267 while (_cups_isspace(*value
))
2270 #ifdef HAVE_AUTHORIZATION_H
2271 if (!strncmp(value
, "@AUTHKEY(", 9))
2274 * Grab "@AUTHKEY(name)" value...
2277 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2283 #endif /* HAVE_AUTHORIZATION_H */
2284 if (*value
== '\"' || *value
== '\'')
2287 * Grab quoted name...
2290 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2297 * Grab literal name.
2300 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2306 cupsdAddName(loc
, value
);
2308 for (value
= valptr
; _cups_isspace(*value
); value
++);
2311 else if (!_cups_strcasecmp(line
, "Satisfy"))
2313 if (!_cups_strcasecmp(value
, "all"))
2314 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2315 else if (!_cups_strcasecmp(value
, "any"))
2316 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2319 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2332 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2335 static int /* O - FatalErrors bits */
2336 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2338 int fatal
; /* FatalErrors bits */
2339 char value
[1024], /* Value string */
2340 *valstart
, /* Pointer into value */
2341 *valend
; /* End of value */
2345 * Empty FatalErrors line yields NULL pointer...
2349 return (CUPSD_FATAL_NONE
);
2352 * Loop through the value string,...
2355 strlcpy(value
, s
, sizeof(value
));
2357 fatal
= CUPSD_FATAL_NONE
;
2359 for (valstart
= value
; *valstart
;)
2362 * Get the current space/comma-delimited kind name...
2365 for (valend
= valstart
; *valend
; valend
++)
2366 if (_cups_isspace(*valend
) || *valend
== ',')
2373 * Add the error to the bitmask...
2376 if (!_cups_strcasecmp(valstart
, "all"))
2377 fatal
= CUPSD_FATAL_ALL
;
2378 else if (!_cups_strcasecmp(valstart
, "browse"))
2379 fatal
|= CUPSD_FATAL_BROWSE
;
2380 else if (!_cups_strcasecmp(valstart
, "-browse"))
2381 fatal
&= ~CUPSD_FATAL_BROWSE
;
2382 else if (!_cups_strcasecmp(valstart
, "config"))
2383 fatal
|= CUPSD_FATAL_CONFIG
;
2384 else if (!_cups_strcasecmp(valstart
, "-config"))
2385 fatal
&= ~CUPSD_FATAL_CONFIG
;
2386 else if (!_cups_strcasecmp(valstart
, "listen"))
2387 fatal
|= CUPSD_FATAL_LISTEN
;
2388 else if (!_cups_strcasecmp(valstart
, "-listen"))
2389 fatal
&= ~CUPSD_FATAL_LISTEN
;
2390 else if (!_cups_strcasecmp(valstart
, "log"))
2391 fatal
|= CUPSD_FATAL_LOG
;
2392 else if (!_cups_strcasecmp(valstart
, "-log"))
2393 fatal
&= ~CUPSD_FATAL_LOG
;
2394 else if (!_cups_strcasecmp(valstart
, "permissions"))
2395 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2396 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2397 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2398 else if (_cups_strcasecmp(valstart
, "none"))
2399 cupsdLogMessage(CUPSD_LOG_ERROR
,
2400 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2402 for (valstart
= valend
; *valstart
; valstart
++)
2403 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2412 * 'parse_groups()' - Parse system group names in a string.
2415 static int /* O - 1 on success, 0 on failure */
2416 parse_groups(const char *s
) /* I - Space-delimited groups */
2418 int status
; /* Return status */
2419 char value
[1024], /* Value string */
2420 *valstart
, /* Pointer into value */
2421 *valend
, /* End of value */
2422 quote
; /* Quote character */
2423 struct group
*group
; /* Group */
2427 * Make a copy of the string and parse out the groups...
2430 strlcpy(value
, s
, sizeof(value
));
2435 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2437 if (*valstart
== '\'' || *valstart
== '\"')
2440 * Scan quoted name...
2443 quote
= *valstart
++;
2445 for (valend
= valstart
; *valend
; valend
++)
2446 if (*valend
== quote
)
2452 * Scan space or comma-delimited name...
2455 for (valend
= valstart
; *valend
; valend
++)
2456 if (_cups_isspace(*valend
) || *valend
== ',')
2463 group
= getgrnam(valstart
);
2466 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2467 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2478 while (*valstart
== ',' || _cups_isspace(*valstart
))
2487 * 'parse_protocols()' - Parse browse protocols in a string.
2490 static int /* O - Browse protocol bits */
2491 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2493 int protocols
; /* Browse protocol bits */
2494 char value
[1024], /* Value string */
2495 *valstart
, /* Pointer into value */
2496 *valend
; /* End of value */
2500 * Empty protocol line yields NULL pointer...
2507 * Loop through the value string,...
2510 strlcpy(value
, s
, sizeof(value
));
2514 for (valstart
= value
; *valstart
;)
2517 * Get the current space/comma-delimited protocol name...
2520 for (valend
= valstart
; *valend
; valend
++)
2521 if (_cups_isspace(*valend
) || *valend
== ',')
2528 * Add the protocol to the bitmask...
2531 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2532 !_cups_strcasecmp(valstart
, "dns-sd") ||
2533 !_cups_strcasecmp(valstart
, "bonjour"))
2534 protocols
|= BROWSE_DNSSD
;
2535 else if (!_cups_strcasecmp(valstart
, "all"))
2536 protocols
|= BROWSE_ALL
;
2537 else if (_cups_strcasecmp(valstart
, "none"))
2538 cupsdLogMessage(CUPSD_LOG_ERROR
,
2539 "Unknown browse protocol \"%s\" ignored.", valstart
);
2541 for (valstart
= valend
; *valstart
; valstart
++)
2542 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2551 * 'read_configuration()' - Read a configuration file.
2554 static int /* O - 1 on success, 0 on failure */
2555 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2557 int i
; /* Looping var */
2558 int linenum
; /* Current line number */
2559 char line
[HTTP_MAX_BUFFER
],
2560 /* Line from file */
2561 temp
[HTTP_MAX_BUFFER
],
2562 /* Temporary buffer for value */
2563 *value
, /* Pointer to value */
2564 *valueptr
; /* Pointer into value */
2565 int valuelen
; /* Length of value */
2566 cupsd_var_t
const *var
; /* Current variable */
2567 http_addrlist_t
*addrlist
, /* Address list */
2568 *addr
; /* Current address */
2569 cups_file_t
*incfile
; /* Include file */
2570 char incname
[1024]; /* Include filename */
2571 struct group
*group
; /* Group */
2575 * Loop through each line in the file...
2580 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2583 * Decode the directive...
2586 if (!_cups_strcasecmp(line
, "Include") && value
)
2592 if (value
[0] == '/')
2593 strlcpy(incname
, value
, sizeof(incname
));
2595 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2597 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2598 cupsdLogMessage(CUPSD_LOG_ERROR
,
2599 "Unable to include config file \"%s\" - %s",
2600 incname
, strerror(errno
));
2603 read_configuration(incfile
);
2604 cupsFileClose(incfile
);
2607 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2613 linenum
= read_location(fp
, value
, linenum
);
2617 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2623 linenum
= read_policy(fp
, value
, linenum
);
2627 else if (!_cups_strcasecmp(line
, "FatalErrors"))
2628 FatalErrors
= parse_fatal_errors(value
);
2629 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2631 JobRetryInterval
= atoi(value
);
2632 cupsdLogMessage(CUPSD_LOG_WARN
,
2633 "FaxRetryInterval is deprecated; use "
2634 "JobRetryInterval on line %d.", linenum
);
2636 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2638 JobRetryLimit
= atoi(value
);
2639 cupsdLogMessage(CUPSD_LOG_WARN
,
2640 "FaxRetryLimit is deprecated; use "
2641 "JobRetryLimit on line %d.", linenum
);
2643 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
2645 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
2646 #endif /* HAVE_SSL */
2650 * Add listening address(es) to the list...
2653 cupsd_listener_t
*lis
; /* New listeners array */
2657 * Get the address list...
2660 addrlist
= get_address(value
, IPP_PORT
);
2664 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2670 * Add each address...
2673 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2676 * See if this address is already present...
2679 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2681 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2682 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2683 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2688 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2689 cupsdLogMessage(CUPSD_LOG_WARN
,
2690 "Duplicate listen address \"%s\" ignored.", temp
);
2695 * Allocate another listener...
2699 Listeners
= cupsArrayNew(NULL
, NULL
);
2703 cupsdLogMessage(CUPSD_LOG_ERROR
,
2704 "Unable to allocate %s at line %d - %s.",
2705 line
, linenum
, strerror(errno
));
2709 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2711 cupsdLogMessage(CUPSD_LOG_ERROR
,
2712 "Unable to allocate %s at line %d - %s.",
2713 line
, linenum
, strerror(errno
));
2717 cupsArrayAdd(Listeners
, lis
);
2720 * Copy the current address and log it...
2723 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2727 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
2728 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2729 #endif /* HAVE_SSL */
2731 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2734 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2735 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2737 #endif /* AF_LOCAL */
2738 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
2739 _httpAddrPort(&(lis
->address
)),
2740 _httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
2742 if (!httpAddrLocalhost(&(lis
->address
)))
2743 RemotePort
= _httpAddrPort(&(lis
->address
));
2750 httpAddrFreeList(addrlist
);
2752 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
2753 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
2756 * "BrowseProtocols name [... name]"
2757 * "BrowseLocalProtocols name [... name]"
2760 int protocols
= parse_protocols(value
);
2764 cupsdLogMessage(CUPSD_LOG_ERROR
,
2765 "Unknown browse protocol \"%s\" on line %d.",
2770 BrowseLocalProtocols
= protocols
;
2772 else if (!_cups_strcasecmp(line
, "default_auth_type") && value
)
2775 * default_auth_type {basic,digest,basicdigest,negotiate}
2778 if (!_cups_strcasecmp(value
, "none"))
2779 default_auth_type
= CUPSD_AUTH_NONE
;
2780 else if (!_cups_strcasecmp(value
, "basic"))
2781 default_auth_type
= CUPSD_AUTH_BASIC
;
2782 else if (!_cups_strcasecmp(value
, "digest"))
2783 default_auth_type
= CUPSD_AUTH_DIGEST
;
2784 else if (!_cups_strcasecmp(value
, "basicdigest"))
2785 default_auth_type
= CUPSD_AUTH_BASICDIGEST
;
2787 else if (!_cups_strcasecmp(value
, "negotiate"))
2788 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
2789 #endif /* HAVE_GSSAPI */
2790 else if (!_cups_strcasecmp(value
, "auto"))
2791 default_auth_type
= CUPSD_AUTH_AUTO
;
2794 cupsdLogMessage(CUPSD_LOG_WARN
,
2795 "Unknown default authorization type %s on line %d.",
2797 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2802 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
2805 * DefaultEncryption {Never,IfRequested,Required}
2808 if (!value
|| !_cups_strcasecmp(value
, "never"))
2809 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2810 else if (!_cups_strcasecmp(value
, "required"))
2811 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2812 else if (!_cups_strcasecmp(value
, "ifrequested"))
2813 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2816 cupsdLogMessage(CUPSD_LOG_WARN
,
2817 "Unknown default encryption %s on line %d.",
2819 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
2823 #endif /* HAVE_SSL */
2824 else if (!_cups_strcasecmp(line
, "User") && value
)
2827 * User ID to run as...
2830 if (isdigit(value
[0] & 255))
2832 int uid
= atoi(value
);
2835 cupsdLogMessage(CUPSD_LOG_ERROR
,
2836 "Will not use User 0 as specified on line %d "
2837 "for security reasons. You must use a non-"
2838 "privileged account instead.",
2845 struct passwd
*p
; /* Password information */
2848 p
= getpwnam(value
);
2853 cupsdLogMessage(CUPSD_LOG_ERROR
,
2854 "Will not use User %s (UID=0) as specified on line "
2855 "%d for security reasons. You must use a non-"
2856 "privileged account instead.",
2862 cupsdLogMessage(CUPSD_LOG_ERROR
,
2863 "Unknown User \"%s\" on line %d, ignoring.",
2867 else if (!_cups_strcasecmp(line
, "Group") && value
)
2870 * Group ID to run as...
2873 if (isdigit(value
[0]))
2874 Group
= atoi(value
);
2878 group
= getgrnam(value
);
2881 Group
= group
->gr_gid
;
2883 cupsdLogMessage(CUPSD_LOG_ERROR
,
2884 "Unknown Group \"%s\" on line %d, ignoring.",
2888 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
2891 * SystemGroup (admin) group(s)...
2894 if (!parse_groups(value
))
2895 cupsdLogMessage(CUPSD_LOG_ERROR
,
2896 "Unknown SystemGroup \"%s\" on line %d, ignoring.",
2899 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
2902 * Do hostname lookups?
2905 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
2906 !_cups_strcasecmp(value
, "false"))
2907 HostNameLookups
= 0;
2908 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
2909 !_cups_strcasecmp(value
, "true"))
2910 HostNameLookups
= 1;
2911 else if (!_cups_strcasecmp(value
, "double"))
2912 HostNameLookups
= 2;
2914 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2917 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
2920 * Amount of logging to do to access log...
2923 if (!_cups_strcasecmp(value
, "all"))
2924 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
2925 else if (!_cups_strcasecmp(value
, "actions"))
2926 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
2927 else if (!_cups_strcasecmp(value
, "config"))
2928 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
2930 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
2933 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
2936 * Amount of logging to do to error log...
2939 if (!_cups_strcasecmp(value
, "debug2"))
2940 LogLevel
= CUPSD_LOG_DEBUG2
;
2941 else if (!_cups_strcasecmp(value
, "debug"))
2942 LogLevel
= CUPSD_LOG_DEBUG
;
2943 else if (!_cups_strcasecmp(value
, "info"))
2944 LogLevel
= CUPSD_LOG_INFO
;
2945 else if (!_cups_strcasecmp(value
, "notice"))
2946 LogLevel
= CUPSD_LOG_NOTICE
;
2947 else if (!_cups_strcasecmp(value
, "warn"))
2948 LogLevel
= CUPSD_LOG_WARN
;
2949 else if (!_cups_strcasecmp(value
, "error"))
2950 LogLevel
= CUPSD_LOG_ERROR
;
2951 else if (!_cups_strcasecmp(value
, "crit"))
2952 LogLevel
= CUPSD_LOG_CRIT
;
2953 else if (!_cups_strcasecmp(value
, "alert"))
2954 LogLevel
= CUPSD_LOG_ALERT
;
2955 else if (!_cups_strcasecmp(value
, "emerg"))
2956 LogLevel
= CUPSD_LOG_EMERG
;
2957 else if (!_cups_strcasecmp(value
, "none"))
2958 LogLevel
= CUPSD_LOG_NONE
;
2960 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2963 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
2966 * Amount of logging to do to error log...
2969 if (!_cups_strcasecmp(value
, "standard"))
2970 LogTimeFormat
= CUPSD_TIME_STANDARD
;
2971 else if (!_cups_strcasecmp(value
, "usecs"))
2972 LogTimeFormat
= CUPSD_TIME_USECS
;
2974 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
2977 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
2980 * Format of printcap file?
2983 if (!_cups_strcasecmp(value
, "bsd"))
2984 PrintcapFormat
= PRINTCAP_BSD
;
2985 else if (!_cups_strcasecmp(value
, "plist"))
2986 PrintcapFormat
= PRINTCAP_PLIST
;
2987 else if (!_cups_strcasecmp(value
, "solaris"))
2988 PrintcapFormat
= PRINTCAP_SOLARIS
;
2990 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2993 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
2996 * Set the string used for the Server header...
2999 struct utsname plat
; /* Platform info */
3004 if (!_cups_strcasecmp(value
, "ProductOnly"))
3005 cupsdSetString(&ServerHeader
, "CUPS");
3006 else if (!_cups_strcasecmp(value
, "Major"))
3007 cupsdSetStringf(&ServerHeader
, "CUPS/%d", CUPS_VERSION_MAJOR
);
3008 else if (!_cups_strcasecmp(value
, "Minor"))
3009 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
3010 CUPS_VERSION_MINOR
);
3011 else if (!_cups_strcasecmp(value
, "Minimal"))
3012 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3013 else if (!_cups_strcasecmp(value
, "OS"))
3014 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3015 else if (!_cups_strcasecmp(value
, "Full"))
3016 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/2.1",
3018 else if (!_cups_strcasecmp(value
, "None"))
3019 cupsdClearString(&ServerHeader
);
3021 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3024 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3027 * PassEnv variable [... variable]
3032 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3033 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3036 if (value
[valuelen
])
3038 value
[valuelen
] = '\0';
3042 cupsdSetEnv(value
, NULL
);
3044 for (value
+= valuelen
; *value
; value
++)
3045 if (!_cups_isspace(*value
) || *value
!= ',')
3049 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3052 * ServerAlias name [... name]
3056 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3060 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3061 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3064 if (value
[valuelen
])
3066 value
[valuelen
] = '\0';
3070 cupsdAddAlias(ServerAlias
, value
);
3072 for (value
+= valuelen
; *value
; value
++)
3073 if (!_cups_isspace(*value
) || *value
!= ',')
3077 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3080 * SetEnv variable value
3083 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3091 while (isspace(*valueptr
& 255))
3094 cupsdSetEnv(value
, valueptr
);
3097 cupsdLogMessage(CUPSD_LOG_ERROR
,
3098 "Missing value for SetEnv directive on line %d.",
3102 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3105 * SSLOptions options
3108 if (!value
|| !_cups_strcasecmp(value
, "none"))
3109 SSLOptions
= CUPSD_SSL_NONE
;
3110 else if (!_cups_strcasecmp(value
, "noemptyfragments"))
3111 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3113 cupsdLogMessage(CUPSD_LOG_ERROR
,
3114 "Unknown value \"%s\" for SSLOptions directive on "
3115 "line %d.", value
, linenum
);
3117 #endif /* HAVE_SSL */
3121 * Find a simple variable in the list...
3124 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3125 if (!_cups_strcasecmp(line
, var
->name
))
3131 * Unknown directive! Output an error message and continue...
3135 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3138 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3145 case CUPSD_VARTYPE_INTEGER
:
3147 cupsdLogMessage(CUPSD_LOG_ERROR
,
3148 "Missing integer value for %s on line %d.",
3150 else if (!isdigit(*value
& 255))
3151 cupsdLogMessage(CUPSD_LOG_ERROR
,
3152 "Bad integer value for %s on line %d.",
3157 char *units
; /* Units */
3159 n
= strtol(value
, &units
, 0);
3161 if (units
&& *units
)
3163 if (tolower(units
[0] & 255) == 'g')
3164 n
*= 1024 * 1024 * 1024;
3165 else if (tolower(units
[0] & 255) == 'm')
3167 else if (tolower(units
[0] & 255) == 'k')
3169 else if (tolower(units
[0] & 255) == 't')
3173 cupsdLogMessage(CUPSD_LOG_ERROR
,
3174 "Unknown integer value for %s on line %d.",
3181 cupsdLogMessage(CUPSD_LOG_ERROR
,
3182 "Bad negative integer value for %s on line %d.",
3185 *((int *)var
->ptr
) = n
;
3189 case CUPSD_VARTYPE_TIME
:
3191 cupsdLogMessage(CUPSD_LOG_ERROR
,
3192 "Missing time interval value for %s on line %d.",
3194 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
3195 (!_cups_strcasecmp(value
, "true") ||
3196 !_cups_strcasecmp(value
, "on") ||
3197 !_cups_strcasecmp(value
, "enabled") ||
3198 !_cups_strcasecmp(value
, "yes")))
3199 *((int *)var
->ptr
) = INT_MAX
;
3200 else if (!_cups_strcasecmp(value
, "false") ||
3201 !_cups_strcasecmp(value
, "off") ||
3202 !_cups_strcasecmp(value
, "disabled") ||
3203 !_cups_strcasecmp(value
, "no"))
3204 *((int *)var
->ptr
) = 0;
3205 else if (!isdigit(*value
& 255))
3206 cupsdLogMessage(CUPSD_LOG_ERROR
,
3207 "Unknown time interval value for %s on line %d.",
3211 double n
; /* Number */
3212 char *units
; /* Units */
3214 n
= strtod(value
, &units
);
3216 if (units
&& *units
)
3218 if (tolower(units
[0] & 255) == 'w')
3219 n
*= 7 * 24 * 60 * 60;
3220 else if (tolower(units
[0] & 255) == 'd')
3222 else if (tolower(units
[0] & 255) == 'h')
3224 else if (tolower(units
[0] & 255) == 'm')
3228 cupsdLogMessage(CUPSD_LOG_ERROR
,
3229 "Unknown time interval value for %s on line "
3230 "%d.", line
, linenum
);
3235 if (n
< 0.0 || n
> INT_MAX
)
3236 cupsdLogMessage(CUPSD_LOG_ERROR
,
3237 "Bad time value for %s on line %d.",
3240 *((int *)var
->ptr
) = (int)n
;
3244 case CUPSD_VARTYPE_BOOLEAN
:
3246 cupsdLogMessage(CUPSD_LOG_ERROR
,
3247 "Missing boolean value for %s on line %d.",
3249 else if (!_cups_strcasecmp(value
, "true") ||
3250 !_cups_strcasecmp(value
, "on") ||
3251 !_cups_strcasecmp(value
, "enabled") ||
3252 !_cups_strcasecmp(value
, "yes") ||
3254 *((int *)var
->ptr
) = TRUE
;
3255 else if (!_cups_strcasecmp(value
, "false") ||
3256 !_cups_strcasecmp(value
, "off") ||
3257 !_cups_strcasecmp(value
, "disabled") ||
3258 !_cups_strcasecmp(value
, "no") ||
3259 !_cups_strcasecmp(value
, "0"))
3260 *((int *)var
->ptr
) = FALSE
;
3262 cupsdLogMessage(CUPSD_LOG_ERROR
,
3263 "Unknown boolean value %s on line %d.",
3267 case CUPSD_VARTYPE_PATHNAME
:
3270 cupsdLogMessage(CUPSD_LOG_ERROR
,
3271 "Missing pathname value for %s on line %d.",
3276 if (value
[0] == '/')
3277 strlcpy(temp
, value
, sizeof(temp
));
3279 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3281 if (access(temp
, 0))
3283 cupsdLogMessage(CUPSD_LOG_ERROR
,
3284 "File or directory for \"%s %s\" on line %d "
3285 "does not exist.", line
, value
, linenum
);
3289 case CUPSD_VARTYPE_STRING
:
3290 cupsdSetString((char **)var
->ptr
, value
);
3301 * 'read_location()' - Read a <Location path> definition.
3304 static int /* O - New line number or 0 on error */
3305 read_location(cups_file_t
*fp
, /* I - Configuration file */
3306 char *location
, /* I - Location name/path */
3307 int linenum
) /* I - Current line number */
3309 cupsd_location_t
*loc
, /* New location */
3310 *parent
; /* Parent location */
3311 char line
[HTTP_MAX_BUFFER
],
3313 *value
, /* Value for directive */
3314 *valptr
; /* Pointer into value */
3317 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3318 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d.",
3320 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3324 cupsdAddLocation(parent
);
3326 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3331 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3334 * Decode the directive...
3337 if (!_cups_strcasecmp(line
, "</Location>"))
3339 else if (!_cups_strcasecmp(line
, "<Limit") ||
3340 !_cups_strcasecmp(line
, "<LimitExcept"))
3344 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3345 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3351 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3354 cupsdAddLocation(loc
);
3359 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3364 if (!strcmp(value
, "ALL"))
3365 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3366 else if (!strcmp(value
, "GET"))
3367 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3368 else if (!strcmp(value
, "HEAD"))
3369 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3370 else if (!strcmp(value
, "OPTIONS"))
3371 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3372 else if (!strcmp(value
, "POST"))
3373 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3374 else if (!strcmp(value
, "PUT"))
3375 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3376 else if (!strcmp(value
, "TRACE"))
3377 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3379 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d.",
3382 for (value
= valptr
; isspace(*value
& 255); value
++);
3385 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3386 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3388 parent
->limit
&= ~loc
->limit
;
3390 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3391 !_cups_strcasecmp(line
, "</LimitExcept>"))
3395 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3396 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3399 else if (!parse_aaa(loc
, line
, value
, linenum
))
3401 cupsdLogMessage(CUPSD_LOG_ERROR
,
3402 "Unknown Location directive %s on line %d.",
3404 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3409 cupsdLogMessage(CUPSD_LOG_ERROR
,
3410 "Unexpected end-of-file at line %d while reading location.",
3413 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3418 * 'read_policy()' - Read a <Policy name> definition.
3421 static int /* O - New line number or 0 on error */
3422 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3423 char *policy
, /* I - Location name/path */
3424 int linenum
) /* I - Current line number */
3426 int i
; /* Looping var */
3427 cupsd_policy_t
*pol
; /* Policy */
3428 cupsd_location_t
*op
; /* Policy operation */
3429 int num_ops
; /* Number of IPP operations */
3430 ipp_op_t ops
[100]; /* Operations */
3431 char line
[HTTP_MAX_BUFFER
],
3433 *value
, /* Value for directive */
3434 *valptr
; /* Pointer into value */
3438 * Create the policy...
3441 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3442 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d.",
3444 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3448 * Read from the file...
3454 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3457 * Decode the directive...
3460 if (!_cups_strcasecmp(line
, "</Policy>"))
3463 cupsdLogMessage(CUPSD_LOG_WARN
,
3464 "Missing </Limit> before </Policy> on line %d.",
3467 set_policy_defaults(pol
);
3471 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3475 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3476 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3483 * Scan for IPP operation names...
3490 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3495 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3497 if (!_cups_strcasecmp(value
, "All"))
3498 ops
[num_ops
] = IPP_ANY_OPERATION
;
3499 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3500 cupsdLogMessage(CUPSD_LOG_ERROR
,
3501 "Bad IPP operation name \"%s\" on line %d.",
3507 cupsdLogMessage(CUPSD_LOG_ERROR
,
3508 "Too many operations listed on line %d.",
3511 for (value
= valptr
; isspace(*value
& 255); value
++);
3515 * If none are specified, apply the policy to all operations...
3520 ops
[0] = IPP_ANY_OPERATION
;
3525 * Add a new policy for the first operation...
3528 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3530 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3533 * Finish the current operation limit...
3539 * Copy the policy to the other operations...
3542 for (i
= 1; i
< num_ops
; i
++)
3543 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3550 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3551 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3554 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3555 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3556 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3557 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3561 cupsdLogMessage(CUPSD_LOG_ERROR
,
3562 "%s directive must appear outside <Limit>...</Limit> "
3563 "on line %d.", line
, linenum
);
3564 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3570 * Pull out whitespace-delimited values...
3576 * Find the end of the current value...
3579 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3585 * Save it appropriately...
3588 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3591 * JobPrivateAccess {all|default|user/group list|@@ACL}
3594 if (!_cups_strcasecmp(value
, "default"))
3596 cupsdAddString(&(pol
->job_access
), "@OWNER");
3597 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3600 cupsdAddString(&(pol
->job_access
), value
);
3602 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3605 * JobPrivateValues {all|none|default|attribute list}
3608 if (!_cups_strcasecmp(value
, "default"))
3610 cupsdAddString(&(pol
->job_attrs
), "job-name");
3611 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3612 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3613 cupsdAddString(&(pol
->job_attrs
), "phone");
3616 cupsdAddString(&(pol
->job_attrs
), value
);
3618 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3621 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3624 if (!_cups_strcasecmp(value
, "default"))
3626 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3627 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3630 cupsdAddString(&(pol
->sub_access
), value
);
3632 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3635 * SubscriptionPrivateValues {all|none|default|attribute list}
3638 if (!_cups_strcasecmp(value
, "default"))
3640 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3641 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3642 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3643 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3644 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3647 cupsdAddString(&(pol
->sub_attrs
), value
);
3651 * Find the next string on the line...
3654 for (value
= valptr
; isspace(*value
& 255); value
++);
3660 cupsdLogMessage(CUPSD_LOG_ERROR
,
3661 "Missing <Limit ops> directive before %s on line %d.",
3663 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3666 else if (!parse_aaa(op
, line
, value
, linenum
))
3668 cupsdLogMessage(CUPSD_LOG_ERROR
,
3669 "Unknown Policy Limit directive %s on line %d.",
3672 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3677 cupsdLogMessage(CUPSD_LOG_ERROR
,
3678 "Unexpected end-of-file at line %d while reading policy "
3679 "\"%s\".", linenum
, policy
);
3681 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3686 * 'set_policy_defaults()' - Set default policy values as needed.
3690 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
3692 cupsd_location_t
*op
; /* Policy operation */
3696 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3697 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3698 * upgrades do not introduce new security issues...
3701 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
3702 op
->op
== IPP_ANY_OPERATION
)
3704 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
3705 op
->op
!= IPP_ANY_OPERATION
)
3708 * Add a new limit for Validate-Job using the Print-Job limit as a
3712 cupsdLogMessage(CUPSD_LOG_WARN
,
3713 "No limit for Validate-Job defined in policy %s "
3714 "- using Print-Job's policy.", pol
->name
);
3716 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
3719 cupsdLogMessage(CUPSD_LOG_WARN
,
3720 "No limit for Validate-Job defined in policy %s "
3721 "and no suitable template found.", pol
->name
);
3724 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
3725 op
->op
== IPP_ANY_OPERATION
)
3727 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
3728 op
->op
!= IPP_ANY_OPERATION
)
3731 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
3735 cupsdLogMessage(CUPSD_LOG_WARN
,
3736 "No limit for Cancel-Jobs defined in policy %s "
3737 "- using Pause-Printer's policy.", pol
->name
);
3739 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
3742 cupsdLogMessage(CUPSD_LOG_WARN
,
3743 "No limit for Cancel-Jobs defined in policy %s "
3744 "and no suitable template found.", pol
->name
);
3747 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
3748 op
->op
== IPP_ANY_OPERATION
)
3750 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3751 op
->op
!= IPP_ANY_OPERATION
)
3754 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3758 cupsdLogMessage(CUPSD_LOG_WARN
,
3759 "No limit for Cancel-My-Jobs defined in policy %s "
3760 "- using Send-Document's policy.", pol
->name
);
3762 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
3765 cupsdLogMessage(CUPSD_LOG_WARN
,
3766 "No limit for Cancel-My-Jobs defined in policy %s "
3767 "and no suitable template found.", pol
->name
);
3770 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
3771 op
->op
== IPP_ANY_OPERATION
)
3773 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3774 op
->op
!= IPP_ANY_OPERATION
)
3777 * Add a new limit for Close-Job using the Send-Document limit as a
3781 cupsdLogMessage(CUPSD_LOG_WARN
,
3782 "No limit for Close-Job defined in policy %s "
3783 "- using Send-Document's policy.", pol
->name
);
3785 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
3788 cupsdLogMessage(CUPSD_LOG_WARN
,
3789 "No limit for Close-Job defined in policy %s "
3790 "and no suitable template found.", pol
->name
);
3793 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3794 op
->op
== IPP_ANY_OPERATION
)
3796 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3797 op
->op
!= IPP_ANY_OPERATION
)
3800 * Add a new limit for CUPS-Get-Document using the Send-Document
3801 * limit as a template...
3804 cupsdLogMessage(CUPSD_LOG_WARN
,
3805 "No limit for CUPS-Get-Document defined in policy %s "
3806 "- using Send-Document's policy.", pol
->name
);
3808 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3811 cupsdLogMessage(CUPSD_LOG_WARN
,
3812 "No limit for CUPS-Get-Document defined in policy %s "
3813 "and no suitable template found.", pol
->name
);
3817 * Verify we have JobPrivateAccess, JobPrivateValues,
3818 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
3821 if (!pol
->job_access
)
3823 cupsdLogMessage(CUPSD_LOG_WARN
,
3824 "No JobPrivateAccess defined in policy %s "
3825 "- using defaults.", pol
->name
);
3826 cupsdAddString(&(pol
->job_access
), "@OWNER");
3827 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3830 if (!pol
->job_attrs
)
3832 cupsdLogMessage(CUPSD_LOG_WARN
,
3833 "No JobPrivateValues defined in policy %s "
3834 "- using defaults.", pol
->name
);
3835 cupsdAddString(&(pol
->job_attrs
), "job-name");
3836 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3837 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3838 cupsdAddString(&(pol
->job_attrs
), "phone");
3841 if (!pol
->sub_access
)
3843 cupsdLogMessage(CUPSD_LOG_WARN
,
3844 "No SubscriptionPrivateAccess defined in policy %s "
3845 "- using defaults.", pol
->name
);
3846 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3847 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3850 if (!pol
->sub_attrs
)
3852 cupsdLogMessage(CUPSD_LOG_WARN
,
3853 "No SubscriptionPrivateValues defined in policy %s "
3854 "- using defaults.", pol
->name
);
3855 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3856 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3857 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3858 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3859 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3865 * End of "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $".