2 * Configuration routines for the CUPS scheduler.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
21 #include <sys/utsname.h>
24 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
25 # define SD_JOURNAL_SUPPRESS_LOCATION
26 # include <systemd/sd-journal.h>
27 #endif /* HAVE_ASL_H */
32 #endif /* HAVE_LIBPAPER */
36 * Possibly missing network definitions...
40 # define INADDR_NONE 0xffffffff
41 #endif /* !INADDR_NONE */
45 * Configuration variable structure...
50 CUPSD_VARTYPE_INTEGER
, /* Integer option */
51 CUPSD_VARTYPE_TIME
, /* Time interval option */
52 CUPSD_VARTYPE_STRING
, /* String option */
53 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
54 CUPSD_VARTYPE_PATHNAME
, /* File/directory name option */
55 CUPSD_VARTYPE_PERM
/* File/directory permissions */
60 const char *name
; /* Name of variable */
61 void *ptr
; /* Pointer to variable */
62 cupsd_vartype_t type
; /* Type (int, string, address) */
70 static const cupsd_var_t cupsd_vars
[] =
72 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
73 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
74 { "BrowseDNSSDSubTypes", &DNSSDSubTypes
, CUPSD_VARTYPE_STRING
},
75 #endif /* HAVE_DNSSD || HAVE_AVAHI */
76 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
77 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
78 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
79 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
80 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
81 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_TIME
},
82 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
83 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
84 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
85 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_TIME
},
86 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
87 { "DNSSDHostName", &DNSSDHostName
, CUPSD_VARTYPE_STRING
},
88 #endif /* HAVE_DNSSD || HAVE_AVAHI */
89 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
90 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
91 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
93 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
94 #endif /* HAVE_GSSAPI */
96 { "IdleExitTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
97 #endif /* HAVE_ONDEMAND */
98 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_TIME
},
99 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
100 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_TIME
},
101 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_TIME
},
102 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
104 { "LaunchdTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
105 #endif /* HAVE_LAUNCHD */
106 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
107 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
108 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
109 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
110 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
111 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
112 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
113 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
114 { "MaxHoldTime", &MaxHoldTime
, CUPSD_VARTYPE_TIME
},
115 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
116 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
117 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
118 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_TIME
},
119 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_TIME
},
120 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
121 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
122 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
123 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
124 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
125 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
126 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_TIME
},
127 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
128 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_TIME
},
129 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_TIME
},
130 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_TIME
},
131 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
132 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_TIME
},
133 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
134 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
135 { "StrictConformance", &StrictConformance
, CUPSD_VARTYPE_BOOLEAN
},
136 { "Timeout", &Timeout
, CUPSD_VARTYPE_TIME
},
137 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
139 static const cupsd_var_t cupsfiles_vars
[] =
141 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
142 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
143 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_PERM
},
145 { "CreateSelfSignedCerts", &CreateSelfSignedCerts
, CUPSD_VARTYPE_BOOLEAN
},
146 #endif /* HAVE_SSL */
147 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
148 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
149 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
150 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
151 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
152 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_PERM
},
153 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
154 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
155 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
156 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
157 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
158 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
160 { "ServerKeychain", &ServerKeychain
, CUPSD_VARTYPE_PATHNAME
},
161 #endif /* HAVE_SSL */
162 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
163 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
164 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
165 { "SyncOnClose", &SyncOnClose
, CUPSD_VARTYPE_BOOLEAN
},
166 #ifdef HAVE_AUTHORIZATION_H
167 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
168 #endif /* HAVE_AUTHORIZATION_H */
169 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
}
172 static int default_auth_type
= CUPSD_AUTH_AUTO
;
173 /* Default AuthType, if not specified */
175 static const unsigned ones
[4] =
177 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
179 static const unsigned zeros
[4] =
181 0x00000000, 0x00000000, 0x00000000, 0x00000000
189 static http_addrlist_t
*get_address(const char *value
, int defport
);
190 static int get_addr_and_mask(const char *value
, unsigned *ip
,
192 static void mime_error_cb(void *ctx
, const char *message
);
193 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
194 char *value
, int linenum
);
195 static int parse_fatal_errors(const char *s
);
196 static int parse_groups(const char *s
, int linenum
);
197 static int parse_protocols(const char *s
);
198 static int parse_variable(const char *filename
, int linenum
,
199 const char *line
, const char *value
,
201 const cupsd_var_t
*vars
);
202 static int read_cupsd_conf(cups_file_t
*fp
);
203 static int read_cups_files_conf(cups_file_t
*fp
);
204 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
205 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
206 static void set_policy_defaults(cupsd_policy_t
*pol
);
210 * 'cupsdAddAlias()' - Add a host alias.
214 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
215 const char *name
) /* I - Name to add */
217 cupsd_alias_t
*a
; /* New alias */
218 size_t namelen
; /* Length of name */
221 namelen
= strlen(name
);
223 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
226 a
->namelen
= namelen
;
227 memcpy(a
->name
, name
, namelen
+ 1); /* OK since a->name is allocated */
229 cupsArrayAdd(aliases
, a
);
234 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
237 int /* O - 0 on success, -1 on error, 1 on warning */
238 cupsdCheckPermissions(
239 const char *filename
, /* I - File/directory name */
240 const char *suffix
, /* I - Additional file/directory name */
241 mode_t mode
, /* I - Permissions */
242 uid_t user
, /* I - Owner */
243 gid_t group
, /* I - Group */
244 int is_dir
, /* I - 1 = directory, 0 = file */
245 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
247 int dir_created
= 0; /* Did we create a directory? */
248 char pathname
[1024]; /* File name with prefix */
249 struct stat fileinfo
; /* Stat buffer */
250 int is_symlink
; /* Is "filename" a symlink? */
254 * Prepend the given root to the filename before testing it...
259 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
264 * See if we can stat the file/directory...
267 if (lstat(filename
, &fileinfo
))
269 if (errno
== ENOENT
&& create_dir
)
272 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
275 if (mkdir(filename
, mode
))
278 cupsdLogMessage(CUPSD_LOG_ERROR
,
279 "Unable to create directory \"%s\" - %s", filename
,
282 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
283 sd_journal_print(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
285 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
286 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
292 fileinfo
.st_mode
= mode
| S_IFDIR
;
295 return (create_dir
? -1 : 1);
298 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
300 if (stat(filename
, &fileinfo
))
302 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
303 filename
, strerror(errno
));
309 * Make sure it's a regular file or a directory as needed...
312 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
314 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
318 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
321 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
323 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
324 sd_journal_print(LOG_ERR
, "\"%s\" is not a directory.", filename
);
326 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
327 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
333 * If the filename is a symlink, do not change permissions (STR #2937)...
340 * Fix owner, group, and mode as needed...
343 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
346 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
349 if (chown(filename
, user
, group
) && !getuid())
352 cupsdLogMessage(CUPSD_LOG_ERROR
,
353 "Unable to change ownership of \"%s\" - %s", filename
,
356 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
357 sd_journal_print(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
359 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
360 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
366 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
369 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
372 if (chmod(filename
, mode
))
375 cupsdLogMessage(CUPSD_LOG_ERROR
,
376 "Unable to change permissions of \"%s\" - %s", filename
,
379 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
380 sd_journal_print(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
382 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
383 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
390 * Everything is OK...
398 * 'cupsdDefaultAuthType()' - Get the default AuthType.
400 * When the default_auth_type is "auto", this function tries to get the GSS
401 * credentials for the server. If that succeeds we use Kerberos authentication,
402 * otherwise we do a fallback to Basic authentication against the local user
406 int /* O - Default AuthType value */
407 cupsdDefaultAuthType(void)
410 OM_uint32 major_status
, /* Major status code */
411 minor_status
; /* Minor status code */
412 gss_name_t server_name
; /* Server name */
413 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
414 /* Service name token */
415 char buf
[1024]; /* Service name buffer */
416 #endif /* HAVE_GSSAPI */
420 * If we have already determined the correct default AuthType, use it...
423 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
424 return (default_auth_type
);
429 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
433 if (&gss_init_sec_context
== NULL
)
434 return (default_auth_type
= CUPSD_AUTH_BASIC
);
435 # endif /* __APPLE__ */
438 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
439 * that fails we must use Basic...
442 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
445 token
.length
= strlen(buf
);
446 server_name
= GSS_C_NO_NAME
;
447 major_status
= gss_import_name(&minor_status
, &token
,
448 GSS_C_NT_HOSTBASED_SERVICE
,
451 memset(&token
, 0, sizeof(token
));
453 if (GSS_ERROR(major_status
))
455 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
456 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
457 return (default_auth_type
= CUPSD_AUTH_BASIC
);
460 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
462 if (GSS_ERROR(major_status
))
464 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
465 "cupsdDefaultAuthType: gss_display_name(%s) failed",
467 return (default_auth_type
= CUPSD_AUTH_BASIC
);
470 cupsdLogMessage(CUPSD_LOG_DEBUG
,
471 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
472 "credentials for %s...", (char *)token
.value
);
474 ServerCreds
= GSS_C_NO_CREDENTIAL
;
475 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
476 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
477 &ServerCreds
, NULL
, NULL
);
478 if (GSS_ERROR(major_status
))
480 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
481 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
482 (char *)token
.value
);
483 gss_release_name(&minor_status
, &server_name
);
484 gss_release_buffer(&minor_status
, &token
);
485 return (default_auth_type
= CUPSD_AUTH_BASIC
);
488 cupsdLogMessage(CUPSD_LOG_DEBUG
,
489 "cupsdDefaultAuthType: Kerberos credentials acquired "
490 "successfully for %s.", (char *)token
.value
);
492 gss_release_name(&minor_status
, &server_name
);
493 gss_release_buffer(&minor_status
, &token
);
497 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
501 * No Kerberos support compiled in so just use Basic all the time...
504 return (default_auth_type
= CUPSD_AUTH_BASIC
);
505 #endif /* HAVE_GSSAPI */
510 * 'cupsdFreeAliases()' - Free all of the alias entries.
514 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
516 cupsd_alias_t
*a
; /* Current alias */
519 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
521 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
524 cupsArrayDelete(aliases
);
529 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
532 int /* O - 1 on success, 0 otherwise */
533 cupsdReadConfiguration(void)
535 int i
; /* Looping var */
536 cups_file_t
*fp
; /* Configuration file */
537 int status
; /* Return status */
538 char temp
[1024], /* Temporary buffer */
539 mimedir
[1024], /* MIME directory */
540 *slash
; /* Directory separator */
541 cups_lang_t
*language
; /* Language */
542 struct passwd
*user
; /* Default user */
543 struct group
*group
; /* Default group */
544 char *old_serverroot
, /* Old ServerRoot */
545 *old_requestroot
; /* Old RequestRoot */
546 int old_remote_port
; /* Old RemotePort */
547 const char *tmpdir
; /* TMPDIR environment variable */
548 struct stat tmpinfo
; /* Temporary directory info */
549 cupsd_policy_t
*p
; /* Policy */
553 * Save the old root paths...
556 old_serverroot
= NULL
;
557 cupsdSetString(&old_serverroot
, ServerRoot
);
558 old_requestroot
= NULL
;
559 cupsdSetString(&old_requestroot
, RequestRoot
);
562 * Reset the server configuration data...
565 cupsdDeleteAllLocations();
567 cupsdDeleteAllListeners();
569 old_remote_port
= RemotePort
;
576 cupsdFreeAliases(ServerAlias
);
579 cupsdClearString(&ServerName
);
580 cupsdClearString(&ServerAdmin
);
581 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
582 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
583 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
584 cupsdSetString(&DataDir
, CUPS_DATADIR
);
585 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
586 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
587 cupsdClearString(&ErrorLog
);
588 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
589 cupsdSetString(&PageLogFormat
,
590 "%p %u %j %T %P %C %{job-billing} "
591 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
592 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
593 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
594 cupsdSetString(&RemoteRoot
, "remroot");
595 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
597 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
599 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
600 PrintcapFormat
= PRINTCAP_SOLARIS
;
601 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
602 "/Library/Preferences/org.cups.printers.plist"))
603 PrintcapFormat
= PRINTCAP_PLIST
;
605 PrintcapFormat
= PRINTCAP_BSD
;
607 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
608 if ((slash
= strrchr(temp
, '/')) != NULL
)
611 cupsdSetString(&ServerRoot
, temp
);
613 cupsdClearString(&Classification
);
614 ClassifyOverride
= 0;
618 cupsdSetString(&ServerKeychain
, "ssl");
620 cupsdSetString(&ServerKeychain
, "/Library/Keychains/System.keychain");
621 # endif /* HAVE_GNUTLS */
623 _httpTLSSetOptions(_HTTP_TLS_NONE
, _HTTP_TLS_1_0
, _HTTP_TLS_MAX
);
624 #endif /* HAVE_SSL */
626 language
= cupsLangDefault();
628 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
629 cupsdSetString(&DefaultLanguage
, "en");
631 cupsdSetString(&DefaultLanguage
, language
->language
);
633 cupsdClearString(&DefaultPaperSize
);
635 cupsdSetString(&RIPCache
, "128m");
637 cupsdSetString(&TempDir
, NULL
);
640 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
644 OM_uint32 minor_status
; /* Minor status code */
646 gss_release_cred(&minor_status
, &ServerCreds
);
651 ServerCreds
= GSS_C_NO_CREDENTIAL
;
652 #endif /* HAVE_GSSAPI */
655 * Find the default user...
658 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
663 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
664 * complement number...)
673 * Find the default group...
676 group
= getgrnam(CUPS_DEFAULT_GROUP
);
680 Group
= group
->gr_gid
;
684 * Fallback to group "nobody"...
687 group
= getgrnam("nobody");
691 Group
= group
->gr_gid
;
695 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
696 * complement number...)
707 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
708 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
709 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
710 default_auth_type
= CUPSD_AUTH_BASIC
;
712 CreateSelfSignedCerts
= TRUE
;
713 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
714 #endif /* HAVE_SSL */
715 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
716 JobKillDelay
= DEFAULT_TIMEOUT
;
718 JobRetryInterval
= 300;
723 HostNameLookups
= FALSE
;
725 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
726 ListenBackLog
= SOMAXCONN
;
727 LogDebugHistory
= 200;
728 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
729 LogLevel
= CUPSD_LOG_WARN
;
730 LogTimeFormat
= CUPSD_TIME_STANDARD
;
732 MaxClientsPerHost
= 0;
733 MaxLogSize
= 1024 * 1024;
735 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
737 ReloadTimeout
= DEFAULT_KEEPALIVE
;
738 RootCertDuration
= 300;
739 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
740 StrictConformance
= FALSE
;
742 Timeout
= DEFAULT_TIMEOUT
;
743 WebInterface
= CUPS_DEFAULT_WEBIF
;
745 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
747 Browsing
= CUPS_DEFAULT_BROWSING
;
748 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
750 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
751 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
752 cupsdClearString(&DNSSDHostName
);
753 #endif /* HAVE_DNSSD || HAVE_AVAHI */
755 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
756 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
758 cupsdSetString(&ErrorPolicy
, "stop-printer");
760 JobHistory
= DEFAULT_HISTORY
;
761 JobFiles
= DEFAULT_FILES
;
767 MaxJobsPerPrinter
= 0;
768 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
769 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
771 cupsdDeleteAllPolicies();
772 cupsdClearString(&DefaultPolicy
);
774 #ifdef HAVE_AUTHORIZATION_H
775 cupsdSetString(&SystemGroupAuthKey
, CUPS_DEFAULT_SYSTEM_AUTHKEY
);
776 #endif /* HAVE_AUTHORIZATION_H */
778 MaxSubscriptions
= 100;
779 MaxSubscriptionsPerJob
= 0;
780 MaxSubscriptionsPerPrinter
= 0;
781 MaxSubscriptionsPerUser
= 0;
782 DefaultLeaseDuration
= 86400;
783 MaxLeaseDuration
= 0;
786 IdleExitTimeout
= 60;
787 #endif /* HAVE_ONDEMAND */
790 * Setup environment variables...
796 * Read the cups-files.conf file...
799 if ((fp
= cupsFileOpen(CupsFilesFile
, "r")) != NULL
)
801 status
= read_cups_files_conf(fp
);
808 printf("\"%s\" contains errors.\n", CupsFilesFile
);
810 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
811 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
813 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
814 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
819 else if (errno
== ENOENT
)
820 cupsdLogMessage(CUPSD_LOG_INFO
, "No %s, using defaults.", CupsFilesFile
);
823 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
824 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
826 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
827 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
833 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
836 * Read the cupsd.conf file...
839 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
841 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
842 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
844 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
845 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
850 status
= read_cupsd_conf(fp
);
857 printf("\"%s\" contains errors.\n", ConfigurationFile
);
859 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
860 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
862 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
863 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
870 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
871 RemotePort
? "enabled" : "disabled");
874 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
877 * See if the ServerName is an IP address...
883 ServerAlias
= cupsArrayNew(NULL
, NULL
);
885 cupsdAddAlias(ServerAlias
, ServerName
);
886 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
890 if (gethostname(temp
, sizeof(temp
)))
892 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
894 strlcpy(temp
, "localhost", sizeof(temp
));
897 cupsdSetString(&ServerName
, temp
);
900 ServerAlias
= cupsArrayNew(NULL
, NULL
);
902 cupsdAddAlias(ServerAlias
, temp
);
903 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
905 if (HostNameLookups
|| RemotePort
)
907 struct hostent
*host
; /* Host entry to get FQDN */
909 if ((host
= gethostbyname(temp
)) != NULL
)
911 if (_cups_strcasecmp(temp
, host
->h_name
))
913 cupsdSetString(&ServerName
, host
->h_name
);
914 cupsdAddAlias(ServerAlias
, host
->h_name
);
915 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
921 for (i
= 0; host
->h_aliases
[i
]; i
++)
922 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
924 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
925 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
933 * Make sure we have the base hostname added as an alias, too!
936 if ((slash
= strchr(temp
, '.')) != NULL
)
939 cupsdAddAlias(ServerAlias
, temp
);
940 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
944 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
946 ServerNameIsIP
= !*slash
;
949 * Make sure ServerAdmin is initialized...
953 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
956 * Use the default system group if none was supplied in cupsd.conf...
959 if (NumSystemGroups
== 0)
961 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
, 0))
964 * Find the group associated with GID 0...
971 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
973 cupsdSetString(&SystemGroups
[0], "unknown");
975 SystemGroupIDs
[0] = 0;
981 * Make sure ConfigFilePerm and LogFilePerm have sane values...
984 ConfigFilePerm
&= 0664;
988 * Open the system log for cupsd if necessary...
993 if (!strcmp(AccessLog
, "stderr"))
994 cupsdSetString(&AccessLog
, "syslog");
996 if (!strcmp(ErrorLog
, "stderr"))
997 cupsdSetString(&ErrorLog
, "syslog");
999 if (!strcmp(PageLog
, "stderr"))
1000 cupsdSetString(&PageLog
, "syslog");
1003 #if defined(HAVE_VSYSLOG) && !defined(HAVE_ASL_H) && !defined(HAVE_SYSTEMD_SD_JOURNAL_H)
1004 if (!strcmp(AccessLog
, "syslog") ||
1005 !strcmp(ErrorLog
, "syslog") ||
1006 !strcmp(PageLog
, "syslog"))
1007 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
1008 #endif /* HAVE_VSYSLOG && !HAVE_ASL_H && !HAVE_SYSTEMD_SD_JOURNAL_H */
1011 * Log the configuration file that was used...
1014 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
1018 * Validate the Group and SystemGroup settings - they cannot be the same,
1019 * otherwise the CGI programs will be able to authenticate as root without
1025 for (i
= 0; i
< NumSystemGroups
; i
++)
1026 if (Group
== SystemGroupIDs
[i
])
1029 if (i
< NumSystemGroups
)
1032 * Log the error and reset the group to a safe value...
1035 cupsdLogMessage(CUPSD_LOG_ERROR
,
1036 "Group and SystemGroup cannot use the same groups.");
1037 if (FatalErrors
& (CUPSD_FATAL_CONFIG
| CUPSD_FATAL_PERMISSIONS
))
1040 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
1042 group
= getgrnam("nobody");
1046 Group
= group
->gr_gid
;
1050 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
1051 * complement number...)
1060 * Check that we have at least one listen/port line; if not, report this
1061 * as an error and exit!
1064 if (cupsArrayCount(Listeners
) == 0)
1070 cupsdLogMessage(CUPSD_LOG_EMERG
,
1071 "No valid Listen or Port lines were found in the "
1072 "configuration file.");
1078 cupsdEndProcess(getpid(), 0);
1082 * Set the default locale using the language and charset...
1085 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1088 * Update all relative filenames to include the full path from ServerRoot...
1091 if (DocumentRoot
[0] != '/')
1092 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1094 if (RequestRoot
[0] != '/')
1095 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1097 if (ServerBin
[0] != '/')
1098 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1100 if (StateDir
[0] != '/')
1101 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1103 if (CacheDir
[0] != '/')
1104 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1107 if (!_cups_strcasecmp(ServerKeychain
, "internal"))
1108 cupsdClearString(&ServerKeychain
);
1109 else if (ServerKeychain
[0] != '/')
1110 cupsdSetStringf(&ServerKeychain
, "%s/%s", ServerRoot
, ServerKeychain
);
1112 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Using keychain \"%s\" for server name \"%s\".", ServerKeychain
? ServerKeychain
: "internal", ServerName
);
1113 if (!CreateSelfSignedCerts
)
1114 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Self-signed TLS certificate generation is disabled.");
1115 cupsSetServerCredentials(ServerKeychain
, ServerName
, CreateSelfSignedCerts
);
1116 #endif /* HAVE_SSL */
1119 * Make sure that directories and config files are owned and
1120 * writable by the user and group in the cupsd.conf file...
1123 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1125 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1127 cupsdCheckPermissions(CacheDir
, NULL
, 0770, RunUser
,
1129 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1131 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1133 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1134 SystemGroupIDs
[0], 1, 1) < 0 ||
1135 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1137 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1139 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1141 cupsdCheckPermissions(ConfigurationFile
, NULL
, ConfigFilePerm
, RunUser
,
1143 cupsdCheckPermissions(CupsFilesFile
, NULL
, ConfigFilePerm
, RunUser
,
1145 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1147 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1149 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1150 Group
, 0, 0) < 0) &&
1151 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1155 * Update TempDir to the default if it hasn't been set already...
1159 if (TempDir
&& !RunUser
&&
1160 (!strncmp(TempDir
, "/private/tmp", 12) || !strncmp(TempDir
, "/tmp", 4)))
1162 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot use %s for TempDir.", TempDir
);
1163 cupsdClearString(&TempDir
);
1165 #endif /* __APPLE__ */
1170 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1171 strncmp(tmpdir
, "/private/tmp", 12) && strncmp(tmpdir
, "/tmp", 4))
1173 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1174 #endif /* __APPLE__ */
1177 * TMPDIR is defined, see if it is OK for us to use...
1180 if (stat(tmpdir
, &tmpinfo
))
1181 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1182 tmpdir
, strerror(errno
));
1183 else if (!S_ISDIR(tmpinfo
.st_mode
))
1184 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1186 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1187 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1188 !(tmpinfo
.st_mode
& S_IWOTH
))
1189 cupsdLogMessage(CUPSD_LOG_ERROR
,
1190 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1192 cupsdSetString(&TempDir
, tmpdir
);
1198 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1200 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1203 setenv("TMPDIR", TempDir
, 1);
1206 * Make sure the temporary directory has the right permissions...
1209 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1213 * Update ownership and permissions if the CUPS temp directory
1214 * is under the spool directory or does not exist...
1217 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1218 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1223 * Update environment variables...
1229 * Validate the default error policy...
1232 if (strcmp(ErrorPolicy
, "retry-current-job") &&
1233 strcmp(ErrorPolicy
, "abort-job") &&
1234 strcmp(ErrorPolicy
, "retry-job") &&
1235 strcmp(ErrorPolicy
, "stop-printer"))
1237 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\", resetting to \"stop-printer\".", ErrorPolicy
);
1238 cupsdSetString(&ErrorPolicy
, "stop-printer");
1242 * Update default paper size setting as needed...
1245 if (!DefaultPaperSize
)
1247 #ifdef HAVE_LIBPAPER
1248 char *paper_result
; /* Paper size name from libpaper */
1250 if ((paper_result
= systempapername()) != NULL
)
1251 cupsdSetString(&DefaultPaperSize
, paper_result
);
1253 #endif /* HAVE_LIBPAPER */
1254 if (!DefaultLanguage
||
1255 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1256 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1257 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1258 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1259 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1260 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1261 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1264 * These are the only locales that will default to "letter" size...
1267 cupsdSetString(&DefaultPaperSize
, "Letter");
1270 cupsdSetString(&DefaultPaperSize
, "A4");
1274 * Update classification setting as needed...
1277 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1278 cupsdClearString(&Classification
);
1281 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1284 * Check the MaxClients setting, and then allocate memory for it...
1287 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1290 cupsdLogMessage(CUPSD_LOG_INFO
,
1291 "MaxClients limited to 1/3 (%d) of the file descriptor "
1293 MaxFDs
/ 3, MaxFDs
);
1295 MaxClients
= MaxFDs
/ 3;
1298 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1302 * Check the MaxActiveJobs setting; limit to 1/3 the available
1303 * file descriptors, since we need a pipe for each job...
1306 if (MaxActiveJobs
> (MaxFDs
/ 3))
1307 MaxActiveJobs
= MaxFDs
/ 3;
1310 * Update the MaxClientsPerHost value, as needed...
1313 if (MaxClientsPerHost
<= 0)
1314 MaxClientsPerHost
= MaxClients
;
1316 if (MaxClientsPerHost
> MaxClients
)
1317 MaxClientsPerHost
= MaxClients
;
1319 cupsdLogMessage(CUPSD_LOG_INFO
,
1320 "Allowing up to %d client connections per host.",
1324 * Update the default policy, as needed...
1328 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1330 DefaultPolicyPtr
= NULL
;
1332 if (!DefaultPolicyPtr
)
1334 cupsd_location_t
*po
; /* New policy operation */
1338 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1341 cupsdSetString(&DefaultPolicy
, "default");
1343 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1344 cupsdLogMessage(CUPSD_LOG_INFO
,
1345 "Using policy \"default\" as the default.");
1348 cupsdLogMessage(CUPSD_LOG_INFO
,
1349 "Creating CUPS default administrative policy:");
1351 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1353 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1355 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1356 cupsdAddString(&(p
->job_access
), "@OWNER");
1357 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1359 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1360 cupsdAddString(&(p
->job_attrs
), "job-name");
1361 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1362 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1363 cupsdAddString(&(p
->job_attrs
), "phone");
1365 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1366 cupsdAddString(&(p
->sub_access
), "@OWNER");
1367 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1369 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1370 cupsdAddString(&(p
->job_attrs
), "notify-events");
1371 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1372 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1373 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1374 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1376 cupsdLogMessage(CUPSD_LOG_INFO
,
1377 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1378 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1380 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1381 po
->order_type
= CUPSD_AUTH_ALLOW
;
1383 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1384 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1385 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1387 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1389 cupsdLogMessage(CUPSD_LOG_INFO
,
1390 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1391 "Release-Job Restart-Job Purge-Jobs "
1392 "Set-Job-Attributes Create-Job-Subscription "
1393 "Renew-Subscription Cancel-Subscription "
1394 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1395 "Suspend-Current-Job Resume-Job "
1396 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1397 "CUPS-Authenticate-Job CUPS-Get-Document>");
1398 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1400 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1401 po
->order_type
= CUPSD_AUTH_ALLOW
;
1402 po
->level
= CUPSD_AUTH_USER
;
1404 cupsdAddName(po
, "@OWNER");
1405 cupsdAddName(po
, "@SYSTEM");
1406 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1408 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1409 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1410 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1411 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1412 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1413 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1414 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1415 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1416 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1417 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1418 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1419 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1420 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1421 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1422 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1423 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1424 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1425 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1426 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1427 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1429 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1431 cupsdLogMessage(CUPSD_LOG_INFO
,
1432 "<Limit Pause-Printer Resume-Printer "
1433 "Set-Printer-Attributes Enable-Printer "
1434 "Disable-Printer Pause-Printer-After-Current-Job "
1435 "Hold-New-Jobs Release-Held-New-Jobs "
1436 "Deactivate-Printer Activate-Printer Restart-Printer "
1437 "Shutdown-Printer Startup-Printer Promote-Job "
1438 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1439 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1440 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1441 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1442 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1444 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1445 po
->order_type
= CUPSD_AUTH_ALLOW
;
1446 po
->type
= CUPSD_AUTH_DEFAULT
;
1447 po
->level
= CUPSD_AUTH_USER
;
1449 cupsdAddName(po
, "@SYSTEM");
1450 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1452 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1453 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1454 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1455 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1456 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1457 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1458 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1459 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1460 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1461 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1462 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1463 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1464 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1465 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1466 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1467 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1468 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1469 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1470 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1471 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1472 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1473 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1475 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1477 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1478 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1480 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1481 po
->order_type
= CUPSD_AUTH_ALLOW
;
1483 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1484 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1488 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1489 cupsArrayCount(Policies
));
1490 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1492 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1493 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1494 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1497 * If we are doing a full reload or the server root has changed, flush
1498 * the jobs, printers, etc. and start from scratch...
1501 if (NeedReload
== RELOAD_ALL
||
1502 old_remote_port
!= RemotePort
||
1503 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1504 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1506 mime_type_t
*type
; /* Current type */
1507 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1508 /* MIME type name */
1511 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1514 * Free all memory...
1517 cupsdDeleteAllSubscriptions();
1519 cupsdDeleteAllPrinters();
1521 DefaultPrinter
= NULL
;
1523 if (MimeDatabase
!= NULL
)
1524 mimeDelete(MimeDatabase
);
1528 for (i
= 0; i
< NumMimeTypes
; i
++)
1529 _cupsStrFree(MimeTypes
[i
]);
1535 * Read the MIME type and conversion database...
1538 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1539 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1541 MimeDatabase
= mimeNew();
1542 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1544 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1545 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1546 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1547 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1551 cupsdLogMessage(CUPSD_LOG_EMERG
,
1552 "Unable to load MIME database from \"%s\" or \"%s\".",
1553 mimedir
, ServerRoot
);
1554 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1558 cupsdLogMessage(CUPSD_LOG_INFO
,
1559 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1560 "%d filters...", mimedir
, ServerRoot
,
1561 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1564 * Create a list of MIME types for the document-format-supported
1568 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1569 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1572 if ((MimeTypes
= calloc((size_t)NumMimeTypes
, sizeof(const char *))) == NULL
)
1574 cupsdLogMessage(CUPSD_LOG_ERROR
,
1575 "Unable to allocate memory for %d MIME types.",
1581 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1583 i
++, type
= mimeNextType(MimeDatabase
))
1585 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1587 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1590 if (i
< NumMimeTypes
)
1591 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1594 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1596 mime_filter_t
*filter
; /* Current filter */
1599 for (type
= mimeFirstType(MimeDatabase
);
1601 type
= mimeNextType(MimeDatabase
))
1602 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1603 type
->super
, type
->type
);
1605 for (filter
= mimeFirstFilter(MimeDatabase
);
1607 filter
= mimeNextFilter(MimeDatabase
))
1608 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1609 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1610 filter
->src
->super
, filter
->src
->type
,
1611 filter
->dst
->super
, filter
->dst
->type
,
1612 filter
->cost
, filter
->filter
);
1619 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1620 cupsdLoadBanners(temp
);
1623 * Load printers and classes...
1626 cupsdLoadAllPrinters();
1627 cupsdLoadAllClasses();
1629 cupsdCreateCommonData();
1632 * Update the printcap file as needed...
1635 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1636 cupsdWritePrintcap();
1639 * Load queued jobs...
1645 * Load subscriptions...
1648 cupsdLoadAllSubscriptions();
1650 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1655 * Not a full reload, so recreate the common printer attributes...
1658 cupsdCreateCommonData();
1661 * Update all jobs as needed...
1667 * Update all printers as needed...
1670 cupsdUpdatePrinters();
1671 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1673 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1677 * Reset the reload state...
1680 NeedReload
= RELOAD_NONE
;
1682 cupsdClearString(&old_serverroot
);
1683 cupsdClearString(&old_requestroot
);
1690 * 'get_address()' - Get an address + port number from a line.
1693 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1694 get_address(const char *value
, /* I - Value string */
1695 int defport
) /* I - Default port */
1697 char buffer
[1024], /* Hostname + port number buffer */
1698 defpname
[255], /* Default port name */
1699 *hostname
, /* Hostname or IP */
1700 *portname
; /* Port number or name */
1701 http_addrlist_t
*addrlist
; /* Address list */
1705 * Check for an empty value...
1710 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1715 * Grab a hostname and port number; if there is no colon and the port name
1716 * is only digits, then we have a port number by itself...
1719 strlcpy(buffer
, value
, sizeof(buffer
));
1721 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1728 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1733 * Use the default port...
1736 sprintf(defpname
, "%d", defport
);
1737 portname
= defpname
;
1743 * The buffer contains just a port number...
1751 if (hostname
&& !strcmp(hostname
, "*"))
1755 * Now lookup the address using httpAddrGetList()...
1758 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1759 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1760 hostname
? hostname
: "(nil)");
1767 * 'get_addr_and_mask()' - Get an IP address and netmask.
1770 static int /* O - 1 on success, 0 on failure */
1771 get_addr_and_mask(const char *value
, /* I - String from config file */
1772 unsigned *ip
, /* O - Address value */
1773 unsigned *mask
) /* O - Mask value */
1775 int i
, j
, /* Looping vars */
1776 family
, /* Address family */
1777 ipcount
; /* Count of fields in address */
1778 unsigned ipval
; /* Value */
1779 const char *maskval
, /* Pointer to start of mask value */
1780 *ptr
, /* Pointer into value */
1785 * Get the address...
1788 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1789 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1791 if ((maskval
= strchr(value
, '/')) != NULL
)
1794 maskval
= value
+ strlen(value
);
1798 * Check for an IPv6 address...
1804 * Parse hexadecimal IPv6/IPv4 address...
1809 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1813 else if (!strncmp(ptr
, "::", 2))
1815 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1817 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1822 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1825 * Read IPv4 dotted quad...
1828 unsigned val
[4] = { 0, 0, 0, 0 };
1829 /* IPv4 address values */
1831 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1835 * Range check the IP numbers...
1838 for (i
= 0; i
< ipcount
; i
++)
1843 * Merge everything into a 32-bit IPv4 address in ip[3]...
1846 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1847 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1850 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1853 * If the leading words are all 0's then this is an IPv4 address...
1856 if (!val
[0] && !val
[1] && !val
[2])
1859 while (isdigit(*ptr
& 255) || *ptr
== '.')
1863 else if (isxdigit(*ptr
& 255))
1865 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1867 if (*ptr
== ':' && ptr
[1] != ':')
1876 ip
[i
/ 2] |= ipval
<< 16;
1887 if (*ptr
&& *ptr
!= '/')
1891 #endif /* AF_INET6 */
1894 * Parse dotted-decimal IPv4 address...
1897 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1901 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1904 * Range check the IP numbers...
1907 for (i
= 0; i
< ipcount
; i
++)
1912 * Merge everything into a 32-bit IPv4 address in ip[3]...
1915 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1916 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1919 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1925 * Get the netmask value(s)...
1928 memset(mask
, 0, sizeof(unsigned) * 4);
1930 if (strchr(maskval
, '.'))
1933 * Get dotted-decimal mask...
1936 if (family
!= AF_INET
)
1939 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1943 mask
[3] |= (((((unsigned)mask
[0] << 8) | (unsigned)mask
[1]) << 8) |
1944 (unsigned)mask
[2]) << 8;
1945 mask
[0] = mask
[1] = mask
[2] = 0;
1950 * Get address/bits format...
1956 if (family
== AF_INET6
)
1964 mask
[0] = 0xffffffff;
1966 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1969 mask
[1] = 0xffffffff;
1973 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1976 mask
[2] = 0xffffffff;
1980 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1983 mask
[3] = 0xffffffff;
1987 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1990 #endif /* AF_INET6 */
1995 mask
[0] = 0xffffffff;
1996 mask
[1] = 0xffffffff;
1997 mask
[2] = 0xffffffff;
2000 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
2002 mask
[3] = 0xffffffff;
2007 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2008 "get_addr_and_mask(value=\"%s\", "
2009 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
2010 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
2014 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2017 if ((ip
[0] & ~mask
[0]) != 0 ||
2018 (ip
[1] & ~mask
[1]) != 0 ||
2019 (ip
[2] & ~mask
[2]) != 0 ||
2020 (ip
[3] & ~mask
[3]) != 0)
2028 * 'mime_error_cb()' - Log a MIME error.
2032 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
2033 const char *message
) /* I - Message */
2037 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
2042 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
2045 static int /* O - 1 on success, 0 on failure */
2046 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
2047 char *line
, /* I - Line from file */
2048 char *value
, /* I - Start of value data */
2049 int linenum
) /* I - Current line number */
2051 char *valptr
; /* Pointer into value */
2052 unsigned ip
[4], /* IP address components */
2053 mask
[4]; /* IP netmask components */
2056 if (!_cups_strcasecmp(line
, "Encryption"))
2059 * "Encryption xxx" - set required encryption level...
2062 if (!_cups_strcasecmp(value
, "never"))
2063 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
2064 else if (!_cups_strcasecmp(value
, "always"))
2066 cupsdLogMessage(CUPSD_LOG_ERROR
,
2067 "Encryption value \"%s\" on line %d of %s is invalid in this "
2068 "context. Using \"required\" instead.", value
, linenum
, ConfigurationFile
);
2070 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2072 else if (!_cups_strcasecmp(value
, "required"))
2073 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2074 else if (!_cups_strcasecmp(value
, "ifrequested"))
2075 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2078 cupsdLogMessage(CUPSD_LOG_ERROR
,
2079 "Unknown Encryption value %s on line %d of %s.", value
, linenum
, ConfigurationFile
);
2083 else if (!_cups_strcasecmp(line
, "Order"))
2086 * "Order Deny,Allow" or "Order Allow,Deny"...
2089 if (!_cups_strncasecmp(value
, "deny", 4))
2090 loc
->order_type
= CUPSD_AUTH_ALLOW
;
2091 else if (!_cups_strncasecmp(value
, "allow", 5))
2092 loc
->order_type
= CUPSD_AUTH_DENY
;
2095 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d of %s.",
2096 value
, linenum
, ConfigurationFile
);
2100 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2103 * Allow [From] host/ip...
2104 * Deny [From] host/ip...
2109 if (!_cups_strncasecmp(value
, "from", 4))
2112 * Strip leading "from"...
2117 while (_cups_isspace(*value
))
2125 * Find the end of the value...
2128 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2130 while (_cups_isspace(*valptr
))
2134 * Figure out what form the allow/deny address takes:
2145 * nnn.nnn.nnn.nnn/mm
2146 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2149 if (!_cups_strcasecmp(value
, "all"))
2155 if (!_cups_strcasecmp(line
, "Allow"))
2156 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2158 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2160 else if (!_cups_strcasecmp(value
, "none"))
2166 if (!_cups_strcasecmp(line
, "Allow"))
2167 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2169 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2172 else if (value
[0] == '*' || value
[0] == '.' ||
2173 (!isdigit(value
[0] & 255) && value
[0] != '['))
2175 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2176 #endif /* AF_INET6 */
2179 * Host or domain name...
2182 if (value
[0] == '*')
2185 if (!_cups_strcasecmp(line
, "Allow"))
2186 cupsdAddNameMask(&(loc
->allow
), value
);
2188 cupsdAddNameMask(&(loc
->deny
), value
);
2193 * One of many IP address forms...
2196 if (!get_addr_and_mask(value
, ip
, mask
))
2198 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d of %s.",
2199 value
, linenum
, ConfigurationFile
);
2203 if (!_cups_strcasecmp(line
, "Allow"))
2204 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2206 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2210 * Advance to next value...
2216 else if (!_cups_strcasecmp(line
, "AuthType"))
2219 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2222 if (!_cups_strcasecmp(value
, "none"))
2224 loc
->type
= CUPSD_AUTH_NONE
;
2225 loc
->level
= CUPSD_AUTH_ANON
;
2227 else if (!_cups_strcasecmp(value
, "basic"))
2229 loc
->type
= CUPSD_AUTH_BASIC
;
2231 if (loc
->level
== CUPSD_AUTH_ANON
)
2232 loc
->level
= CUPSD_AUTH_USER
;
2234 else if (!_cups_strcasecmp(value
, "default"))
2236 loc
->type
= CUPSD_AUTH_DEFAULT
;
2238 if (loc
->level
== CUPSD_AUTH_ANON
)
2239 loc
->level
= CUPSD_AUTH_USER
;
2241 else if (!_cups_strcasecmp(value
, "negotiate"))
2243 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2245 if (loc
->level
== CUPSD_AUTH_ANON
)
2246 loc
->level
= CUPSD_AUTH_USER
;
2250 cupsdLogMessage(CUPSD_LOG_WARN
,
2251 "Unknown authorization type %s on line %d of %s.",
2252 value
, linenum
, ConfigurationFile
);
2256 else if (!_cups_strcasecmp(line
, "AuthClass"))
2259 * AuthClass anonymous, user, system, group
2262 if (!_cups_strcasecmp(value
, "anonymous"))
2264 loc
->type
= CUPSD_AUTH_NONE
;
2265 loc
->level
= CUPSD_AUTH_ANON
;
2267 cupsdLogMessage(CUPSD_LOG_WARN
,
2268 "\"AuthClass %s\" is deprecated; consider removing "
2272 else if (!_cups_strcasecmp(value
, "user"))
2274 loc
->level
= CUPSD_AUTH_USER
;
2276 cupsdLogMessage(CUPSD_LOG_WARN
,
2277 "\"AuthClass %s\" is deprecated; consider using "
2278 "\"Require valid-user\" on line %d of %s.",
2279 value
, linenum
, ConfigurationFile
);
2281 else if (!_cups_strcasecmp(value
, "group"))
2283 loc
->level
= CUPSD_AUTH_GROUP
;
2285 cupsdLogMessage(CUPSD_LOG_WARN
,
2286 "\"AuthClass %s\" is deprecated; consider using "
2287 "\"Require user @groupname\" on line %d of %s.",
2288 value
, linenum
, ConfigurationFile
);
2290 else if (!_cups_strcasecmp(value
, "system"))
2292 loc
->level
= CUPSD_AUTH_GROUP
;
2294 cupsdAddName(loc
, "@SYSTEM");
2296 cupsdLogMessage(CUPSD_LOG_WARN
,
2297 "\"AuthClass %s\" is deprecated; consider using "
2298 "\"Require user @SYSTEM\" on line %d of %s.",
2299 value
, linenum
, ConfigurationFile
);
2303 cupsdLogMessage(CUPSD_LOG_WARN
,
2304 "Unknown authorization class %s on line %d of %s.",
2305 value
, linenum
, ConfigurationFile
);
2309 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2311 cupsdAddName(loc
, value
);
2313 cupsdLogMessage(CUPSD_LOG_WARN
,
2314 "\"AuthGroupName %s\" directive is deprecated; consider "
2315 "using \"Require user @%s\" on line %d of %s.",
2316 value
, value
, linenum
, ConfigurationFile
);
2318 else if (!_cups_strcasecmp(line
, "Require"))
2321 * Apache synonym for AuthClass and AuthGroupName...
2325 * Require valid-user
2326 * Require group names
2327 * Require user names
2330 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2335 if (!_cups_strcasecmp(value
, "valid-user") ||
2336 !_cups_strcasecmp(value
, "user"))
2337 loc
->level
= CUPSD_AUTH_USER
;
2338 else if (!_cups_strcasecmp(value
, "group"))
2339 loc
->level
= CUPSD_AUTH_GROUP
;
2342 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d of %s.",
2343 value
, linenum
, ConfigurationFile
);
2348 * Get the list of names from the line...
2351 for (value
= valptr
; *value
;)
2353 while (_cups_isspace(*value
))
2356 #ifdef HAVE_AUTHORIZATION_H
2357 if (!strncmp(value
, "@AUTHKEY(", 9))
2360 * Grab "@AUTHKEY(name)" value...
2363 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2369 #endif /* HAVE_AUTHORIZATION_H */
2370 if (*value
== '\"' || *value
== '\'')
2373 * Grab quoted name...
2376 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2383 * Grab literal name.
2386 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2392 cupsdAddName(loc
, value
);
2394 for (value
= valptr
; _cups_isspace(*value
); value
++);
2397 else if (!_cups_strcasecmp(line
, "Satisfy"))
2399 if (!_cups_strcasecmp(value
, "all"))
2400 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2401 else if (!_cups_strcasecmp(value
, "any"))
2402 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2405 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d of %s.",
2406 value
, linenum
, ConfigurationFile
);
2418 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2421 static int /* O - FatalErrors bits */
2422 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2424 int fatal
; /* FatalErrors bits */
2425 char value
[1024], /* Value string */
2426 *valstart
, /* Pointer into value */
2427 *valend
; /* End of value */
2431 * Empty FatalErrors line yields NULL pointer...
2435 return (CUPSD_FATAL_NONE
);
2438 * Loop through the value string,...
2441 strlcpy(value
, s
, sizeof(value
));
2443 fatal
= CUPSD_FATAL_NONE
;
2445 for (valstart
= value
; *valstart
;)
2448 * Get the current space/comma-delimited kind name...
2451 for (valend
= valstart
; *valend
; valend
++)
2452 if (_cups_isspace(*valend
) || *valend
== ',')
2459 * Add the error to the bitmask...
2462 if (!_cups_strcasecmp(valstart
, "all"))
2463 fatal
= CUPSD_FATAL_ALL
;
2464 else if (!_cups_strcasecmp(valstart
, "browse"))
2465 fatal
|= CUPSD_FATAL_BROWSE
;
2466 else if (!_cups_strcasecmp(valstart
, "-browse"))
2467 fatal
&= ~CUPSD_FATAL_BROWSE
;
2468 else if (!_cups_strcasecmp(valstart
, "config"))
2469 fatal
|= CUPSD_FATAL_CONFIG
;
2470 else if (!_cups_strcasecmp(valstart
, "-config"))
2471 fatal
&= ~CUPSD_FATAL_CONFIG
;
2472 else if (!_cups_strcasecmp(valstart
, "listen"))
2473 fatal
|= CUPSD_FATAL_LISTEN
;
2474 else if (!_cups_strcasecmp(valstart
, "-listen"))
2475 fatal
&= ~CUPSD_FATAL_LISTEN
;
2476 else if (!_cups_strcasecmp(valstart
, "log"))
2477 fatal
|= CUPSD_FATAL_LOG
;
2478 else if (!_cups_strcasecmp(valstart
, "-log"))
2479 fatal
&= ~CUPSD_FATAL_LOG
;
2480 else if (!_cups_strcasecmp(valstart
, "permissions"))
2481 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2482 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2483 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2484 else if (_cups_strcasecmp(valstart
, "none"))
2485 cupsdLogMessage(CUPSD_LOG_ERROR
,
2486 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2488 for (valstart
= valend
; *valstart
; valstart
++)
2489 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2498 * 'parse_groups()' - Parse system group names in a string.
2501 static int /* O - 1 on success, 0 on failure */
2502 parse_groups(const char *s
, /* I - Space-delimited groups */
2503 int linenum
) /* I - Line number in cups-files.conf */
2505 int status
; /* Return status */
2506 char value
[1024], /* Value string */
2507 *valstart
, /* Pointer into value */
2508 *valend
, /* End of value */
2509 quote
; /* Quote character */
2510 struct group
*group
; /* Group */
2514 * Make a copy of the string and parse out the groups...
2517 strlcpy(value
, s
, sizeof(value
));
2522 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2524 if (*valstart
== '\'' || *valstart
== '\"')
2527 * Scan quoted name...
2530 quote
= *valstart
++;
2532 for (valend
= valstart
; *valend
; valend
++)
2533 if (*valend
== quote
)
2539 * Scan space or comma-delimited name...
2542 for (valend
= valstart
; *valend
; valend
++)
2543 if (_cups_isspace(*valend
) || *valend
== ',')
2550 group
= getgrnam(valstart
);
2553 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2554 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2561 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown SystemGroup \"%s\" on line %d of %s.", valstart
, linenum
, CupsFilesFile
);
2563 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown default SystemGroup \"%s\".", valstart
);
2572 while (*valstart
== ',' || _cups_isspace(*valstart
))
2581 * 'parse_protocols()' - Parse browse protocols in a string.
2584 static int /* O - Browse protocol bits */
2585 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2587 int protocols
; /* Browse protocol bits */
2588 char value
[1024], /* Value string */
2589 *valstart
, /* Pointer into value */
2590 *valend
; /* End of value */
2594 * Empty protocol line yields NULL pointer...
2601 * Loop through the value string,...
2604 strlcpy(value
, s
, sizeof(value
));
2608 for (valstart
= value
; *valstart
;)
2611 * Get the current space/comma-delimited protocol name...
2614 for (valend
= valstart
; *valend
; valend
++)
2615 if (_cups_isspace(*valend
) || *valend
== ',')
2622 * Add the protocol to the bitmask...
2625 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2626 !_cups_strcasecmp(valstart
, "dns-sd") ||
2627 !_cups_strcasecmp(valstart
, "bonjour"))
2628 protocols
|= BROWSE_DNSSD
;
2629 else if (!_cups_strcasecmp(valstart
, "all"))
2630 protocols
|= BROWSE_ALL
;
2631 else if (_cups_strcasecmp(valstart
, "none"))
2632 cupsdLogMessage(CUPSD_LOG_ERROR
,
2633 "Unknown browse protocol \"%s\" ignored.", valstart
);
2635 for (valstart
= valend
; *valstart
; valstart
++)
2636 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2645 * 'parse_variable()' - Parse a variable line.
2648 static int /* O - 1 on success, 0 on failure */
2650 const char *filename
, /* I - Name of configuration file */
2651 int linenum
, /* I - Line in configuration file */
2652 const char *line
, /* I - Line from configuration file */
2653 const char *value
, /* I - Value from configuration file */
2654 size_t num_vars
, /* I - Number of variables */
2655 const cupsd_var_t
*vars
) /* I - Variables */
2657 size_t i
; /* Looping var */
2658 const cupsd_var_t
*var
; /* Variables */
2659 char temp
[1024]; /* Temporary string */
2662 for (i
= num_vars
, var
= vars
; i
> 0; i
--, var
++)
2663 if (!_cups_strcasecmp(line
, var
->name
))
2669 * Unknown directive! Output an error message and continue...
2673 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d of %s.",
2674 line
, linenum
, filename
);
2676 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d of %s.",
2677 line
, linenum
, filename
);
2684 case CUPSD_VARTYPE_INTEGER
:
2687 cupsdLogMessage(CUPSD_LOG_ERROR
,
2688 "Missing integer value for %s on line %d of %s.",
2689 line
, linenum
, filename
);
2692 else if (!isdigit(*value
& 255))
2694 cupsdLogMessage(CUPSD_LOG_ERROR
,
2695 "Bad integer value for %s on line %d of %s.",
2696 line
, linenum
, filename
);
2702 char *units
; /* Units */
2704 n
= strtol(value
, &units
, 0);
2706 if (units
&& *units
)
2708 if (tolower(units
[0] & 255) == 'g')
2709 n
*= 1024 * 1024 * 1024;
2710 else if (tolower(units
[0] & 255) == 'm')
2712 else if (tolower(units
[0] & 255) == 'k')
2714 else if (tolower(units
[0] & 255) == 't')
2718 cupsdLogMessage(CUPSD_LOG_ERROR
,
2719 "Unknown integer value for %s on line %d of %s.",
2720 line
, linenum
, filename
);
2727 cupsdLogMessage(CUPSD_LOG_ERROR
,
2728 "Bad negative integer value for %s on line %d of "
2729 "%s.", line
, linenum
, filename
);
2734 *((int *)var
->ptr
) = n
;
2739 case CUPSD_VARTYPE_PERM
:
2742 cupsdLogMessage(CUPSD_LOG_ERROR
,
2743 "Missing permissions value for %s on line %d of %s.",
2744 line
, linenum
, filename
);
2747 else if (!isdigit(*value
& 255))
2749 /* TODO: Add chmod UGO syntax support */
2750 cupsdLogMessage(CUPSD_LOG_ERROR
,
2751 "Bad permissions value for %s on line %d of %s.",
2752 line
, linenum
, filename
);
2757 int n
= strtol(value
, NULL
, 8);
2758 /* Permissions value */
2762 cupsdLogMessage(CUPSD_LOG_ERROR
,
2763 "Bad negative permissions value for %s on line %d of "
2764 "%s.", line
, linenum
, filename
);
2769 *((mode_t
*)var
->ptr
) = (mode_t
)n
;
2774 case CUPSD_VARTYPE_TIME
:
2777 cupsdLogMessage(CUPSD_LOG_ERROR
,
2778 "Missing time interval value for %s on line %d of "
2779 "%s.", line
, linenum
, filename
);
2782 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
2783 (!_cups_strcasecmp(value
, "true") ||
2784 !_cups_strcasecmp(value
, "on") ||
2785 !_cups_strcasecmp(value
, "enabled") ||
2786 !_cups_strcasecmp(value
, "yes")))
2788 *((int *)var
->ptr
) = INT_MAX
;
2790 else if (!_cups_strcasecmp(value
, "false") ||
2791 !_cups_strcasecmp(value
, "off") ||
2792 !_cups_strcasecmp(value
, "disabled") ||
2793 !_cups_strcasecmp(value
, "no"))
2795 *((int *)var
->ptr
) = 0;
2797 else if (!isdigit(*value
& 255))
2799 cupsdLogMessage(CUPSD_LOG_ERROR
,
2800 "Unknown time interval value for %s on line %d of "
2801 "%s.", line
, linenum
, filename
);
2806 double n
; /* Number */
2807 char *units
; /* Units */
2809 n
= strtod(value
, &units
);
2811 if (units
&& *units
)
2813 if (tolower(units
[0] & 255) == 'w')
2814 n
*= 7 * 24 * 60 * 60;
2815 else if (tolower(units
[0] & 255) == 'd')
2817 else if (tolower(units
[0] & 255) == 'h')
2819 else if (tolower(units
[0] & 255) == 'm')
2823 cupsdLogMessage(CUPSD_LOG_ERROR
,
2824 "Unknown time interval value for %s on line "
2825 "%d of %s.", line
, linenum
, filename
);
2830 if (n
< 0.0 || n
> INT_MAX
)
2832 cupsdLogMessage(CUPSD_LOG_ERROR
,
2833 "Bad time value for %s on line %d of %s.",
2834 line
, linenum
, filename
);
2839 *((int *)var
->ptr
) = (int)n
;
2844 case CUPSD_VARTYPE_BOOLEAN
:
2847 cupsdLogMessage(CUPSD_LOG_ERROR
,
2848 "Missing boolean value for %s on line %d of %s.",
2849 line
, linenum
, filename
);
2852 else if (!_cups_strcasecmp(value
, "true") ||
2853 !_cups_strcasecmp(value
, "on") ||
2854 !_cups_strcasecmp(value
, "enabled") ||
2855 !_cups_strcasecmp(value
, "yes") ||
2858 *((int *)var
->ptr
) = TRUE
;
2860 else if (!_cups_strcasecmp(value
, "false") ||
2861 !_cups_strcasecmp(value
, "off") ||
2862 !_cups_strcasecmp(value
, "disabled") ||
2863 !_cups_strcasecmp(value
, "no") ||
2864 !_cups_strcasecmp(value
, "0"))
2866 *((int *)var
->ptr
) = FALSE
;
2870 cupsdLogMessage(CUPSD_LOG_ERROR
,
2871 "Unknown boolean value %s on line %d of %s.",
2872 value
, linenum
, filename
);
2877 case CUPSD_VARTYPE_PATHNAME
:
2880 cupsdLogMessage(CUPSD_LOG_ERROR
,
2881 "Missing pathname value for %s on line %d of %s.",
2882 line
, linenum
, filename
);
2886 if (value
[0] == '/')
2887 strlcpy(temp
, value
, sizeof(temp
));
2889 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
2891 if (access(temp
, 0) && _cups_strcasecmp(value
, "internal") && _cups_strcasecmp(line
, "ServerKeychain"))
2893 cupsdLogMessage(CUPSD_LOG_ERROR
,
2894 "File or directory for \"%s %s\" on line %d of %s "
2895 "does not exist.", line
, value
, linenum
, filename
);
2899 cupsdSetString((char **)var
->ptr
, temp
);
2902 case CUPSD_VARTYPE_STRING
:
2903 cupsdSetString((char **)var
->ptr
, value
);
2912 * 'read_cupsd_conf()' - Read the cupsd.conf configuration file.
2915 static int /* O - 1 on success, 0 on failure */
2916 read_cupsd_conf(cups_file_t
*fp
) /* I - File to read from */
2918 int linenum
; /* Current line number */
2919 char line
[HTTP_MAX_BUFFER
],
2920 /* Line from file */
2921 temp
[HTTP_MAX_BUFFER
],
2922 /* Temporary buffer for value */
2923 *value
, /* Pointer to value */
2924 *valueptr
; /* Pointer into value */
2925 int valuelen
; /* Length of value */
2926 http_addrlist_t
*addrlist
, /* Address list */
2927 *addr
; /* Current address */
2928 cups_file_t
*incfile
; /* Include file */
2929 char incname
[1024]; /* Include filename */
2933 * Loop through each line in the file...
2938 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2941 * Decode the directive...
2944 if (!_cups_strcasecmp(line
, "Include") && value
)
2950 if (value
[0] == '/')
2951 strlcpy(incname
, value
, sizeof(incname
));
2953 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2955 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2956 cupsdLogMessage(CUPSD_LOG_ERROR
,
2957 "Unable to include config file \"%s\" - %s",
2958 incname
, strerror(errno
));
2961 read_cupsd_conf(incfile
);
2962 cupsFileClose(incfile
);
2965 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2971 linenum
= read_location(fp
, value
, linenum
);
2975 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2981 linenum
= read_policy(fp
, value
, linenum
);
2985 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2987 JobRetryInterval
= atoi(value
);
2988 cupsdLogMessage(CUPSD_LOG_WARN
,
2989 "FaxRetryInterval is deprecated; use "
2990 "JobRetryInterval on line %d of %s.", linenum
, ConfigurationFile
);
2992 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2994 JobRetryLimit
= atoi(value
);
2995 cupsdLogMessage(CUPSD_LOG_WARN
,
2996 "FaxRetryLimit is deprecated; use "
2997 "JobRetryLimit on line %d of %s.", linenum
, ConfigurationFile
);
3000 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3003 * SSLOptions [AllowRC4] [AllowSSL3] [AllowDH] [DenyCBC] [DenyTLS1.0] [None]
3006 int options
= _HTTP_TLS_NONE
,/* SSL/TLS options */
3007 min_version
= _HTTP_TLS_1_0
,
3008 max_version
= _HTTP_TLS_MAX
;
3012 char *start
, /* Start of option */
3013 *end
; /* End of option */
3015 for (start
= value
; *start
; start
= end
)
3018 * Find end of keyword...
3022 while (*end
&& !_cups_isspace(*end
))
3032 if (!_cups_strcasecmp(start
, "AllowRC4"))
3033 options
|= _HTTP_TLS_ALLOW_RC4
;
3034 else if (!_cups_strcasecmp(start
, "AllowSSL3"))
3035 min_version
= _HTTP_TLS_SSL3
;
3036 else if (!_cups_strcasecmp(start
, "AllowDH"))
3037 options
|= _HTTP_TLS_ALLOW_DH
;
3038 else if (!_cups_strcasecmp(start
, "DenyCBC"))
3039 options
|= _HTTP_TLS_DENY_CBC
;
3040 else if (!_cups_strcasecmp(start
, "DenyTLS1.0"))
3041 min_version
= _HTTP_TLS_1_1
;
3042 else if (!_cups_strcasecmp(start
, "MaxTLS1.0"))
3043 max_version
= _HTTP_TLS_1_0
;
3044 else if (!_cups_strcasecmp(start
, "MaxTLS1.1"))
3045 max_version
= _HTTP_TLS_1_1
;
3046 else if (!_cups_strcasecmp(start
, "MaxTLS1.2"))
3047 max_version
= _HTTP_TLS_1_2
;
3048 else if (!_cups_strcasecmp(start
, "MaxTLS1.3"))
3049 max_version
= _HTTP_TLS_1_3
;
3050 else if (!_cups_strcasecmp(start
, "MinTLS1.0"))
3051 min_version
= _HTTP_TLS_1_0
;
3052 else if (!_cups_strcasecmp(start
, "MinTLS1.1"))
3053 min_version
= _HTTP_TLS_1_1
;
3054 else if (!_cups_strcasecmp(start
, "MinTLS1.2"))
3055 min_version
= _HTTP_TLS_1_2
;
3056 else if (!_cups_strcasecmp(start
, "MinTLS1.3"))
3057 min_version
= _HTTP_TLS_1_3
;
3058 else if (!_cups_strcasecmp(start
, "None"))
3059 options
= _HTTP_TLS_NONE
;
3060 else if (_cups_strcasecmp(start
, "NoEmptyFragments"))
3061 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown SSL option %s at line %d.", start
, linenum
);
3065 _httpTLSSetOptions(options
, min_version
, max_version
);
3067 #endif /* HAVE_SSL */
3068 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
3070 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
3071 #endif /* HAVE_SSL */
3075 * Add listening address(es) to the list...
3078 cupsd_listener_t
*lis
; /* New listeners array */
3082 * Get the address list...
3085 addrlist
= get_address(value
, IPP_PORT
);
3089 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
3095 * Add each address...
3098 for (addr
= addrlist
; addr
; addr
= addr
->next
)
3101 * See if this address is already present...
3104 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
3106 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
3107 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
3108 httpAddrPort(&(addr
->addr
)) == httpAddrPort(&(lis
->address
)))
3113 #ifdef HAVE_ONDEMAND
3114 if (!lis
->on_demand
)
3115 #endif /* HAVE_ONDEMAND */
3117 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3118 cupsdLogMessage(CUPSD_LOG_WARN
,
3119 "Duplicate listen address \"%s\" ignored.", temp
);
3126 * Allocate another listener...
3130 Listeners
= cupsArrayNew(NULL
, NULL
);
3134 cupsdLogMessage(CUPSD_LOG_ERROR
,
3135 "Unable to allocate %s at line %d - %s.",
3136 line
, linenum
, strerror(errno
));
3140 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
3142 cupsdLogMessage(CUPSD_LOG_ERROR
,
3143 "Unable to allocate %s at line %d - %s.",
3144 line
, linenum
, strerror(errno
));
3148 cupsArrayAdd(Listeners
, lis
);
3151 * Copy the current address and log it...
3154 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
3158 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
3159 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
3160 #endif /* HAVE_SSL */
3162 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3165 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
3166 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
3168 #endif /* AF_LOCAL */
3169 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
3170 httpAddrPort(&(lis
->address
)),
3171 httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
3173 if (!httpAddrLocalhost(&(lis
->address
)))
3174 RemotePort
= httpAddrPort(&(lis
->address
));
3181 httpAddrFreeList(addrlist
);
3183 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
3184 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
3187 * "BrowseProtocols name [... name]"
3188 * "BrowseLocalProtocols name [... name]"
3191 int protocols
= parse_protocols(value
);
3195 cupsdLogMessage(CUPSD_LOG_ERROR
,
3196 "Unknown browse protocol \"%s\" on line %d of %s.",
3197 value
, linenum
, ConfigurationFile
);
3201 BrowseLocalProtocols
= protocols
;
3203 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
3206 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3209 if (!_cups_strcasecmp(value
, "none"))
3210 default_auth_type
= CUPSD_AUTH_NONE
;
3211 else if (!_cups_strcasecmp(value
, "basic"))
3212 default_auth_type
= CUPSD_AUTH_BASIC
;
3213 else if (!_cups_strcasecmp(value
, "negotiate"))
3214 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
3215 else if (!_cups_strcasecmp(value
, "auto"))
3216 default_auth_type
= CUPSD_AUTH_AUTO
;
3219 cupsdLogMessage(CUPSD_LOG_WARN
,
3220 "Unknown default authorization type %s on line %d of %s.",
3221 value
, linenum
, ConfigurationFile
);
3222 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3227 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
3230 * DefaultEncryption {Never,IfRequested,Required}
3233 if (!value
|| !_cups_strcasecmp(value
, "never"))
3234 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3235 else if (!_cups_strcasecmp(value
, "required"))
3236 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3237 else if (!_cups_strcasecmp(value
, "ifrequested"))
3238 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3241 cupsdLogMessage(CUPSD_LOG_WARN
,
3242 "Unknown default encryption %s on line %d of %s.",
3243 value
, linenum
, ConfigurationFile
);
3244 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3248 #endif /* HAVE_SSL */
3249 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
3252 * Do hostname lookups?
3255 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
3256 !_cups_strcasecmp(value
, "false"))
3257 HostNameLookups
= 0;
3258 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
3259 !_cups_strcasecmp(value
, "true"))
3260 HostNameLookups
= 1;
3261 else if (!_cups_strcasecmp(value
, "double"))
3262 HostNameLookups
= 2;
3264 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d of %s.",
3265 value
, linenum
, ConfigurationFile
);
3267 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
3270 * Amount of logging to do to access log...
3273 if (!_cups_strcasecmp(value
, "all"))
3274 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3275 else if (!_cups_strcasecmp(value
, "actions"))
3276 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3277 else if (!_cups_strcasecmp(value
, "config"))
3278 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3279 else if (!_cups_strcasecmp(value
, "none"))
3280 AccessLogLevel
= CUPSD_ACCESSLOG_NONE
;
3282 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d of %s.",
3283 value
, linenum
, ConfigurationFile
);
3285 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
3288 * Amount of logging to do to error log...
3291 if (!_cups_strcasecmp(value
, "debug2"))
3292 LogLevel
= CUPSD_LOG_DEBUG2
;
3293 else if (!_cups_strcasecmp(value
, "debug"))
3294 LogLevel
= CUPSD_LOG_DEBUG
;
3295 else if (!_cups_strcasecmp(value
, "info"))
3296 LogLevel
= CUPSD_LOG_INFO
;
3297 else if (!_cups_strcasecmp(value
, "notice"))
3298 LogLevel
= CUPSD_LOG_NOTICE
;
3299 else if (!_cups_strcasecmp(value
, "warn"))
3300 LogLevel
= CUPSD_LOG_WARN
;
3301 else if (!_cups_strcasecmp(value
, "error"))
3302 LogLevel
= CUPSD_LOG_ERROR
;
3303 else if (!_cups_strcasecmp(value
, "crit"))
3304 LogLevel
= CUPSD_LOG_CRIT
;
3305 else if (!_cups_strcasecmp(value
, "alert"))
3306 LogLevel
= CUPSD_LOG_ALERT
;
3307 else if (!_cups_strcasecmp(value
, "emerg"))
3308 LogLevel
= CUPSD_LOG_EMERG
;
3309 else if (!_cups_strcasecmp(value
, "none"))
3310 LogLevel
= CUPSD_LOG_NONE
;
3312 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d of %s.",
3313 value
, linenum
, ConfigurationFile
);
3315 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
3318 * Amount of logging to do to error log...
3321 if (!_cups_strcasecmp(value
, "standard"))
3322 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3323 else if (!_cups_strcasecmp(value
, "usecs"))
3324 LogTimeFormat
= CUPSD_TIME_USECS
;
3326 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d of %s.",
3327 value
, linenum
, ConfigurationFile
);
3329 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
3332 * Set the string used for the Server header...
3335 struct utsname plat
; /* Platform info */
3340 if (!_cups_strcasecmp(value
, "ProductOnly"))
3341 cupsdSetString(&ServerHeader
, "CUPS IPP");
3342 else if (!_cups_strcasecmp(value
, "Major"))
3343 cupsdSetStringf(&ServerHeader
, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR
);
3344 else if (!_cups_strcasecmp(value
, "Minor"))
3345 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
3346 CUPS_VERSION_MINOR
);
3347 else if (!_cups_strcasecmp(value
, "Minimal"))
3348 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
" IPP/2.1");
3349 else if (!_cups_strcasecmp(value
, "OS"))
3350 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s) IPP/2.1",
3351 plat
.sysname
, plat
.release
);
3352 else if (!_cups_strcasecmp(value
, "Full"))
3353 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s; %s) IPP/2.1",
3354 plat
.sysname
, plat
.release
, plat
.machine
);
3355 else if (!_cups_strcasecmp(value
, "None"))
3356 cupsdSetString(&ServerHeader
, "");
3358 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d of %s.",
3359 value
, linenum
, ConfigurationFile
);
3361 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3364 * PassEnv variable [... variable]
3369 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3370 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3373 if (value
[valuelen
])
3375 value
[valuelen
] = '\0';
3379 cupsdSetEnv(value
, NULL
);
3381 for (value
+= valuelen
; *value
; value
++)
3382 if (!_cups_isspace(*value
) || *value
!= ',')
3386 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3389 * ServerAlias name [... name]
3393 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3397 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3398 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3401 if (value
[valuelen
])
3403 value
[valuelen
] = '\0';
3407 cupsdAddAlias(ServerAlias
, value
);
3409 for (value
+= valuelen
; *value
; value
++)
3410 if (!_cups_isspace(*value
) || *value
!= ',')
3414 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3417 * SetEnv variable value
3420 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3428 while (isspace(*valueptr
& 255))
3431 cupsdSetEnv(value
, valueptr
);
3434 cupsdLogMessage(CUPSD_LOG_ERROR
,
3435 "Missing value for SetEnv directive on line %d of %s.",
3436 linenum
, ConfigurationFile
);
3438 else if (!_cups_strcasecmp(line
, "AccessLog") ||
3439 !_cups_strcasecmp(line
, "CacheDir") ||
3440 !_cups_strcasecmp(line
, "ConfigFilePerm") ||
3441 !_cups_strcasecmp(line
, "DataDir") ||
3442 !_cups_strcasecmp(line
, "DocumentRoot") ||
3443 !_cups_strcasecmp(line
, "ErrorLog") ||
3444 !_cups_strcasecmp(line
, "FatalErrors") ||
3445 !_cups_strcasecmp(line
, "FileDevice") ||
3446 !_cups_strcasecmp(line
, "FontPath") ||
3447 !_cups_strcasecmp(line
, "Group") ||
3448 !_cups_strcasecmp(line
, "LogFilePerm") ||
3449 !_cups_strcasecmp(line
, "LPDConfigFile") ||
3450 !_cups_strcasecmp(line
, "PageLog") ||
3451 !_cups_strcasecmp(line
, "Printcap") ||
3452 !_cups_strcasecmp(line
, "PrintcapFormat") ||
3453 !_cups_strcasecmp(line
, "RemoteRoot") ||
3454 !_cups_strcasecmp(line
, "RequestRoot") ||
3455 !_cups_strcasecmp(line
, "ServerBin") ||
3456 !_cups_strcasecmp(line
, "ServerCertificate") ||
3457 !_cups_strcasecmp(line
, "ServerKey") ||
3458 !_cups_strcasecmp(line
, "ServerKeychain") ||
3459 !_cups_strcasecmp(line
, "ServerRoot") ||
3460 !_cups_strcasecmp(line
, "SMBConfigFile") ||
3461 !_cups_strcasecmp(line
, "StateDir") ||
3462 !_cups_strcasecmp(line
, "SystemGroup") ||
3463 !_cups_strcasecmp(line
, "SystemGroupAuthKey") ||
3464 !_cups_strcasecmp(line
, "TempDir") ||
3465 !_cups_strcasecmp(line
, "User"))
3467 cupsdLogMessage(CUPSD_LOG_INFO
,
3468 "Please move \"%s%s%s\" on line %d of %s to the %s file; "
3469 "this will become an error in a future release.",
3470 line
, value
? " " : "", value
? value
: "", linenum
,
3471 ConfigurationFile
, CupsFilesFile
);
3474 parse_variable(ConfigurationFile
, linenum
, line
, value
,
3475 sizeof(cupsd_vars
) / sizeof(cupsd_vars
[0]), cupsd_vars
);
3483 * 'read_cups_files_conf()' - Read the cups-files.conf configuration file.
3486 static int /* O - 1 on success, 0 on failure */
3487 read_cups_files_conf(cups_file_t
*fp
) /* I - File to read from */
3489 int linenum
; /* Current line number */
3490 char line
[HTTP_MAX_BUFFER
], /* Line from file */
3491 *value
; /* Value from line */
3492 struct group
*group
; /* Group */
3496 * Loop through each line in the file...
3501 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3503 if (!_cups_strcasecmp(line
, "FatalErrors"))
3504 FatalErrors
= parse_fatal_errors(value
);
3505 else if (!_cups_strcasecmp(line
, "Group") && value
)
3508 * Group ID to run as...
3511 if (isdigit(value
[0]))
3512 Group
= (gid_t
)atoi(value
);
3516 group
= getgrnam(value
);
3519 Group
= group
->gr_gid
;
3522 cupsdLogMessage(CUPSD_LOG_ERROR
,
3523 "Unknown Group \"%s\" on line %d of %s.", value
,
3524 linenum
, CupsFilesFile
);
3525 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3530 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
3533 * Format of printcap file?
3536 if (!_cups_strcasecmp(value
, "bsd"))
3537 PrintcapFormat
= PRINTCAP_BSD
;
3538 else if (!_cups_strcasecmp(value
, "plist"))
3539 PrintcapFormat
= PRINTCAP_PLIST
;
3540 else if (!_cups_strcasecmp(value
, "solaris"))
3541 PrintcapFormat
= PRINTCAP_SOLARIS
;
3544 cupsdLogMessage(CUPSD_LOG_ERROR
,
3545 "Unknown PrintcapFormat \"%s\" on line %d of %s.",
3546 value
, linenum
, CupsFilesFile
);
3547 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3551 else if (!_cups_strcasecmp(line
, "Sandboxing") && value
)
3554 * Level of sandboxing?
3557 if (!_cups_strcasecmp(value
, "off") && getuid())
3559 Sandboxing
= CUPSD_SANDBOXING_OFF
;
3560 cupsdLogMessage(CUPSD_LOG_WARN
, "Disabling sandboxing is not recommended (line %d of %s)", linenum
, CupsFilesFile
);
3562 else if (!_cups_strcasecmp(value
, "relaxed"))
3563 Sandboxing
= CUPSD_SANDBOXING_RELAXED
;
3564 else if (!_cups_strcasecmp(value
, "strict"))
3565 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
3568 cupsdLogMessage(CUPSD_LOG_ERROR
,
3569 "Unknown Sandboxing \"%s\" on line %d of %s.",
3570 value
, linenum
, CupsFilesFile
);
3571 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3575 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
3578 * SystemGroup (admin) group(s)...
3581 if (!parse_groups(value
, linenum
))
3583 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3587 else if (!_cups_strcasecmp(line
, "User") && value
)
3590 * User ID to run as...
3593 if (isdigit(value
[0] & 255))
3595 int uid
= atoi(value
);
3599 cupsdLogMessage(CUPSD_LOG_ERROR
,
3600 "Will not use User 0 as specified on line %d of %s "
3601 "for security reasons. You must use a non-"
3602 "privileged account instead.",
3603 linenum
, CupsFilesFile
);
3604 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3608 User
= (uid_t
)atoi(value
);
3612 struct passwd
*p
; /* Password information */
3615 p
= getpwnam(value
);
3621 cupsdLogMessage(CUPSD_LOG_ERROR
,
3622 "Will not use User %s (UID=0) as specified on line "
3623 "%d of %s for security reasons. You must use a "
3624 "non-privileged account instead.",
3625 value
, linenum
, CupsFilesFile
);
3626 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3634 cupsdLogMessage(CUPSD_LOG_ERROR
,
3635 "Unknown User \"%s\" on line %d of %s.",
3636 value
, linenum
, CupsFilesFile
);
3637 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3642 else if (!_cups_strcasecmp(line
, "ServerCertificate") ||
3643 !_cups_strcasecmp(line
, "ServerKey"))
3645 cupsdLogMessage(CUPSD_LOG_INFO
,
3646 "The \"%s\" directive on line %d of %s is no longer "
3647 "supported; this will become an error in a future "
3649 line
, linenum
, CupsFilesFile
);
3651 else if (!parse_variable(CupsFilesFile
, linenum
, line
, value
,
3652 sizeof(cupsfiles_vars
) / sizeof(cupsfiles_vars
[0]),
3654 (FatalErrors
& CUPSD_FATAL_CONFIG
))
3663 * 'read_location()' - Read a <Location path> definition.
3666 static int /* O - New line number or 0 on error */
3667 read_location(cups_file_t
*fp
, /* I - Configuration file */
3668 char *location
, /* I - Location name/path */
3669 int linenum
) /* I - Current line number */
3671 cupsd_location_t
*loc
, /* New location */
3672 *parent
; /* Parent location */
3673 char line
[HTTP_MAX_BUFFER
],
3675 *value
, /* Value for directive */
3676 *valptr
; /* Pointer into value */
3679 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3680 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d of %s.",
3681 location
, linenum
, ConfigurationFile
);
3682 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3686 cupsdAddLocation(parent
);
3688 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3693 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3696 * Decode the directive...
3699 if (!_cups_strcasecmp(line
, "</Location>"))
3701 else if (!_cups_strcasecmp(line
, "<Limit") ||
3702 !_cups_strcasecmp(line
, "<LimitExcept"))
3706 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3707 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3713 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3716 cupsdAddLocation(loc
);
3721 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3726 if (!strcmp(value
, "ALL"))
3727 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3728 else if (!strcmp(value
, "GET"))
3729 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3730 else if (!strcmp(value
, "HEAD"))
3731 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3732 else if (!strcmp(value
, "OPTIONS"))
3733 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3734 else if (!strcmp(value
, "POST"))
3735 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3736 else if (!strcmp(value
, "PUT"))
3737 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3738 else if (!strcmp(value
, "TRACE"))
3739 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3741 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d of %s.",
3742 value
, linenum
, ConfigurationFile
);
3744 for (value
= valptr
; isspace(*value
& 255); value
++);
3747 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3748 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3750 parent
->limit
&= ~loc
->limit
;
3752 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3753 !_cups_strcasecmp(line
, "</LimitExcept>"))
3757 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3758 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3761 else if (!parse_aaa(loc
, line
, value
, linenum
))
3763 cupsdLogMessage(CUPSD_LOG_ERROR
,
3764 "Unknown Location directive %s on line %d of %s.",
3765 line
, linenum
, ConfigurationFile
);
3766 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3771 cupsdLogMessage(CUPSD_LOG_ERROR
,
3772 "Unexpected end-of-file at line %d while reading location.",
3775 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3780 * 'read_policy()' - Read a <Policy name> definition.
3783 static int /* O - New line number or 0 on error */
3784 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3785 char *policy
, /* I - Location name/path */
3786 int linenum
) /* I - Current line number */
3788 int i
; /* Looping var */
3789 cupsd_policy_t
*pol
; /* Policy */
3790 cupsd_location_t
*op
; /* Policy operation */
3791 int num_ops
; /* Number of IPP operations */
3792 ipp_op_t ops
[100]; /* Operations */
3793 char line
[HTTP_MAX_BUFFER
],
3795 *value
, /* Value for directive */
3796 *valptr
; /* Pointer into value */
3800 * Create the policy...
3803 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3804 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d of %s.",
3805 policy
, linenum
, ConfigurationFile
);
3806 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3810 * Read from the file...
3816 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3819 * Decode the directive...
3822 if (!_cups_strcasecmp(line
, "</Policy>"))
3825 cupsdLogMessage(CUPSD_LOG_WARN
,
3826 "Missing </Limit> before </Policy> on line %d of %s.",
3827 linenum
, ConfigurationFile
);
3829 set_policy_defaults(pol
);
3833 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3837 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3838 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3845 * Scan for IPP operation names...
3852 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3857 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3859 if (!_cups_strcasecmp(value
, "All"))
3860 ops
[num_ops
] = IPP_ANY_OPERATION
;
3861 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3862 cupsdLogMessage(CUPSD_LOG_ERROR
,
3863 "Bad IPP operation name \"%s\" on line %d of %s.",
3864 value
, linenum
, ConfigurationFile
);
3869 cupsdLogMessage(CUPSD_LOG_ERROR
,
3870 "Too many operations listed on line %d of %s.",
3871 linenum
, ConfigurationFile
);
3873 for (value
= valptr
; isspace(*value
& 255); value
++);
3877 * If none are specified, apply the policy to all operations...
3882 ops
[0] = IPP_ANY_OPERATION
;
3887 * Add a new policy for the first operation...
3890 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3892 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3895 * Finish the current operation limit...
3901 * Copy the policy to the other operations...
3904 for (i
= 1; i
< num_ops
; i
++)
3905 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3912 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3913 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3916 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3917 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3918 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3919 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3923 cupsdLogMessage(CUPSD_LOG_ERROR
,
3924 "%s directive must appear outside <Limit>...</Limit> "
3925 "on line %d of %s.", line
, linenum
, ConfigurationFile
);
3926 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3932 * Pull out whitespace-delimited values...
3938 * Find the end of the current value...
3941 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3947 * Save it appropriately...
3950 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3953 * JobPrivateAccess {all|default|user/group list|@@ACL}
3956 if (!_cups_strcasecmp(value
, "default"))
3958 cupsdAddString(&(pol
->job_access
), "@OWNER");
3959 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3962 cupsdAddString(&(pol
->job_access
), value
);
3964 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3967 * JobPrivateValues {all|none|default|attribute list}
3970 if (!_cups_strcasecmp(value
, "default"))
3972 cupsdAddString(&(pol
->job_attrs
), "job-name");
3973 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3974 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3975 cupsdAddString(&(pol
->job_attrs
), "phone");
3978 cupsdAddString(&(pol
->job_attrs
), value
);
3980 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3983 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3986 if (!_cups_strcasecmp(value
, "default"))
3988 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3989 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3992 cupsdAddString(&(pol
->sub_access
), value
);
3994 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3997 * SubscriptionPrivateValues {all|none|default|attribute list}
4000 if (!_cups_strcasecmp(value
, "default"))
4002 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4003 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4004 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4005 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4006 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
4009 cupsdAddString(&(pol
->sub_attrs
), value
);
4013 * Find the next string on the line...
4016 for (value
= valptr
; isspace(*value
& 255); value
++);
4022 cupsdLogMessage(CUPSD_LOG_ERROR
,
4023 "Missing <Limit ops> directive before %s on line %d of %s.",
4024 line
, linenum
, ConfigurationFile
);
4025 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4028 else if (!parse_aaa(op
, line
, value
, linenum
))
4030 cupsdLogMessage(CUPSD_LOG_ERROR
,
4031 "Unknown Policy Limit directive %s on line %d of %s.",
4032 line
, linenum
, ConfigurationFile
);
4034 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4039 cupsdLogMessage(CUPSD_LOG_ERROR
,
4040 "Unexpected end-of-file at line %d while reading policy "
4041 "\"%s\".", linenum
, policy
);
4043 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
4048 * 'set_policy_defaults()' - Set default policy values as needed.
4052 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
4054 cupsd_location_t
*op
; /* Policy operation */
4058 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
4059 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
4060 * upgrades do not introduce new security issues...
4062 * CUPS STR #4659: Allow a lone <Limit All> policy.
4065 if (cupsArrayCount(pol
->ops
) > 1)
4067 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
4068 op
->op
== IPP_ANY_OPERATION
)
4070 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
4071 op
->op
!= IPP_ANY_OPERATION
)
4074 * Add a new limit for Validate-Job using the Print-Job limit as a
4078 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s - using Print-Job's policy.", pol
->name
);
4080 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
4083 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s and no suitable template found.", pol
->name
);
4086 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
4087 op
->op
== IPP_ANY_OPERATION
)
4089 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
4090 op
->op
!= IPP_ANY_OPERATION
)
4093 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
4097 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s - using Pause-Printer's policy.", pol
->name
);
4099 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
4102 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s and no suitable template found.", pol
->name
);
4105 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
4106 op
->op
== IPP_ANY_OPERATION
)
4108 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4109 op
->op
!= IPP_ANY_OPERATION
)
4112 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
4116 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-My-Jobs defined in policy %s - using Send-Document's policy.", pol
->name
);
4118 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
4121 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-My-Jobs defined in policy %s and no suitable template found.", pol
->name
);
4124 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
4125 op
->op
== IPP_ANY_OPERATION
)
4127 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4128 op
->op
!= IPP_ANY_OPERATION
)
4131 * Add a new limit for Close-Job using the Send-Document limit as a
4135 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s - using Send-Document's policy.", pol
->name
);
4137 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
4140 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s and no suitable template found.", pol
->name
);
4143 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
4144 op
->op
== IPP_ANY_OPERATION
)
4146 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4147 op
->op
!= IPP_ANY_OPERATION
)
4150 * Add a new limit for CUPS-Get-Document using the Send-Document
4151 * limit as a template...
4154 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s - using Send-Document's policy.", pol
->name
);
4156 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
4159 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s and no suitable template found.", pol
->name
);
4164 * Verify we have JobPrivateAccess, JobPrivateValues,
4165 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4168 if (!pol
->job_access
)
4170 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4171 cupsdAddString(&(pol
->job_access
), "@OWNER");
4172 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4175 if (!pol
->job_attrs
)
4177 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateValues defined in policy %s - using defaults.", pol
->name
);
4178 cupsdAddString(&(pol
->job_attrs
), "job-name");
4179 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4180 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4181 cupsdAddString(&(pol
->job_attrs
), "phone");
4184 if (!pol
->sub_access
)
4186 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4187 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4188 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4191 if (!pol
->sub_attrs
)
4193 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateValues defined in policy %s - using defaults.", pol
->name
);
4194 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4195 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4196 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4197 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4198 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");