2 * Configuration routines for the CUPS scheduler.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
21 #include <sys/utsname.h>
24 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
25 # define SD_JOURNAL_SUPPRESS_LOCATION
26 # include <systemd/sd-journal.h>
27 #endif /* HAVE_ASL_H */
32 #endif /* HAVE_LIBPAPER */
36 * Possibly missing network definitions...
40 # define INADDR_NONE 0xffffffff
41 #endif /* !INADDR_NONE */
45 * Configuration variable structure...
50 CUPSD_VARTYPE_INTEGER
, /* Integer option */
51 CUPSD_VARTYPE_TIME
, /* Time interval option */
52 CUPSD_VARTYPE_STRING
, /* String option */
53 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
54 CUPSD_VARTYPE_PATHNAME
, /* File/directory name option */
55 CUPSD_VARTYPE_PERM
/* File/directory permissions */
60 const char *name
; /* Name of variable */
61 void *ptr
; /* Pointer to variable */
62 cupsd_vartype_t type
; /* Type (int, string, address) */
70 static const cupsd_var_t cupsd_vars
[] =
72 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
73 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
74 { "BrowseDNSSDSubTypes", &DNSSDSubTypes
, CUPSD_VARTYPE_STRING
},
75 #endif /* HAVE_DNSSD || HAVE_AVAHI */
76 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
77 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
78 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
79 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
80 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
81 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_TIME
},
82 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
83 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
84 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
85 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_TIME
},
86 { "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
);
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(0);
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
= DEFAULT_TIMEOUT
;
734 ReloadTimeout
= DEFAULT_KEEPALIVE
;
735 RootCertDuration
= 300;
736 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
737 StrictConformance
= FALSE
;
739 Timeout
= DEFAULT_TIMEOUT
;
740 WebInterface
= CUPS_DEFAULT_WEBIF
;
742 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
744 Browsing
= CUPS_DEFAULT_BROWSING
;
745 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
747 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
748 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
749 #endif /* HAVE_DNSSD || HAVE_AVAHI */
751 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
752 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
754 cupsdSetString(&ErrorPolicy
, "stop-printer");
756 JobHistory
= DEFAULT_HISTORY
;
757 JobFiles
= DEFAULT_FILES
;
763 MaxJobsPerPrinter
= 0;
764 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
765 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
767 cupsdDeleteAllPolicies();
768 cupsdClearString(&DefaultPolicy
);
770 #ifdef HAVE_AUTHORIZATION_H
771 cupsdSetString(&SystemGroupAuthKey
, CUPS_DEFAULT_SYSTEM_AUTHKEY
);
772 #endif /* HAVE_AUTHORIZATION_H */
774 MaxSubscriptions
= 100;
775 MaxSubscriptionsPerJob
= 0;
776 MaxSubscriptionsPerPrinter
= 0;
777 MaxSubscriptionsPerUser
= 0;
778 DefaultLeaseDuration
= 86400;
779 MaxLeaseDuration
= 0;
782 IdleExitTimeout
= 60;
783 #endif /* HAVE_ONDEMAND */
786 * Setup environment variables...
792 * Read the cups-files.conf file...
795 if ((fp
= cupsFileOpen(CupsFilesFile
, "r")) != NULL
)
797 status
= read_cups_files_conf(fp
);
804 printf("\"%s\" contains errors.\n", CupsFilesFile
);
806 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
807 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
809 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
810 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
815 else if (errno
== ENOENT
)
816 cupsdLogMessage(CUPSD_LOG_INFO
, "No %s, using defaults.", CupsFilesFile
);
819 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
820 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
822 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
823 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
829 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
832 * Read the cupsd.conf file...
835 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
837 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
838 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
840 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
841 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
846 status
= read_cupsd_conf(fp
);
853 printf("\"%s\" contains errors.\n", ConfigurationFile
);
855 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
856 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
858 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
859 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
866 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
867 RemotePort
? "enabled" : "disabled");
870 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
873 * See if the ServerName is an IP address...
879 ServerAlias
= cupsArrayNew(NULL
, NULL
);
881 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
885 if (gethostname(temp
, sizeof(temp
)))
887 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
889 strlcpy(temp
, "localhost", sizeof(temp
));
892 cupsdSetString(&ServerName
, temp
);
895 ServerAlias
= cupsArrayNew(NULL
, NULL
);
897 cupsdAddAlias(ServerAlias
, temp
);
898 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
900 if (HostNameLookups
|| RemotePort
)
902 struct hostent
*host
; /* Host entry to get FQDN */
904 if ((host
= gethostbyname(temp
)) != NULL
)
906 if (_cups_strcasecmp(temp
, host
->h_name
))
908 cupsdSetString(&ServerName
, host
->h_name
);
909 cupsdAddAlias(ServerAlias
, host
->h_name
);
910 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
916 for (i
= 0; host
->h_aliases
[i
]; i
++)
917 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
919 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
920 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
928 * Make sure we have the base hostname added as an alias, too!
931 if ((slash
= strchr(temp
, '.')) != NULL
)
934 cupsdAddAlias(ServerAlias
, temp
);
935 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
939 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
941 ServerNameIsIP
= !*slash
;
944 * Make sure ServerAdmin is initialized...
948 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
951 * Use the default system group if none was supplied in cupsd.conf...
954 if (NumSystemGroups
== 0)
956 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
959 * Find the group associated with GID 0...
966 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
968 cupsdSetString(&SystemGroups
[0], "unknown");
970 SystemGroupIDs
[0] = 0;
976 * Make sure ConfigFilePerm and LogFilePerm have sane values...
979 ConfigFilePerm
&= 0664;
983 * Open the system log for cupsd if necessary...
988 if (!strcmp(AccessLog
, "stderr"))
989 cupsdSetString(&AccessLog
, "syslog");
991 if (!strcmp(ErrorLog
, "stderr"))
992 cupsdSetString(&ErrorLog
, "syslog");
994 if (!strcmp(PageLog
, "stderr"))
995 cupsdSetString(&PageLog
, "syslog");
998 #if defined(HAVE_VSYSLOG) && !defined(HAVE_ASL_H) && !defined(HAVE_SYSTEMD_SD_JOURNAL_H)
999 if (!strcmp(AccessLog
, "syslog") ||
1000 !strcmp(ErrorLog
, "syslog") ||
1001 !strcmp(PageLog
, "syslog"))
1002 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
1003 #endif /* HAVE_VSYSLOG && !HAVE_ASL_H && !HAVE_SYSTEMD_SD_JOURNAL_H */
1006 * Log the configuration file that was used...
1009 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
1013 * Validate the Group and SystemGroup settings - they cannot be the same,
1014 * otherwise the CGI programs will be able to authenticate as root without
1020 for (i
= 0; i
< NumSystemGroups
; i
++)
1021 if (Group
== SystemGroupIDs
[i
])
1024 if (i
< NumSystemGroups
)
1027 * Log the error and reset the group to a safe value...
1030 cupsdLogMessage(CUPSD_LOG_ERROR
,
1031 "Group and SystemGroup cannot use the same groups.");
1032 if (FatalErrors
& (CUPSD_FATAL_CONFIG
| CUPSD_FATAL_PERMISSIONS
))
1035 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
1037 group
= getgrnam("nobody");
1041 Group
= group
->gr_gid
;
1045 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
1046 * complement number...)
1055 * Check that we have at least one listen/port line; if not, report this
1056 * as an error and exit!
1059 if (cupsArrayCount(Listeners
) == 0)
1065 cupsdLogMessage(CUPSD_LOG_EMERG
,
1066 "No valid Listen or Port lines were found in the "
1067 "configuration file.");
1073 cupsdEndProcess(getpid(), 0);
1077 * Set the default locale using the language and charset...
1080 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1083 * Update all relative filenames to include the full path from ServerRoot...
1086 if (DocumentRoot
[0] != '/')
1087 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1089 if (RequestRoot
[0] != '/')
1090 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1092 if (ServerBin
[0] != '/')
1093 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1095 if (StateDir
[0] != '/')
1096 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1098 if (CacheDir
[0] != '/')
1099 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1102 if (!_cups_strcasecmp(ServerKeychain
, "internal"))
1103 cupsdClearString(&ServerKeychain
);
1104 else if (ServerKeychain
[0] != '/')
1105 cupsdSetStringf(&ServerKeychain
, "%s/%s", ServerRoot
, ServerKeychain
);
1107 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Using keychain \"%s\" for server name \"%s\".", ServerKeychain
? ServerKeychain
: "internal", ServerName
);
1108 if (!CreateSelfSignedCerts
)
1109 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Self-signed TLS certificate generation is disabled.");
1110 cupsSetServerCredentials(ServerKeychain
, ServerName
, CreateSelfSignedCerts
);
1111 #endif /* HAVE_SSL */
1114 * Make sure that directories and config files are owned and
1115 * writable by the user and group in the cupsd.conf file...
1118 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1120 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1122 cupsdCheckPermissions(CacheDir
, NULL
, 0770, RunUser
,
1124 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1126 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1128 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1129 SystemGroupIDs
[0], 1, 1) < 0 ||
1130 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1132 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1134 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1136 cupsdCheckPermissions(ConfigurationFile
, NULL
, ConfigFilePerm
, RunUser
,
1138 cupsdCheckPermissions(CupsFilesFile
, NULL
, ConfigFilePerm
, RunUser
,
1140 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1142 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1144 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1145 Group
, 0, 0) < 0) &&
1146 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1150 * Update TempDir to the default if it hasn't been set already...
1154 if (TempDir
&& !RunUser
&&
1155 (!strncmp(TempDir
, "/private/tmp", 12) || !strncmp(TempDir
, "/tmp", 4)))
1157 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot use %s for TempDir.", TempDir
);
1158 cupsdClearString(&TempDir
);
1160 #endif /* __APPLE__ */
1165 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1166 strncmp(tmpdir
, "/private/tmp", 12) && strncmp(tmpdir
, "/tmp", 4))
1168 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1169 #endif /* __APPLE__ */
1172 * TMPDIR is defined, see if it is OK for us to use...
1175 if (stat(tmpdir
, &tmpinfo
))
1176 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1177 tmpdir
, strerror(errno
));
1178 else if (!S_ISDIR(tmpinfo
.st_mode
))
1179 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1181 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1182 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1183 !(tmpinfo
.st_mode
& S_IWOTH
))
1184 cupsdLogMessage(CUPSD_LOG_ERROR
,
1185 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1187 cupsdSetString(&TempDir
, tmpdir
);
1193 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1195 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1198 setenv("TMPDIR", TempDir
, 1);
1201 * Make sure the temporary directory has the right permissions...
1204 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1208 * Update ownership and permissions if the CUPS temp directory
1209 * is under the spool directory or does not exist...
1212 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1213 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1218 * Update environment variables...
1224 * Validate the default error policy...
1227 if (strcmp(ErrorPolicy
, "retry-current-job") &&
1228 strcmp(ErrorPolicy
, "abort-job") &&
1229 strcmp(ErrorPolicy
, "retry-job") &&
1230 strcmp(ErrorPolicy
, "stop-printer"))
1232 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\", resetting to \"stop-printer\".", ErrorPolicy
);
1233 cupsdSetString(&ErrorPolicy
, "stop-printer");
1237 * Update default paper size setting as needed...
1240 if (!DefaultPaperSize
)
1242 #ifdef HAVE_LIBPAPER
1243 char *paper_result
; /* Paper size name from libpaper */
1245 if ((paper_result
= systempapername()) != NULL
)
1246 cupsdSetString(&DefaultPaperSize
, paper_result
);
1248 #endif /* HAVE_LIBPAPER */
1249 if (!DefaultLanguage
||
1250 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1251 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1252 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1253 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1254 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1255 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1256 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1259 * These are the only locales that will default to "letter" size...
1262 cupsdSetString(&DefaultPaperSize
, "Letter");
1265 cupsdSetString(&DefaultPaperSize
, "A4");
1269 * Update classification setting as needed...
1272 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1273 cupsdClearString(&Classification
);
1276 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1279 * Check the MaxClients setting, and then allocate memory for it...
1282 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1285 cupsdLogMessage(CUPSD_LOG_INFO
,
1286 "MaxClients limited to 1/3 (%d) of the file descriptor "
1288 MaxFDs
/ 3, MaxFDs
);
1290 MaxClients
= MaxFDs
/ 3;
1293 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1297 * Check the MaxActiveJobs setting; limit to 1/3 the available
1298 * file descriptors, since we need a pipe for each job...
1301 if (MaxActiveJobs
> (MaxFDs
/ 3))
1302 MaxActiveJobs
= MaxFDs
/ 3;
1305 * Update the MaxClientsPerHost value, as needed...
1308 if (MaxClientsPerHost
<= 0)
1309 MaxClientsPerHost
= MaxClients
;
1311 if (MaxClientsPerHost
> MaxClients
)
1312 MaxClientsPerHost
= MaxClients
;
1314 cupsdLogMessage(CUPSD_LOG_INFO
,
1315 "Allowing up to %d client connections per host.",
1319 * Update the default policy, as needed...
1323 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1325 DefaultPolicyPtr
= NULL
;
1327 if (!DefaultPolicyPtr
)
1329 cupsd_location_t
*po
; /* New policy operation */
1333 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1336 cupsdSetString(&DefaultPolicy
, "default");
1338 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1339 cupsdLogMessage(CUPSD_LOG_INFO
,
1340 "Using policy \"default\" as the default.");
1343 cupsdLogMessage(CUPSD_LOG_INFO
,
1344 "Creating CUPS default administrative policy:");
1346 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1348 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1350 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1351 cupsdAddString(&(p
->job_access
), "@OWNER");
1352 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1354 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1355 cupsdAddString(&(p
->job_attrs
), "job-name");
1356 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1357 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1358 cupsdAddString(&(p
->job_attrs
), "phone");
1360 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1361 cupsdAddString(&(p
->sub_access
), "@OWNER");
1362 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1364 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1365 cupsdAddString(&(p
->job_attrs
), "notify-events");
1366 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1367 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1368 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1369 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1371 cupsdLogMessage(CUPSD_LOG_INFO
,
1372 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1373 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1375 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1376 po
->order_type
= CUPSD_AUTH_ALLOW
;
1378 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1379 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1380 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1382 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1384 cupsdLogMessage(CUPSD_LOG_INFO
,
1385 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1386 "Release-Job Restart-Job Purge-Jobs "
1387 "Set-Job-Attributes Create-Job-Subscription "
1388 "Renew-Subscription Cancel-Subscription "
1389 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1390 "Suspend-Current-Job Resume-Job "
1391 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1392 "CUPS-Authenticate-Job CUPS-Get-Document>");
1393 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1395 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1396 po
->order_type
= CUPSD_AUTH_ALLOW
;
1397 po
->level
= CUPSD_AUTH_USER
;
1399 cupsdAddName(po
, "@OWNER");
1400 cupsdAddName(po
, "@SYSTEM");
1401 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1403 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1404 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1405 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1406 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1407 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1408 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1409 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1410 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1411 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1412 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1413 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1414 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1415 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1416 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1417 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1418 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1419 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1420 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1421 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1422 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1424 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1426 cupsdLogMessage(CUPSD_LOG_INFO
,
1427 "<Limit Pause-Printer Resume-Printer "
1428 "Set-Printer-Attributes Enable-Printer "
1429 "Disable-Printer Pause-Printer-After-Current-Job "
1430 "Hold-New-Jobs Release-Held-New-Jobs "
1431 "Deactivate-Printer Activate-Printer Restart-Printer "
1432 "Shutdown-Printer Startup-Printer Promote-Job "
1433 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1434 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1435 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1436 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1437 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1439 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1440 po
->order_type
= CUPSD_AUTH_ALLOW
;
1441 po
->type
= CUPSD_AUTH_DEFAULT
;
1442 po
->level
= CUPSD_AUTH_USER
;
1444 cupsdAddName(po
, "@SYSTEM");
1445 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1447 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1448 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1449 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1450 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1451 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1452 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1453 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1454 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1455 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1456 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1457 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1458 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1459 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1460 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1461 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1462 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1463 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1464 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1465 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1466 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1467 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1468 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1470 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1472 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1473 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1475 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1476 po
->order_type
= CUPSD_AUTH_ALLOW
;
1478 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1479 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1483 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1484 cupsArrayCount(Policies
));
1485 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1487 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1488 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1489 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1492 * If we are doing a full reload or the server root has changed, flush
1493 * the jobs, printers, etc. and start from scratch...
1496 if (NeedReload
== RELOAD_ALL
||
1497 old_remote_port
!= RemotePort
||
1498 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1499 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1501 mime_type_t
*type
; /* Current type */
1502 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1503 /* MIME type name */
1506 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1509 * Free all memory...
1512 cupsdDeleteAllSubscriptions();
1514 cupsdDeleteAllPrinters();
1516 DefaultPrinter
= NULL
;
1518 if (MimeDatabase
!= NULL
)
1519 mimeDelete(MimeDatabase
);
1523 for (i
= 0; i
< NumMimeTypes
; i
++)
1524 _cupsStrFree(MimeTypes
[i
]);
1530 * Read the MIME type and conversion database...
1533 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1534 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1536 MimeDatabase
= mimeNew();
1537 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1539 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1540 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1541 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1542 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1546 cupsdLogMessage(CUPSD_LOG_EMERG
,
1547 "Unable to load MIME database from \"%s\" or \"%s\".",
1548 mimedir
, ServerRoot
);
1549 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1553 cupsdLogMessage(CUPSD_LOG_INFO
,
1554 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1555 "%d filters...", mimedir
, ServerRoot
,
1556 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1559 * Create a list of MIME types for the document-format-supported
1563 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1564 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1567 if ((MimeTypes
= calloc((size_t)NumMimeTypes
, sizeof(const char *))) == NULL
)
1569 cupsdLogMessage(CUPSD_LOG_ERROR
,
1570 "Unable to allocate memory for %d MIME types.",
1576 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1578 i
++, type
= mimeNextType(MimeDatabase
))
1580 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1582 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1585 if (i
< NumMimeTypes
)
1586 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1589 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1591 mime_filter_t
*filter
; /* Current filter */
1594 for (type
= mimeFirstType(MimeDatabase
);
1596 type
= mimeNextType(MimeDatabase
))
1597 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1598 type
->super
, type
->type
);
1600 for (filter
= mimeFirstFilter(MimeDatabase
);
1602 filter
= mimeNextFilter(MimeDatabase
))
1603 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1604 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1605 filter
->src
->super
, filter
->src
->type
,
1606 filter
->dst
->super
, filter
->dst
->type
,
1607 filter
->cost
, filter
->filter
);
1614 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1615 cupsdLoadBanners(temp
);
1618 * Load printers and classes...
1621 cupsdLoadAllPrinters();
1622 cupsdLoadAllClasses();
1624 cupsdCreateCommonData();
1627 * Update the printcap file as needed...
1630 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1631 cupsdWritePrintcap();
1634 * Load queued jobs...
1640 * Load subscriptions...
1643 cupsdLoadAllSubscriptions();
1645 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1650 * Not a full reload, so recreate the common printer attributes...
1653 cupsdCreateCommonData();
1656 * Update all jobs as needed...
1662 * Update all printers as needed...
1665 cupsdUpdatePrinters();
1666 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1668 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1672 * Reset the reload state...
1675 NeedReload
= RELOAD_NONE
;
1677 cupsdClearString(&old_serverroot
);
1678 cupsdClearString(&old_requestroot
);
1685 * 'get_address()' - Get an address + port number from a line.
1688 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1689 get_address(const char *value
, /* I - Value string */
1690 int defport
) /* I - Default port */
1692 char buffer
[1024], /* Hostname + port number buffer */
1693 defpname
[255], /* Default port name */
1694 *hostname
, /* Hostname or IP */
1695 *portname
; /* Port number or name */
1696 http_addrlist_t
*addrlist
; /* Address list */
1700 * Check for an empty value...
1705 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1710 * Grab a hostname and port number; if there is no colon and the port name
1711 * is only digits, then we have a port number by itself...
1714 strlcpy(buffer
, value
, sizeof(buffer
));
1716 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1723 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1728 * Use the default port...
1731 sprintf(defpname
, "%d", defport
);
1732 portname
= defpname
;
1738 * The buffer contains just a port number...
1746 if (hostname
&& !strcmp(hostname
, "*"))
1750 * Now lookup the address using httpAddrGetList()...
1753 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1754 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1755 hostname
? hostname
: "(nil)");
1762 * 'get_addr_and_mask()' - Get an IP address and netmask.
1765 static int /* O - 1 on success, 0 on failure */
1766 get_addr_and_mask(const char *value
, /* I - String from config file */
1767 unsigned *ip
, /* O - Address value */
1768 unsigned *mask
) /* O - Mask value */
1770 int i
, j
, /* Looping vars */
1771 family
, /* Address family */
1772 ipcount
; /* Count of fields in address */
1773 unsigned ipval
; /* Value */
1774 const char *maskval
, /* Pointer to start of mask value */
1775 *ptr
, /* Pointer into value */
1780 * Get the address...
1783 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1784 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1786 if ((maskval
= strchr(value
, '/')) != NULL
)
1789 maskval
= value
+ strlen(value
);
1793 * Check for an IPv6 address...
1799 * Parse hexadecimal IPv6/IPv4 address...
1804 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1808 else if (!strncmp(ptr
, "::", 2))
1810 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1812 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1817 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1820 * Read IPv4 dotted quad...
1823 unsigned val
[4] = { 0, 0, 0, 0 };
1824 /* IPv4 address values */
1826 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1830 * Range check the IP numbers...
1833 for (i
= 0; i
< ipcount
; i
++)
1838 * Merge everything into a 32-bit IPv4 address in ip[3]...
1841 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1842 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1845 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1848 * If the leading words are all 0's then this is an IPv4 address...
1851 if (!val
[0] && !val
[1] && !val
[2])
1854 while (isdigit(*ptr
& 255) || *ptr
== '.')
1858 else if (isxdigit(*ptr
& 255))
1860 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1862 if (*ptr
== ':' && ptr
[1] != ':')
1871 ip
[i
/ 2] |= ipval
<< 16;
1882 if (*ptr
&& *ptr
!= '/')
1886 #endif /* AF_INET6 */
1889 * Parse dotted-decimal IPv4 address...
1892 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1896 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1899 * Range check the IP numbers...
1902 for (i
= 0; i
< ipcount
; i
++)
1907 * Merge everything into a 32-bit IPv4 address in ip[3]...
1910 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1911 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1914 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1920 * Get the netmask value(s)...
1923 memset(mask
, 0, sizeof(unsigned) * 4);
1925 if (strchr(maskval
, '.'))
1928 * Get dotted-decimal mask...
1931 if (family
!= AF_INET
)
1934 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1938 mask
[3] |= (((((unsigned)mask
[0] << 8) | (unsigned)mask
[1]) << 8) |
1939 (unsigned)mask
[2]) << 8;
1940 mask
[0] = mask
[1] = mask
[2] = 0;
1945 * Get address/bits format...
1951 if (family
== AF_INET6
)
1959 mask
[0] = 0xffffffff;
1961 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1964 mask
[1] = 0xffffffff;
1968 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1971 mask
[2] = 0xffffffff;
1975 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1978 mask
[3] = 0xffffffff;
1982 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1985 #endif /* AF_INET6 */
1990 mask
[0] = 0xffffffff;
1991 mask
[1] = 0xffffffff;
1992 mask
[2] = 0xffffffff;
1995 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1997 mask
[3] = 0xffffffff;
2002 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2003 "get_addr_and_mask(value=\"%s\", "
2004 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
2005 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
2009 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2012 if ((ip
[0] & ~mask
[0]) != 0 ||
2013 (ip
[1] & ~mask
[1]) != 0 ||
2014 (ip
[2] & ~mask
[2]) != 0 ||
2015 (ip
[3] & ~mask
[3]) != 0)
2023 * 'mime_error_cb()' - Log a MIME error.
2027 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
2028 const char *message
) /* I - Message */
2032 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
2037 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
2040 static int /* O - 1 on success, 0 on failure */
2041 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
2042 char *line
, /* I - Line from file */
2043 char *value
, /* I - Start of value data */
2044 int linenum
) /* I - Current line number */
2046 char *valptr
; /* Pointer into value */
2047 unsigned ip
[4], /* IP address components */
2048 mask
[4]; /* IP netmask components */
2051 if (!_cups_strcasecmp(line
, "Encryption"))
2054 * "Encryption xxx" - set required encryption level...
2057 if (!_cups_strcasecmp(value
, "never"))
2058 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
2059 else if (!_cups_strcasecmp(value
, "always"))
2061 cupsdLogMessage(CUPSD_LOG_ERROR
,
2062 "Encryption value \"%s\" on line %d of %s is invalid in this "
2063 "context. Using \"required\" instead.", value
, linenum
, ConfigurationFile
);
2065 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2067 else if (!_cups_strcasecmp(value
, "required"))
2068 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2069 else if (!_cups_strcasecmp(value
, "ifrequested"))
2070 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2073 cupsdLogMessage(CUPSD_LOG_ERROR
,
2074 "Unknown Encryption value %s on line %d of %s.", value
, linenum
, ConfigurationFile
);
2078 else if (!_cups_strcasecmp(line
, "Order"))
2081 * "Order Deny,Allow" or "Order Allow,Deny"...
2084 if (!_cups_strncasecmp(value
, "deny", 4))
2085 loc
->order_type
= CUPSD_AUTH_ALLOW
;
2086 else if (!_cups_strncasecmp(value
, "allow", 5))
2087 loc
->order_type
= CUPSD_AUTH_DENY
;
2090 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d of %s.",
2091 value
, linenum
, ConfigurationFile
);
2095 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2098 * Allow [From] host/ip...
2099 * Deny [From] host/ip...
2104 if (!_cups_strncasecmp(value
, "from", 4))
2107 * Strip leading "from"...
2112 while (_cups_isspace(*value
))
2120 * Find the end of the value...
2123 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2125 while (_cups_isspace(*valptr
))
2129 * Figure out what form the allow/deny address takes:
2140 * nnn.nnn.nnn.nnn/mm
2141 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2144 if (!_cups_strcasecmp(value
, "all"))
2150 if (!_cups_strcasecmp(line
, "Allow"))
2151 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2153 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2155 else if (!_cups_strcasecmp(value
, "none"))
2161 if (!_cups_strcasecmp(line
, "Allow"))
2162 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2164 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2167 else if (value
[0] == '*' || value
[0] == '.' ||
2168 (!isdigit(value
[0] & 255) && value
[0] != '['))
2170 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2171 #endif /* AF_INET6 */
2174 * Host or domain name...
2177 if (value
[0] == '*')
2180 if (!_cups_strcasecmp(line
, "Allow"))
2181 cupsdAddNameMask(&(loc
->allow
), value
);
2183 cupsdAddNameMask(&(loc
->deny
), value
);
2188 * One of many IP address forms...
2191 if (!get_addr_and_mask(value
, ip
, mask
))
2193 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d of %s.",
2194 value
, linenum
, ConfigurationFile
);
2198 if (!_cups_strcasecmp(line
, "Allow"))
2199 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2201 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2205 * Advance to next value...
2211 else if (!_cups_strcasecmp(line
, "AuthType"))
2214 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2217 if (!_cups_strcasecmp(value
, "none"))
2219 loc
->type
= CUPSD_AUTH_NONE
;
2220 loc
->level
= CUPSD_AUTH_ANON
;
2222 else if (!_cups_strcasecmp(value
, "basic"))
2224 loc
->type
= CUPSD_AUTH_BASIC
;
2226 if (loc
->level
== CUPSD_AUTH_ANON
)
2227 loc
->level
= CUPSD_AUTH_USER
;
2229 else if (!_cups_strcasecmp(value
, "default"))
2231 loc
->type
= CUPSD_AUTH_DEFAULT
;
2233 if (loc
->level
== CUPSD_AUTH_ANON
)
2234 loc
->level
= CUPSD_AUTH_USER
;
2237 else if (!_cups_strcasecmp(value
, "negotiate"))
2239 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2241 if (loc
->level
== CUPSD_AUTH_ANON
)
2242 loc
->level
= CUPSD_AUTH_USER
;
2244 #endif /* HAVE_GSSAPI */
2247 cupsdLogMessage(CUPSD_LOG_WARN
,
2248 "Unknown authorization type %s on line %d of %s.",
2249 value
, linenum
, ConfigurationFile
);
2253 else if (!_cups_strcasecmp(line
, "AuthClass"))
2256 * AuthClass anonymous, user, system, group
2259 if (!_cups_strcasecmp(value
, "anonymous"))
2261 loc
->type
= CUPSD_AUTH_NONE
;
2262 loc
->level
= CUPSD_AUTH_ANON
;
2264 cupsdLogMessage(CUPSD_LOG_WARN
,
2265 "\"AuthClass %s\" is deprecated; consider removing "
2269 else if (!_cups_strcasecmp(value
, "user"))
2271 loc
->level
= CUPSD_AUTH_USER
;
2273 cupsdLogMessage(CUPSD_LOG_WARN
,
2274 "\"AuthClass %s\" is deprecated; consider using "
2275 "\"Require valid-user\" on line %d of %s.",
2276 value
, linenum
, ConfigurationFile
);
2278 else if (!_cups_strcasecmp(value
, "group"))
2280 loc
->level
= CUPSD_AUTH_GROUP
;
2282 cupsdLogMessage(CUPSD_LOG_WARN
,
2283 "\"AuthClass %s\" is deprecated; consider using "
2284 "\"Require user @groupname\" on line %d of %s.",
2285 value
, linenum
, ConfigurationFile
);
2287 else if (!_cups_strcasecmp(value
, "system"))
2289 loc
->level
= CUPSD_AUTH_GROUP
;
2291 cupsdAddName(loc
, "@SYSTEM");
2293 cupsdLogMessage(CUPSD_LOG_WARN
,
2294 "\"AuthClass %s\" is deprecated; consider using "
2295 "\"Require user @SYSTEM\" on line %d of %s.",
2296 value
, linenum
, ConfigurationFile
);
2300 cupsdLogMessage(CUPSD_LOG_WARN
,
2301 "Unknown authorization class %s on line %d of %s.",
2302 value
, linenum
, ConfigurationFile
);
2306 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2308 cupsdAddName(loc
, value
);
2310 cupsdLogMessage(CUPSD_LOG_WARN
,
2311 "\"AuthGroupName %s\" directive is deprecated; consider "
2312 "using \"Require user @%s\" on line %d of %s.",
2313 value
, value
, linenum
, ConfigurationFile
);
2315 else if (!_cups_strcasecmp(line
, "Require"))
2318 * Apache synonym for AuthClass and AuthGroupName...
2322 * Require valid-user
2323 * Require group names
2324 * Require user names
2327 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2332 if (!_cups_strcasecmp(value
, "valid-user") ||
2333 !_cups_strcasecmp(value
, "user"))
2334 loc
->level
= CUPSD_AUTH_USER
;
2335 else if (!_cups_strcasecmp(value
, "group"))
2336 loc
->level
= CUPSD_AUTH_GROUP
;
2339 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d of %s.",
2340 value
, linenum
, ConfigurationFile
);
2345 * Get the list of names from the line...
2348 for (value
= valptr
; *value
;)
2350 while (_cups_isspace(*value
))
2353 #ifdef HAVE_AUTHORIZATION_H
2354 if (!strncmp(value
, "@AUTHKEY(", 9))
2357 * Grab "@AUTHKEY(name)" value...
2360 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2366 #endif /* HAVE_AUTHORIZATION_H */
2367 if (*value
== '\"' || *value
== '\'')
2370 * Grab quoted name...
2373 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2380 * Grab literal name.
2383 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2389 cupsdAddName(loc
, value
);
2391 for (value
= valptr
; _cups_isspace(*value
); value
++);
2394 else if (!_cups_strcasecmp(line
, "Satisfy"))
2396 if (!_cups_strcasecmp(value
, "all"))
2397 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2398 else if (!_cups_strcasecmp(value
, "any"))
2399 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2402 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d of %s.",
2403 value
, linenum
, ConfigurationFile
);
2415 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2418 static int /* O - FatalErrors bits */
2419 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2421 int fatal
; /* FatalErrors bits */
2422 char value
[1024], /* Value string */
2423 *valstart
, /* Pointer into value */
2424 *valend
; /* End of value */
2428 * Empty FatalErrors line yields NULL pointer...
2432 return (CUPSD_FATAL_NONE
);
2435 * Loop through the value string,...
2438 strlcpy(value
, s
, sizeof(value
));
2440 fatal
= CUPSD_FATAL_NONE
;
2442 for (valstart
= value
; *valstart
;)
2445 * Get the current space/comma-delimited kind name...
2448 for (valend
= valstart
; *valend
; valend
++)
2449 if (_cups_isspace(*valend
) || *valend
== ',')
2456 * Add the error to the bitmask...
2459 if (!_cups_strcasecmp(valstart
, "all"))
2460 fatal
= CUPSD_FATAL_ALL
;
2461 else if (!_cups_strcasecmp(valstart
, "browse"))
2462 fatal
|= CUPSD_FATAL_BROWSE
;
2463 else if (!_cups_strcasecmp(valstart
, "-browse"))
2464 fatal
&= ~CUPSD_FATAL_BROWSE
;
2465 else if (!_cups_strcasecmp(valstart
, "config"))
2466 fatal
|= CUPSD_FATAL_CONFIG
;
2467 else if (!_cups_strcasecmp(valstart
, "-config"))
2468 fatal
&= ~CUPSD_FATAL_CONFIG
;
2469 else if (!_cups_strcasecmp(valstart
, "listen"))
2470 fatal
|= CUPSD_FATAL_LISTEN
;
2471 else if (!_cups_strcasecmp(valstart
, "-listen"))
2472 fatal
&= ~CUPSD_FATAL_LISTEN
;
2473 else if (!_cups_strcasecmp(valstart
, "log"))
2474 fatal
|= CUPSD_FATAL_LOG
;
2475 else if (!_cups_strcasecmp(valstart
, "-log"))
2476 fatal
&= ~CUPSD_FATAL_LOG
;
2477 else if (!_cups_strcasecmp(valstart
, "permissions"))
2478 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2479 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2480 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2481 else if (_cups_strcasecmp(valstart
, "none"))
2482 cupsdLogMessage(CUPSD_LOG_ERROR
,
2483 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2485 for (valstart
= valend
; *valstart
; valstart
++)
2486 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2495 * 'parse_groups()' - Parse system group names in a string.
2498 static int /* O - 1 on success, 0 on failure */
2499 parse_groups(const char *s
) /* I - Space-delimited groups */
2501 int status
; /* Return status */
2502 char value
[1024], /* Value string */
2503 *valstart
, /* Pointer into value */
2504 *valend
, /* End of value */
2505 quote
; /* Quote character */
2506 struct group
*group
; /* Group */
2510 * Make a copy of the string and parse out the groups...
2513 strlcpy(value
, s
, sizeof(value
));
2518 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2520 if (*valstart
== '\'' || *valstart
== '\"')
2523 * Scan quoted name...
2526 quote
= *valstart
++;
2528 for (valend
= valstart
; *valend
; valend
++)
2529 if (*valend
== quote
)
2535 * Scan space or comma-delimited name...
2538 for (valend
= valstart
; *valend
; valend
++)
2539 if (_cups_isspace(*valend
) || *valend
== ',')
2546 group
= getgrnam(valstart
);
2549 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2550 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2561 while (*valstart
== ',' || _cups_isspace(*valstart
))
2570 * 'parse_protocols()' - Parse browse protocols in a string.
2573 static int /* O - Browse protocol bits */
2574 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2576 int protocols
; /* Browse protocol bits */
2577 char value
[1024], /* Value string */
2578 *valstart
, /* Pointer into value */
2579 *valend
; /* End of value */
2583 * Empty protocol line yields NULL pointer...
2590 * Loop through the value string,...
2593 strlcpy(value
, s
, sizeof(value
));
2597 for (valstart
= value
; *valstart
;)
2600 * Get the current space/comma-delimited protocol name...
2603 for (valend
= valstart
; *valend
; valend
++)
2604 if (_cups_isspace(*valend
) || *valend
== ',')
2611 * Add the protocol to the bitmask...
2614 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2615 !_cups_strcasecmp(valstart
, "dns-sd") ||
2616 !_cups_strcasecmp(valstart
, "bonjour"))
2617 protocols
|= BROWSE_DNSSD
;
2618 else if (!_cups_strcasecmp(valstart
, "all"))
2619 protocols
|= BROWSE_ALL
;
2620 else if (_cups_strcasecmp(valstart
, "none"))
2621 cupsdLogMessage(CUPSD_LOG_ERROR
,
2622 "Unknown browse protocol \"%s\" ignored.", valstart
);
2624 for (valstart
= valend
; *valstart
; valstart
++)
2625 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2634 * 'parse_variable()' - Parse a variable line.
2637 static int /* O - 1 on success, 0 on failure */
2639 const char *filename
, /* I - Name of configuration file */
2640 int linenum
, /* I - Line in configuration file */
2641 const char *line
, /* I - Line from configuration file */
2642 const char *value
, /* I - Value from configuration file */
2643 size_t num_vars
, /* I - Number of variables */
2644 const cupsd_var_t
*vars
) /* I - Variables */
2646 size_t i
; /* Looping var */
2647 const cupsd_var_t
*var
; /* Variables */
2648 char temp
[1024]; /* Temporary string */
2651 for (i
= num_vars
, var
= vars
; i
> 0; i
--, var
++)
2652 if (!_cups_strcasecmp(line
, var
->name
))
2658 * Unknown directive! Output an error message and continue...
2662 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d of %s.",
2663 line
, linenum
, filename
);
2665 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d of %s.",
2666 line
, linenum
, filename
);
2673 case CUPSD_VARTYPE_INTEGER
:
2676 cupsdLogMessage(CUPSD_LOG_ERROR
,
2677 "Missing integer value for %s on line %d of %s.",
2678 line
, linenum
, filename
);
2681 else if (!isdigit(*value
& 255))
2683 cupsdLogMessage(CUPSD_LOG_ERROR
,
2684 "Bad integer value for %s on line %d of %s.",
2685 line
, linenum
, filename
);
2691 char *units
; /* Units */
2693 n
= strtol(value
, &units
, 0);
2695 if (units
&& *units
)
2697 if (tolower(units
[0] & 255) == 'g')
2698 n
*= 1024 * 1024 * 1024;
2699 else if (tolower(units
[0] & 255) == 'm')
2701 else if (tolower(units
[0] & 255) == 'k')
2703 else if (tolower(units
[0] & 255) == 't')
2707 cupsdLogMessage(CUPSD_LOG_ERROR
,
2708 "Unknown integer value for %s on line %d of %s.",
2709 line
, linenum
, filename
);
2716 cupsdLogMessage(CUPSD_LOG_ERROR
,
2717 "Bad negative integer value for %s on line %d of "
2718 "%s.", line
, linenum
, filename
);
2723 *((int *)var
->ptr
) = n
;
2728 case CUPSD_VARTYPE_PERM
:
2731 cupsdLogMessage(CUPSD_LOG_ERROR
,
2732 "Missing permissions value for %s on line %d of %s.",
2733 line
, linenum
, filename
);
2736 else if (!isdigit(*value
& 255))
2738 /* TODO: Add chmod UGO syntax support */
2739 cupsdLogMessage(CUPSD_LOG_ERROR
,
2740 "Bad permissions value for %s on line %d of %s.",
2741 line
, linenum
, filename
);
2746 int n
= strtol(value
, NULL
, 8);
2747 /* Permissions value */
2751 cupsdLogMessage(CUPSD_LOG_ERROR
,
2752 "Bad negative permissions value for %s on line %d of "
2753 "%s.", line
, linenum
, filename
);
2758 *((mode_t
*)var
->ptr
) = (mode_t
)n
;
2763 case CUPSD_VARTYPE_TIME
:
2766 cupsdLogMessage(CUPSD_LOG_ERROR
,
2767 "Missing time interval value for %s on line %d of "
2768 "%s.", line
, linenum
, filename
);
2771 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
2772 (!_cups_strcasecmp(value
, "true") ||
2773 !_cups_strcasecmp(value
, "on") ||
2774 !_cups_strcasecmp(value
, "enabled") ||
2775 !_cups_strcasecmp(value
, "yes")))
2777 *((int *)var
->ptr
) = INT_MAX
;
2779 else if (!_cups_strcasecmp(value
, "false") ||
2780 !_cups_strcasecmp(value
, "off") ||
2781 !_cups_strcasecmp(value
, "disabled") ||
2782 !_cups_strcasecmp(value
, "no"))
2784 *((int *)var
->ptr
) = 0;
2786 else if (!isdigit(*value
& 255))
2788 cupsdLogMessage(CUPSD_LOG_ERROR
,
2789 "Unknown time interval value for %s on line %d of "
2790 "%s.", line
, linenum
, filename
);
2795 double n
; /* Number */
2796 char *units
; /* Units */
2798 n
= strtod(value
, &units
);
2800 if (units
&& *units
)
2802 if (tolower(units
[0] & 255) == 'w')
2803 n
*= 7 * 24 * 60 * 60;
2804 else if (tolower(units
[0] & 255) == 'd')
2806 else if (tolower(units
[0] & 255) == 'h')
2808 else if (tolower(units
[0] & 255) == 'm')
2812 cupsdLogMessage(CUPSD_LOG_ERROR
,
2813 "Unknown time interval value for %s on line "
2814 "%d of %s.", line
, linenum
, filename
);
2819 if (n
< 0.0 || n
> INT_MAX
)
2821 cupsdLogMessage(CUPSD_LOG_ERROR
,
2822 "Bad time value for %s on line %d of %s.",
2823 line
, linenum
, filename
);
2828 *((int *)var
->ptr
) = (int)n
;
2833 case CUPSD_VARTYPE_BOOLEAN
:
2836 cupsdLogMessage(CUPSD_LOG_ERROR
,
2837 "Missing boolean value for %s on line %d of %s.",
2838 line
, linenum
, filename
);
2841 else if (!_cups_strcasecmp(value
, "true") ||
2842 !_cups_strcasecmp(value
, "on") ||
2843 !_cups_strcasecmp(value
, "enabled") ||
2844 !_cups_strcasecmp(value
, "yes") ||
2847 *((int *)var
->ptr
) = TRUE
;
2849 else if (!_cups_strcasecmp(value
, "false") ||
2850 !_cups_strcasecmp(value
, "off") ||
2851 !_cups_strcasecmp(value
, "disabled") ||
2852 !_cups_strcasecmp(value
, "no") ||
2853 !_cups_strcasecmp(value
, "0"))
2855 *((int *)var
->ptr
) = FALSE
;
2859 cupsdLogMessage(CUPSD_LOG_ERROR
,
2860 "Unknown boolean value %s on line %d of %s.",
2861 value
, linenum
, filename
);
2866 case CUPSD_VARTYPE_PATHNAME
:
2869 cupsdLogMessage(CUPSD_LOG_ERROR
,
2870 "Missing pathname value for %s on line %d of %s.",
2871 line
, linenum
, filename
);
2875 if (value
[0] == '/')
2876 strlcpy(temp
, value
, sizeof(temp
));
2878 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
2880 if (access(temp
, 0) && _cups_strcasecmp(value
, "internal") && _cups_strcasecmp(line
, "ServerKeychain"))
2882 cupsdLogMessage(CUPSD_LOG_ERROR
,
2883 "File or directory for \"%s %s\" on line %d of %s "
2884 "does not exist.", line
, value
, linenum
, filename
);
2888 cupsdSetString((char **)var
->ptr
, temp
);
2891 case CUPSD_VARTYPE_STRING
:
2892 cupsdSetString((char **)var
->ptr
, value
);
2901 * 'read_cupsd_conf()' - Read the cupsd.conf configuration file.
2904 static int /* O - 1 on success, 0 on failure */
2905 read_cupsd_conf(cups_file_t
*fp
) /* I - File to read from */
2907 int linenum
; /* Current line number */
2908 char line
[HTTP_MAX_BUFFER
],
2909 /* Line from file */
2910 temp
[HTTP_MAX_BUFFER
],
2911 /* Temporary buffer for value */
2912 *value
, /* Pointer to value */
2913 *valueptr
; /* Pointer into value */
2914 int valuelen
; /* Length of value */
2915 http_addrlist_t
*addrlist
, /* Address list */
2916 *addr
; /* Current address */
2917 cups_file_t
*incfile
; /* Include file */
2918 char incname
[1024]; /* Include filename */
2922 * Loop through each line in the file...
2927 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2930 * Decode the directive...
2933 if (!_cups_strcasecmp(line
, "Include") && value
)
2939 if (value
[0] == '/')
2940 strlcpy(incname
, value
, sizeof(incname
));
2942 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2944 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2945 cupsdLogMessage(CUPSD_LOG_ERROR
,
2946 "Unable to include config file \"%s\" - %s",
2947 incname
, strerror(errno
));
2950 read_cupsd_conf(incfile
);
2951 cupsFileClose(incfile
);
2954 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2960 linenum
= read_location(fp
, value
, linenum
);
2964 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2970 linenum
= read_policy(fp
, value
, linenum
);
2974 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2976 JobRetryInterval
= atoi(value
);
2977 cupsdLogMessage(CUPSD_LOG_WARN
,
2978 "FaxRetryInterval is deprecated; use "
2979 "JobRetryInterval on line %d of %s.", linenum
, ConfigurationFile
);
2981 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2983 JobRetryLimit
= atoi(value
);
2984 cupsdLogMessage(CUPSD_LOG_WARN
,
2985 "FaxRetryLimit is deprecated; use "
2986 "JobRetryLimit on line %d of %s.", linenum
, ConfigurationFile
);
2989 else if (!_cups_strcasecmp(line
, "SSLOptions"))
2992 * SSLOptions [AllowRC4] [AllowSSL3] [None]
2995 int options
= 0; /* SSL/TLS options */
2999 char *start
, /* Start of option */
3000 *end
; /* End of option */
3002 for (start
= value
; *start
; start
= end
)
3005 * Find end of keyword...
3009 while (*end
&& !_cups_isspace(*end
))
3019 if (!_cups_strcasecmp(start
, "AllowRC4"))
3020 options
|= _HTTP_TLS_ALLOW_RC4
;
3021 else if (!_cups_strcasecmp(start
, "AllowSSL3"))
3022 options
|= _HTTP_TLS_ALLOW_SSL3
;
3023 else if (!_cups_strcasecmp(start
, "None"))
3025 else if (_cups_strcasecmp(start
, "NoEmptyFragments"))
3026 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown SSL option %s at line %d.", start
, linenum
);
3030 _httpTLSSetOptions(options
);
3032 #endif /* HAVE_SSL */
3033 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
3035 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
3036 #endif /* HAVE_SSL */
3040 * Add listening address(es) to the list...
3043 cupsd_listener_t
*lis
; /* New listeners array */
3047 * Get the address list...
3050 addrlist
= get_address(value
, IPP_PORT
);
3054 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
3060 * Add each address...
3063 for (addr
= addrlist
; addr
; addr
= addr
->next
)
3066 * See if this address is already present...
3069 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
3071 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
3072 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
3073 httpAddrPort(&(addr
->addr
)) == httpAddrPort(&(lis
->address
)))
3078 #ifdef HAVE_ONDEMAND
3079 if (!lis
->on_demand
)
3080 #endif /* HAVE_ONDEMAND */
3082 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3083 cupsdLogMessage(CUPSD_LOG_WARN
,
3084 "Duplicate listen address \"%s\" ignored.", temp
);
3091 * Allocate another listener...
3095 Listeners
= cupsArrayNew(NULL
, NULL
);
3099 cupsdLogMessage(CUPSD_LOG_ERROR
,
3100 "Unable to allocate %s at line %d - %s.",
3101 line
, linenum
, strerror(errno
));
3105 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
3107 cupsdLogMessage(CUPSD_LOG_ERROR
,
3108 "Unable to allocate %s at line %d - %s.",
3109 line
, linenum
, strerror(errno
));
3113 cupsArrayAdd(Listeners
, lis
);
3116 * Copy the current address and log it...
3119 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
3123 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
3124 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
3125 #endif /* HAVE_SSL */
3127 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3130 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
3131 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
3133 #endif /* AF_LOCAL */
3134 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
3135 httpAddrPort(&(lis
->address
)),
3136 httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
3138 if (!httpAddrLocalhost(&(lis
->address
)))
3139 RemotePort
= httpAddrPort(&(lis
->address
));
3146 httpAddrFreeList(addrlist
);
3148 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
3149 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
3152 * "BrowseProtocols name [... name]"
3153 * "BrowseLocalProtocols name [... name]"
3156 int protocols
= parse_protocols(value
);
3160 cupsdLogMessage(CUPSD_LOG_ERROR
,
3161 "Unknown browse protocol \"%s\" on line %d of %s.",
3162 value
, linenum
, ConfigurationFile
);
3166 BrowseLocalProtocols
= protocols
;
3168 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
3171 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3174 if (!_cups_strcasecmp(value
, "none"))
3175 default_auth_type
= CUPSD_AUTH_NONE
;
3176 else if (!_cups_strcasecmp(value
, "basic"))
3177 default_auth_type
= CUPSD_AUTH_BASIC
;
3179 else if (!_cups_strcasecmp(value
, "negotiate"))
3180 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
3181 #endif /* HAVE_GSSAPI */
3182 else if (!_cups_strcasecmp(value
, "auto"))
3183 default_auth_type
= CUPSD_AUTH_AUTO
;
3186 cupsdLogMessage(CUPSD_LOG_WARN
,
3187 "Unknown default authorization type %s on line %d of %s.",
3188 value
, linenum
, ConfigurationFile
);
3189 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3194 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
3197 * DefaultEncryption {Never,IfRequested,Required}
3200 if (!value
|| !_cups_strcasecmp(value
, "never"))
3201 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3202 else if (!_cups_strcasecmp(value
, "required"))
3203 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3204 else if (!_cups_strcasecmp(value
, "ifrequested"))
3205 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3208 cupsdLogMessage(CUPSD_LOG_WARN
,
3209 "Unknown default encryption %s on line %d of %s.",
3210 value
, linenum
, ConfigurationFile
);
3211 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3215 #endif /* HAVE_SSL */
3216 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
3219 * Do hostname lookups?
3222 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
3223 !_cups_strcasecmp(value
, "false"))
3224 HostNameLookups
= 0;
3225 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
3226 !_cups_strcasecmp(value
, "true"))
3227 HostNameLookups
= 1;
3228 else if (!_cups_strcasecmp(value
, "double"))
3229 HostNameLookups
= 2;
3231 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d of %s.",
3232 value
, linenum
, ConfigurationFile
);
3234 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
3237 * Amount of logging to do to access log...
3240 if (!_cups_strcasecmp(value
, "all"))
3241 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3242 else if (!_cups_strcasecmp(value
, "actions"))
3243 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3244 else if (!_cups_strcasecmp(value
, "config"))
3245 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3246 else if (!_cups_strcasecmp(value
, "none"))
3247 AccessLogLevel
= CUPSD_ACCESSLOG_NONE
;
3249 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d of %s.",
3250 value
, linenum
, ConfigurationFile
);
3252 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
3255 * Amount of logging to do to error log...
3258 if (!_cups_strcasecmp(value
, "debug2"))
3259 LogLevel
= CUPSD_LOG_DEBUG2
;
3260 else if (!_cups_strcasecmp(value
, "debug"))
3261 LogLevel
= CUPSD_LOG_DEBUG
;
3262 else if (!_cups_strcasecmp(value
, "info"))
3263 LogLevel
= CUPSD_LOG_INFO
;
3264 else if (!_cups_strcasecmp(value
, "notice"))
3265 LogLevel
= CUPSD_LOG_NOTICE
;
3266 else if (!_cups_strcasecmp(value
, "warn"))
3267 LogLevel
= CUPSD_LOG_WARN
;
3268 else if (!_cups_strcasecmp(value
, "error"))
3269 LogLevel
= CUPSD_LOG_ERROR
;
3270 else if (!_cups_strcasecmp(value
, "crit"))
3271 LogLevel
= CUPSD_LOG_CRIT
;
3272 else if (!_cups_strcasecmp(value
, "alert"))
3273 LogLevel
= CUPSD_LOG_ALERT
;
3274 else if (!_cups_strcasecmp(value
, "emerg"))
3275 LogLevel
= CUPSD_LOG_EMERG
;
3276 else if (!_cups_strcasecmp(value
, "none"))
3277 LogLevel
= CUPSD_LOG_NONE
;
3279 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d of %s.",
3280 value
, linenum
, ConfigurationFile
);
3282 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
3285 * Amount of logging to do to error log...
3288 if (!_cups_strcasecmp(value
, "standard"))
3289 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3290 else if (!_cups_strcasecmp(value
, "usecs"))
3291 LogTimeFormat
= CUPSD_TIME_USECS
;
3293 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d of %s.",
3294 value
, linenum
, ConfigurationFile
);
3296 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
3299 * Set the string used for the Server header...
3302 struct utsname plat
; /* Platform info */
3307 if (!_cups_strcasecmp(value
, "ProductOnly"))
3308 cupsdSetString(&ServerHeader
, "CUPS IPP");
3309 else if (!_cups_strcasecmp(value
, "Major"))
3310 cupsdSetStringf(&ServerHeader
, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR
);
3311 else if (!_cups_strcasecmp(value
, "Minor"))
3312 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
3313 CUPS_VERSION_MINOR
);
3314 else if (!_cups_strcasecmp(value
, "Minimal"))
3315 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
" IPP/2.1");
3316 else if (!_cups_strcasecmp(value
, "OS"))
3317 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s) IPP/2.1",
3318 plat
.sysname
, plat
.release
);
3319 else if (!_cups_strcasecmp(value
, "Full"))
3320 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s; %s) IPP/2.1",
3321 plat
.sysname
, plat
.release
, plat
.machine
);
3322 else if (!_cups_strcasecmp(value
, "None"))
3323 cupsdClearString(&ServerHeader
);
3325 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d of %s.",
3326 value
, linenum
, ConfigurationFile
);
3328 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3331 * PassEnv variable [... variable]
3336 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3337 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3340 if (value
[valuelen
])
3342 value
[valuelen
] = '\0';
3346 cupsdSetEnv(value
, NULL
);
3348 for (value
+= valuelen
; *value
; value
++)
3349 if (!_cups_isspace(*value
) || *value
!= ',')
3353 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3356 * ServerAlias name [... name]
3360 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3364 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3365 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3368 if (value
[valuelen
])
3370 value
[valuelen
] = '\0';
3374 cupsdAddAlias(ServerAlias
, value
);
3376 for (value
+= valuelen
; *value
; value
++)
3377 if (!_cups_isspace(*value
) || *value
!= ',')
3381 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3384 * SetEnv variable value
3387 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3395 while (isspace(*valueptr
& 255))
3398 cupsdSetEnv(value
, valueptr
);
3401 cupsdLogMessage(CUPSD_LOG_ERROR
,
3402 "Missing value for SetEnv directive on line %d of %s.",
3403 linenum
, ConfigurationFile
);
3405 else if (!_cups_strcasecmp(line
, "AccessLog") ||
3406 !_cups_strcasecmp(line
, "CacheDir") ||
3407 !_cups_strcasecmp(line
, "ConfigFilePerm") ||
3408 !_cups_strcasecmp(line
, "DataDir") ||
3409 !_cups_strcasecmp(line
, "DocumentRoot") ||
3410 !_cups_strcasecmp(line
, "ErrorLog") ||
3411 !_cups_strcasecmp(line
, "FatalErrors") ||
3412 !_cups_strcasecmp(line
, "FileDevice") ||
3413 !_cups_strcasecmp(line
, "FontPath") ||
3414 !_cups_strcasecmp(line
, "Group") ||
3415 !_cups_strcasecmp(line
, "LogFilePerm") ||
3416 !_cups_strcasecmp(line
, "LPDConfigFile") ||
3417 !_cups_strcasecmp(line
, "PageLog") ||
3418 !_cups_strcasecmp(line
, "Printcap") ||
3419 !_cups_strcasecmp(line
, "PrintcapFormat") ||
3420 !_cups_strcasecmp(line
, "RemoteRoot") ||
3421 !_cups_strcasecmp(line
, "RequestRoot") ||
3422 !_cups_strcasecmp(line
, "ServerBin") ||
3423 !_cups_strcasecmp(line
, "ServerCertificate") ||
3424 !_cups_strcasecmp(line
, "ServerKey") ||
3425 !_cups_strcasecmp(line
, "ServerKeychain") ||
3426 !_cups_strcasecmp(line
, "ServerRoot") ||
3427 !_cups_strcasecmp(line
, "SMBConfigFile") ||
3428 !_cups_strcasecmp(line
, "StateDir") ||
3429 !_cups_strcasecmp(line
, "SystemGroup") ||
3430 !_cups_strcasecmp(line
, "SystemGroupAuthKey") ||
3431 !_cups_strcasecmp(line
, "TempDir") ||
3432 !_cups_strcasecmp(line
, "User"))
3434 cupsdLogMessage(CUPSD_LOG_INFO
,
3435 "Please move \"%s%s%s\" on line %d of %s to the %s file; "
3436 "this will become an error in a future release.",
3437 line
, value
? " " : "", value
? value
: "", linenum
,
3438 ConfigurationFile
, CupsFilesFile
);
3441 parse_variable(ConfigurationFile
, linenum
, line
, value
,
3442 sizeof(cupsd_vars
) / sizeof(cupsd_vars
[0]), cupsd_vars
);
3450 * 'read_cups_files_conf()' - Read the cups-files.conf configuration file.
3453 static int /* O - 1 on success, 0 on failure */
3454 read_cups_files_conf(cups_file_t
*fp
) /* I - File to read from */
3456 int linenum
; /* Current line number */
3457 char line
[HTTP_MAX_BUFFER
], /* Line from file */
3458 *value
; /* Value from line */
3459 struct group
*group
; /* Group */
3463 * Loop through each line in the file...
3468 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3470 if (!_cups_strcasecmp(line
, "FatalErrors"))
3471 FatalErrors
= parse_fatal_errors(value
);
3472 else if (!_cups_strcasecmp(line
, "Group") && value
)
3475 * Group ID to run as...
3478 if (isdigit(value
[0]))
3479 Group
= (gid_t
)atoi(value
);
3483 group
= getgrnam(value
);
3486 Group
= group
->gr_gid
;
3489 cupsdLogMessage(CUPSD_LOG_ERROR
,
3490 "Unknown Group \"%s\" on line %d of %s.", value
,
3491 linenum
, CupsFilesFile
);
3492 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3497 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
3500 * Format of printcap file?
3503 if (!_cups_strcasecmp(value
, "bsd"))
3504 PrintcapFormat
= PRINTCAP_BSD
;
3505 else if (!_cups_strcasecmp(value
, "plist"))
3506 PrintcapFormat
= PRINTCAP_PLIST
;
3507 else if (!_cups_strcasecmp(value
, "solaris"))
3508 PrintcapFormat
= PRINTCAP_SOLARIS
;
3511 cupsdLogMessage(CUPSD_LOG_ERROR
,
3512 "Unknown PrintcapFormat \"%s\" on line %d of %s.",
3513 value
, linenum
, CupsFilesFile
);
3514 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3518 else if (!_cups_strcasecmp(line
, "Sandboxing") && value
)
3521 * Level of sandboxing?
3524 if (!_cups_strcasecmp(value
, "off") && getuid())
3526 Sandboxing
= CUPSD_SANDBOXING_OFF
;
3527 cupsdLogMessage(CUPSD_LOG_WARN
, "Disabling sandboxing is not recommended (line %d of %s)", linenum
, CupsFilesFile
);
3529 else if (!_cups_strcasecmp(value
, "relaxed"))
3530 Sandboxing
= CUPSD_SANDBOXING_RELAXED
;
3531 else if (!_cups_strcasecmp(value
, "strict"))
3532 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
3535 cupsdLogMessage(CUPSD_LOG_ERROR
,
3536 "Unknown Sandboxing \"%s\" on line %d of %s.",
3537 value
, linenum
, CupsFilesFile
);
3538 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3542 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
3545 * SystemGroup (admin) group(s)...
3548 if (!parse_groups(value
))
3550 cupsdLogMessage(CUPSD_LOG_ERROR
,
3551 "Unknown SystemGroup \"%s\" on line %d of %s.", value
,
3552 linenum
, CupsFilesFile
);
3553 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3557 else if (!_cups_strcasecmp(line
, "User") && value
)
3560 * User ID to run as...
3563 if (isdigit(value
[0] & 255))
3565 int uid
= atoi(value
);
3569 cupsdLogMessage(CUPSD_LOG_ERROR
,
3570 "Will not use User 0 as specified on line %d of %s "
3571 "for security reasons. You must use a non-"
3572 "privileged account instead.",
3573 linenum
, CupsFilesFile
);
3574 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3578 User
= (uid_t
)atoi(value
);
3582 struct passwd
*p
; /* Password information */
3585 p
= getpwnam(value
);
3591 cupsdLogMessage(CUPSD_LOG_ERROR
,
3592 "Will not use User %s (UID=0) as specified on line "
3593 "%d of %s for security reasons. You must use a "
3594 "non-privileged account instead.",
3595 value
, linenum
, CupsFilesFile
);
3596 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3604 cupsdLogMessage(CUPSD_LOG_ERROR
,
3605 "Unknown User \"%s\" on line %d of %s.",
3606 value
, linenum
, CupsFilesFile
);
3607 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3612 else if (!_cups_strcasecmp(line
, "ServerCertificate") ||
3613 !_cups_strcasecmp(line
, "ServerKey"))
3615 cupsdLogMessage(CUPSD_LOG_INFO
,
3616 "The \"%s\" directive on line %d of %s is no longer "
3617 "supported; this will become an error in a future "
3619 line
, linenum
, CupsFilesFile
);
3621 else if (!parse_variable(CupsFilesFile
, linenum
, line
, value
,
3622 sizeof(cupsfiles_vars
) / sizeof(cupsfiles_vars
[0]),
3624 (FatalErrors
& CUPSD_FATAL_CONFIG
))
3633 * 'read_location()' - Read a <Location path> definition.
3636 static int /* O - New line number or 0 on error */
3637 read_location(cups_file_t
*fp
, /* I - Configuration file */
3638 char *location
, /* I - Location name/path */
3639 int linenum
) /* I - Current line number */
3641 cupsd_location_t
*loc
, /* New location */
3642 *parent
; /* Parent location */
3643 char line
[HTTP_MAX_BUFFER
],
3645 *value
, /* Value for directive */
3646 *valptr
; /* Pointer into value */
3649 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3650 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d of %s.",
3651 location
, linenum
, ConfigurationFile
);
3652 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3656 cupsdAddLocation(parent
);
3658 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3663 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3666 * Decode the directive...
3669 if (!_cups_strcasecmp(line
, "</Location>"))
3671 else if (!_cups_strcasecmp(line
, "<Limit") ||
3672 !_cups_strcasecmp(line
, "<LimitExcept"))
3676 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3677 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3683 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3686 cupsdAddLocation(loc
);
3691 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3696 if (!strcmp(value
, "ALL"))
3697 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3698 else if (!strcmp(value
, "GET"))
3699 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3700 else if (!strcmp(value
, "HEAD"))
3701 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3702 else if (!strcmp(value
, "OPTIONS"))
3703 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3704 else if (!strcmp(value
, "POST"))
3705 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3706 else if (!strcmp(value
, "PUT"))
3707 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3708 else if (!strcmp(value
, "TRACE"))
3709 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3711 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d of %s.",
3712 value
, linenum
, ConfigurationFile
);
3714 for (value
= valptr
; isspace(*value
& 255); value
++);
3717 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3718 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3720 parent
->limit
&= ~loc
->limit
;
3722 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3723 !_cups_strcasecmp(line
, "</LimitExcept>"))
3727 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3728 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3731 else if (!parse_aaa(loc
, line
, value
, linenum
))
3733 cupsdLogMessage(CUPSD_LOG_ERROR
,
3734 "Unknown Location directive %s on line %d of %s.",
3735 line
, linenum
, ConfigurationFile
);
3736 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3741 cupsdLogMessage(CUPSD_LOG_ERROR
,
3742 "Unexpected end-of-file at line %d while reading location.",
3745 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3750 * 'read_policy()' - Read a <Policy name> definition.
3753 static int /* O - New line number or 0 on error */
3754 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3755 char *policy
, /* I - Location name/path */
3756 int linenum
) /* I - Current line number */
3758 int i
; /* Looping var */
3759 cupsd_policy_t
*pol
; /* Policy */
3760 cupsd_location_t
*op
; /* Policy operation */
3761 int num_ops
; /* Number of IPP operations */
3762 ipp_op_t ops
[100]; /* Operations */
3763 char line
[HTTP_MAX_BUFFER
],
3765 *value
, /* Value for directive */
3766 *valptr
; /* Pointer into value */
3770 * Create the policy...
3773 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3774 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d of %s.",
3775 policy
, linenum
, ConfigurationFile
);
3776 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3780 * Read from the file...
3786 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3789 * Decode the directive...
3792 if (!_cups_strcasecmp(line
, "</Policy>"))
3795 cupsdLogMessage(CUPSD_LOG_WARN
,
3796 "Missing </Limit> before </Policy> on line %d of %s.",
3797 linenum
, ConfigurationFile
);
3799 set_policy_defaults(pol
);
3803 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3807 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3808 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3815 * Scan for IPP operation names...
3822 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3827 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3829 if (!_cups_strcasecmp(value
, "All"))
3830 ops
[num_ops
] = IPP_ANY_OPERATION
;
3831 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3832 cupsdLogMessage(CUPSD_LOG_ERROR
,
3833 "Bad IPP operation name \"%s\" on line %d of %s.",
3834 value
, linenum
, ConfigurationFile
);
3839 cupsdLogMessage(CUPSD_LOG_ERROR
,
3840 "Too many operations listed on line %d of %s.",
3841 linenum
, ConfigurationFile
);
3843 for (value
= valptr
; isspace(*value
& 255); value
++);
3847 * If none are specified, apply the policy to all operations...
3852 ops
[0] = IPP_ANY_OPERATION
;
3857 * Add a new policy for the first operation...
3860 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3862 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3865 * Finish the current operation limit...
3871 * Copy the policy to the other operations...
3874 for (i
= 1; i
< num_ops
; i
++)
3875 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3882 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3883 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3886 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3887 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3888 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3889 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3893 cupsdLogMessage(CUPSD_LOG_ERROR
,
3894 "%s directive must appear outside <Limit>...</Limit> "
3895 "on line %d of %s.", line
, linenum
, ConfigurationFile
);
3896 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3902 * Pull out whitespace-delimited values...
3908 * Find the end of the current value...
3911 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3917 * Save it appropriately...
3920 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3923 * JobPrivateAccess {all|default|user/group list|@@ACL}
3926 if (!_cups_strcasecmp(value
, "default"))
3928 cupsdAddString(&(pol
->job_access
), "@OWNER");
3929 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3932 cupsdAddString(&(pol
->job_access
), value
);
3934 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3937 * JobPrivateValues {all|none|default|attribute list}
3940 if (!_cups_strcasecmp(value
, "default"))
3942 cupsdAddString(&(pol
->job_attrs
), "job-name");
3943 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3944 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3945 cupsdAddString(&(pol
->job_attrs
), "phone");
3948 cupsdAddString(&(pol
->job_attrs
), value
);
3950 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3953 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3956 if (!_cups_strcasecmp(value
, "default"))
3958 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3959 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3962 cupsdAddString(&(pol
->sub_access
), value
);
3964 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3967 * SubscriptionPrivateValues {all|none|default|attribute list}
3970 if (!_cups_strcasecmp(value
, "default"))
3972 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3973 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3974 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3975 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3976 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3979 cupsdAddString(&(pol
->sub_attrs
), value
);
3983 * Find the next string on the line...
3986 for (value
= valptr
; isspace(*value
& 255); value
++);
3992 cupsdLogMessage(CUPSD_LOG_ERROR
,
3993 "Missing <Limit ops> directive before %s on line %d of %s.",
3994 line
, linenum
, ConfigurationFile
);
3995 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3998 else if (!parse_aaa(op
, line
, value
, linenum
))
4000 cupsdLogMessage(CUPSD_LOG_ERROR
,
4001 "Unknown Policy Limit directive %s on line %d of %s.",
4002 line
, linenum
, ConfigurationFile
);
4004 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4009 cupsdLogMessage(CUPSD_LOG_ERROR
,
4010 "Unexpected end-of-file at line %d while reading policy "
4011 "\"%s\".", linenum
, policy
);
4013 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
4018 * 'set_policy_defaults()' - Set default policy values as needed.
4022 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
4024 cupsd_location_t
*op
; /* Policy operation */
4028 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
4029 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
4030 * upgrades do not introduce new security issues...
4032 * CUPS STR #4659: Allow a lone <Limit All> policy.
4035 if (cupsArrayCount(pol
->ops
) > 1)
4037 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
4038 op
->op
== IPP_ANY_OPERATION
)
4040 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
4041 op
->op
!= IPP_ANY_OPERATION
)
4044 * Add a new limit for Validate-Job using the Print-Job limit as a
4048 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s - using Print-Job's policy.", pol
->name
);
4050 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
4053 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s and no suitable template found.", pol
->name
);
4056 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
4057 op
->op
== IPP_ANY_OPERATION
)
4059 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
4060 op
->op
!= IPP_ANY_OPERATION
)
4063 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
4067 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s - using Pause-Printer's policy.", pol
->name
);
4069 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
4072 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s and no suitable template found.", pol
->name
);
4075 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
4076 op
->op
== IPP_ANY_OPERATION
)
4078 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4079 op
->op
!= IPP_ANY_OPERATION
)
4082 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
4086 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-My-Jobs defined in policy %s - using Send-Document's policy.", pol
->name
);
4088 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
4091 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-My-Jobs defined in policy %s and no suitable template found.", pol
->name
);
4094 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
4095 op
->op
== IPP_ANY_OPERATION
)
4097 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4098 op
->op
!= IPP_ANY_OPERATION
)
4101 * Add a new limit for Close-Job using the Send-Document limit as a
4105 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s - using Send-Document's policy.", pol
->name
);
4107 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
4110 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s and no suitable template found.", pol
->name
);
4113 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
4114 op
->op
== IPP_ANY_OPERATION
)
4116 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4117 op
->op
!= IPP_ANY_OPERATION
)
4120 * Add a new limit for CUPS-Get-Document using the Send-Document
4121 * limit as a template...
4124 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s - using Send-Document's policy.", pol
->name
);
4126 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
4129 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s and no suitable template found.", pol
->name
);
4134 * Verify we have JobPrivateAccess, JobPrivateValues,
4135 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4138 if (!pol
->job_access
)
4140 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4141 cupsdAddString(&(pol
->job_access
), "@OWNER");
4142 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4145 if (!pol
->job_attrs
)
4147 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateValues defined in policy %s - using defaults.", pol
->name
);
4148 cupsdAddString(&(pol
->job_attrs
), "job-name");
4149 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4150 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4151 cupsdAddString(&(pol
->job_attrs
), "phone");
4154 if (!pol
->sub_access
)
4156 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4157 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4158 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4161 if (!pol
->sub_attrs
)
4163 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateValues defined in policy %s - using defaults.", pol
->name
);
4164 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4165 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4166 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4167 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4168 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");