2 * Configuration routines for the CUPS scheduler.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
18 #include <sys/utsname.h>
21 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
22 # define SD_JOURNAL_SUPPRESS_LOCATION
23 # include <systemd/sd-journal.h>
24 #endif /* HAVE_ASL_H */
29 #endif /* HAVE_LIBPAPER */
33 * Possibly missing network definitions...
37 # define INADDR_NONE 0xffffffff
38 #endif /* !INADDR_NONE */
42 * Configuration variable structure...
47 CUPSD_VARTYPE_INTEGER
, /* Integer option */
48 CUPSD_VARTYPE_TIME
, /* Time interval option */
49 CUPSD_VARTYPE_STRING
, /* String option */
50 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
51 CUPSD_VARTYPE_PATHNAME
, /* File/directory name option */
52 CUPSD_VARTYPE_PERM
/* File/directory permissions */
57 const char *name
; /* Name of variable */
58 void *ptr
; /* Pointer to variable */
59 cupsd_vartype_t type
; /* Type (int, string, address) */
67 static const cupsd_var_t cupsd_vars
[] =
69 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
70 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
71 { "BrowseDNSSDSubTypes", &DNSSDSubTypes
, CUPSD_VARTYPE_STRING
},
72 #endif /* HAVE_DNSSD || HAVE_AVAHI */
73 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
74 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
75 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
76 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
77 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
78 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_TIME
},
79 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
80 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
81 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
82 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_TIME
},
83 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
84 { "DNSSDHostName", &DNSSDHostName
, CUPSD_VARTYPE_STRING
},
85 #endif /* HAVE_DNSSD || HAVE_AVAHI */
86 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
87 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
88 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
90 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
91 #endif /* HAVE_GSSAPI */
93 { "IdleExitTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
94 #endif /* HAVE_ONDEMAND */
95 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_TIME
},
96 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
97 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_TIME
},
98 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_TIME
},
99 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
101 { "LaunchdTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
102 #endif /* HAVE_LAUNCHD */
103 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
104 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
105 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
106 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
107 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
108 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
109 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
110 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
111 { "MaxHoldTime", &MaxHoldTime
, CUPSD_VARTYPE_TIME
},
112 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
113 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
114 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
115 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_TIME
},
116 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_TIME
},
117 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
118 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
119 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
120 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
121 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
122 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
123 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_TIME
},
124 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
125 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_TIME
},
126 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_TIME
},
127 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_TIME
},
128 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
129 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_TIME
},
130 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
131 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
132 { "StrictConformance", &StrictConformance
, CUPSD_VARTYPE_BOOLEAN
},
133 { "Timeout", &Timeout
, CUPSD_VARTYPE_TIME
},
134 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
136 static const cupsd_var_t cupsfiles_vars
[] =
138 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
139 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
140 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_PERM
},
142 { "CreateSelfSignedCerts", &CreateSelfSignedCerts
, CUPSD_VARTYPE_BOOLEAN
},
143 #endif /* HAVE_SSL */
144 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
145 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
146 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
147 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
148 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
149 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_PERM
},
150 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
151 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
152 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
153 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
154 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
155 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
157 { "ServerKeychain", &ServerKeychain
, CUPSD_VARTYPE_PATHNAME
},
158 #endif /* HAVE_SSL */
159 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
160 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
161 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
162 { "SyncOnClose", &SyncOnClose
, CUPSD_VARTYPE_BOOLEAN
},
163 #ifdef HAVE_AUTHORIZATION_H
164 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
165 #endif /* HAVE_AUTHORIZATION_H */
166 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
}
169 static int default_auth_type
= CUPSD_AUTH_AUTO
;
170 /* Default AuthType, if not specified */
172 static const unsigned ones
[4] =
174 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
176 static const unsigned zeros
[4] =
178 0x00000000, 0x00000000, 0x00000000, 0x00000000
186 static http_addrlist_t
*get_address(const char *value
, int defport
);
187 static int get_addr_and_mask(const char *value
, unsigned *ip
,
189 static void mime_error_cb(void *ctx
, const char *message
);
190 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
191 char *value
, int linenum
);
192 static int parse_fatal_errors(const char *s
);
193 static int parse_groups(const char *s
, int linenum
);
194 static int parse_protocols(const char *s
);
195 static int parse_variable(const char *filename
, int linenum
,
196 const char *line
, const char *value
,
198 const cupsd_var_t
*vars
);
199 static int read_cupsd_conf(cups_file_t
*fp
);
200 static int read_cups_files_conf(cups_file_t
*fp
);
201 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
202 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
203 static void set_policy_defaults(cupsd_policy_t
*pol
);
207 * 'cupsdAddAlias()' - Add a host alias.
211 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
212 const char *name
) /* I - Name to add */
214 cupsd_alias_t
*a
; /* New alias */
215 size_t namelen
; /* Length of name */
218 namelen
= strlen(name
);
220 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
223 a
->namelen
= namelen
;
224 memcpy(a
->name
, name
, namelen
+ 1); /* OK since a->name is allocated */
226 cupsArrayAdd(aliases
, a
);
231 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
234 int /* O - 0 on success, -1 on error, 1 on warning */
235 cupsdCheckPermissions(
236 const char *filename
, /* I - File/directory name */
237 const char *suffix
, /* I - Additional file/directory name */
238 mode_t mode
, /* I - Permissions */
239 uid_t user
, /* I - Owner */
240 gid_t group
, /* I - Group */
241 int is_dir
, /* I - 1 = directory, 0 = file */
242 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
244 int dir_created
= 0; /* Did we create a directory? */
245 char pathname
[1024]; /* File name with prefix */
246 struct stat fileinfo
; /* Stat buffer */
247 int is_symlink
; /* Is "filename" a symlink? */
251 * Prepend the given root to the filename before testing it...
256 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
261 * See if we can stat the file/directory...
264 if (lstat(filename
, &fileinfo
))
266 if (errno
== ENOENT
&& create_dir
)
269 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
272 if (mkdir(filename
, mode
))
275 cupsdLogMessage(CUPSD_LOG_ERROR
,
276 "Unable to create directory \"%s\" - %s", filename
,
279 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
280 sd_journal_print(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
282 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
283 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
289 fileinfo
.st_mode
= mode
| S_IFDIR
;
292 return (create_dir
? -1 : 1);
295 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
297 if (stat(filename
, &fileinfo
))
299 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
300 filename
, strerror(errno
));
306 * Make sure it's a regular file or a directory as needed...
309 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
311 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
315 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
318 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
320 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
321 sd_journal_print(LOG_ERR
, "\"%s\" is not a directory.", filename
);
323 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
324 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
330 * If the filename is a symlink, do not change permissions (STR #2937)...
337 * Fix owner, group, and mode as needed...
340 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
343 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
346 if (chown(filename
, user
, group
) && !getuid())
349 cupsdLogMessage(CUPSD_LOG_ERROR
,
350 "Unable to change ownership of \"%s\" - %s", filename
,
353 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
354 sd_journal_print(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
356 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
357 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
363 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
366 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
369 if (chmod(filename
, mode
))
372 cupsdLogMessage(CUPSD_LOG_ERROR
,
373 "Unable to change permissions of \"%s\" - %s", filename
,
376 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
377 sd_journal_print(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
379 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
380 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
387 * Everything is OK...
395 * 'cupsdDefaultAuthType()' - Get the default AuthType.
397 * When the default_auth_type is "auto", this function tries to get the GSS
398 * credentials for the server. If that succeeds we use Kerberos authentication,
399 * otherwise we do a fallback to Basic authentication against the local user
403 int /* O - Default AuthType value */
404 cupsdDefaultAuthType(void)
407 OM_uint32 major_status
, /* Major status code */
408 minor_status
; /* Minor status code */
409 gss_name_t server_name
; /* Server name */
410 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
411 /* Service name token */
412 char buf
[1024]; /* Service name buffer */
413 #endif /* HAVE_GSSAPI */
417 * If we have already determined the correct default AuthType, use it...
420 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
421 return (default_auth_type
);
426 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
430 if (&gss_init_sec_context
== NULL
)
431 return (default_auth_type
= CUPSD_AUTH_BASIC
);
432 # endif /* __APPLE__ */
435 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
436 * that fails we must use Basic...
439 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
442 token
.length
= strlen(buf
);
443 server_name
= GSS_C_NO_NAME
;
444 major_status
= gss_import_name(&minor_status
, &token
,
445 GSS_C_NT_HOSTBASED_SERVICE
,
448 memset(&token
, 0, sizeof(token
));
450 if (GSS_ERROR(major_status
))
452 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
453 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
454 return (default_auth_type
= CUPSD_AUTH_BASIC
);
457 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
459 if (GSS_ERROR(major_status
))
461 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
462 "cupsdDefaultAuthType: gss_display_name(%s) failed",
464 return (default_auth_type
= CUPSD_AUTH_BASIC
);
467 cupsdLogMessage(CUPSD_LOG_DEBUG
,
468 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
469 "credentials for %s...", (char *)token
.value
);
471 ServerCreds
= GSS_C_NO_CREDENTIAL
;
472 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
473 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
474 &ServerCreds
, NULL
, NULL
);
475 if (GSS_ERROR(major_status
))
477 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
478 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
479 (char *)token
.value
);
480 gss_release_name(&minor_status
, &server_name
);
481 gss_release_buffer(&minor_status
, &token
);
482 return (default_auth_type
= CUPSD_AUTH_BASIC
);
485 cupsdLogMessage(CUPSD_LOG_DEBUG
,
486 "cupsdDefaultAuthType: Kerberos credentials acquired "
487 "successfully for %s.", (char *)token
.value
);
489 gss_release_name(&minor_status
, &server_name
);
490 gss_release_buffer(&minor_status
, &token
);
494 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
498 * No Kerberos support compiled in so just use Basic all the time...
501 return (default_auth_type
= CUPSD_AUTH_BASIC
);
502 #endif /* HAVE_GSSAPI */
507 * 'cupsdFreeAliases()' - Free all of the alias entries.
511 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
513 cupsd_alias_t
*a
; /* Current alias */
516 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
518 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
521 cupsArrayDelete(aliases
);
526 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
529 int /* O - 1 on success, 0 otherwise */
530 cupsdReadConfiguration(void)
532 int i
; /* Looping var */
533 cups_file_t
*fp
; /* Configuration file */
534 int status
; /* Return status */
535 char temp
[1024], /* Temporary buffer */
536 mimedir
[1024], /* MIME directory */
537 *slash
; /* Directory separator */
538 cups_lang_t
*language
; /* Language */
539 struct passwd
*user
; /* Default user */
540 struct group
*group
; /* Default group */
541 char *old_serverroot
, /* Old ServerRoot */
542 *old_requestroot
; /* Old RequestRoot */
543 int old_remote_port
; /* Old RemotePort */
544 const char *tmpdir
; /* TMPDIR environment variable */
545 struct stat tmpinfo
; /* Temporary directory info */
546 cupsd_policy_t
*p
; /* Policy */
550 * Save the old root paths...
553 old_serverroot
= NULL
;
554 cupsdSetString(&old_serverroot
, ServerRoot
);
555 old_requestroot
= NULL
;
556 cupsdSetString(&old_requestroot
, RequestRoot
);
559 * Reset the server configuration data...
562 cupsdDeleteAllLocations();
564 cupsdDeleteAllListeners();
566 old_remote_port
= RemotePort
;
573 cupsdFreeAliases(ServerAlias
);
576 cupsdClearString(&ServerName
);
577 cupsdClearString(&ServerAdmin
);
578 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
579 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
580 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
581 cupsdSetString(&DataDir
, CUPS_DATADIR
);
582 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
583 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
584 cupsdClearString(&ErrorLog
);
585 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
586 cupsdSetString(&PageLogFormat
,
587 "%p %u %j %T %P %C %{job-billing} "
588 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
589 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
590 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
591 cupsdSetString(&RemoteRoot
, "remroot");
592 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
594 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
596 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
597 PrintcapFormat
= PRINTCAP_SOLARIS
;
598 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
599 "/Library/Preferences/org.cups.printers.plist"))
600 PrintcapFormat
= PRINTCAP_PLIST
;
602 PrintcapFormat
= PRINTCAP_BSD
;
604 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
605 if ((slash
= strrchr(temp
, '/')) != NULL
)
608 cupsdSetString(&ServerRoot
, temp
);
610 cupsdClearString(&Classification
);
611 ClassifyOverride
= 0;
615 cupsdSetString(&ServerKeychain
, "ssl");
617 cupsdSetString(&ServerKeychain
, "/Library/Keychains/System.keychain");
618 # endif /* HAVE_GNUTLS */
620 _httpTLSSetOptions(_HTTP_TLS_NONE
, _HTTP_TLS_1_0
, _HTTP_TLS_MAX
);
621 #endif /* HAVE_SSL */
623 language
= cupsLangDefault();
625 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
626 cupsdSetString(&DefaultLanguage
, "en");
628 cupsdSetString(&DefaultLanguage
, language
->language
);
630 cupsdClearString(&DefaultPaperSize
);
632 cupsdSetString(&RIPCache
, "128m");
634 cupsdSetString(&TempDir
, NULL
);
637 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
641 OM_uint32 minor_status
; /* Minor status code */
643 gss_release_cred(&minor_status
, &ServerCreds
);
648 ServerCreds
= GSS_C_NO_CREDENTIAL
;
649 #endif /* HAVE_GSSAPI */
652 * Find the default user...
655 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
660 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
661 * complement number...)
670 * Find the default group...
673 group
= getgrnam(CUPS_DEFAULT_GROUP
);
677 Group
= group
->gr_gid
;
681 * Fallback to group "nobody"...
684 group
= getgrnam("nobody");
688 Group
= group
->gr_gid
;
692 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
693 * complement number...)
704 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
705 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
706 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
707 default_auth_type
= CUPSD_AUTH_BASIC
;
709 CreateSelfSignedCerts
= TRUE
;
710 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
711 #endif /* HAVE_SSL */
712 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
713 JobKillDelay
= DEFAULT_TIMEOUT
;
715 JobRetryInterval
= 300;
720 HostNameLookups
= FALSE
;
722 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
723 ListenBackLog
= SOMAXCONN
;
724 LogDebugHistory
= 200;
725 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
726 LogLevel
= CUPSD_LOG_WARN
;
727 LogTimeFormat
= CUPSD_TIME_STANDARD
;
729 MaxClientsPerHost
= 0;
730 MaxLogSize
= 1024 * 1024;
732 MultipleOperationTimeout
= 900;
734 ReloadTimeout
= DEFAULT_KEEPALIVE
;
735 RootCertDuration
= 300;
736 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
737 StrictConformance
= FALSE
;
740 WebInterface
= CUPS_DEFAULT_WEBIF
;
742 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
744 Browsing
= CUPS_DEFAULT_BROWSING
;
745 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
747 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
748 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
749 cupsdClearString(&DNSSDHostName
);
750 #endif /* HAVE_DNSSD || HAVE_AVAHI */
752 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
753 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
755 cupsdSetString(&ErrorPolicy
, "stop-printer");
757 JobHistory
= DEFAULT_HISTORY
;
758 JobFiles
= DEFAULT_FILES
;
764 MaxJobsPerPrinter
= 0;
765 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
766 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
768 cupsdDeleteAllPolicies();
769 cupsdClearString(&DefaultPolicy
);
771 #ifdef HAVE_AUTHORIZATION_H
772 cupsdSetString(&SystemGroupAuthKey
, CUPS_DEFAULT_SYSTEM_AUTHKEY
);
773 #endif /* HAVE_AUTHORIZATION_H */
775 MaxSubscriptions
= 100;
776 MaxSubscriptionsPerJob
= 0;
777 MaxSubscriptionsPerPrinter
= 0;
778 MaxSubscriptionsPerUser
= 0;
779 DefaultLeaseDuration
= 86400;
780 MaxLeaseDuration
= 0;
783 IdleExitTimeout
= 60;
784 #endif /* HAVE_ONDEMAND */
787 * Setup environment variables...
793 * Read the cups-files.conf file...
796 if ((fp
= cupsFileOpen(CupsFilesFile
, "r")) != NULL
)
798 status
= read_cups_files_conf(fp
);
805 printf("\"%s\" contains errors.\n", CupsFilesFile
);
807 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
808 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
810 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
811 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
816 else if (errno
== ENOENT
)
817 cupsdLogMessage(CUPSD_LOG_INFO
, "No %s, using defaults.", CupsFilesFile
);
820 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
821 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
823 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
824 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
830 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
833 * Read the cupsd.conf file...
836 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
838 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
839 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
841 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
842 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
847 status
= read_cupsd_conf(fp
);
854 printf("\"%s\" contains errors.\n", ConfigurationFile
);
856 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
857 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
859 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
860 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
867 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
868 RemotePort
? "enabled" : "disabled");
871 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
874 * See if the ServerName is an IP address...
880 ServerAlias
= cupsArrayNew(NULL
, NULL
);
882 cupsdAddAlias(ServerAlias
, ServerName
);
883 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
887 if (gethostname(temp
, sizeof(temp
)))
889 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
891 strlcpy(temp
, "localhost", sizeof(temp
));
894 cupsdSetString(&ServerName
, temp
);
897 ServerAlias
= cupsArrayNew(NULL
, NULL
);
899 cupsdAddAlias(ServerAlias
, temp
);
900 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
902 if (HostNameLookups
|| RemotePort
)
904 struct hostent
*host
; /* Host entry to get FQDN */
906 if ((host
= gethostbyname(temp
)) != NULL
)
908 if (_cups_strcasecmp(temp
, host
->h_name
))
910 cupsdSetString(&ServerName
, host
->h_name
);
911 cupsdAddAlias(ServerAlias
, host
->h_name
);
912 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
918 for (i
= 0; host
->h_aliases
[i
]; i
++)
919 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
921 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
922 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
930 * Make sure we have the base hostname added as an alias, too!
933 if ((slash
= strchr(temp
, '.')) != NULL
)
936 cupsdAddAlias(ServerAlias
, temp
);
937 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
941 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
943 ServerNameIsIP
= !*slash
;
946 * Make sure ServerAdmin is initialized...
950 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
953 * Use the default system group if none was supplied in cupsd.conf...
956 if (NumSystemGroups
== 0)
958 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
, 0))
961 * Find the group associated with GID 0...
968 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
970 cupsdSetString(&SystemGroups
[0], "unknown");
972 SystemGroupIDs
[0] = 0;
978 * Make sure ConfigFilePerm and LogFilePerm have sane values...
981 ConfigFilePerm
&= 0664;
985 * Open the system log for cupsd if necessary...
990 if (!strcmp(AccessLog
, "stderr"))
991 cupsdSetString(&AccessLog
, "syslog");
993 if (!strcmp(ErrorLog
, "stderr"))
994 cupsdSetString(&ErrorLog
, "syslog");
996 if (!strcmp(PageLog
, "stderr"))
997 cupsdSetString(&PageLog
, "syslog");
1000 #if defined(HAVE_VSYSLOG) && !defined(HAVE_ASL_H) && !defined(HAVE_SYSTEMD_SD_JOURNAL_H)
1001 if (!strcmp(AccessLog
, "syslog") ||
1002 !strcmp(ErrorLog
, "syslog") ||
1003 !strcmp(PageLog
, "syslog"))
1004 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
1005 #endif /* HAVE_VSYSLOG && !HAVE_ASL_H && !HAVE_SYSTEMD_SD_JOURNAL_H */
1008 * Log the configuration file that was used...
1011 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
1015 * Validate the Group and SystemGroup settings - they cannot be the same,
1016 * otherwise the CGI programs will be able to authenticate as root without
1022 for (i
= 0; i
< NumSystemGroups
; i
++)
1023 if (Group
== SystemGroupIDs
[i
])
1026 if (i
< NumSystemGroups
)
1029 * Log the error and reset the group to a safe value...
1032 cupsdLogMessage(CUPSD_LOG_ERROR
,
1033 "Group and SystemGroup cannot use the same groups.");
1034 if (FatalErrors
& (CUPSD_FATAL_CONFIG
| CUPSD_FATAL_PERMISSIONS
))
1037 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
1039 group
= getgrnam("nobody");
1043 Group
= group
->gr_gid
;
1047 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
1048 * complement number...)
1057 * Check that we have at least one listen/port line; if not, report this
1058 * as an error and exit!
1061 if (cupsArrayCount(Listeners
) == 0)
1067 cupsdLogMessage(CUPSD_LOG_EMERG
,
1068 "No valid Listen or Port lines were found in the "
1069 "configuration file.");
1075 cupsdEndProcess(getpid(), 0);
1079 * Set the default locale using the language and charset...
1082 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1085 * Update all relative filenames to include the full path from ServerRoot...
1088 if (DocumentRoot
[0] != '/')
1089 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1091 if (RequestRoot
[0] != '/')
1092 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1094 if (ServerBin
[0] != '/')
1095 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1097 if (StateDir
[0] != '/')
1098 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1100 if (CacheDir
[0] != '/')
1101 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1104 if (!_cups_strcasecmp(ServerKeychain
, "internal"))
1105 cupsdClearString(&ServerKeychain
);
1106 else if (ServerKeychain
[0] != '/')
1107 cupsdSetStringf(&ServerKeychain
, "%s/%s", ServerRoot
, ServerKeychain
);
1109 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Using keychain \"%s\" for server name \"%s\".", ServerKeychain
? ServerKeychain
: "internal", ServerName
);
1110 if (!CreateSelfSignedCerts
)
1111 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Self-signed TLS certificate generation is disabled.");
1112 cupsSetServerCredentials(ServerKeychain
, ServerName
, CreateSelfSignedCerts
);
1113 #endif /* HAVE_SSL */
1116 * Make sure that directories and config files are owned and
1117 * writable by the user and group in the cupsd.conf file...
1120 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1122 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1124 cupsdCheckPermissions(CacheDir
, NULL
, 0770, RunUser
,
1126 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1128 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1130 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1131 SystemGroupIDs
[0], 1, 1) < 0 ||
1132 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1134 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1136 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1138 cupsdCheckPermissions(ConfigurationFile
, NULL
, ConfigFilePerm
, RunUser
,
1140 cupsdCheckPermissions(CupsFilesFile
, NULL
, ConfigFilePerm
, RunUser
,
1142 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1144 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1146 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1147 Group
, 0, 0) < 0) &&
1148 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1152 * Update TempDir to the default if it hasn't been set already...
1156 if (TempDir
&& !RunUser
&&
1157 (!strncmp(TempDir
, "/private/tmp", 12) || !strncmp(TempDir
, "/tmp", 4)))
1159 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot use %s for TempDir.", TempDir
);
1160 cupsdClearString(&TempDir
);
1162 #endif /* __APPLE__ */
1167 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1168 strncmp(tmpdir
, "/private/tmp", 12) && strncmp(tmpdir
, "/tmp", 4))
1170 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1171 #endif /* __APPLE__ */
1174 * TMPDIR is defined, see if it is OK for us to use...
1177 if (stat(tmpdir
, &tmpinfo
))
1178 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1179 tmpdir
, strerror(errno
));
1180 else if (!S_ISDIR(tmpinfo
.st_mode
))
1181 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1183 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1184 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1185 !(tmpinfo
.st_mode
& S_IWOTH
))
1186 cupsdLogMessage(CUPSD_LOG_ERROR
,
1187 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1189 cupsdSetString(&TempDir
, tmpdir
);
1195 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1197 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1200 setenv("TMPDIR", TempDir
, 1);
1203 * Make sure the temporary directory has the right permissions...
1206 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1210 * Update ownership and permissions if the CUPS temp directory
1211 * is under the spool directory or does not exist...
1214 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1215 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1220 * Update environment variables...
1226 * Validate the default error policy...
1229 if (strcmp(ErrorPolicy
, "retry-current-job") &&
1230 strcmp(ErrorPolicy
, "abort-job") &&
1231 strcmp(ErrorPolicy
, "retry-job") &&
1232 strcmp(ErrorPolicy
, "stop-printer"))
1234 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\", resetting to \"stop-printer\".", ErrorPolicy
);
1235 cupsdSetString(&ErrorPolicy
, "stop-printer");
1239 * Update default paper size setting as needed...
1242 if (!DefaultPaperSize
)
1244 #ifdef HAVE_LIBPAPER
1245 char *paper_result
; /* Paper size name from libpaper */
1247 if ((paper_result
= systempapername()) != NULL
)
1248 cupsdSetString(&DefaultPaperSize
, paper_result
);
1250 #endif /* HAVE_LIBPAPER */
1251 if (!DefaultLanguage
||
1252 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1253 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1254 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1255 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1256 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1257 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1258 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1261 * These are the only locales that will default to "letter" size...
1264 cupsdSetString(&DefaultPaperSize
, "Letter");
1267 cupsdSetString(&DefaultPaperSize
, "A4");
1271 * Update classification setting as needed...
1274 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1275 cupsdClearString(&Classification
);
1278 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1281 * Check the MaxClients setting, and then allocate memory for it...
1284 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1287 cupsdLogMessage(CUPSD_LOG_INFO
,
1288 "MaxClients limited to 1/3 (%d) of the file descriptor "
1290 MaxFDs
/ 3, MaxFDs
);
1292 MaxClients
= MaxFDs
/ 3;
1295 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1299 * Check the MaxActiveJobs setting; limit to 1/3 the available
1300 * file descriptors, since we need a pipe for each job...
1303 if (MaxActiveJobs
> (MaxFDs
/ 3))
1304 MaxActiveJobs
= MaxFDs
/ 3;
1307 * Update the MaxClientsPerHost value, as needed...
1310 if (MaxClientsPerHost
<= 0)
1311 MaxClientsPerHost
= MaxClients
;
1313 if (MaxClientsPerHost
> MaxClients
)
1314 MaxClientsPerHost
= MaxClients
;
1316 cupsdLogMessage(CUPSD_LOG_INFO
,
1317 "Allowing up to %d client connections per host.",
1321 * Update the default policy, as needed...
1325 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1327 DefaultPolicyPtr
= NULL
;
1329 if (!DefaultPolicyPtr
)
1331 cupsd_location_t
*po
; /* New policy operation */
1335 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1338 cupsdSetString(&DefaultPolicy
, "default");
1340 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1341 cupsdLogMessage(CUPSD_LOG_INFO
,
1342 "Using policy \"default\" as the default.");
1345 cupsdLogMessage(CUPSD_LOG_INFO
,
1346 "Creating CUPS default administrative policy:");
1348 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1350 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1352 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1353 cupsdAddString(&(p
->job_access
), "@OWNER");
1354 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1356 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1357 cupsdAddString(&(p
->job_attrs
), "job-name");
1358 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1359 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1360 cupsdAddString(&(p
->job_attrs
), "phone");
1362 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1363 cupsdAddString(&(p
->sub_access
), "@OWNER");
1364 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1366 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1367 cupsdAddString(&(p
->job_attrs
), "notify-events");
1368 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1369 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1370 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1371 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1373 cupsdLogMessage(CUPSD_LOG_INFO
,
1374 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1375 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1377 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1378 po
->order_type
= CUPSD_AUTH_ALLOW
;
1380 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1381 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1382 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1384 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1386 cupsdLogMessage(CUPSD_LOG_INFO
,
1387 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1388 "Release-Job Restart-Job Purge-Jobs "
1389 "Set-Job-Attributes Create-Job-Subscription "
1390 "Renew-Subscription Cancel-Subscription "
1391 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1392 "Suspend-Current-Job Resume-Job "
1393 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1394 "CUPS-Authenticate-Job CUPS-Get-Document>");
1395 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1397 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1398 po
->order_type
= CUPSD_AUTH_ALLOW
;
1399 po
->level
= CUPSD_AUTH_USER
;
1401 cupsdAddName(po
, "@OWNER");
1402 cupsdAddName(po
, "@SYSTEM");
1403 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1405 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1406 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1407 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1408 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1409 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1410 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1411 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1412 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1413 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1414 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1415 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1416 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1417 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1418 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1419 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1420 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1421 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1422 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1423 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1424 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1426 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1428 cupsdLogMessage(CUPSD_LOG_INFO
,
1429 "<Limit Pause-Printer Resume-Printer "
1430 "Set-Printer-Attributes Enable-Printer "
1431 "Disable-Printer Pause-Printer-After-Current-Job "
1432 "Hold-New-Jobs Release-Held-New-Jobs "
1433 "Deactivate-Printer Activate-Printer Restart-Printer "
1434 "Shutdown-Printer Startup-Printer Promote-Job "
1435 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1436 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1437 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1438 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1439 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1441 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1442 po
->order_type
= CUPSD_AUTH_ALLOW
;
1443 po
->type
= CUPSD_AUTH_DEFAULT
;
1444 po
->level
= CUPSD_AUTH_USER
;
1446 cupsdAddName(po
, "@SYSTEM");
1447 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1449 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1450 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1451 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1452 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1453 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1454 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1455 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1456 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1457 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1458 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1459 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1460 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1461 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1462 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1463 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1464 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1465 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1466 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1467 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1468 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1469 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1470 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1472 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1474 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1475 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1477 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1478 po
->order_type
= CUPSD_AUTH_ALLOW
;
1480 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1481 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1485 if (LogLevel
>= CUPSD_LOG_DEBUG2
)
1487 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1488 cupsArrayCount(Policies
));
1489 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1491 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1493 int j
; /* Looping var */
1494 cupsd_location_t
*loc
; /* Current location */
1496 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1498 for (j
= 0, loc
= (cupsd_location_t
*)cupsArrayFirst(p
->ops
); loc
; j
++, loc
= (cupsd_location_t
*)cupsArrayNext(p
->ops
))
1500 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: ops[%d]=%s", j
, ippOpString(loc
->op
));
1506 * If we are doing a full reload or the server root has changed, flush
1507 * the jobs, printers, etc. and start from scratch...
1510 if (NeedReload
== RELOAD_ALL
||
1511 old_remote_port
!= RemotePort
||
1512 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1513 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1515 mime_type_t
*type
; /* Current type */
1516 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1517 /* MIME type name */
1520 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1523 * Free all memory...
1526 cupsdDeleteAllSubscriptions();
1528 cupsdDeleteAllPrinters();
1530 DefaultPrinter
= NULL
;
1532 if (MimeDatabase
!= NULL
)
1533 mimeDelete(MimeDatabase
);
1537 for (i
= 0; i
< NumMimeTypes
; i
++)
1538 _cupsStrFree(MimeTypes
[i
]);
1544 * Read the MIME type and conversion database...
1547 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1548 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1550 MimeDatabase
= mimeNew();
1551 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1553 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1554 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1555 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1556 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1560 cupsdLogMessage(CUPSD_LOG_EMERG
,
1561 "Unable to load MIME database from \"%s\" or \"%s\".",
1562 mimedir
, ServerRoot
);
1563 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1567 cupsdLogMessage(CUPSD_LOG_INFO
,
1568 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1569 "%d filters...", mimedir
, ServerRoot
,
1570 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1573 * Create a list of MIME types for the document-format-supported
1577 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1578 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1581 if ((MimeTypes
= calloc((size_t)NumMimeTypes
, sizeof(const char *))) == NULL
)
1583 cupsdLogMessage(CUPSD_LOG_ERROR
,
1584 "Unable to allocate memory for %d MIME types.",
1590 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1592 i
++, type
= mimeNextType(MimeDatabase
))
1594 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1596 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1599 if (i
< NumMimeTypes
)
1600 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1603 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1605 mime_filter_t
*filter
; /* Current filter */
1608 for (type
= mimeFirstType(MimeDatabase
);
1610 type
= mimeNextType(MimeDatabase
))
1611 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1612 type
->super
, type
->type
);
1614 for (filter
= mimeFirstFilter(MimeDatabase
);
1616 filter
= mimeNextFilter(MimeDatabase
))
1617 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1618 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1619 filter
->src
->super
, filter
->src
->type
,
1620 filter
->dst
->super
, filter
->dst
->type
,
1621 filter
->cost
, filter
->filter
);
1628 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1629 cupsdLoadBanners(temp
);
1632 * Load printers and classes...
1635 cupsdLoadAllPrinters();
1636 cupsdLoadAllClasses();
1638 cupsdCreateCommonData();
1641 * Update the printcap file as needed...
1644 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1645 cupsdWritePrintcap();
1648 * Load queued jobs...
1654 * Load subscriptions...
1657 cupsdLoadAllSubscriptions();
1659 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1664 * Not a full reload, so recreate the common printer attributes...
1667 cupsdCreateCommonData();
1670 * Update all jobs as needed...
1676 * Update all printers as needed...
1679 cupsdUpdatePrinters();
1680 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1682 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1686 * Reset the reload state...
1689 NeedReload
= RELOAD_NONE
;
1691 cupsdClearString(&old_serverroot
);
1692 cupsdClearString(&old_requestroot
);
1699 * 'get_address()' - Get an address + port number from a line.
1702 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1703 get_address(const char *value
, /* I - Value string */
1704 int defport
) /* I - Default port */
1706 char buffer
[1024], /* Hostname + port number buffer */
1707 defpname
[255], /* Default port name */
1708 *hostname
, /* Hostname or IP */
1709 *portname
; /* Port number or name */
1710 http_addrlist_t
*addrlist
; /* Address list */
1714 * Check for an empty value...
1719 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1724 * Grab a hostname and port number; if there is no colon and the port name
1725 * is only digits, then we have a port number by itself...
1728 strlcpy(buffer
, value
, sizeof(buffer
));
1730 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1737 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1742 * Use the default port...
1745 sprintf(defpname
, "%d", defport
);
1746 portname
= defpname
;
1752 * The buffer contains just a port number...
1760 if (hostname
&& !strcmp(hostname
, "*"))
1764 * Now lookup the address using httpAddrGetList()...
1767 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1768 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1769 hostname
? hostname
: "(nil)");
1776 * 'get_addr_and_mask()' - Get an IP address and netmask.
1779 static int /* O - 1 on success, 0 on failure */
1780 get_addr_and_mask(const char *value
, /* I - String from config file */
1781 unsigned *ip
, /* O - Address value */
1782 unsigned *mask
) /* O - Mask value */
1784 int i
, j
, /* Looping vars */
1785 family
, /* Address family */
1786 ipcount
; /* Count of fields in address */
1787 unsigned ipval
; /* Value */
1788 const char *maskval
, /* Pointer to start of mask value */
1789 *ptr
, /* Pointer into value */
1794 * Get the address...
1797 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1798 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1800 if ((maskval
= strchr(value
, '/')) != NULL
)
1803 maskval
= value
+ strlen(value
);
1807 * Check for an IPv6 address...
1813 * Parse hexadecimal IPv6/IPv4 address...
1818 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1822 else if (!strncmp(ptr
, "::", 2))
1824 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1826 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1831 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1834 * Read IPv4 dotted quad...
1837 unsigned val
[4] = { 0, 0, 0, 0 };
1838 /* IPv4 address values */
1840 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1844 * Range check the IP numbers...
1847 for (i
= 0; i
< ipcount
; i
++)
1852 * Merge everything into a 32-bit IPv4 address in ip[3]...
1855 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1856 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1859 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1862 * If the leading words are all 0's then this is an IPv4 address...
1865 if (!val
[0] && !val
[1] && !val
[2])
1868 while (isdigit(*ptr
& 255) || *ptr
== '.')
1872 else if (isxdigit(*ptr
& 255))
1874 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1876 if (*ptr
== ':' && ptr
[1] != ':')
1885 ip
[i
/ 2] |= ipval
<< 16;
1896 if (*ptr
&& *ptr
!= '/')
1900 #endif /* AF_INET6 */
1903 * Parse dotted-decimal IPv4 address...
1906 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1910 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1913 * Range check the IP numbers...
1916 for (i
= 0; i
< ipcount
; i
++)
1921 * Merge everything into a 32-bit IPv4 address in ip[3]...
1924 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1925 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1928 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1934 * Get the netmask value(s)...
1937 memset(mask
, 0, sizeof(unsigned) * 4);
1939 if (strchr(maskval
, '.'))
1942 * Get dotted-decimal mask...
1945 if (family
!= AF_INET
)
1948 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1952 mask
[3] |= (((((unsigned)mask
[0] << 8) | (unsigned)mask
[1]) << 8) |
1953 (unsigned)mask
[2]) << 8;
1954 mask
[0] = mask
[1] = mask
[2] = 0;
1959 * Get address/bits format...
1965 if (family
== AF_INET6
)
1973 mask
[0] = 0xffffffff;
1975 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1978 mask
[1] = 0xffffffff;
1982 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1985 mask
[2] = 0xffffffff;
1989 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1992 mask
[3] = 0xffffffff;
1996 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1999 #endif /* AF_INET6 */
2004 mask
[0] = 0xffffffff;
2005 mask
[1] = 0xffffffff;
2006 mask
[2] = 0xffffffff;
2009 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
2011 mask
[3] = 0xffffffff;
2016 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2017 "get_addr_and_mask(value=\"%s\", "
2018 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
2019 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
2023 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2026 if ((ip
[0] & ~mask
[0]) != 0 ||
2027 (ip
[1] & ~mask
[1]) != 0 ||
2028 (ip
[2] & ~mask
[2]) != 0 ||
2029 (ip
[3] & ~mask
[3]) != 0)
2037 * 'mime_error_cb()' - Log a MIME error.
2041 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
2042 const char *message
) /* I - Message */
2046 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
2051 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
2054 static int /* O - 1 on success, 0 on failure */
2055 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
2056 char *line
, /* I - Line from file */
2057 char *value
, /* I - Start of value data */
2058 int linenum
) /* I - Current line number */
2060 char *valptr
; /* Pointer into value */
2061 unsigned ip
[4], /* IP address components */
2062 mask
[4]; /* IP netmask components */
2065 if (!_cups_strcasecmp(line
, "Encryption"))
2068 * "Encryption xxx" - set required encryption level...
2071 if (!_cups_strcasecmp(value
, "never"))
2072 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
2073 else if (!_cups_strcasecmp(value
, "always"))
2075 cupsdLogMessage(CUPSD_LOG_ERROR
,
2076 "Encryption value \"%s\" on line %d of %s is invalid in this "
2077 "context. Using \"required\" instead.", value
, linenum
, ConfigurationFile
);
2079 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2081 else if (!_cups_strcasecmp(value
, "required"))
2082 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2083 else if (!_cups_strcasecmp(value
, "ifrequested"))
2084 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2087 cupsdLogMessage(CUPSD_LOG_ERROR
,
2088 "Unknown Encryption value %s on line %d of %s.", value
, linenum
, ConfigurationFile
);
2092 else if (!_cups_strcasecmp(line
, "Order"))
2095 * "Order Deny,Allow" or "Order Allow,Deny"...
2098 if (!_cups_strncasecmp(value
, "deny", 4))
2099 loc
->order_type
= CUPSD_AUTH_ALLOW
;
2100 else if (!_cups_strncasecmp(value
, "allow", 5))
2101 loc
->order_type
= CUPSD_AUTH_DENY
;
2104 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d of %s.",
2105 value
, linenum
, ConfigurationFile
);
2109 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2112 * Allow [From] host/ip...
2113 * Deny [From] host/ip...
2118 if (!_cups_strncasecmp(value
, "from", 4))
2121 * Strip leading "from"...
2126 while (_cups_isspace(*value
))
2134 * Find the end of the value...
2137 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2139 while (_cups_isspace(*valptr
))
2143 * Figure out what form the allow/deny address takes:
2154 * nnn.nnn.nnn.nnn/mm
2155 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2158 if (!_cups_strcasecmp(value
, "all"))
2164 if (!_cups_strcasecmp(line
, "Allow"))
2165 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2167 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2169 else if (!_cups_strcasecmp(value
, "none"))
2175 if (!_cups_strcasecmp(line
, "Allow"))
2176 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2178 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2181 else if (value
[0] == '*' || value
[0] == '.' ||
2182 (!isdigit(value
[0] & 255) && value
[0] != '['))
2184 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2185 #endif /* AF_INET6 */
2188 * Host or domain name...
2191 if (value
[0] == '*')
2194 if (!_cups_strcasecmp(line
, "Allow"))
2195 cupsdAddNameMask(&(loc
->allow
), value
);
2197 cupsdAddNameMask(&(loc
->deny
), value
);
2202 * One of many IP address forms...
2205 if (!get_addr_and_mask(value
, ip
, mask
))
2207 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d of %s.",
2208 value
, linenum
, ConfigurationFile
);
2212 if (!_cups_strcasecmp(line
, "Allow"))
2213 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2215 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2219 * Advance to next value...
2225 else if (!_cups_strcasecmp(line
, "AuthType"))
2228 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2231 if (!_cups_strcasecmp(value
, "none"))
2233 loc
->type
= CUPSD_AUTH_NONE
;
2234 loc
->level
= CUPSD_AUTH_ANON
;
2236 else if (!_cups_strcasecmp(value
, "basic"))
2238 loc
->type
= CUPSD_AUTH_BASIC
;
2240 if (loc
->level
== CUPSD_AUTH_ANON
)
2241 loc
->level
= CUPSD_AUTH_USER
;
2243 else if (!_cups_strcasecmp(value
, "default"))
2245 loc
->type
= CUPSD_AUTH_DEFAULT
;
2247 if (loc
->level
== CUPSD_AUTH_ANON
)
2248 loc
->level
= CUPSD_AUTH_USER
;
2250 else if (!_cups_strcasecmp(value
, "negotiate"))
2252 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2254 if (loc
->level
== CUPSD_AUTH_ANON
)
2255 loc
->level
= CUPSD_AUTH_USER
;
2259 cupsdLogMessage(CUPSD_LOG_WARN
,
2260 "Unknown authorization type %s on line %d of %s.",
2261 value
, linenum
, ConfigurationFile
);
2265 else if (!_cups_strcasecmp(line
, "AuthClass"))
2268 * AuthClass anonymous, user, system, group
2271 if (!_cups_strcasecmp(value
, "anonymous"))
2273 loc
->type
= CUPSD_AUTH_NONE
;
2274 loc
->level
= CUPSD_AUTH_ANON
;
2276 cupsdLogMessage(CUPSD_LOG_WARN
,
2277 "\"AuthClass %s\" is deprecated; consider removing "
2281 else if (!_cups_strcasecmp(value
, "user"))
2283 loc
->level
= CUPSD_AUTH_USER
;
2285 cupsdLogMessage(CUPSD_LOG_WARN
,
2286 "\"AuthClass %s\" is deprecated; consider using "
2287 "\"Require valid-user\" on line %d of %s.",
2288 value
, linenum
, ConfigurationFile
);
2290 else if (!_cups_strcasecmp(value
, "group"))
2292 loc
->level
= CUPSD_AUTH_GROUP
;
2294 cupsdLogMessage(CUPSD_LOG_WARN
,
2295 "\"AuthClass %s\" is deprecated; consider using "
2296 "\"Require user @groupname\" on line %d of %s.",
2297 value
, linenum
, ConfigurationFile
);
2299 else if (!_cups_strcasecmp(value
, "system"))
2301 loc
->level
= CUPSD_AUTH_GROUP
;
2303 cupsdAddName(loc
, "@SYSTEM");
2305 cupsdLogMessage(CUPSD_LOG_WARN
,
2306 "\"AuthClass %s\" is deprecated; consider using "
2307 "\"Require user @SYSTEM\" on line %d of %s.",
2308 value
, linenum
, ConfigurationFile
);
2312 cupsdLogMessage(CUPSD_LOG_WARN
,
2313 "Unknown authorization class %s on line %d of %s.",
2314 value
, linenum
, ConfigurationFile
);
2318 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2320 cupsdAddName(loc
, value
);
2322 cupsdLogMessage(CUPSD_LOG_WARN
,
2323 "\"AuthGroupName %s\" directive is deprecated; consider "
2324 "using \"Require user @%s\" on line %d of %s.",
2325 value
, value
, linenum
, ConfigurationFile
);
2327 else if (!_cups_strcasecmp(line
, "Require"))
2330 * Apache synonym for AuthClass and AuthGroupName...
2334 * Require valid-user
2335 * Require group names
2336 * Require user names
2339 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2344 if (!_cups_strcasecmp(value
, "valid-user") ||
2345 !_cups_strcasecmp(value
, "user"))
2346 loc
->level
= CUPSD_AUTH_USER
;
2347 else if (!_cups_strcasecmp(value
, "group"))
2348 loc
->level
= CUPSD_AUTH_GROUP
;
2351 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d of %s.",
2352 value
, linenum
, ConfigurationFile
);
2357 * Get the list of names from the line...
2360 for (value
= valptr
; *value
;)
2362 while (_cups_isspace(*value
))
2365 #ifdef HAVE_AUTHORIZATION_H
2366 if (!strncmp(value
, "@AUTHKEY(", 9))
2369 * Grab "@AUTHKEY(name)" value...
2372 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2378 #endif /* HAVE_AUTHORIZATION_H */
2379 if (*value
== '\"' || *value
== '\'')
2382 * Grab quoted name...
2385 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2392 * Grab literal name.
2395 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2401 cupsdAddName(loc
, value
);
2403 for (value
= valptr
; _cups_isspace(*value
); value
++);
2406 else if (!_cups_strcasecmp(line
, "Satisfy"))
2408 if (!_cups_strcasecmp(value
, "all"))
2409 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2410 else if (!_cups_strcasecmp(value
, "any"))
2411 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2414 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d of %s.",
2415 value
, linenum
, ConfigurationFile
);
2427 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2430 static int /* O - FatalErrors bits */
2431 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2433 int fatal
; /* FatalErrors bits */
2434 char value
[1024], /* Value string */
2435 *valstart
, /* Pointer into value */
2436 *valend
; /* End of value */
2440 * Empty FatalErrors line yields NULL pointer...
2444 return (CUPSD_FATAL_NONE
);
2447 * Loop through the value string,...
2450 strlcpy(value
, s
, sizeof(value
));
2452 fatal
= CUPSD_FATAL_NONE
;
2454 for (valstart
= value
; *valstart
;)
2457 * Get the current space/comma-delimited kind name...
2460 for (valend
= valstart
; *valend
; valend
++)
2461 if (_cups_isspace(*valend
) || *valend
== ',')
2468 * Add the error to the bitmask...
2471 if (!_cups_strcasecmp(valstart
, "all"))
2472 fatal
= CUPSD_FATAL_ALL
;
2473 else if (!_cups_strcasecmp(valstart
, "browse"))
2474 fatal
|= CUPSD_FATAL_BROWSE
;
2475 else if (!_cups_strcasecmp(valstart
, "-browse"))
2476 fatal
&= ~CUPSD_FATAL_BROWSE
;
2477 else if (!_cups_strcasecmp(valstart
, "config"))
2478 fatal
|= CUPSD_FATAL_CONFIG
;
2479 else if (!_cups_strcasecmp(valstart
, "-config"))
2480 fatal
&= ~CUPSD_FATAL_CONFIG
;
2481 else if (!_cups_strcasecmp(valstart
, "listen"))
2482 fatal
|= CUPSD_FATAL_LISTEN
;
2483 else if (!_cups_strcasecmp(valstart
, "-listen"))
2484 fatal
&= ~CUPSD_FATAL_LISTEN
;
2485 else if (!_cups_strcasecmp(valstart
, "log"))
2486 fatal
|= CUPSD_FATAL_LOG
;
2487 else if (!_cups_strcasecmp(valstart
, "-log"))
2488 fatal
&= ~CUPSD_FATAL_LOG
;
2489 else if (!_cups_strcasecmp(valstart
, "permissions"))
2490 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2491 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2492 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2493 else if (_cups_strcasecmp(valstart
, "none"))
2494 cupsdLogMessage(CUPSD_LOG_ERROR
,
2495 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2497 for (valstart
= valend
; *valstart
; valstart
++)
2498 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2507 * 'parse_groups()' - Parse system group names in a string.
2510 static int /* O - 1 on success, 0 on failure */
2511 parse_groups(const char *s
, /* I - Space-delimited groups */
2512 int linenum
) /* I - Line number in cups-files.conf */
2514 int status
; /* Return status */
2515 char value
[1024], /* Value string */
2516 *valstart
, /* Pointer into value */
2517 *valend
, /* End of value */
2518 quote
; /* Quote character */
2519 struct group
*group
; /* Group */
2523 * Make a copy of the string and parse out the groups...
2526 strlcpy(value
, s
, sizeof(value
));
2531 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2533 if (*valstart
== '\'' || *valstart
== '\"')
2536 * Scan quoted name...
2539 quote
= *valstart
++;
2541 for (valend
= valstart
; *valend
; valend
++)
2542 if (*valend
== quote
)
2548 * Scan space or comma-delimited name...
2551 for (valend
= valstart
; *valend
; valend
++)
2552 if (_cups_isspace(*valend
) || *valend
== ',')
2559 group
= getgrnam(valstart
);
2562 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2563 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2570 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown SystemGroup \"%s\" on line %d of %s.", valstart
, linenum
, CupsFilesFile
);
2572 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown default SystemGroup \"%s\".", valstart
);
2581 while (*valstart
== ',' || _cups_isspace(*valstart
))
2590 * 'parse_protocols()' - Parse browse protocols in a string.
2593 static int /* O - Browse protocol bits */
2594 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2596 int protocols
; /* Browse protocol bits */
2597 char value
[1024], /* Value string */
2598 *valstart
, /* Pointer into value */
2599 *valend
; /* End of value */
2603 * Empty protocol line yields NULL pointer...
2610 * Loop through the value string,...
2613 strlcpy(value
, s
, sizeof(value
));
2617 for (valstart
= value
; *valstart
;)
2620 * Get the current space/comma-delimited protocol name...
2623 for (valend
= valstart
; *valend
; valend
++)
2624 if (_cups_isspace(*valend
) || *valend
== ',')
2631 * Add the protocol to the bitmask...
2634 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2635 !_cups_strcasecmp(valstart
, "dns-sd") ||
2636 !_cups_strcasecmp(valstart
, "bonjour"))
2637 protocols
|= BROWSE_DNSSD
;
2638 else if (!_cups_strcasecmp(valstart
, "all"))
2639 protocols
|= BROWSE_ALL
;
2640 else if (_cups_strcasecmp(valstart
, "none"))
2641 cupsdLogMessage(CUPSD_LOG_ERROR
,
2642 "Unknown browse protocol \"%s\" ignored.", valstart
);
2644 for (valstart
= valend
; *valstart
; valstart
++)
2645 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2654 * 'parse_variable()' - Parse a variable line.
2657 static int /* O - 1 on success, 0 on failure */
2659 const char *filename
, /* I - Name of configuration file */
2660 int linenum
, /* I - Line in configuration file */
2661 const char *line
, /* I - Line from configuration file */
2662 const char *value
, /* I - Value from configuration file */
2663 size_t num_vars
, /* I - Number of variables */
2664 const cupsd_var_t
*vars
) /* I - Variables */
2666 size_t i
; /* Looping var */
2667 const cupsd_var_t
*var
; /* Variables */
2668 char temp
[1024]; /* Temporary string */
2671 for (i
= num_vars
, var
= vars
; i
> 0; i
--, var
++)
2672 if (!_cups_strcasecmp(line
, var
->name
))
2678 * Unknown directive! Output an error message and continue...
2682 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d of %s.",
2683 line
, linenum
, filename
);
2685 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d of %s.",
2686 line
, linenum
, filename
);
2693 case CUPSD_VARTYPE_INTEGER
:
2696 cupsdLogMessage(CUPSD_LOG_ERROR
,
2697 "Missing integer value for %s on line %d of %s.",
2698 line
, linenum
, filename
);
2701 else if (!isdigit(*value
& 255))
2703 cupsdLogMessage(CUPSD_LOG_ERROR
,
2704 "Bad integer value for %s on line %d of %s.",
2705 line
, linenum
, filename
);
2711 char *units
; /* Units */
2713 n
= strtol(value
, &units
, 0);
2715 if (units
&& *units
)
2717 if (tolower(units
[0] & 255) == 'g')
2718 n
*= 1024 * 1024 * 1024;
2719 else if (tolower(units
[0] & 255) == 'm')
2721 else if (tolower(units
[0] & 255) == 'k')
2723 else if (tolower(units
[0] & 255) == 't')
2727 cupsdLogMessage(CUPSD_LOG_ERROR
,
2728 "Unknown integer value for %s on line %d of %s.",
2729 line
, linenum
, filename
);
2736 cupsdLogMessage(CUPSD_LOG_ERROR
,
2737 "Bad negative integer value for %s on line %d of "
2738 "%s.", line
, linenum
, filename
);
2743 *((int *)var
->ptr
) = n
;
2748 case CUPSD_VARTYPE_PERM
:
2751 cupsdLogMessage(CUPSD_LOG_ERROR
,
2752 "Missing permissions value for %s on line %d of %s.",
2753 line
, linenum
, filename
);
2756 else if (!isdigit(*value
& 255))
2758 /* TODO: Add chmod UGO syntax support */
2759 cupsdLogMessage(CUPSD_LOG_ERROR
,
2760 "Bad permissions value for %s on line %d of %s.",
2761 line
, linenum
, filename
);
2766 int n
= strtol(value
, NULL
, 8);
2767 /* Permissions value */
2771 cupsdLogMessage(CUPSD_LOG_ERROR
,
2772 "Bad negative permissions value for %s on line %d of "
2773 "%s.", line
, linenum
, filename
);
2778 *((mode_t
*)var
->ptr
) = (mode_t
)n
;
2783 case CUPSD_VARTYPE_TIME
:
2786 cupsdLogMessage(CUPSD_LOG_ERROR
,
2787 "Missing time interval value for %s on line %d of "
2788 "%s.", line
, linenum
, filename
);
2791 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
2792 (!_cups_strcasecmp(value
, "true") ||
2793 !_cups_strcasecmp(value
, "on") ||
2794 !_cups_strcasecmp(value
, "enabled") ||
2795 !_cups_strcasecmp(value
, "yes")))
2797 *((int *)var
->ptr
) = INT_MAX
;
2799 else if (!_cups_strcasecmp(value
, "false") ||
2800 !_cups_strcasecmp(value
, "off") ||
2801 !_cups_strcasecmp(value
, "disabled") ||
2802 !_cups_strcasecmp(value
, "no"))
2804 *((int *)var
->ptr
) = 0;
2806 else if (!isdigit(*value
& 255))
2808 cupsdLogMessage(CUPSD_LOG_ERROR
,
2809 "Unknown time interval value for %s on line %d of "
2810 "%s.", line
, linenum
, filename
);
2815 double n
; /* Number */
2816 char *units
; /* Units */
2818 n
= strtod(value
, &units
);
2820 if (units
&& *units
)
2822 if (tolower(units
[0] & 255) == 'w')
2823 n
*= 7 * 24 * 60 * 60;
2824 else if (tolower(units
[0] & 255) == 'd')
2826 else if (tolower(units
[0] & 255) == 'h')
2828 else if (tolower(units
[0] & 255) == 'm')
2832 cupsdLogMessage(CUPSD_LOG_ERROR
,
2833 "Unknown time interval value for %s on line "
2834 "%d of %s.", line
, linenum
, filename
);
2839 if (n
< 0.0 || n
> INT_MAX
)
2841 cupsdLogMessage(CUPSD_LOG_ERROR
,
2842 "Bad time value for %s on line %d of %s.",
2843 line
, linenum
, filename
);
2848 *((int *)var
->ptr
) = (int)n
;
2853 case CUPSD_VARTYPE_BOOLEAN
:
2856 cupsdLogMessage(CUPSD_LOG_ERROR
,
2857 "Missing boolean value for %s on line %d of %s.",
2858 line
, linenum
, filename
);
2861 else if (!_cups_strcasecmp(value
, "true") ||
2862 !_cups_strcasecmp(value
, "on") ||
2863 !_cups_strcasecmp(value
, "enabled") ||
2864 !_cups_strcasecmp(value
, "yes") ||
2867 *((int *)var
->ptr
) = TRUE
;
2869 else if (!_cups_strcasecmp(value
, "false") ||
2870 !_cups_strcasecmp(value
, "off") ||
2871 !_cups_strcasecmp(value
, "disabled") ||
2872 !_cups_strcasecmp(value
, "no") ||
2873 !_cups_strcasecmp(value
, "0"))
2875 *((int *)var
->ptr
) = FALSE
;
2879 cupsdLogMessage(CUPSD_LOG_ERROR
,
2880 "Unknown boolean value %s on line %d of %s.",
2881 value
, linenum
, filename
);
2886 case CUPSD_VARTYPE_PATHNAME
:
2889 cupsdLogMessage(CUPSD_LOG_ERROR
,
2890 "Missing pathname value for %s on line %d of %s.",
2891 line
, linenum
, filename
);
2895 if (value
[0] == '/')
2896 strlcpy(temp
, value
, sizeof(temp
));
2898 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
2900 if (access(temp
, 0) && _cups_strcasecmp(value
, "internal") && _cups_strcasecmp(line
, "ServerKeychain"))
2902 cupsdLogMessage(CUPSD_LOG_ERROR
,
2903 "File or directory for \"%s %s\" on line %d of %s "
2904 "does not exist.", line
, value
, linenum
, filename
);
2908 cupsdSetString((char **)var
->ptr
, temp
);
2911 case CUPSD_VARTYPE_STRING
:
2912 cupsdSetString((char **)var
->ptr
, value
);
2921 * 'read_cupsd_conf()' - Read the cupsd.conf configuration file.
2924 static int /* O - 1 on success, 0 on failure */
2925 read_cupsd_conf(cups_file_t
*fp
) /* I - File to read from */
2927 int linenum
; /* Current line number */
2928 char line
[HTTP_MAX_BUFFER
],
2929 /* Line from file */
2930 temp
[HTTP_MAX_BUFFER
],
2931 /* Temporary buffer for value */
2932 *value
; /* Pointer to value */
2933 int valuelen
; /* Length of value */
2934 http_addrlist_t
*addrlist
, /* Address list */
2935 *addr
; /* Current address */
2939 * Loop through each line in the file...
2944 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2947 * Decode the directive...
2950 if (!_cups_strcasecmp(line
, "<Location") && value
)
2956 linenum
= read_location(fp
, value
, linenum
);
2960 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2966 linenum
= read_policy(fp
, value
, linenum
);
2970 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2972 JobRetryInterval
= atoi(value
);
2973 cupsdLogMessage(CUPSD_LOG_WARN
,
2974 "FaxRetryInterval is deprecated; use "
2975 "JobRetryInterval on line %d of %s.", linenum
, ConfigurationFile
);
2977 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2979 JobRetryLimit
= atoi(value
);
2980 cupsdLogMessage(CUPSD_LOG_WARN
,
2981 "FaxRetryLimit is deprecated; use "
2982 "JobRetryLimit on line %d of %s.", linenum
, ConfigurationFile
);
2985 else if (!_cups_strcasecmp(line
, "SSLOptions"))
2988 * SSLOptions [AllowRC4] [AllowSSL3] [AllowDH] [DenyCBC] [DenyTLS1.0] [None]
2991 int options
= _HTTP_TLS_NONE
,/* SSL/TLS options */
2992 min_version
= _HTTP_TLS_1_0
,
2993 max_version
= _HTTP_TLS_MAX
;
2997 char *start
, /* Start of option */
2998 *end
; /* End of option */
3000 for (start
= value
; *start
; start
= end
)
3003 * Find end of keyword...
3007 while (*end
&& !_cups_isspace(*end
))
3017 if (!_cups_strcasecmp(start
, "AllowRC4"))
3018 options
|= _HTTP_TLS_ALLOW_RC4
;
3019 else if (!_cups_strcasecmp(start
, "AllowSSL3"))
3020 min_version
= _HTTP_TLS_SSL3
;
3021 else if (!_cups_strcasecmp(start
, "AllowDH"))
3022 options
|= _HTTP_TLS_ALLOW_DH
;
3023 else if (!_cups_strcasecmp(start
, "DenyCBC"))
3024 options
|= _HTTP_TLS_DENY_CBC
;
3025 else if (!_cups_strcasecmp(start
, "DenyTLS1.0"))
3026 min_version
= _HTTP_TLS_1_1
;
3027 else if (!_cups_strcasecmp(start
, "MaxTLS1.0"))
3028 max_version
= _HTTP_TLS_1_0
;
3029 else if (!_cups_strcasecmp(start
, "MaxTLS1.1"))
3030 max_version
= _HTTP_TLS_1_1
;
3031 else if (!_cups_strcasecmp(start
, "MaxTLS1.2"))
3032 max_version
= _HTTP_TLS_1_2
;
3033 else if (!_cups_strcasecmp(start
, "MaxTLS1.3"))
3034 max_version
= _HTTP_TLS_1_3
;
3035 else if (!_cups_strcasecmp(start
, "MinTLS1.0"))
3036 min_version
= _HTTP_TLS_1_0
;
3037 else if (!_cups_strcasecmp(start
, "MinTLS1.1"))
3038 min_version
= _HTTP_TLS_1_1
;
3039 else if (!_cups_strcasecmp(start
, "MinTLS1.2"))
3040 min_version
= _HTTP_TLS_1_2
;
3041 else if (!_cups_strcasecmp(start
, "MinTLS1.3"))
3042 min_version
= _HTTP_TLS_1_3
;
3043 else if (!_cups_strcasecmp(start
, "None"))
3044 options
= _HTTP_TLS_NONE
;
3045 else if (_cups_strcasecmp(start
, "NoEmptyFragments"))
3046 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown SSL option %s at line %d.", start
, linenum
);
3050 _httpTLSSetOptions(options
, min_version
, max_version
);
3052 #endif /* HAVE_SSL */
3053 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
3055 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
3056 #endif /* HAVE_SSL */
3060 * Add listening address(es) to the list...
3063 cupsd_listener_t
*lis
; /* New listeners array */
3067 * Get the address list...
3070 addrlist
= get_address(value
, IPP_PORT
);
3074 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
3080 * Add each address...
3083 for (addr
= addrlist
; addr
; addr
= addr
->next
)
3086 * See if this address is already present...
3089 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
3091 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
3092 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
3093 httpAddrPort(&(addr
->addr
)) == httpAddrPort(&(lis
->address
)))
3098 #ifdef HAVE_ONDEMAND
3099 if (!lis
->on_demand
)
3100 #endif /* HAVE_ONDEMAND */
3102 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3103 cupsdLogMessage(CUPSD_LOG_WARN
,
3104 "Duplicate listen address \"%s\" ignored.", temp
);
3111 * Allocate another listener...
3115 Listeners
= cupsArrayNew(NULL
, NULL
);
3119 cupsdLogMessage(CUPSD_LOG_ERROR
,
3120 "Unable to allocate %s at line %d - %s.",
3121 line
, linenum
, strerror(errno
));
3125 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
3127 cupsdLogMessage(CUPSD_LOG_ERROR
,
3128 "Unable to allocate %s at line %d - %s.",
3129 line
, linenum
, strerror(errno
));
3133 cupsArrayAdd(Listeners
, lis
);
3136 * Copy the current address and log it...
3139 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
3143 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
3144 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
3145 #endif /* HAVE_SSL */
3147 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3150 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
3151 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
3153 #endif /* AF_LOCAL */
3154 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
3155 httpAddrPort(&(lis
->address
)),
3156 httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
3158 if (!httpAddrLocalhost(&(lis
->address
)))
3159 RemotePort
= httpAddrPort(&(lis
->address
));
3166 httpAddrFreeList(addrlist
);
3168 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
3169 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
3172 * "BrowseProtocols name [... name]"
3173 * "BrowseLocalProtocols name [... name]"
3176 int protocols
= parse_protocols(value
);
3180 cupsdLogMessage(CUPSD_LOG_ERROR
,
3181 "Unknown browse protocol \"%s\" on line %d of %s.",
3182 value
, linenum
, ConfigurationFile
);
3186 BrowseLocalProtocols
= protocols
;
3188 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
3191 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3194 if (!_cups_strcasecmp(value
, "none"))
3195 default_auth_type
= CUPSD_AUTH_NONE
;
3196 else if (!_cups_strcasecmp(value
, "basic"))
3197 default_auth_type
= CUPSD_AUTH_BASIC
;
3198 else if (!_cups_strcasecmp(value
, "negotiate"))
3199 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
3200 else if (!_cups_strcasecmp(value
, "auto"))
3201 default_auth_type
= CUPSD_AUTH_AUTO
;
3204 cupsdLogMessage(CUPSD_LOG_WARN
,
3205 "Unknown default authorization type %s on line %d of %s.",
3206 value
, linenum
, ConfigurationFile
);
3207 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3212 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
3215 * DefaultEncryption {Never,IfRequested,Required}
3218 if (!value
|| !_cups_strcasecmp(value
, "never"))
3219 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3220 else if (!_cups_strcasecmp(value
, "required"))
3221 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3222 else if (!_cups_strcasecmp(value
, "ifrequested"))
3223 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3226 cupsdLogMessage(CUPSD_LOG_WARN
,
3227 "Unknown default encryption %s on line %d of %s.",
3228 value
, linenum
, ConfigurationFile
);
3229 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3233 #endif /* HAVE_SSL */
3234 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
3237 * Do hostname lookups?
3240 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
3241 !_cups_strcasecmp(value
, "false"))
3242 HostNameLookups
= 0;
3243 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
3244 !_cups_strcasecmp(value
, "true"))
3245 HostNameLookups
= 1;
3246 else if (!_cups_strcasecmp(value
, "double"))
3247 HostNameLookups
= 2;
3249 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d of %s.",
3250 value
, linenum
, ConfigurationFile
);
3252 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
3255 * Amount of logging to do to access log...
3258 if (!_cups_strcasecmp(value
, "all"))
3259 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3260 else if (!_cups_strcasecmp(value
, "actions"))
3261 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3262 else if (!_cups_strcasecmp(value
, "config"))
3263 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3264 else if (!_cups_strcasecmp(value
, "none"))
3265 AccessLogLevel
= CUPSD_ACCESSLOG_NONE
;
3267 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d of %s.",
3268 value
, linenum
, ConfigurationFile
);
3270 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
3273 * Amount of logging to do to error log...
3276 if (!_cups_strcasecmp(value
, "debug2"))
3277 LogLevel
= CUPSD_LOG_DEBUG2
;
3278 else if (!_cups_strcasecmp(value
, "debug"))
3279 LogLevel
= CUPSD_LOG_DEBUG
;
3280 else if (!_cups_strcasecmp(value
, "info"))
3281 LogLevel
= CUPSD_LOG_INFO
;
3282 else if (!_cups_strcasecmp(value
, "notice"))
3283 LogLevel
= CUPSD_LOG_NOTICE
;
3284 else if (!_cups_strcasecmp(value
, "warn"))
3285 LogLevel
= CUPSD_LOG_WARN
;
3286 else if (!_cups_strcasecmp(value
, "error"))
3287 LogLevel
= CUPSD_LOG_ERROR
;
3288 else if (!_cups_strcasecmp(value
, "crit"))
3289 LogLevel
= CUPSD_LOG_CRIT
;
3290 else if (!_cups_strcasecmp(value
, "alert"))
3291 LogLevel
= CUPSD_LOG_ALERT
;
3292 else if (!_cups_strcasecmp(value
, "emerg"))
3293 LogLevel
= CUPSD_LOG_EMERG
;
3294 else if (!_cups_strcasecmp(value
, "none"))
3295 LogLevel
= CUPSD_LOG_NONE
;
3297 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d of %s.",
3298 value
, linenum
, ConfigurationFile
);
3300 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
3303 * Amount of logging to do to error log...
3306 if (!_cups_strcasecmp(value
, "standard"))
3307 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3308 else if (!_cups_strcasecmp(value
, "usecs"))
3309 LogTimeFormat
= CUPSD_TIME_USECS
;
3311 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d of %s.",
3312 value
, linenum
, ConfigurationFile
);
3314 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
3317 * Set the string used for the Server header...
3320 struct utsname plat
; /* Platform info */
3325 if (!_cups_strcasecmp(value
, "ProductOnly"))
3326 cupsdSetString(&ServerHeader
, "CUPS IPP");
3327 else if (!_cups_strcasecmp(value
, "Major"))
3328 cupsdSetStringf(&ServerHeader
, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR
);
3329 else if (!_cups_strcasecmp(value
, "Minor"))
3330 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
3331 CUPS_VERSION_MINOR
);
3332 else if (!_cups_strcasecmp(value
, "Minimal"))
3333 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
" IPP/2.1");
3334 else if (!_cups_strcasecmp(value
, "OS"))
3335 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s) IPP/2.1",
3336 plat
.sysname
, plat
.release
);
3337 else if (!_cups_strcasecmp(value
, "Full"))
3338 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s; %s) IPP/2.1",
3339 plat
.sysname
, plat
.release
, plat
.machine
);
3340 else if (!_cups_strcasecmp(value
, "None"))
3341 cupsdSetString(&ServerHeader
, "");
3343 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d of %s.",
3344 value
, linenum
, ConfigurationFile
);
3346 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3349 * ServerAlias name [... name]
3353 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3357 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3358 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3361 if (value
[valuelen
])
3363 value
[valuelen
] = '\0';
3367 cupsdAddAlias(ServerAlias
, value
);
3369 for (value
+= valuelen
; *value
; value
++)
3370 if (!_cups_isspace(*value
) || *value
!= ',')
3374 else if (!_cups_strcasecmp(line
, "AccessLog") ||
3375 !_cups_strcasecmp(line
, "CacheDir") ||
3376 !_cups_strcasecmp(line
, "ConfigFilePerm") ||
3377 !_cups_strcasecmp(line
, "DataDir") ||
3378 !_cups_strcasecmp(line
, "DocumentRoot") ||
3379 !_cups_strcasecmp(line
, "ErrorLog") ||
3380 !_cups_strcasecmp(line
, "FatalErrors") ||
3381 !_cups_strcasecmp(line
, "FileDevice") ||
3382 !_cups_strcasecmp(line
, "FontPath") ||
3383 !_cups_strcasecmp(line
, "Group") ||
3384 !_cups_strcasecmp(line
, "LogFilePerm") ||
3385 !_cups_strcasecmp(line
, "LPDConfigFile") ||
3386 !_cups_strcasecmp(line
, "PageLog") ||
3387 !_cups_strcasecmp(line
, "PassEnv") ||
3388 !_cups_strcasecmp(line
, "Printcap") ||
3389 !_cups_strcasecmp(line
, "PrintcapFormat") ||
3390 !_cups_strcasecmp(line
, "RemoteRoot") ||
3391 !_cups_strcasecmp(line
, "RequestRoot") ||
3392 !_cups_strcasecmp(line
, "ServerBin") ||
3393 !_cups_strcasecmp(line
, "ServerCertificate") ||
3394 !_cups_strcasecmp(line
, "ServerKey") ||
3395 !_cups_strcasecmp(line
, "ServerKeychain") ||
3396 !_cups_strcasecmp(line
, "ServerRoot") ||
3397 !_cups_strcasecmp(line
, "SetEnv") ||
3398 !_cups_strcasecmp(line
, "SMBConfigFile") ||
3399 !_cups_strcasecmp(line
, "StateDir") ||
3400 !_cups_strcasecmp(line
, "SystemGroup") ||
3401 !_cups_strcasecmp(line
, "SystemGroupAuthKey") ||
3402 !_cups_strcasecmp(line
, "TempDir") ||
3403 !_cups_strcasecmp(line
, "User"))
3405 cupsdLogMessage(CUPSD_LOG_INFO
,
3406 "Please move \"%s%s%s\" on line %d of %s to the %s file; "
3407 "this will become an error in a future release.",
3408 line
, value
? " " : "", value
? value
: "", linenum
,
3409 ConfigurationFile
, CupsFilesFile
);
3412 parse_variable(ConfigurationFile
, linenum
, line
, value
,
3413 sizeof(cupsd_vars
) / sizeof(cupsd_vars
[0]), cupsd_vars
);
3421 * 'read_cups_files_conf()' - Read the cups-files.conf configuration file.
3424 static int /* O - 1 on success, 0 on failure */
3425 read_cups_files_conf(cups_file_t
*fp
) /* I - File to read from */
3427 int i
, /* Looping var */
3428 linenum
; /* Current line number */
3429 char line
[HTTP_MAX_BUFFER
], /* Line from file */
3430 *value
; /* Value from line */
3431 struct group
*group
; /* Group */
3432 static const char * const prohibited_env
[] =
3433 { /* Prohibited environment variables */
3436 "AUTH_INFO_REQUIRED",
3456 "FINAL_CONTENT_TYPE",
3463 "PRINTER_STATE_REASONS",
3473 * Loop through each line in the file...
3478 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3480 if (!_cups_strcasecmp(line
, "FatalErrors"))
3481 FatalErrors
= parse_fatal_errors(value
);
3482 else if (!_cups_strcasecmp(line
, "Group") && value
)
3485 * Group ID to run as...
3488 if (isdigit(value
[0]))
3489 Group
= (gid_t
)atoi(value
);
3493 group
= getgrnam(value
);
3496 Group
= group
->gr_gid
;
3499 cupsdLogMessage(CUPSD_LOG_ERROR
,
3500 "Unknown Group \"%s\" on line %d of %s.", value
,
3501 linenum
, CupsFilesFile
);
3502 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3507 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3510 * PassEnv variable [... variable]
3513 int valuelen
; /* Length of variable name */
3517 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3518 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3521 if (value
[valuelen
])
3523 value
[valuelen
] = '\0';
3527 for (i
= 0; i
< (int)(sizeof(prohibited_env
) / sizeof(prohibited_env
[0])); i
++)
3529 if (!strcmp(value
, prohibited_env
[i
]))
3531 cupsdLogMessage(CUPSD_LOG_ERROR
, "Environment variable \"%s\" cannot be passed through on line %d of %s.", value
, linenum
, CupsFilesFile
);
3533 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3540 if (i
>= (int)(sizeof(prohibited_env
) / sizeof(prohibited_env
[0])))
3541 cupsdSetEnv(value
, NULL
);
3543 for (value
+= valuelen
; *value
; value
++)
3544 if (!_cups_isspace(*value
) || *value
!= ',')
3548 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
3551 * Format of printcap file?
3554 if (!_cups_strcasecmp(value
, "bsd"))
3555 PrintcapFormat
= PRINTCAP_BSD
;
3556 else if (!_cups_strcasecmp(value
, "plist"))
3557 PrintcapFormat
= PRINTCAP_PLIST
;
3558 else if (!_cups_strcasecmp(value
, "solaris"))
3559 PrintcapFormat
= PRINTCAP_SOLARIS
;
3562 cupsdLogMessage(CUPSD_LOG_ERROR
,
3563 "Unknown PrintcapFormat \"%s\" on line %d of %s.",
3564 value
, linenum
, CupsFilesFile
);
3565 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3569 else if (!_cups_strcasecmp(line
, "Sandboxing") && value
)
3572 * Level of sandboxing?
3575 if (!_cups_strcasecmp(value
, "off") && getuid())
3576 Sandboxing
= CUPSD_SANDBOXING_OFF
;
3577 else if (!_cups_strcasecmp(value
, "relaxed"))
3578 Sandboxing
= CUPSD_SANDBOXING_RELAXED
;
3579 else if (!_cups_strcasecmp(value
, "strict"))
3580 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
3583 cupsdLogMessage(CUPSD_LOG_ERROR
,
3584 "Unknown Sandboxing \"%s\" on line %d of %s.",
3585 value
, linenum
, CupsFilesFile
);
3586 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3590 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3593 * SetEnv variable value
3596 char *valueptr
; /* Pointer to environment variable value */
3598 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3606 while (isspace(*valueptr
& 255))
3609 for (i
= 0; i
< (int)(sizeof(prohibited_env
) / sizeof(prohibited_env
[0])); i
++)
3611 if (!strcmp(value
, prohibited_env
[i
]))
3613 cupsdLogMessage(CUPSD_LOG_ERROR
, "Environment variable \"%s\" cannot be set on line %d of %s.", value
, linenum
, CupsFilesFile
);
3615 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3622 if (i
>= (int)(sizeof(prohibited_env
) / sizeof(prohibited_env
[0])))
3623 cupsdSetEnv(value
, valueptr
);
3626 cupsdLogMessage(CUPSD_LOG_ERROR
,
3627 "Missing value for SetEnv directive on line %d of %s.",
3628 linenum
, ConfigurationFile
);
3630 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
3633 * SystemGroup (admin) group(s)...
3636 if (!parse_groups(value
, linenum
))
3638 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3642 else if (!_cups_strcasecmp(line
, "User") && value
)
3645 * User ID to run as...
3648 if (isdigit(value
[0] & 255))
3650 int uid
= atoi(value
);
3654 cupsdLogMessage(CUPSD_LOG_ERROR
,
3655 "Will not use User 0 as specified on line %d of %s "
3656 "for security reasons. You must use a non-"
3657 "privileged account instead.",
3658 linenum
, CupsFilesFile
);
3659 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3663 User
= (uid_t
)atoi(value
);
3667 struct passwd
*p
; /* Password information */
3670 p
= getpwnam(value
);
3676 cupsdLogMessage(CUPSD_LOG_ERROR
,
3677 "Will not use User %s (UID=0) as specified on line "
3678 "%d of %s for security reasons. You must use a "
3679 "non-privileged account instead.",
3680 value
, linenum
, CupsFilesFile
);
3681 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3689 cupsdLogMessage(CUPSD_LOG_ERROR
,
3690 "Unknown User \"%s\" on line %d of %s.",
3691 value
, linenum
, CupsFilesFile
);
3692 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3697 else if (!_cups_strcasecmp(line
, "ServerCertificate") ||
3698 !_cups_strcasecmp(line
, "ServerKey"))
3700 cupsdLogMessage(CUPSD_LOG_INFO
,
3701 "The \"%s\" directive on line %d of %s is no longer "
3702 "supported; this will become an error in a future "
3704 line
, linenum
, CupsFilesFile
);
3706 else if (!parse_variable(CupsFilesFile
, linenum
, line
, value
,
3707 sizeof(cupsfiles_vars
) / sizeof(cupsfiles_vars
[0]),
3709 (FatalErrors
& CUPSD_FATAL_CONFIG
))
3718 * 'read_location()' - Read a <Location path> definition.
3721 static int /* O - New line number or 0 on error */
3722 read_location(cups_file_t
*fp
, /* I - Configuration file */
3723 char *location
, /* I - Location name/path */
3724 int linenum
) /* I - Current line number */
3726 cupsd_location_t
*loc
, /* New location */
3727 *parent
; /* Parent location */
3728 char line
[HTTP_MAX_BUFFER
],
3730 *value
, /* Value for directive */
3731 *valptr
; /* Pointer into value */
3734 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3735 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d of %s.",
3736 location
, linenum
, ConfigurationFile
);
3737 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3741 cupsdAddLocation(parent
);
3743 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3748 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3751 * Decode the directive...
3754 if (!_cups_strcasecmp(line
, "</Location>"))
3756 else if (!_cups_strcasecmp(line
, "<Limit") ||
3757 !_cups_strcasecmp(line
, "<LimitExcept"))
3761 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3762 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3768 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3771 cupsdAddLocation(loc
);
3776 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3781 if (!strcmp(value
, "ALL"))
3782 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3783 else if (!strcmp(value
, "GET"))
3784 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3785 else if (!strcmp(value
, "HEAD"))
3786 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3787 else if (!strcmp(value
, "OPTIONS"))
3788 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3789 else if (!strcmp(value
, "POST"))
3790 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3791 else if (!strcmp(value
, "PUT"))
3792 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3793 else if (!strcmp(value
, "TRACE"))
3794 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3796 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d of %s.",
3797 value
, linenum
, ConfigurationFile
);
3799 for (value
= valptr
; isspace(*value
& 255); value
++);
3802 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3803 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3805 parent
->limit
&= ~loc
->limit
;
3807 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3808 !_cups_strcasecmp(line
, "</LimitExcept>"))
3812 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3813 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3816 else if (!parse_aaa(loc
, line
, value
, linenum
))
3818 cupsdLogMessage(CUPSD_LOG_ERROR
,
3819 "Unknown Location directive %s on line %d of %s.",
3820 line
, linenum
, ConfigurationFile
);
3821 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3826 cupsdLogMessage(CUPSD_LOG_ERROR
,
3827 "Unexpected end-of-file at line %d while reading location.",
3830 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3835 * 'read_policy()' - Read a <Policy name> definition.
3838 static int /* O - New line number or 0 on error */
3839 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3840 char *policy
, /* I - Location name/path */
3841 int linenum
) /* I - Current line number */
3843 int i
; /* Looping var */
3844 cupsd_policy_t
*pol
; /* Policy */
3845 cupsd_location_t
*op
; /* Policy operation */
3846 int num_ops
; /* Number of IPP operations */
3847 ipp_op_t ops
[100]; /* Operations */
3848 char line
[HTTP_MAX_BUFFER
],
3850 *value
, /* Value for directive */
3851 *valptr
; /* Pointer into value */
3855 * Create the policy...
3858 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3859 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d of %s.",
3860 policy
, linenum
, ConfigurationFile
);
3861 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3865 * Read from the file...
3871 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3874 * Decode the directive...
3877 if (!_cups_strcasecmp(line
, "</Policy>"))
3880 cupsdLogMessage(CUPSD_LOG_WARN
,
3881 "Missing </Limit> before </Policy> on line %d of %s.",
3882 linenum
, ConfigurationFile
);
3884 set_policy_defaults(pol
);
3888 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3892 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3893 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3900 * Scan for IPP operation names...
3907 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3912 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3914 if (!_cups_strcasecmp(value
, "All"))
3915 ops
[num_ops
++] = IPP_ANY_OPERATION
;
3916 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3917 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad IPP operation name \"%s\" on line %d of %s.", value
, linenum
, ConfigurationFile
);
3922 cupsdLogMessage(CUPSD_LOG_ERROR
,
3923 "Too many operations listed on line %d of %s.",
3924 linenum
, ConfigurationFile
);
3926 for (value
= valptr
; isspace(*value
& 255); value
++);
3930 * If none are specified, apply the policy to all operations...
3935 ops
[0] = IPP_ANY_OPERATION
;
3940 * Add a new policy for the first operation...
3943 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3945 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3948 * Finish the current operation limit...
3954 * Copy the policy to the other operations...
3957 for (i
= 1; i
< num_ops
; i
++)
3958 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3965 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3966 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3969 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3970 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3971 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3972 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3976 cupsdLogMessage(CUPSD_LOG_ERROR
,
3977 "%s directive must appear outside <Limit>...</Limit> "
3978 "on line %d of %s.", line
, linenum
, ConfigurationFile
);
3979 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3985 * Pull out whitespace-delimited values...
3991 * Find the end of the current value...
3994 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
4000 * Save it appropriately...
4003 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
4006 * JobPrivateAccess {all|default|user/group list|@@ACL}
4009 if (!_cups_strcasecmp(value
, "default"))
4011 cupsdAddString(&(pol
->job_access
), "@OWNER");
4012 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4015 cupsdAddString(&(pol
->job_access
), value
);
4017 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
4020 * JobPrivateValues {all|none|default|attribute list}
4023 if (!_cups_strcasecmp(value
, "default"))
4025 cupsdAddString(&(pol
->job_attrs
), "job-name");
4026 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4027 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4028 cupsdAddString(&(pol
->job_attrs
), "phone");
4031 cupsdAddString(&(pol
->job_attrs
), value
);
4033 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
4036 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
4039 if (!_cups_strcasecmp(value
, "default"))
4041 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4042 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4045 cupsdAddString(&(pol
->sub_access
), value
);
4047 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
4050 * SubscriptionPrivateValues {all|none|default|attribute list}
4053 if (!_cups_strcasecmp(value
, "default"))
4055 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4056 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4057 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4058 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4059 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
4062 cupsdAddString(&(pol
->sub_attrs
), value
);
4066 * Find the next string on the line...
4069 for (value
= valptr
; isspace(*value
& 255); value
++);
4075 cupsdLogMessage(CUPSD_LOG_ERROR
,
4076 "Missing <Limit ops> directive before %s on line %d of %s.",
4077 line
, linenum
, ConfigurationFile
);
4078 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4081 else if (!parse_aaa(op
, line
, value
, linenum
))
4083 cupsdLogMessage(CUPSD_LOG_ERROR
,
4084 "Unknown Policy Limit directive %s on line %d of %s.",
4085 line
, linenum
, ConfigurationFile
);
4087 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4092 cupsdLogMessage(CUPSD_LOG_ERROR
,
4093 "Unexpected end-of-file at line %d while reading policy "
4094 "\"%s\".", linenum
, policy
);
4096 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
4101 * 'set_policy_defaults()' - Set default policy values as needed.
4105 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
4107 cupsd_location_t
*op
; /* Policy operation */
4111 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
4112 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
4113 * upgrades do not introduce new security issues...
4115 * CUPS STR #4659: Allow a lone <Limit All> policy.
4118 if (cupsArrayCount(pol
->ops
) > 1)
4120 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
4121 op
->op
== IPP_ANY_OPERATION
)
4123 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
4124 op
->op
!= IPP_ANY_OPERATION
)
4127 * Add a new limit for Validate-Job using the Print-Job limit as a
4131 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s - using Print-Job's policy.", pol
->name
);
4133 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
4136 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s and no suitable template found.", pol
->name
);
4139 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
4140 op
->op
== IPP_ANY_OPERATION
)
4142 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
4143 op
->op
!= IPP_ANY_OPERATION
)
4146 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
4150 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s - using Pause-Printer's policy.", pol
->name
);
4152 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
4155 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s and no suitable template found.", pol
->name
);
4158 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
4159 op
->op
== IPP_ANY_OPERATION
)
4161 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4162 op
->op
!= IPP_ANY_OPERATION
)
4165 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
4169 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-My-Jobs defined in policy %s - using Send-Document's policy.", pol
->name
);
4171 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
4174 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-My-Jobs defined in policy %s and no suitable template found.", pol
->name
);
4177 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
4178 op
->op
== IPP_ANY_OPERATION
)
4180 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4181 op
->op
!= IPP_ANY_OPERATION
)
4184 * Add a new limit for Close-Job using the Send-Document limit as a
4188 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s - using Send-Document's policy.", pol
->name
);
4190 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
4193 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s and no suitable template found.", pol
->name
);
4196 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
4197 op
->op
== IPP_ANY_OPERATION
)
4199 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4200 op
->op
!= IPP_ANY_OPERATION
)
4203 * Add a new limit for CUPS-Get-Document using the Send-Document
4204 * limit as a template...
4207 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s - using Send-Document's policy.", pol
->name
);
4209 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
4212 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s and no suitable template found.", pol
->name
);
4217 * Verify we have JobPrivateAccess, JobPrivateValues,
4218 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4221 if (!pol
->job_access
)
4223 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4224 cupsdAddString(&(pol
->job_access
), "@OWNER");
4225 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4228 if (!pol
->job_attrs
)
4230 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateValues defined in policy %s - using defaults.", pol
->name
);
4231 cupsdAddString(&(pol
->job_attrs
), "job-name");
4232 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4233 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4234 cupsdAddString(&(pol
->job_attrs
), "phone");
4237 if (!pol
->sub_access
)
4239 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4240 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4241 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4244 if (!pol
->sub_attrs
)
4246 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateValues defined in policy %s - using defaults.", pol
->name
);
4247 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4248 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4249 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4250 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4251 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");