4 * Configuration routines for the CUPS scheduler.
6 * Copyright 2007-2013 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 * parse_variable() - Parse a variable line.
32 * read_cupsd_conf() - Read the cupsd.conf configuration file.
33 * read_cups_files_conf() - Read the cups-files.conf configuration file.
34 * read_location() - Read a <Location path> definition.
35 * read_policy() - Read a <Policy name> definition.
36 * set_policy_defaults() - Set default policy values as needed.
40 * Include necessary headers...
46 #include <sys/utsname.h>
51 #endif /* HAVE_LIBPAPER */
55 * Possibly missing network definitions...
59 # define INADDR_NONE 0xffffffff
60 #endif /* !INADDR_NONE */
64 * Configuration variable structure...
69 CUPSD_VARTYPE_INTEGER
, /* Integer option */
70 CUPSD_VARTYPE_TIME
, /* Time interval option */
71 CUPSD_VARTYPE_STRING
, /* String option */
72 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
73 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
78 const char *name
; /* Name of variable */
79 void *ptr
; /* Pointer to variable */
80 cupsd_vartype_t type
; /* Type (int, string, address) */
88 static const cupsd_var_t cupsd_vars
[] =
90 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
91 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
92 { "BrowseDNSSDSubTypes", &DNSSDSubTypes
, CUPSD_VARTYPE_STRING
},
93 #endif /* HAVE_DNSSD || HAVE_AVAHI */
94 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
95 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
96 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
97 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
98 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
99 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_TIME
},
100 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
101 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
102 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
103 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_TIME
},
104 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
105 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
106 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
108 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
109 #endif /* HAVE_GSSAPI */
110 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_TIME
},
111 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
112 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_TIME
},
113 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_TIME
},
114 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
116 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_TIME
},
117 #endif /* HAVE_LAUNCHD */
118 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
119 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
120 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
121 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
122 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
123 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
124 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
126 { "MaxHoldTime", &MaxHoldTime
, CUPSD_VARTYPE_TIME
},
127 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
128 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
129 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_TIME
},
132 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
138 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_TIME
},
139 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
140 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_TIME
},
141 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_TIME
},
142 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_TIME
},
143 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
144 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_TIME
},
145 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
146 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
147 { "StrictConformance", &StrictConformance
, CUPSD_VARTYPE_BOOLEAN
},
148 { "Timeout", &Timeout
, CUPSD_VARTYPE_TIME
},
149 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
151 static const cupsd_var_t cupsfiles_vars
[] =
153 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
154 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
155 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
156 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
157 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
158 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
159 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
160 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
161 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
162 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
163 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
164 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
165 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
166 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
167 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
169 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
170 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
171 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
172 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
173 #endif /* HAVE_SSL */
174 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
175 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
176 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
177 { "SyncOnClose", &SyncOnClose
, CUPSD_VARTYPE_BOOLEAN
},
178 #ifdef HAVE_AUTHORIZATION_H
179 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
180 #endif /* HAVE_AUTHORIZATION_H */
181 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
}
184 static int default_auth_type
= CUPSD_AUTH_AUTO
;
185 /* Default AuthType, if not specified */
187 static const unsigned ones
[4] =
189 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
191 static const unsigned zeros
[4] =
193 0x00000000, 0x00000000, 0x00000000, 0x00000000
201 static http_addrlist_t
*get_address(const char *value
, int defport
);
202 static int get_addr_and_mask(const char *value
, unsigned *ip
,
204 static void mime_error_cb(void *ctx
, const char *message
);
205 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
206 char *value
, int linenum
);
207 static int parse_fatal_errors(const char *s
);
208 static int parse_groups(const char *s
);
209 static int parse_protocols(const char *s
);
210 static int parse_variable(const char *filename
, int linenum
,
211 const char *line
, const char *value
,
213 const cupsd_var_t
*vars
);
214 static int read_cupsd_conf(cups_file_t
*fp
);
215 static int read_cups_files_conf(cups_file_t
*fp
);
216 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
217 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
218 static void set_policy_defaults(cupsd_policy_t
*pol
);
222 * 'cupsdAddAlias()' - Add a host alias.
226 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
227 const char *name
) /* I - Name to add */
229 cupsd_alias_t
*a
; /* New alias */
230 size_t namelen
; /* Length of name */
233 namelen
= strlen(name
);
235 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
238 a
->namelen
= namelen
;
239 memcpy(a
->name
, name
, namelen
+ 1); /* OK since a->name is allocated */
241 cupsArrayAdd(aliases
, a
);
246 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
249 int /* O - 0 on success, -1 on error, 1 on warning */
250 cupsdCheckPermissions(
251 const char *filename
, /* I - File/directory name */
252 const char *suffix
, /* I - Additional file/directory name */
253 int mode
, /* I - Permissions */
254 int user
, /* I - Owner */
255 int group
, /* I - Group */
256 int is_dir
, /* I - 1 = directory, 0 = file */
257 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
259 int dir_created
= 0; /* Did we create a directory? */
260 char pathname
[1024]; /* File name with prefix */
261 struct stat fileinfo
; /* Stat buffer */
262 int is_symlink
; /* Is "filename" a symlink? */
266 * Prepend the given root to the filename before testing it...
271 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
276 * See if we can stat the file/directory...
279 if (lstat(filename
, &fileinfo
))
281 if (errno
== ENOENT
&& create_dir
)
284 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
287 if (mkdir(filename
, mode
))
290 cupsdLogMessage(CUPSD_LOG_ERROR
,
291 "Unable to create directory \"%s\" - %s", filename
,
294 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
301 fileinfo
.st_mode
= mode
| S_IFDIR
;
304 return (create_dir
? -1 : 1);
307 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
309 if (stat(filename
, &fileinfo
))
311 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
312 filename
, strerror(errno
));
318 * Make sure it's a regular file or a directory as needed...
321 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
323 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
327 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
330 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
332 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
338 * If the filename is a symlink, do not change permissions (STR #2937)...
345 * Fix owner, group, and mode as needed...
348 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
351 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
354 if (chown(filename
, user
, group
) && !getuid())
357 cupsdLogMessage(CUPSD_LOG_ERROR
,
358 "Unable to change ownership of \"%s\" - %s", filename
,
361 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
368 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
371 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
374 if (chmod(filename
, mode
))
377 cupsdLogMessage(CUPSD_LOG_ERROR
,
378 "Unable to change permissions of \"%s\" - %s", filename
,
381 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
389 * Everything is OK...
397 * 'cupsdDefaultAuthType()' - Get the default AuthType.
399 * When the default_auth_type is "auto", this function tries to get the GSS
400 * credentials for the server. If that succeeds we use Kerberos authentication,
401 * otherwise we do a fallback to Basic authentication against the local user
405 int /* O - Default AuthType value */
406 cupsdDefaultAuthType(void)
409 OM_uint32 major_status
, /* Major status code */
410 minor_status
; /* Minor status code */
411 gss_name_t server_name
; /* Server name */
412 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
413 /* Service name token */
414 char buf
[1024]; /* Service name buffer */
415 #endif /* HAVE_GSSAPI */
419 * If we have already determined the correct default AuthType, use it...
422 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
423 return (default_auth_type
);
428 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
432 if (gss_init_sec_context
== NULL
)
433 return (default_auth_type
= CUPSD_AUTH_BASIC
);
434 # endif /* __APPLE__ */
437 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
438 * that fails we must use Basic...
441 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
444 token
.length
= strlen(buf
);
445 server_name
= GSS_C_NO_NAME
;
446 major_status
= gss_import_name(&minor_status
, &token
,
447 GSS_C_NT_HOSTBASED_SERVICE
,
450 memset(&token
, 0, sizeof(token
));
452 if (GSS_ERROR(major_status
))
454 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
455 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
456 return (default_auth_type
= CUPSD_AUTH_BASIC
);
459 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
461 if (GSS_ERROR(major_status
))
463 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
464 "cupsdDefaultAuthType: gss_display_name(%s) failed",
466 return (default_auth_type
= CUPSD_AUTH_BASIC
);
469 cupsdLogMessage(CUPSD_LOG_DEBUG
,
470 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
471 "credentials for %s...", (char *)token
.value
);
473 ServerCreds
= GSS_C_NO_CREDENTIAL
;
474 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
475 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
476 &ServerCreds
, NULL
, NULL
);
477 if (GSS_ERROR(major_status
))
479 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
480 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
481 (char *)token
.value
);
482 gss_release_name(&minor_status
, &server_name
);
483 gss_release_buffer(&minor_status
, &token
);
484 return (default_auth_type
= CUPSD_AUTH_BASIC
);
487 cupsdLogMessage(CUPSD_LOG_DEBUG
,
488 "cupsdDefaultAuthType: Kerberos credentials acquired "
489 "successfully for %s.", (char *)token
.value
);
491 gss_release_name(&minor_status
, &server_name
);
492 gss_release_buffer(&minor_status
, &token
);
496 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
500 * No Kerberos support compiled in so just use Basic all the time...
503 return (default_auth_type
= CUPSD_AUTH_BASIC
);
504 #endif /* HAVE_GSSAPI */
509 * 'cupsdFreeAliases()' - Free all of the alias entries.
513 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
515 cupsd_alias_t
*a
; /* Current alias */
518 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
520 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
523 cupsArrayDelete(aliases
);
528 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
531 int /* O - 1 on success, 0 otherwise */
532 cupsdReadConfiguration(void)
534 int i
; /* Looping var */
535 cups_file_t
*fp
; /* Configuration file */
536 int status
; /* Return status */
537 char temp
[1024], /* Temporary buffer */
538 mimedir
[1024], /* MIME directory */
539 *slash
; /* Directory separator */
540 cups_lang_t
*language
; /* Language */
541 struct passwd
*user
; /* Default user */
542 struct group
*group
; /* Default group */
543 char *old_serverroot
, /* Old ServerRoot */
544 *old_requestroot
; /* Old RequestRoot */
545 int old_remote_port
; /* Old RemotePort */
546 const char *tmpdir
; /* TMPDIR environment variable */
547 struct stat tmpinfo
; /* Temporary directory info */
548 cupsd_policy_t
*p
; /* Policy */
552 * Save the old root paths...
555 old_serverroot
= NULL
;
556 cupsdSetString(&old_serverroot
, ServerRoot
);
557 old_requestroot
= NULL
;
558 cupsdSetString(&old_requestroot
, RequestRoot
);
561 * Reset the server configuration data...
564 cupsdDeleteAllLocations();
566 cupsdDeleteAllListeners();
568 old_remote_port
= RemotePort
;
575 cupsdFreeAliases(ServerAlias
);
578 cupsdClearString(&ServerName
);
579 cupsdClearString(&ServerAdmin
);
580 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
581 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
582 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
583 cupsdSetString(&DataDir
, CUPS_DATADIR
);
584 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
585 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
586 cupsdClearString(&ErrorLog
);
587 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
588 cupsdSetString(&PageLogFormat
,
589 "%p %u %j %T %P %C %{job-billing} "
590 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
591 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
592 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
593 cupsdSetString(&RemoteRoot
, "remroot");
594 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
596 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
598 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
599 PrintcapFormat
= PRINTCAP_SOLARIS
;
600 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
601 "/Library/Preferences/org.cups.printers.plist"))
602 PrintcapFormat
= PRINTCAP_PLIST
;
604 PrintcapFormat
= PRINTCAP_BSD
;
606 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
607 if ((slash
= strrchr(temp
, '/')) != NULL
)
610 cupsdSetString(&ServerRoot
, temp
);
612 cupsdClearString(&Classification
);
613 ClassifyOverride
= 0;
617 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
619 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
620 cupsdSetString(&ServerKey
, "ssl/server.key");
621 # endif /* HAVE_CDSASSL */
622 #endif /* HAVE_SSL */
624 language
= cupsLangDefault();
626 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
627 cupsdSetString(&DefaultLanguage
, "en");
629 cupsdSetString(&DefaultLanguage
, language
->language
);
631 cupsdClearString(&DefaultPaperSize
);
633 cupsdSetString(&RIPCache
, "128m");
635 cupsdSetString(&TempDir
, NULL
);
638 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
642 OM_uint32 minor_status
; /* Minor status code */
644 gss_release_cred(&minor_status
, &ServerCreds
);
649 ServerCreds
= GSS_C_NO_CREDENTIAL
;
650 #endif /* HAVE_GSSAPI */
653 * Find the default user...
656 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
661 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
662 * complement number...)
671 * Find the default group...
674 group
= getgrnam(CUPS_DEFAULT_GROUP
);
678 Group
= group
->gr_gid
;
682 * Fallback to group "nobody"...
685 group
= getgrnam("nobody");
689 Group
= group
->gr_gid
;
693 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
694 * complement number...)
705 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
706 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
707 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
708 default_auth_type
= CUPSD_AUTH_BASIC
;
710 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
711 SSLOptions
= CUPSD_SSL_NONE
;
712 #endif /* HAVE_SSL */
713 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
714 JobKillDelay
= DEFAULT_TIMEOUT
;
716 JobRetryInterval
= 300;
721 HostNameLookups
= FALSE
;
723 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
724 ListenBackLog
= SOMAXCONN
;
725 LogDebugHistory
= 200;
726 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
727 LogLevel
= CUPSD_LOG_WARN
;
728 LogTimeFormat
= CUPSD_TIME_STANDARD
;
730 MaxClientsPerHost
= 0;
731 MaxLogSize
= 1024 * 1024;
733 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
735 ReloadTimeout
= DEFAULT_KEEPALIVE
;
736 RootCertDuration
= 300;
737 StrictConformance
= FALSE
;
739 Timeout
= DEFAULT_TIMEOUT
;
740 WebInterface
= CUPS_DEFAULT_WEBIF
;
742 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
744 Browsing
= CUPS_DEFAULT_BROWSING
;
745 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
747 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
748 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
749 #endif /* HAVE_DNSSD || HAVE_AVAHI */
751 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
752 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
754 cupsdSetString(&ErrorPolicy
, "stop-printer");
756 JobHistory
= DEFAULT_HISTORY
;
757 JobFiles
= DEFAULT_FILES
;
763 MaxJobsPerPrinter
= 0;
764 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
765 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
767 cupsdDeleteAllPolicies();
768 cupsdClearString(&DefaultPolicy
);
770 #ifdef HAVE_AUTHORIZATION_H
771 cupsdSetString(&SystemGroupAuthKey
, CUPS_DEFAULT_SYSTEM_AUTHKEY
);
772 #endif /* HAVE_AUTHORIZATION_H */
774 MaxSubscriptions
= 100;
775 MaxSubscriptionsPerJob
= 0;
776 MaxSubscriptionsPerPrinter
= 0;
777 MaxSubscriptionsPerUser
= 0;
778 DefaultLeaseDuration
= 86400;
779 MaxLeaseDuration
= 0;
783 #endif /* HAVE_LAUNCHD */
786 * Setup environment variables...
792 * Read the cups-files.conf file...
795 if ((fp
= cupsFileOpen(CupsFilesFile
, "r")) != NULL
)
797 status
= read_cups_files_conf(fp
);
804 printf("\"%s\" contains errors.\n", CupsFilesFile
);
806 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.",
812 else if (errno
== ENOENT
)
813 cupsdLogMessage(CUPSD_LOG_INFO
, "No %s, using defaults.", CupsFilesFile
);
816 syslog(LOG_LPR
, "Unable to open \"%s\": %s", CupsFilesFile
,
822 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
825 * Read the cupsd.conf file...
828 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
830 syslog(LOG_LPR
, "Unable to open \"%s\": %s", ConfigurationFile
,
835 status
= read_cupsd_conf(fp
);
842 printf("\"%s\" contains errors.\n", ConfigurationFile
);
844 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.",
852 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
853 RemotePort
? "enabled" : "disabled");
856 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
859 * See if the ServerName is an IP address...
865 ServerAlias
= cupsArrayNew(NULL
, NULL
);
867 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
871 if (gethostname(temp
, sizeof(temp
)))
873 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
875 strlcpy(temp
, "localhost", sizeof(temp
));
878 cupsdSetString(&ServerName
, temp
);
881 ServerAlias
= cupsArrayNew(NULL
, NULL
);
883 cupsdAddAlias(ServerAlias
, temp
);
884 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
886 if (HostNameLookups
|| RemotePort
)
888 struct hostent
*host
; /* Host entry to get FQDN */
890 if ((host
= gethostbyname(temp
)) != NULL
)
892 if (_cups_strcasecmp(temp
, host
->h_name
))
894 cupsdSetString(&ServerName
, host
->h_name
);
895 cupsdAddAlias(ServerAlias
, host
->h_name
);
896 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
902 for (i
= 0; host
->h_aliases
[i
]; i
++)
903 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
905 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
906 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
914 * Make sure we have the base hostname added as an alias, too!
917 if ((slash
= strchr(temp
, '.')) != NULL
)
920 cupsdAddAlias(ServerAlias
, temp
);
921 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
925 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
927 ServerNameIsIP
= !*slash
;
930 * Make sure ServerAdmin is initialized...
934 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
937 * Use the default system group if none was supplied in cupsd.conf...
940 if (NumSystemGroups
== 0)
942 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
945 * Find the group associated with GID 0...
952 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
954 cupsdSetString(&SystemGroups
[0], "unknown");
956 SystemGroupIDs
[0] = 0;
962 * Make sure ConfigFilePerm and LogFilePerm have sane values...
965 ConfigFilePerm
&= 0664;
969 * Open the system log for cupsd if necessary...
973 if (!strcmp(AccessLog
, "syslog") ||
974 !strcmp(ErrorLog
, "syslog") ||
975 !strcmp(PageLog
, "syslog"))
976 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
977 #endif /* HAVE_VSYSLOG */
980 * Make sure each of the log files exists and gets rotated as necessary...
983 if (strcmp(AccessLog
, "syslog"))
984 cupsdCheckLogFile(&AccessFile
, AccessLog
);
986 if (strcmp(ErrorLog
, "syslog"))
987 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
989 if (strcmp(PageLog
, "syslog"))
990 cupsdCheckLogFile(&PageFile
, PageLog
);
993 * Log the configuration file that was used...
996 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
1000 * Validate the Group and SystemGroup settings - they cannot be the same,
1001 * otherwise the CGI programs will be able to authenticate as root without
1007 for (i
= 0; i
< NumSystemGroups
; i
++)
1008 if (Group
== SystemGroupIDs
[i
])
1011 if (i
< NumSystemGroups
)
1014 * Log the error and reset the group to a safe value...
1017 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1018 "Group and SystemGroup cannot use the same groups.");
1019 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
1021 group
= getgrnam("nobody");
1025 Group
= group
->gr_gid
;
1029 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
1030 * complement number...)
1039 * Check that we have at least one listen/port line; if not, report this
1040 * as an error and exit!
1043 if (cupsArrayCount(Listeners
) == 0)
1049 cupsdLogMessage(CUPSD_LOG_EMERG
,
1050 "No valid Listen or Port lines were found in the "
1051 "configuration file.");
1057 cupsdEndProcess(getpid(), 0);
1061 * Set the default locale using the language and charset...
1064 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1067 * Update all relative filenames to include the full path from ServerRoot...
1070 if (DocumentRoot
[0] != '/')
1071 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1073 if (RequestRoot
[0] != '/')
1074 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1076 if (ServerBin
[0] != '/')
1077 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1079 if (StateDir
[0] != '/')
1080 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1082 if (CacheDir
[0] != '/')
1083 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1086 if (ServerCertificate
[0] != '/')
1087 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
1089 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
1090 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
1092 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1095 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
1096 if (ServerKey
[0] != '/')
1097 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
1099 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
1100 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
1101 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1103 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
1104 #endif /* HAVE_SSL */
1107 * Make sure that directories and config files are owned and
1108 * writable by the user and group in the cupsd.conf file...
1111 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1113 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1115 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
1117 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1119 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1121 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1122 SystemGroupIDs
[0], 1, 1) < 0 ||
1123 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1125 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1127 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1129 cupsdCheckPermissions(ConfigurationFile
, NULL
, ConfigFilePerm
, RunUser
,
1131 cupsdCheckPermissions(CupsFilesFile
, NULL
, ConfigFilePerm
, RunUser
,
1133 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1135 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1137 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1138 Group
, 0, 0) < 0) &&
1139 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1143 * Update TempDir to the default if it hasn't been set already...
1147 if (TempDir
&& !RunUser
&&
1148 (!strncmp(TempDir
, "/private/tmp", 12) || !strncmp(TempDir
, "/tmp", 4)))
1150 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot use %s for TempDir.", TempDir
);
1151 cupsdClearString(&TempDir
);
1153 #endif /* __APPLE__ */
1158 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1159 strncmp(tmpdir
, "/private/tmp", 12) && strncmp(tmpdir
, "/tmp", 4))
1161 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1162 #endif /* __APPLE__ */
1165 * TMPDIR is defined, see if it is OK for us to use...
1168 if (stat(tmpdir
, &tmpinfo
))
1169 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1170 tmpdir
, strerror(errno
));
1171 else if (!S_ISDIR(tmpinfo
.st_mode
))
1172 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1174 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1175 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1176 !(tmpinfo
.st_mode
& S_IWOTH
))
1177 cupsdLogMessage(CUPSD_LOG_ERROR
,
1178 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1180 cupsdSetString(&TempDir
, tmpdir
);
1186 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1188 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1192 * Make sure the temporary directory has the right permissions...
1195 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1199 * Update ownership and permissions if the CUPS temp directory
1200 * is under the spool directory or does not exist...
1203 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1204 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1209 * Update environment variables...
1215 * Update default paper size setting as needed...
1218 if (!DefaultPaperSize
)
1220 #ifdef HAVE_LIBPAPER
1221 char *paper_result
; /* Paper size name from libpaper */
1223 if ((paper_result
= systempapername()) != NULL
)
1224 cupsdSetString(&DefaultPaperSize
, paper_result
);
1226 #endif /* HAVE_LIBPAPER */
1227 if (!DefaultLanguage
||
1228 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1229 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1230 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1231 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1232 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1233 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1234 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1237 * These are the only locales that will default to "letter" size...
1240 cupsdSetString(&DefaultPaperSize
, "Letter");
1243 cupsdSetString(&DefaultPaperSize
, "A4");
1247 * Update classification setting as needed...
1250 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1251 cupsdClearString(&Classification
);
1254 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1257 * Check the MaxClients setting, and then allocate memory for it...
1260 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1263 cupsdLogMessage(CUPSD_LOG_INFO
,
1264 "MaxClients limited to 1/3 (%d) of the file descriptor "
1266 MaxFDs
/ 3, MaxFDs
);
1268 MaxClients
= MaxFDs
/ 3;
1271 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1275 * Check the MaxActiveJobs setting; limit to 1/3 the available
1276 * file descriptors, since we need a pipe for each job...
1279 if (MaxActiveJobs
> (MaxFDs
/ 3))
1280 MaxActiveJobs
= MaxFDs
/ 3;
1283 * Update the MaxClientsPerHost value, as needed...
1286 if (MaxClientsPerHost
<= 0)
1287 MaxClientsPerHost
= MaxClients
;
1289 if (MaxClientsPerHost
> MaxClients
)
1290 MaxClientsPerHost
= MaxClients
;
1292 cupsdLogMessage(CUPSD_LOG_INFO
,
1293 "Allowing up to %d client connections per host.",
1297 * Update the default policy, as needed...
1301 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1303 DefaultPolicyPtr
= NULL
;
1305 if (!DefaultPolicyPtr
)
1307 cupsd_location_t
*po
; /* New policy operation */
1311 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1314 cupsdSetString(&DefaultPolicy
, "default");
1316 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1317 cupsdLogMessage(CUPSD_LOG_INFO
,
1318 "Using policy \"default\" as the default.");
1321 cupsdLogMessage(CUPSD_LOG_INFO
,
1322 "Creating CUPS default administrative policy:");
1324 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1326 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1328 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1329 cupsdAddString(&(p
->job_access
), "@OWNER");
1330 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1332 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1333 cupsdAddString(&(p
->job_attrs
), "job-name");
1334 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1335 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1337 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1338 cupsdAddString(&(p
->sub_access
), "@OWNER");
1339 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1341 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1342 cupsdAddString(&(p
->job_attrs
), "notify-events");
1343 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1344 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1345 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1346 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1348 cupsdLogMessage(CUPSD_LOG_INFO
,
1349 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1350 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1352 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1353 po
->order_type
= CUPSD_AUTH_ALLOW
;
1355 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1356 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1357 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1359 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1361 cupsdLogMessage(CUPSD_LOG_INFO
,
1362 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1363 "Release-Job Restart-Job Purge-Jobs "
1364 "Set-Job-Attributes Create-Job-Subscription "
1365 "Renew-Subscription Cancel-Subscription "
1366 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1367 "Suspend-Current-Job Resume-Job "
1368 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1369 "CUPS-Authenticate-Job CUPS-Get-Document>");
1370 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1372 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1373 po
->order_type
= CUPSD_AUTH_ALLOW
;
1374 po
->level
= CUPSD_AUTH_USER
;
1376 cupsdAddName(po
, "@OWNER");
1377 cupsdAddName(po
, "@SYSTEM");
1378 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1380 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1381 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1382 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1383 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1384 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1385 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1386 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1387 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1388 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1389 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1390 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1391 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1392 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1393 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1394 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1395 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1396 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1397 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1398 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1399 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1401 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1403 cupsdLogMessage(CUPSD_LOG_INFO
,
1404 "<Limit Pause-Printer Resume-Printer "
1405 "Set-Printer-Attributes Enable-Printer "
1406 "Disable-Printer Pause-Printer-After-Current-Job "
1407 "Hold-New-Jobs Release-Held-New-Jobs "
1408 "Deactivate-Printer Activate-Printer Restart-Printer "
1409 "Shutdown-Printer Startup-Printer Promote-Job "
1410 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1411 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1412 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1413 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1414 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1416 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1417 po
->order_type
= CUPSD_AUTH_ALLOW
;
1418 po
->type
= CUPSD_AUTH_DEFAULT
;
1419 po
->level
= CUPSD_AUTH_USER
;
1421 cupsdAddName(po
, "@SYSTEM");
1422 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1424 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1425 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1426 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1427 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1428 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1429 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1430 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1431 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1432 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1433 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1434 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1435 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1436 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1437 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1438 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1439 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1440 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1441 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1442 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1443 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1444 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1445 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1447 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1449 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1450 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1452 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1453 po
->order_type
= CUPSD_AUTH_ALLOW
;
1455 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1456 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1460 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1461 cupsArrayCount(Policies
));
1462 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1464 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1465 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1466 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1469 * If we are doing a full reload or the server root has changed, flush
1470 * the jobs, printers, etc. and start from scratch...
1473 if (NeedReload
== RELOAD_ALL
||
1474 old_remote_port
!= RemotePort
||
1475 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1476 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1478 mime_type_t
*type
; /* Current type */
1479 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1480 /* MIME type name */
1483 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1486 * Free all memory...
1489 cupsdDeleteAllSubscriptions();
1491 cupsdDeleteAllPrinters();
1493 DefaultPrinter
= NULL
;
1495 if (MimeDatabase
!= NULL
)
1496 mimeDelete(MimeDatabase
);
1500 for (i
= 0; i
< NumMimeTypes
; i
++)
1501 _cupsStrFree(MimeTypes
[i
]);
1507 * Read the MIME type and conversion database...
1510 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1511 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1513 MimeDatabase
= mimeNew();
1514 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1516 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1517 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1518 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1519 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1523 cupsdLogMessage(CUPSD_LOG_EMERG
,
1524 "Unable to load MIME database from \"%s\" or \"%s\".",
1525 mimedir
, ServerRoot
);
1526 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1530 cupsdLogMessage(CUPSD_LOG_INFO
,
1531 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1532 "%d filters...", mimedir
, ServerRoot
,
1533 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1536 * Create a list of MIME types for the document-format-supported
1540 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1541 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1544 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1546 cupsdLogMessage(CUPSD_LOG_ERROR
,
1547 "Unable to allocate memory for %d MIME types.",
1553 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1555 i
++, type
= mimeNextType(MimeDatabase
))
1557 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1559 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1562 if (i
< NumMimeTypes
)
1563 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1566 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1568 mime_filter_t
*filter
; /* Current filter */
1571 for (type
= mimeFirstType(MimeDatabase
);
1573 type
= mimeNextType(MimeDatabase
))
1574 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1575 type
->super
, type
->type
);
1577 for (filter
= mimeFirstFilter(MimeDatabase
);
1579 filter
= mimeNextFilter(MimeDatabase
))
1580 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1581 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1582 filter
->src
->super
, filter
->src
->type
,
1583 filter
->dst
->super
, filter
->dst
->type
,
1584 filter
->cost
, filter
->filter
);
1591 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1592 cupsdLoadBanners(temp
);
1595 * Load printers and classes...
1598 cupsdLoadAllPrinters();
1599 cupsdLoadAllClasses();
1601 cupsdCreateCommonData();
1604 * Update the printcap file as needed...
1607 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1608 cupsdWritePrintcap();
1611 * Load queued jobs...
1617 * Load subscriptions...
1620 cupsdLoadAllSubscriptions();
1622 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1627 * Not a full reload, so recreate the common printer attributes...
1630 cupsdCreateCommonData();
1633 * Update all jobs as needed...
1639 * Update all printers as needed...
1642 cupsdUpdatePrinters();
1643 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1645 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1649 * Reset the reload state...
1652 NeedReload
= RELOAD_NONE
;
1654 cupsdClearString(&old_serverroot
);
1655 cupsdClearString(&old_requestroot
);
1662 * 'get_address()' - Get an address + port number from a line.
1665 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1666 get_address(const char *value
, /* I - Value string */
1667 int defport
) /* I - Default port */
1669 char buffer
[1024], /* Hostname + port number buffer */
1670 defpname
[255], /* Default port name */
1671 *hostname
, /* Hostname or IP */
1672 *portname
; /* Port number or name */
1673 http_addrlist_t
*addrlist
; /* Address list */
1677 * Check for an empty value...
1682 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1687 * Grab a hostname and port number; if there is no colon and the port name
1688 * is only digits, then we have a port number by itself...
1691 strlcpy(buffer
, value
, sizeof(buffer
));
1693 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1700 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1705 * Use the default port...
1708 sprintf(defpname
, "%d", defport
);
1709 portname
= defpname
;
1715 * The buffer contains just a port number...
1723 if (hostname
&& !strcmp(hostname
, "*"))
1727 * Now lookup the address using httpAddrGetList()...
1730 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1731 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1732 hostname
? hostname
: "(nil)");
1739 * 'get_addr_and_mask()' - Get an IP address and netmask.
1742 static int /* O - 1 on success, 0 on failure */
1743 get_addr_and_mask(const char *value
, /* I - String from config file */
1744 unsigned *ip
, /* O - Address value */
1745 unsigned *mask
) /* O - Mask value */
1747 int i
, j
, /* Looping vars */
1748 family
, /* Address family */
1749 ipcount
; /* Count of fields in address */
1750 unsigned ipval
; /* Value */
1751 const char *maskval
, /* Pointer to start of mask value */
1752 *ptr
, /* Pointer into value */
1757 * Get the address...
1760 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1761 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1763 if ((maskval
= strchr(value
, '/')) != NULL
)
1766 maskval
= value
+ strlen(value
);
1770 * Check for an IPv6 address...
1776 * Parse hexadecimal IPv6/IPv4 address...
1781 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1785 else if (!strncmp(ptr
, "::", 2))
1787 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1789 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1794 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1797 * Read IPv4 dotted quad...
1800 unsigned val
[4] = { 0, 0, 0, 0 };
1801 /* IPv4 address values */
1803 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1807 * Range check the IP numbers...
1810 for (i
= 0; i
< ipcount
; i
++)
1815 * Merge everything into a 32-bit IPv4 address in ip[3]...
1818 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1821 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1824 * If the leading words are all 0's then this is an IPv4 address...
1827 if (!val
[0] && !val
[1] && !val
[2])
1830 while (isdigit(*ptr
& 255) || *ptr
== '.')
1834 else if (isxdigit(*ptr
& 255))
1836 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1838 if (*ptr
== ':' && ptr
[1] != ':')
1847 ip
[i
/ 2] |= ipval
<< 16;
1858 if (*ptr
&& *ptr
!= '/')
1862 #endif /* AF_INET6 */
1865 * Parse dotted-decimal IPv4 address...
1868 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1872 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1875 * Range check the IP numbers...
1878 for (i
= 0; i
< ipcount
; i
++)
1883 * Merge everything into a 32-bit IPv4 address in ip[3]...
1886 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1889 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1895 * Get the netmask value(s)...
1898 memset(mask
, 0, sizeof(unsigned) * 4);
1900 if (strchr(maskval
, '.'))
1903 * Get dotted-decimal mask...
1906 if (family
!= AF_INET
)
1909 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1913 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1914 mask
[0] = mask
[1] = mask
[2] = 0;
1919 * Get address/bits format...
1925 if (family
== AF_INET6
)
1933 mask
[0] = 0xffffffff;
1935 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1938 mask
[1] = 0xffffffff;
1942 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1945 mask
[2] = 0xffffffff;
1949 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1952 mask
[3] = 0xffffffff;
1956 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1959 #endif /* AF_INET6 */
1964 mask
[0] = 0xffffffff;
1965 mask
[1] = 0xffffffff;
1966 mask
[2] = 0xffffffff;
1969 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1971 mask
[3] = 0xffffffff;
1976 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1977 "get_addr_and_mask(value=\"%s\", "
1978 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1979 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1983 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1986 if ((ip
[0] & ~mask
[0]) != 0 ||
1987 (ip
[1] & ~mask
[1]) != 0 ||
1988 (ip
[2] & ~mask
[2]) != 0 ||
1989 (ip
[3] & ~mask
[3]) != 0)
1997 * 'mime_error_cb()' - Log a MIME error.
2001 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
2002 const char *message
) /* I - Message */
2006 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
2011 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
2014 static int /* O - 1 on success, 0 on failure */
2015 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
2016 char *line
, /* I - Line from file */
2017 char *value
, /* I - Start of value data */
2018 int linenum
) /* I - Current line number */
2020 char *valptr
; /* Pointer into value */
2021 unsigned ip
[4], /* IP address components */
2022 mask
[4]; /* IP netmask components */
2025 if (!_cups_strcasecmp(line
, "Encryption"))
2028 * "Encryption xxx" - set required encryption level...
2031 if (!_cups_strcasecmp(value
, "never"))
2032 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
2033 else if (!_cups_strcasecmp(value
, "always"))
2035 cupsdLogMessage(CUPSD_LOG_ERROR
,
2036 "Encryption value \"%s\" on line %d is invalid in this "
2037 "context. Using \"required\" instead.", value
, linenum
);
2039 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2041 else if (!_cups_strcasecmp(value
, "required"))
2042 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2043 else if (!_cups_strcasecmp(value
, "ifrequested"))
2044 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2047 cupsdLogMessage(CUPSD_LOG_ERROR
,
2048 "Unknown Encryption value %s on line %d.", value
, linenum
);
2052 else if (!_cups_strcasecmp(line
, "Order"))
2055 * "Order Deny,Allow" or "Order Allow,Deny"...
2058 if (!_cups_strncasecmp(value
, "deny", 4))
2059 loc
->order_type
= CUPSD_AUTH_ALLOW
;
2060 else if (!_cups_strncasecmp(value
, "allow", 5))
2061 loc
->order_type
= CUPSD_AUTH_DENY
;
2064 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
2069 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2072 * Allow [From] host/ip...
2073 * Deny [From] host/ip...
2078 if (!_cups_strncasecmp(value
, "from", 4))
2081 * Strip leading "from"...
2086 while (_cups_isspace(*value
))
2094 * Find the end of the value...
2097 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2099 while (_cups_isspace(*valptr
))
2103 * Figure out what form the allow/deny address takes:
2114 * nnn.nnn.nnn.nnn/mm
2115 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2118 if (!_cups_strcasecmp(value
, "all"))
2124 if (!_cups_strcasecmp(line
, "Allow"))
2125 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2127 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2129 else if (!_cups_strcasecmp(value
, "none"))
2135 if (!_cups_strcasecmp(line
, "Allow"))
2136 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2138 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2141 else if (value
[0] == '*' || value
[0] == '.' ||
2142 (!isdigit(value
[0] & 255) && value
[0] != '['))
2144 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2145 #endif /* AF_INET6 */
2148 * Host or domain name...
2151 if (value
[0] == '*')
2154 if (!_cups_strcasecmp(line
, "Allow"))
2155 cupsdAddNameMask(&(loc
->allow
), value
);
2157 cupsdAddNameMask(&(loc
->deny
), value
);
2162 * One of many IP address forms...
2165 if (!get_addr_and_mask(value
, ip
, mask
))
2167 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2172 if (!_cups_strcasecmp(line
, "Allow"))
2173 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2175 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2179 * Advance to next value...
2185 else if (!_cups_strcasecmp(line
, "AuthType"))
2188 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2191 if (!_cups_strcasecmp(value
, "none"))
2193 loc
->type
= CUPSD_AUTH_NONE
;
2194 loc
->level
= CUPSD_AUTH_ANON
;
2196 else if (!_cups_strcasecmp(value
, "basic"))
2198 loc
->type
= CUPSD_AUTH_BASIC
;
2200 if (loc
->level
== CUPSD_AUTH_ANON
)
2201 loc
->level
= CUPSD_AUTH_USER
;
2203 else if (!_cups_strcasecmp(value
, "digest"))
2205 loc
->type
= CUPSD_AUTH_DIGEST
;
2207 if (loc
->level
== CUPSD_AUTH_ANON
)
2208 loc
->level
= CUPSD_AUTH_USER
;
2210 else if (!_cups_strcasecmp(value
, "basicdigest"))
2212 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
2214 if (loc
->level
== CUPSD_AUTH_ANON
)
2215 loc
->level
= CUPSD_AUTH_USER
;
2217 else if (!_cups_strcasecmp(value
, "default"))
2219 loc
->type
= CUPSD_AUTH_DEFAULT
;
2221 if (loc
->level
== CUPSD_AUTH_ANON
)
2222 loc
->level
= CUPSD_AUTH_USER
;
2225 else if (!_cups_strcasecmp(value
, "negotiate"))
2227 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2229 if (loc
->level
== CUPSD_AUTH_ANON
)
2230 loc
->level
= CUPSD_AUTH_USER
;
2232 #endif /* HAVE_GSSAPI */
2235 cupsdLogMessage(CUPSD_LOG_WARN
,
2236 "Unknown authorization type %s on line %d.",
2241 else if (!_cups_strcasecmp(line
, "AuthClass"))
2244 * AuthClass anonymous, user, system, group
2247 if (!_cups_strcasecmp(value
, "anonymous"))
2249 loc
->type
= CUPSD_AUTH_NONE
;
2250 loc
->level
= CUPSD_AUTH_ANON
;
2252 cupsdLogMessage(CUPSD_LOG_WARN
,
2253 "\"AuthClass %s\" is deprecated; consider removing "
2257 else if (!_cups_strcasecmp(value
, "user"))
2259 loc
->level
= CUPSD_AUTH_USER
;
2261 cupsdLogMessage(CUPSD_LOG_WARN
,
2262 "\"AuthClass %s\" is deprecated; consider using "
2263 "\"Require valid-user\" on line %d.",
2266 else if (!_cups_strcasecmp(value
, "group"))
2268 loc
->level
= CUPSD_AUTH_GROUP
;
2270 cupsdLogMessage(CUPSD_LOG_WARN
,
2271 "\"AuthClass %s\" is deprecated; consider using "
2272 "\"Require user @groupname\" on line %d.",
2275 else if (!_cups_strcasecmp(value
, "system"))
2277 loc
->level
= CUPSD_AUTH_GROUP
;
2279 cupsdAddName(loc
, "@SYSTEM");
2281 cupsdLogMessage(CUPSD_LOG_WARN
,
2282 "\"AuthClass %s\" is deprecated; consider using "
2283 "\"Require user @SYSTEM\" on line %d.",
2288 cupsdLogMessage(CUPSD_LOG_WARN
,
2289 "Unknown authorization class %s on line %d.",
2294 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2296 cupsdAddName(loc
, value
);
2298 cupsdLogMessage(CUPSD_LOG_WARN
,
2299 "\"AuthGroupName %s\" directive is deprecated; consider "
2300 "using \"Require user @%s\" on line %d.",
2301 value
, value
, linenum
);
2303 else if (!_cups_strcasecmp(line
, "Require"))
2306 * Apache synonym for AuthClass and AuthGroupName...
2310 * Require valid-user
2311 * Require group names
2312 * Require user names
2315 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2320 if (!_cups_strcasecmp(value
, "valid-user") ||
2321 !_cups_strcasecmp(value
, "user"))
2322 loc
->level
= CUPSD_AUTH_USER
;
2323 else if (!_cups_strcasecmp(value
, "group"))
2324 loc
->level
= CUPSD_AUTH_GROUP
;
2327 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2333 * Get the list of names from the line...
2336 for (value
= valptr
; *value
;)
2338 while (_cups_isspace(*value
))
2341 #ifdef HAVE_AUTHORIZATION_H
2342 if (!strncmp(value
, "@AUTHKEY(", 9))
2345 * Grab "@AUTHKEY(name)" value...
2348 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2354 #endif /* HAVE_AUTHORIZATION_H */
2355 if (*value
== '\"' || *value
== '\'')
2358 * Grab quoted name...
2361 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2368 * Grab literal name.
2371 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2377 cupsdAddName(loc
, value
);
2379 for (value
= valptr
; _cups_isspace(*value
); value
++);
2382 else if (!_cups_strcasecmp(line
, "Satisfy"))
2384 if (!_cups_strcasecmp(value
, "all"))
2385 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2386 else if (!_cups_strcasecmp(value
, "any"))
2387 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2390 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2403 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2406 static int /* O - FatalErrors bits */
2407 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2409 int fatal
; /* FatalErrors bits */
2410 char value
[1024], /* Value string */
2411 *valstart
, /* Pointer into value */
2412 *valend
; /* End of value */
2416 * Empty FatalErrors line yields NULL pointer...
2420 return (CUPSD_FATAL_NONE
);
2423 * Loop through the value string,...
2426 strlcpy(value
, s
, sizeof(value
));
2428 fatal
= CUPSD_FATAL_NONE
;
2430 for (valstart
= value
; *valstart
;)
2433 * Get the current space/comma-delimited kind name...
2436 for (valend
= valstart
; *valend
; valend
++)
2437 if (_cups_isspace(*valend
) || *valend
== ',')
2444 * Add the error to the bitmask...
2447 if (!_cups_strcasecmp(valstart
, "all"))
2448 fatal
= CUPSD_FATAL_ALL
;
2449 else if (!_cups_strcasecmp(valstart
, "browse"))
2450 fatal
|= CUPSD_FATAL_BROWSE
;
2451 else if (!_cups_strcasecmp(valstart
, "-browse"))
2452 fatal
&= ~CUPSD_FATAL_BROWSE
;
2453 else if (!_cups_strcasecmp(valstart
, "config"))
2454 fatal
|= CUPSD_FATAL_CONFIG
;
2455 else if (!_cups_strcasecmp(valstart
, "-config"))
2456 fatal
&= ~CUPSD_FATAL_CONFIG
;
2457 else if (!_cups_strcasecmp(valstart
, "listen"))
2458 fatal
|= CUPSD_FATAL_LISTEN
;
2459 else if (!_cups_strcasecmp(valstart
, "-listen"))
2460 fatal
&= ~CUPSD_FATAL_LISTEN
;
2461 else if (!_cups_strcasecmp(valstart
, "log"))
2462 fatal
|= CUPSD_FATAL_LOG
;
2463 else if (!_cups_strcasecmp(valstart
, "-log"))
2464 fatal
&= ~CUPSD_FATAL_LOG
;
2465 else if (!_cups_strcasecmp(valstart
, "permissions"))
2466 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2467 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2468 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2469 else if (_cups_strcasecmp(valstart
, "none"))
2470 cupsdLogMessage(CUPSD_LOG_ERROR
,
2471 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2473 for (valstart
= valend
; *valstart
; valstart
++)
2474 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2483 * 'parse_groups()' - Parse system group names in a string.
2486 static int /* O - 1 on success, 0 on failure */
2487 parse_groups(const char *s
) /* I - Space-delimited groups */
2489 int status
; /* Return status */
2490 char value
[1024], /* Value string */
2491 *valstart
, /* Pointer into value */
2492 *valend
, /* End of value */
2493 quote
; /* Quote character */
2494 struct group
*group
; /* Group */
2498 * Make a copy of the string and parse out the groups...
2501 strlcpy(value
, s
, sizeof(value
));
2506 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2508 if (*valstart
== '\'' || *valstart
== '\"')
2511 * Scan quoted name...
2514 quote
= *valstart
++;
2516 for (valend
= valstart
; *valend
; valend
++)
2517 if (*valend
== quote
)
2523 * Scan space or comma-delimited name...
2526 for (valend
= valstart
; *valend
; valend
++)
2527 if (_cups_isspace(*valend
) || *valend
== ',')
2534 group
= getgrnam(valstart
);
2537 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2538 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2549 while (*valstart
== ',' || _cups_isspace(*valstart
))
2558 * 'parse_protocols()' - Parse browse protocols in a string.
2561 static int /* O - Browse protocol bits */
2562 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2564 int protocols
; /* Browse protocol bits */
2565 char value
[1024], /* Value string */
2566 *valstart
, /* Pointer into value */
2567 *valend
; /* End of value */
2571 * Empty protocol line yields NULL pointer...
2578 * Loop through the value string,...
2581 strlcpy(value
, s
, sizeof(value
));
2585 for (valstart
= value
; *valstart
;)
2588 * Get the current space/comma-delimited protocol name...
2591 for (valend
= valstart
; *valend
; valend
++)
2592 if (_cups_isspace(*valend
) || *valend
== ',')
2599 * Add the protocol to the bitmask...
2602 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2603 !_cups_strcasecmp(valstart
, "dns-sd") ||
2604 !_cups_strcasecmp(valstart
, "bonjour"))
2605 protocols
|= BROWSE_DNSSD
;
2606 else if (!_cups_strcasecmp(valstart
, "all"))
2607 protocols
|= BROWSE_ALL
;
2608 else if (_cups_strcasecmp(valstart
, "none"))
2609 cupsdLogMessage(CUPSD_LOG_ERROR
,
2610 "Unknown browse protocol \"%s\" ignored.", valstart
);
2612 for (valstart
= valend
; *valstart
; valstart
++)
2613 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2622 * 'parse_variable()' - Parse a variable line.
2625 static int /* O - 1 on success, 0 on failure */
2627 const char *filename
, /* I - Name of configuration file */
2628 int linenum
, /* I - Line in configuration file */
2629 const char *line
, /* I - Line from configuration file */
2630 const char *value
, /* I - Value from configuration file */
2631 size_t num_vars
, /* I - Number of variables */
2632 const cupsd_var_t
*vars
) /* I - Variables */
2634 size_t i
; /* Looping var */
2635 const cupsd_var_t
*var
; /* Variables */
2636 char temp
[1024]; /* Temporary string */
2639 for (i
= num_vars
, var
= vars
; i
> 0; i
--, var
++)
2640 if (!_cups_strcasecmp(line
, var
->name
))
2646 * Unknown directive! Output an error message and continue...
2650 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d of %s.",
2651 line
, linenum
, filename
);
2653 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d of %s.",
2654 line
, linenum
, filename
);
2661 case CUPSD_VARTYPE_INTEGER
:
2664 cupsdLogMessage(CUPSD_LOG_ERROR
,
2665 "Missing integer value for %s on line %d of %s.",
2666 line
, linenum
, filename
);
2669 else if (!isdigit(*value
& 255))
2671 cupsdLogMessage(CUPSD_LOG_ERROR
,
2672 "Bad integer value for %s on line %d of %s.",
2673 line
, linenum
, filename
);
2679 char *units
; /* Units */
2681 n
= strtol(value
, &units
, 0);
2683 if (units
&& *units
)
2685 if (tolower(units
[0] & 255) == 'g')
2686 n
*= 1024 * 1024 * 1024;
2687 else if (tolower(units
[0] & 255) == 'm')
2689 else if (tolower(units
[0] & 255) == 'k')
2691 else if (tolower(units
[0] & 255) == 't')
2695 cupsdLogMessage(CUPSD_LOG_ERROR
,
2696 "Unknown integer value for %s on line %d of %s.",
2697 line
, linenum
, filename
);
2704 cupsdLogMessage(CUPSD_LOG_ERROR
,
2705 "Bad negative integer value for %s on line %d of "
2706 "%s.", line
, linenum
, filename
);
2711 *((int *)var
->ptr
) = n
;
2716 case CUPSD_VARTYPE_TIME
:
2719 cupsdLogMessage(CUPSD_LOG_ERROR
,
2720 "Missing time interval value for %s on line %d of "
2721 "%s.", line
, linenum
, filename
);
2724 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
2725 (!_cups_strcasecmp(value
, "true") ||
2726 !_cups_strcasecmp(value
, "on") ||
2727 !_cups_strcasecmp(value
, "enabled") ||
2728 !_cups_strcasecmp(value
, "yes")))
2730 *((int *)var
->ptr
) = INT_MAX
;
2732 else if (!_cups_strcasecmp(value
, "false") ||
2733 !_cups_strcasecmp(value
, "off") ||
2734 !_cups_strcasecmp(value
, "disabled") ||
2735 !_cups_strcasecmp(value
, "no"))
2737 *((int *)var
->ptr
) = 0;
2739 else if (!isdigit(*value
& 255))
2741 cupsdLogMessage(CUPSD_LOG_ERROR
,
2742 "Unknown time interval value for %s on line %d of "
2743 "%s.", line
, linenum
, filename
);
2748 double n
; /* Number */
2749 char *units
; /* Units */
2751 n
= strtod(value
, &units
);
2753 if (units
&& *units
)
2755 if (tolower(units
[0] & 255) == 'w')
2756 n
*= 7 * 24 * 60 * 60;
2757 else if (tolower(units
[0] & 255) == 'd')
2759 else if (tolower(units
[0] & 255) == 'h')
2761 else if (tolower(units
[0] & 255) == 'm')
2765 cupsdLogMessage(CUPSD_LOG_ERROR
,
2766 "Unknown time interval value for %s on line "
2767 "%d of %s.", line
, linenum
, filename
);
2772 if (n
< 0.0 || n
> INT_MAX
)
2774 cupsdLogMessage(CUPSD_LOG_ERROR
,
2775 "Bad time value for %s on line %d of %s.",
2776 line
, linenum
, filename
);
2781 *((int *)var
->ptr
) = (int)n
;
2786 case CUPSD_VARTYPE_BOOLEAN
:
2789 cupsdLogMessage(CUPSD_LOG_ERROR
,
2790 "Missing boolean value for %s on line %d of %s.",
2791 line
, linenum
, filename
);
2794 else if (!_cups_strcasecmp(value
, "true") ||
2795 !_cups_strcasecmp(value
, "on") ||
2796 !_cups_strcasecmp(value
, "enabled") ||
2797 !_cups_strcasecmp(value
, "yes") ||
2800 *((int *)var
->ptr
) = TRUE
;
2802 else if (!_cups_strcasecmp(value
, "false") ||
2803 !_cups_strcasecmp(value
, "off") ||
2804 !_cups_strcasecmp(value
, "disabled") ||
2805 !_cups_strcasecmp(value
, "no") ||
2806 !_cups_strcasecmp(value
, "0"))
2808 *((int *)var
->ptr
) = FALSE
;
2812 cupsdLogMessage(CUPSD_LOG_ERROR
,
2813 "Unknown boolean value %s on line %d of %s.",
2814 value
, linenum
, filename
);
2819 case CUPSD_VARTYPE_PATHNAME
:
2822 cupsdLogMessage(CUPSD_LOG_ERROR
,
2823 "Missing pathname value for %s on line %d of %s.",
2824 line
, linenum
, filename
);
2828 if (value
[0] == '/')
2829 strlcpy(temp
, value
, sizeof(temp
));
2831 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
2833 if (access(temp
, 0))
2835 cupsdLogMessage(CUPSD_LOG_ERROR
,
2836 "File or directory for \"%s %s\" on line %d of %s "
2837 "does not exist.", line
, value
, linenum
, filename
);
2841 cupsdSetString((char **)var
->ptr
, temp
);
2844 case CUPSD_VARTYPE_STRING
:
2845 cupsdSetString((char **)var
->ptr
, value
);
2854 * 'read_cupsd_conf()' - Read the cupsd.conf configuration file.
2857 static int /* O - 1 on success, 0 on failure */
2858 read_cupsd_conf(cups_file_t
*fp
) /* I - File to read from */
2860 int linenum
; /* Current line number */
2861 char line
[HTTP_MAX_BUFFER
],
2862 /* Line from file */
2863 temp
[HTTP_MAX_BUFFER
],
2864 /* Temporary buffer for value */
2865 *value
, /* Pointer to value */
2866 *valueptr
; /* Pointer into value */
2867 int valuelen
; /* Length of value */
2868 http_addrlist_t
*addrlist
, /* Address list */
2869 *addr
; /* Current address */
2870 cups_file_t
*incfile
; /* Include file */
2871 char incname
[1024]; /* Include filename */
2875 * Loop through each line in the file...
2880 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2883 * Decode the directive...
2886 if (!_cups_strcasecmp(line
, "Include") && value
)
2892 if (value
[0] == '/')
2893 strlcpy(incname
, value
, sizeof(incname
));
2895 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2897 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2898 cupsdLogMessage(CUPSD_LOG_ERROR
,
2899 "Unable to include config file \"%s\" - %s",
2900 incname
, strerror(errno
));
2903 read_cupsd_conf(incfile
);
2904 cupsFileClose(incfile
);
2907 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2913 linenum
= read_location(fp
, value
, linenum
);
2917 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2923 linenum
= read_policy(fp
, value
, linenum
);
2927 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2929 JobRetryInterval
= atoi(value
);
2930 cupsdLogMessage(CUPSD_LOG_WARN
,
2931 "FaxRetryInterval is deprecated; use "
2932 "JobRetryInterval on line %d.", linenum
);
2934 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2936 JobRetryLimit
= atoi(value
);
2937 cupsdLogMessage(CUPSD_LOG_WARN
,
2938 "FaxRetryLimit is deprecated; use "
2939 "JobRetryLimit on line %d.", linenum
);
2941 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
2943 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
2944 #endif /* HAVE_SSL */
2948 * Add listening address(es) to the list...
2951 cupsd_listener_t
*lis
; /* New listeners array */
2955 * Get the address list...
2958 addrlist
= get_address(value
, IPP_PORT
);
2962 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2968 * Add each address...
2971 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2974 * See if this address is already present...
2977 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2979 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2980 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2981 httpAddrPort(&(addr
->addr
)) == httpAddrPort(&(lis
->address
)))
2986 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2987 cupsdLogMessage(CUPSD_LOG_WARN
,
2988 "Duplicate listen address \"%s\" ignored.", temp
);
2993 * Allocate another listener...
2997 Listeners
= cupsArrayNew(NULL
, NULL
);
3001 cupsdLogMessage(CUPSD_LOG_ERROR
,
3002 "Unable to allocate %s at line %d - %s.",
3003 line
, linenum
, strerror(errno
));
3007 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
3009 cupsdLogMessage(CUPSD_LOG_ERROR
,
3010 "Unable to allocate %s at line %d - %s.",
3011 line
, linenum
, strerror(errno
));
3015 cupsArrayAdd(Listeners
, lis
);
3018 * Copy the current address and log it...
3021 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
3025 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
3026 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
3027 #endif /* HAVE_SSL */
3029 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3032 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
3033 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
3035 #endif /* AF_LOCAL */
3036 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
3037 httpAddrPort(&(lis
->address
)),
3038 httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
3040 if (!httpAddrLocalhost(&(lis
->address
)))
3041 RemotePort
= httpAddrPort(&(lis
->address
));
3048 httpAddrFreeList(addrlist
);
3050 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
3051 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
3054 * "BrowseProtocols name [... name]"
3055 * "BrowseLocalProtocols name [... name]"
3058 int protocols
= parse_protocols(value
);
3062 cupsdLogMessage(CUPSD_LOG_ERROR
,
3063 "Unknown browse protocol \"%s\" on line %d.",
3068 BrowseLocalProtocols
= protocols
;
3070 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
3073 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3076 if (!_cups_strcasecmp(value
, "none"))
3077 default_auth_type
= CUPSD_AUTH_NONE
;
3078 else if (!_cups_strcasecmp(value
, "basic"))
3079 default_auth_type
= CUPSD_AUTH_BASIC
;
3080 else if (!_cups_strcasecmp(value
, "digest"))
3081 default_auth_type
= CUPSD_AUTH_DIGEST
;
3082 else if (!_cups_strcasecmp(value
, "basicdigest"))
3083 default_auth_type
= CUPSD_AUTH_BASICDIGEST
;
3085 else if (!_cups_strcasecmp(value
, "negotiate"))
3086 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
3087 #endif /* HAVE_GSSAPI */
3088 else if (!_cups_strcasecmp(value
, "auto"))
3089 default_auth_type
= CUPSD_AUTH_AUTO
;
3092 cupsdLogMessage(CUPSD_LOG_WARN
,
3093 "Unknown default authorization type %s on line %d.",
3095 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3100 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
3103 * DefaultEncryption {Never,IfRequested,Required}
3106 if (!value
|| !_cups_strcasecmp(value
, "never"))
3107 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3108 else if (!_cups_strcasecmp(value
, "required"))
3109 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3110 else if (!_cups_strcasecmp(value
, "ifrequested"))
3111 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3114 cupsdLogMessage(CUPSD_LOG_WARN
,
3115 "Unknown default encryption %s on line %d.",
3117 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3121 #endif /* HAVE_SSL */
3122 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
3125 * Do hostname lookups?
3128 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
3129 !_cups_strcasecmp(value
, "false"))
3130 HostNameLookups
= 0;
3131 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
3132 !_cups_strcasecmp(value
, "true"))
3133 HostNameLookups
= 1;
3134 else if (!_cups_strcasecmp(value
, "double"))
3135 HostNameLookups
= 2;
3137 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3140 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
3143 * Amount of logging to do to access log...
3146 if (!_cups_strcasecmp(value
, "all"))
3147 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3148 else if (!_cups_strcasecmp(value
, "actions"))
3149 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3150 else if (!_cups_strcasecmp(value
, "config"))
3151 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3153 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3156 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
3159 * Amount of logging to do to error log...
3162 if (!_cups_strcasecmp(value
, "debug2"))
3163 LogLevel
= CUPSD_LOG_DEBUG2
;
3164 else if (!_cups_strcasecmp(value
, "debug"))
3165 LogLevel
= CUPSD_LOG_DEBUG
;
3166 else if (!_cups_strcasecmp(value
, "info"))
3167 LogLevel
= CUPSD_LOG_INFO
;
3168 else if (!_cups_strcasecmp(value
, "notice"))
3169 LogLevel
= CUPSD_LOG_NOTICE
;
3170 else if (!_cups_strcasecmp(value
, "warn"))
3171 LogLevel
= CUPSD_LOG_WARN
;
3172 else if (!_cups_strcasecmp(value
, "error"))
3173 LogLevel
= CUPSD_LOG_ERROR
;
3174 else if (!_cups_strcasecmp(value
, "crit"))
3175 LogLevel
= CUPSD_LOG_CRIT
;
3176 else if (!_cups_strcasecmp(value
, "alert"))
3177 LogLevel
= CUPSD_LOG_ALERT
;
3178 else if (!_cups_strcasecmp(value
, "emerg"))
3179 LogLevel
= CUPSD_LOG_EMERG
;
3180 else if (!_cups_strcasecmp(value
, "none"))
3181 LogLevel
= CUPSD_LOG_NONE
;
3183 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3186 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
3189 * Amount of logging to do to error log...
3192 if (!_cups_strcasecmp(value
, "standard"))
3193 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3194 else if (!_cups_strcasecmp(value
, "usecs"))
3195 LogTimeFormat
= CUPSD_TIME_USECS
;
3197 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3200 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
3203 * Set the string used for the Server header...
3206 struct utsname plat
; /* Platform info */
3211 if (!_cups_strcasecmp(value
, "ProductOnly"))
3212 cupsdSetString(&ServerHeader
, "CUPS IPP");
3213 else if (!_cups_strcasecmp(value
, "Major"))
3214 cupsdSetStringf(&ServerHeader
, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR
);
3215 else if (!_cups_strcasecmp(value
, "Minor"))
3216 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
3217 CUPS_VERSION_MINOR
);
3218 else if (!_cups_strcasecmp(value
, "Minimal"))
3219 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
" IPP/2.1");
3220 else if (!_cups_strcasecmp(value
, "OS"))
3221 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s) IPP/2.1",
3222 plat
.sysname
, plat
.release
);
3223 else if (!_cups_strcasecmp(value
, "Full"))
3224 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s; %s) IPP/2.1",
3225 plat
.sysname
, plat
.release
, plat
.machine
);
3226 else if (!_cups_strcasecmp(value
, "None"))
3227 cupsdClearString(&ServerHeader
);
3229 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3232 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3235 * PassEnv variable [... variable]
3240 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3241 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3244 if (value
[valuelen
])
3246 value
[valuelen
] = '\0';
3250 cupsdSetEnv(value
, NULL
);
3252 for (value
+= valuelen
; *value
; value
++)
3253 if (!_cups_isspace(*value
) || *value
!= ',')
3257 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3260 * ServerAlias name [... name]
3264 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3268 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3269 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3272 if (value
[valuelen
])
3274 value
[valuelen
] = '\0';
3278 cupsdAddAlias(ServerAlias
, value
);
3280 for (value
+= valuelen
; *value
; value
++)
3281 if (!_cups_isspace(*value
) || *value
!= ',')
3285 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3288 * SetEnv variable value
3291 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3299 while (isspace(*valueptr
& 255))
3302 cupsdSetEnv(value
, valueptr
);
3305 cupsdLogMessage(CUPSD_LOG_ERROR
,
3306 "Missing value for SetEnv directive on line %d.",
3310 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3313 * SSLOptions options
3316 if (!value
|| !_cups_strcasecmp(value
, "none"))
3317 SSLOptions
= CUPSD_SSL_NONE
;
3318 else if (!_cups_strcasecmp(value
, "noemptyfragments"))
3319 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3321 cupsdLogMessage(CUPSD_LOG_ERROR
,
3322 "Unknown value \"%s\" for SSLOptions directive on "
3323 "line %d.", value
, linenum
);
3325 #endif /* HAVE_SSL */
3326 else if (!_cups_strcasecmp(line
, "AccessLog") ||
3327 !_cups_strcasecmp(line
, "CacheDir") ||
3328 !_cups_strcasecmp(line
, "ConfigFilePerm") ||
3329 !_cups_strcasecmp(line
, "DataDir") ||
3330 !_cups_strcasecmp(line
, "DocumentRoot") ||
3331 !_cups_strcasecmp(line
, "ErrorLog") ||
3332 !_cups_strcasecmp(line
, "FatalErrors") ||
3333 !_cups_strcasecmp(line
, "FileDevice") ||
3334 !_cups_strcasecmp(line
, "FontPath") ||
3335 !_cups_strcasecmp(line
, "Group") ||
3336 !_cups_strcasecmp(line
, "LogFilePerm") ||
3337 !_cups_strcasecmp(line
, "LPDConfigFile") ||
3338 !_cups_strcasecmp(line
, "PageLog") ||
3339 !_cups_strcasecmp(line
, "Printcap") ||
3340 !_cups_strcasecmp(line
, "PrintcapFormat") ||
3341 !_cups_strcasecmp(line
, "RemoteRoot") ||
3342 !_cups_strcasecmp(line
, "RequestRoot") ||
3343 !_cups_strcasecmp(line
, "ServerBin") ||
3344 !_cups_strcasecmp(line
, "ServerCertificate") ||
3345 !_cups_strcasecmp(line
, "ServerKey") ||
3346 !_cups_strcasecmp(line
, "ServerRoot") ||
3347 !_cups_strcasecmp(line
, "SMBConfigFile") ||
3348 !_cups_strcasecmp(line
, "StateDir") ||
3349 !_cups_strcasecmp(line
, "SystemGroup") ||
3350 !_cups_strcasecmp(line
, "SystemGroupAuthKey") ||
3351 !_cups_strcasecmp(line
, "TempDir") ||
3352 !_cups_strcasecmp(line
, "User"))
3354 cupsdLogMessage(CUPSD_LOG_INFO
,
3355 "Please move \"%s%s%s\" on line %d of %s to the %s file; "
3356 "this will become an error in a future release.",
3357 line
, value
? " " : "", value
? value
: "", linenum
,
3358 ConfigurationFile
, CupsFilesFile
);
3361 parse_variable(ConfigurationFile
, linenum
, line
, value
,
3362 sizeof(cupsd_vars
) / sizeof(cupsd_vars
[0]), cupsd_vars
);
3370 * 'read_cups_files_conf()' - Read the cups-files.conf configuration file.
3373 static int /* O - 1 on success, 0 on failure */
3374 read_cups_files_conf(cups_file_t
*fp
) /* I - File to read from */
3376 int linenum
; /* Current line number */
3377 char line
[HTTP_MAX_BUFFER
], /* Line from file */
3378 *value
; /* Value from line */
3379 struct group
*group
; /* Group */
3383 * Loop through each line in the file...
3388 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3390 if (!_cups_strcasecmp(line
, "FatalErrors"))
3391 FatalErrors
= parse_fatal_errors(value
);
3392 else if (!_cups_strcasecmp(line
, "Group") && value
)
3395 * Group ID to run as...
3398 if (isdigit(value
[0]))
3399 Group
= atoi(value
);
3403 group
= getgrnam(value
);
3406 Group
= group
->gr_gid
;
3409 cupsdLogMessage(CUPSD_LOG_ERROR
,
3410 "Unknown Group \"%s\" on line %d of %s.", value
,
3411 linenum
, CupsFilesFile
);
3412 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3417 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
3420 * Format of printcap file?
3423 if (!_cups_strcasecmp(value
, "bsd"))
3424 PrintcapFormat
= PRINTCAP_BSD
;
3425 else if (!_cups_strcasecmp(value
, "plist"))
3426 PrintcapFormat
= PRINTCAP_PLIST
;
3427 else if (!_cups_strcasecmp(value
, "solaris"))
3428 PrintcapFormat
= PRINTCAP_SOLARIS
;
3431 cupsdLogMessage(CUPSD_LOG_ERROR
,
3432 "Unknown PrintcapFormat \"%s\" on line %d of %s.",
3433 value
, linenum
, CupsFilesFile
);
3434 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3438 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
3441 * SystemGroup (admin) group(s)...
3444 if (!parse_groups(value
))
3446 cupsdLogMessage(CUPSD_LOG_ERROR
,
3447 "Unknown SystemGroup \"%s\" on line %d of %s.", value
,
3448 linenum
, CupsFilesFile
);
3449 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3453 else if (!_cups_strcasecmp(line
, "User") && value
)
3456 * User ID to run as...
3459 if (isdigit(value
[0] & 255))
3461 int uid
= atoi(value
);
3465 cupsdLogMessage(CUPSD_LOG_ERROR
,
3466 "Will not use User 0 as specified on line %d of %s "
3467 "for security reasons. You must use a non-"
3468 "privileged account instead.",
3469 linenum
, CupsFilesFile
);
3470 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3478 struct passwd
*p
; /* Password information */
3481 p
= getpwnam(value
);
3487 cupsdLogMessage(CUPSD_LOG_ERROR
,
3488 "Will not use User %s (UID=0) as specified on line "
3489 "%d of %s for security reasons. You must use a "
3490 "non-privileged account instead.",
3491 value
, linenum
, CupsFilesFile
);
3492 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3500 cupsdLogMessage(CUPSD_LOG_ERROR
,
3501 "Unknown User \"%s\" on line %d of %s.",
3502 value
, linenum
, CupsFilesFile
);
3503 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3508 else if (!parse_variable(CupsFilesFile
, linenum
, line
, value
,
3509 sizeof(cupsfiles_vars
) / sizeof(cupsfiles_vars
[0]),
3511 (FatalErrors
& CUPSD_FATAL_CONFIG
))
3520 * 'read_location()' - Read a <Location path> definition.
3523 static int /* O - New line number or 0 on error */
3524 read_location(cups_file_t
*fp
, /* I - Configuration file */
3525 char *location
, /* I - Location name/path */
3526 int linenum
) /* I - Current line number */
3528 cupsd_location_t
*loc
, /* New location */
3529 *parent
; /* Parent location */
3530 char line
[HTTP_MAX_BUFFER
],
3532 *value
, /* Value for directive */
3533 *valptr
; /* Pointer into value */
3536 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3537 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d.",
3539 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3543 cupsdAddLocation(parent
);
3545 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3550 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3553 * Decode the directive...
3556 if (!_cups_strcasecmp(line
, "</Location>"))
3558 else if (!_cups_strcasecmp(line
, "<Limit") ||
3559 !_cups_strcasecmp(line
, "<LimitExcept"))
3563 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3564 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3570 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3573 cupsdAddLocation(loc
);
3578 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3583 if (!strcmp(value
, "ALL"))
3584 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3585 else if (!strcmp(value
, "GET"))
3586 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3587 else if (!strcmp(value
, "HEAD"))
3588 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3589 else if (!strcmp(value
, "OPTIONS"))
3590 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3591 else if (!strcmp(value
, "POST"))
3592 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3593 else if (!strcmp(value
, "PUT"))
3594 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3595 else if (!strcmp(value
, "TRACE"))
3596 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3598 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d.",
3601 for (value
= valptr
; isspace(*value
& 255); value
++);
3604 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3605 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3607 parent
->limit
&= ~loc
->limit
;
3609 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3610 !_cups_strcasecmp(line
, "</LimitExcept>"))
3614 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3615 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3618 else if (!parse_aaa(loc
, line
, value
, linenum
))
3620 cupsdLogMessage(CUPSD_LOG_ERROR
,
3621 "Unknown Location directive %s on line %d.",
3623 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3628 cupsdLogMessage(CUPSD_LOG_ERROR
,
3629 "Unexpected end-of-file at line %d while reading location.",
3632 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3637 * 'read_policy()' - Read a <Policy name> definition.
3640 static int /* O - New line number or 0 on error */
3641 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3642 char *policy
, /* I - Location name/path */
3643 int linenum
) /* I - Current line number */
3645 int i
; /* Looping var */
3646 cupsd_policy_t
*pol
; /* Policy */
3647 cupsd_location_t
*op
; /* Policy operation */
3648 int num_ops
; /* Number of IPP operations */
3649 ipp_op_t ops
[100]; /* Operations */
3650 char line
[HTTP_MAX_BUFFER
],
3652 *value
, /* Value for directive */
3653 *valptr
; /* Pointer into value */
3657 * Create the policy...
3660 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3661 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d.",
3663 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3667 * Read from the file...
3673 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3676 * Decode the directive...
3679 if (!_cups_strcasecmp(line
, "</Policy>"))
3682 cupsdLogMessage(CUPSD_LOG_WARN
,
3683 "Missing </Limit> before </Policy> on line %d.",
3686 set_policy_defaults(pol
);
3690 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3694 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3695 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3702 * Scan for IPP operation names...
3709 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3714 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3716 if (!_cups_strcasecmp(value
, "All"))
3717 ops
[num_ops
] = IPP_ANY_OPERATION
;
3718 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3719 cupsdLogMessage(CUPSD_LOG_ERROR
,
3720 "Bad IPP operation name \"%s\" on line %d.",
3726 cupsdLogMessage(CUPSD_LOG_ERROR
,
3727 "Too many operations listed on line %d.",
3730 for (value
= valptr
; isspace(*value
& 255); value
++);
3734 * If none are specified, apply the policy to all operations...
3739 ops
[0] = IPP_ANY_OPERATION
;
3744 * Add a new policy for the first operation...
3747 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3749 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3752 * Finish the current operation limit...
3758 * Copy the policy to the other operations...
3761 for (i
= 1; i
< num_ops
; i
++)
3762 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3769 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3770 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3773 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3774 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3775 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3776 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3780 cupsdLogMessage(CUPSD_LOG_ERROR
,
3781 "%s directive must appear outside <Limit>...</Limit> "
3782 "on line %d.", line
, linenum
);
3783 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3789 * Pull out whitespace-delimited values...
3795 * Find the end of the current value...
3798 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3804 * Save it appropriately...
3807 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3810 * JobPrivateAccess {all|default|user/group list|@@ACL}
3813 if (!_cups_strcasecmp(value
, "default"))
3815 cupsdAddString(&(pol
->job_access
), "@OWNER");
3816 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3819 cupsdAddString(&(pol
->job_access
), value
);
3821 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3824 * JobPrivateValues {all|none|default|attribute list}
3827 if (!_cups_strcasecmp(value
, "default"))
3829 cupsdAddString(&(pol
->job_attrs
), "job-name");
3830 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3831 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3832 cupsdAddString(&(pol
->job_attrs
), "phone");
3835 cupsdAddString(&(pol
->job_attrs
), value
);
3837 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3840 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3843 if (!_cups_strcasecmp(value
, "default"))
3845 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3846 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3849 cupsdAddString(&(pol
->sub_access
), value
);
3851 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3854 * SubscriptionPrivateValues {all|none|default|attribute list}
3857 if (!_cups_strcasecmp(value
, "default"))
3859 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3860 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3861 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3862 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3863 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3866 cupsdAddString(&(pol
->sub_attrs
), value
);
3870 * Find the next string on the line...
3873 for (value
= valptr
; isspace(*value
& 255); value
++);
3879 cupsdLogMessage(CUPSD_LOG_ERROR
,
3880 "Missing <Limit ops> directive before %s on line %d.",
3882 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3885 else if (!parse_aaa(op
, line
, value
, linenum
))
3887 cupsdLogMessage(CUPSD_LOG_ERROR
,
3888 "Unknown Policy Limit directive %s on line %d.",
3891 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3896 cupsdLogMessage(CUPSD_LOG_ERROR
,
3897 "Unexpected end-of-file at line %d while reading policy "
3898 "\"%s\".", linenum
, policy
);
3900 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3905 * 'set_policy_defaults()' - Set default policy values as needed.
3909 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
3911 cupsd_location_t
*op
; /* Policy operation */
3915 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3916 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3917 * upgrades do not introduce new security issues...
3920 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
3921 op
->op
== IPP_ANY_OPERATION
)
3923 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
3924 op
->op
!= IPP_ANY_OPERATION
)
3927 * Add a new limit for Validate-Job using the Print-Job limit as a
3931 cupsdLogMessage(CUPSD_LOG_WARN
,
3932 "No limit for Validate-Job defined in policy %s "
3933 "- using Print-Job's policy.", pol
->name
);
3935 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
3938 cupsdLogMessage(CUPSD_LOG_WARN
,
3939 "No limit for Validate-Job defined in policy %s "
3940 "and no suitable template found.", pol
->name
);
3943 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
3944 op
->op
== IPP_ANY_OPERATION
)
3946 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
3947 op
->op
!= IPP_ANY_OPERATION
)
3950 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
3954 cupsdLogMessage(CUPSD_LOG_WARN
,
3955 "No limit for Cancel-Jobs defined in policy %s "
3956 "- using Pause-Printer's policy.", pol
->name
);
3958 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
3961 cupsdLogMessage(CUPSD_LOG_WARN
,
3962 "No limit for Cancel-Jobs defined in policy %s "
3963 "and no suitable template found.", pol
->name
);
3966 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
3967 op
->op
== IPP_ANY_OPERATION
)
3969 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3970 op
->op
!= IPP_ANY_OPERATION
)
3973 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3977 cupsdLogMessage(CUPSD_LOG_WARN
,
3978 "No limit for Cancel-My-Jobs defined in policy %s "
3979 "- using Send-Document's policy.", pol
->name
);
3981 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
3984 cupsdLogMessage(CUPSD_LOG_WARN
,
3985 "No limit for Cancel-My-Jobs defined in policy %s "
3986 "and no suitable template found.", pol
->name
);
3989 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
3990 op
->op
== IPP_ANY_OPERATION
)
3992 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3993 op
->op
!= IPP_ANY_OPERATION
)
3996 * Add a new limit for Close-Job using the Send-Document limit as a
4000 cupsdLogMessage(CUPSD_LOG_WARN
,
4001 "No limit for Close-Job defined in policy %s "
4002 "- using Send-Document's policy.", pol
->name
);
4004 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
4007 cupsdLogMessage(CUPSD_LOG_WARN
,
4008 "No limit for Close-Job defined in policy %s "
4009 "and no suitable template found.", pol
->name
);
4012 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
4013 op
->op
== IPP_ANY_OPERATION
)
4015 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4016 op
->op
!= IPP_ANY_OPERATION
)
4019 * Add a new limit for CUPS-Get-Document using the Send-Document
4020 * limit as a template...
4023 cupsdLogMessage(CUPSD_LOG_WARN
,
4024 "No limit for CUPS-Get-Document defined in policy %s "
4025 "- using Send-Document's policy.", pol
->name
);
4027 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
4030 cupsdLogMessage(CUPSD_LOG_WARN
,
4031 "No limit for CUPS-Get-Document defined in policy %s "
4032 "and no suitable template found.", pol
->name
);
4036 * Verify we have JobPrivateAccess, JobPrivateValues,
4037 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4040 if (!pol
->job_access
)
4042 cupsdLogMessage(CUPSD_LOG_WARN
,
4043 "No JobPrivateAccess defined in policy %s "
4044 "- using defaults.", pol
->name
);
4045 cupsdAddString(&(pol
->job_access
), "@OWNER");
4046 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4049 if (!pol
->job_attrs
)
4051 cupsdLogMessage(CUPSD_LOG_WARN
,
4052 "No JobPrivateValues defined in policy %s "
4053 "- using defaults.", pol
->name
);
4054 cupsdAddString(&(pol
->job_attrs
), "job-name");
4055 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4056 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4057 cupsdAddString(&(pol
->job_attrs
), "phone");
4060 if (!pol
->sub_access
)
4062 cupsdLogMessage(CUPSD_LOG_WARN
,
4063 "No SubscriptionPrivateAccess defined in policy %s "
4064 "- using defaults.", pol
->name
);
4065 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4066 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4069 if (!pol
->sub_attrs
)
4071 cupsdLogMessage(CUPSD_LOG_WARN
,
4072 "No SubscriptionPrivateValues defined in policy %s "
4073 "- using defaults.", pol
->name
);
4074 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4075 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4076 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4077 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4078 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");