4 * Configuration routines for the CUPS scheduler.
6 * Copyright 2007-2015 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
23 #include <sys/utsname.h>
26 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
27 # define SD_JOURNAL_SUPPRESS_LOCATION
28 # include <systemd/sd-journal.h>
29 #endif /* HAVE_ASL_H */
34 #endif /* HAVE_LIBPAPER */
38 * Possibly missing network definitions...
42 # define INADDR_NONE 0xffffffff
43 #endif /* !INADDR_NONE */
47 * Configuration variable structure...
52 CUPSD_VARTYPE_INTEGER
, /* Integer option */
53 CUPSD_VARTYPE_TIME
, /* Time interval option */
54 CUPSD_VARTYPE_STRING
, /* String option */
55 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
56 CUPSD_VARTYPE_PATHNAME
, /* File/directory name option */
57 CUPSD_VARTYPE_PERM
/* File/directory permissions */
62 const char *name
; /* Name of variable */
63 void *ptr
; /* Pointer to variable */
64 cupsd_vartype_t type
; /* Type (int, string, address) */
72 static const cupsd_var_t cupsd_vars
[] =
74 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
75 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
76 { "BrowseDNSSDSubTypes", &DNSSDSubTypes
, CUPSD_VARTYPE_STRING
},
77 #endif /* HAVE_DNSSD || HAVE_AVAHI */
78 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
79 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
80 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
81 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
82 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
83 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_TIME
},
84 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
85 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
86 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
87 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_TIME
},
88 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
89 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
90 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
92 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
93 #endif /* HAVE_GSSAPI */
94 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
95 { "IdleExitTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
96 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
97 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_TIME
},
98 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
99 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_TIME
},
100 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_TIME
},
101 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
103 { "LaunchdTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
104 #endif /* HAVE_LAUNCHD */
105 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
106 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
107 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
108 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
109 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
110 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
111 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
112 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
113 { "MaxHoldTime", &MaxHoldTime
, CUPSD_VARTYPE_TIME
},
114 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
115 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
116 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
117 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_TIME
},
118 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_TIME
},
119 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
120 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
121 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
122 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
123 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
124 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
125 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_TIME
},
126 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
127 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_TIME
},
128 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_TIME
},
129 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_TIME
},
130 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
131 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_TIME
},
132 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
133 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
134 { "StrictConformance", &StrictConformance
, CUPSD_VARTYPE_BOOLEAN
},
135 { "Timeout", &Timeout
, CUPSD_VARTYPE_TIME
},
136 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
138 static const cupsd_var_t cupsfiles_vars
[] =
140 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
141 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
142 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_PERM
},
143 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
144 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
145 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
146 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
147 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
148 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_PERM
},
149 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
150 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
151 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
152 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
153 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
154 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
156 { "ServerKeychain", &ServerKeychain
, CUPSD_VARTYPE_PATHNAME
},
157 #endif /* HAVE_SSL */
158 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
159 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
160 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
161 { "SyncOnClose", &SyncOnClose
, CUPSD_VARTYPE_BOOLEAN
},
162 #ifdef HAVE_AUTHORIZATION_H
163 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
164 #endif /* HAVE_AUTHORIZATION_H */
165 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
}
168 static int default_auth_type
= CUPSD_AUTH_AUTO
;
169 /* Default AuthType, if not specified */
171 static const unsigned ones
[4] =
173 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
175 static const unsigned zeros
[4] =
177 0x00000000, 0x00000000, 0x00000000, 0x00000000
185 static http_addrlist_t
*get_address(const char *value
, int defport
);
186 static int get_addr_and_mask(const char *value
, unsigned *ip
,
188 static void mime_error_cb(void *ctx
, const char *message
);
189 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
190 char *value
, int linenum
);
191 static int parse_fatal_errors(const char *s
);
192 static int parse_groups(const char *s
);
193 static int parse_protocols(const char *s
);
194 static int parse_variable(const char *filename
, int linenum
,
195 const char *line
, const char *value
,
197 const cupsd_var_t
*vars
);
198 static int read_cupsd_conf(cups_file_t
*fp
);
199 static int read_cups_files_conf(cups_file_t
*fp
);
200 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
201 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
202 static void set_policy_defaults(cupsd_policy_t
*pol
);
206 * 'cupsdAddAlias()' - Add a host alias.
210 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
211 const char *name
) /* I - Name to add */
213 cupsd_alias_t
*a
; /* New alias */
214 size_t namelen
; /* Length of name */
217 namelen
= strlen(name
);
219 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
222 a
->namelen
= namelen
;
223 memcpy(a
->name
, name
, namelen
+ 1); /* OK since a->name is allocated */
225 cupsArrayAdd(aliases
, a
);
230 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
233 int /* O - 0 on success, -1 on error, 1 on warning */
234 cupsdCheckPermissions(
235 const char *filename
, /* I - File/directory name */
236 const char *suffix
, /* I - Additional file/directory name */
237 mode_t mode
, /* I - Permissions */
238 uid_t user
, /* I - Owner */
239 gid_t group
, /* I - Group */
240 int is_dir
, /* I - 1 = directory, 0 = file */
241 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
243 int dir_created
= 0; /* Did we create a directory? */
244 char pathname
[1024]; /* File name with prefix */
245 struct stat fileinfo
; /* Stat buffer */
246 int is_symlink
; /* Is "filename" a symlink? */
250 * Prepend the given root to the filename before testing it...
255 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
260 * See if we can stat the file/directory...
263 if (lstat(filename
, &fileinfo
))
265 if (errno
== ENOENT
&& create_dir
)
268 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
271 if (mkdir(filename
, mode
))
274 cupsdLogMessage(CUPSD_LOG_ERROR
,
275 "Unable to create directory \"%s\" - %s", filename
,
280 asl_object_t m
; /* Log message */
282 m
= asl_new(ASL_TYPE_MSG
);
283 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
284 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
287 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
288 sd_journal_print(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
290 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
291 #endif /* HAVE_ASL_H */
297 fileinfo
.st_mode
= mode
| S_IFDIR
;
300 return (create_dir
? -1 : 1);
303 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
305 if (stat(filename
, &fileinfo
))
307 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
308 filename
, strerror(errno
));
314 * Make sure it's a regular file or a directory as needed...
317 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
319 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
323 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
326 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
330 asl_object_t m
; /* Log message */
332 m
= asl_new(ASL_TYPE_MSG
);
333 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
334 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "\"%s\" is not a directory.", filename
);
337 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
338 sd_journal_print(LOG_ERR
, "\"%s\" is not a directory.", filename
);
340 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
341 #endif /* HAVE_ASL_H */
347 * If the filename is a symlink, do not change permissions (STR #2937)...
354 * Fix owner, group, and mode as needed...
357 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
360 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
363 if (chown(filename
, user
, group
) && !getuid())
366 cupsdLogMessage(CUPSD_LOG_ERROR
,
367 "Unable to change ownership of \"%s\" - %s", filename
,
372 asl_object_t m
; /* Log message */
374 m
= asl_new(ASL_TYPE_MSG
);
375 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
376 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
379 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
380 sd_journal_print(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
382 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
383 #endif /* HAVE_ASL_H */
389 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
392 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
395 if (chmod(filename
, mode
))
398 cupsdLogMessage(CUPSD_LOG_ERROR
,
399 "Unable to change permissions of \"%s\" - %s", filename
,
404 asl_object_t m
; /* Log message */
406 m
= asl_new(ASL_TYPE_MSG
);
407 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
408 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
411 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
412 sd_journal_print(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
414 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
415 #endif /* HAVE_ASL_H */
422 * Everything is OK...
430 * 'cupsdDefaultAuthType()' - Get the default AuthType.
432 * When the default_auth_type is "auto", this function tries to get the GSS
433 * credentials for the server. If that succeeds we use Kerberos authentication,
434 * otherwise we do a fallback to Basic authentication against the local user
438 int /* O - Default AuthType value */
439 cupsdDefaultAuthType(void)
442 OM_uint32 major_status
, /* Major status code */
443 minor_status
; /* Minor status code */
444 gss_name_t server_name
; /* Server name */
445 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
446 /* Service name token */
447 char buf
[1024]; /* Service name buffer */
448 #endif /* HAVE_GSSAPI */
452 * If we have already determined the correct default AuthType, use it...
455 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
456 return (default_auth_type
);
461 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
465 if (&gss_init_sec_context
== NULL
)
466 return (default_auth_type
= CUPSD_AUTH_BASIC
);
467 # endif /* __APPLE__ */
470 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
471 * that fails we must use Basic...
474 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
477 token
.length
= strlen(buf
);
478 server_name
= GSS_C_NO_NAME
;
479 major_status
= gss_import_name(&minor_status
, &token
,
480 GSS_C_NT_HOSTBASED_SERVICE
,
483 memset(&token
, 0, sizeof(token
));
485 if (GSS_ERROR(major_status
))
487 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
488 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
489 return (default_auth_type
= CUPSD_AUTH_BASIC
);
492 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
494 if (GSS_ERROR(major_status
))
496 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
497 "cupsdDefaultAuthType: gss_display_name(%s) failed",
499 return (default_auth_type
= CUPSD_AUTH_BASIC
);
502 cupsdLogMessage(CUPSD_LOG_DEBUG
,
503 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
504 "credentials for %s...", (char *)token
.value
);
506 ServerCreds
= GSS_C_NO_CREDENTIAL
;
507 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
508 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
509 &ServerCreds
, NULL
, NULL
);
510 if (GSS_ERROR(major_status
))
512 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
513 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
514 (char *)token
.value
);
515 gss_release_name(&minor_status
, &server_name
);
516 gss_release_buffer(&minor_status
, &token
);
517 return (default_auth_type
= CUPSD_AUTH_BASIC
);
520 cupsdLogMessage(CUPSD_LOG_DEBUG
,
521 "cupsdDefaultAuthType: Kerberos credentials acquired "
522 "successfully for %s.", (char *)token
.value
);
524 gss_release_name(&minor_status
, &server_name
);
525 gss_release_buffer(&minor_status
, &token
);
529 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
533 * No Kerberos support compiled in so just use Basic all the time...
536 return (default_auth_type
= CUPSD_AUTH_BASIC
);
537 #endif /* HAVE_GSSAPI */
542 * 'cupsdFreeAliases()' - Free all of the alias entries.
546 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
548 cupsd_alias_t
*a
; /* Current alias */
551 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
553 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
556 cupsArrayDelete(aliases
);
561 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
564 int /* O - 1 on success, 0 otherwise */
565 cupsdReadConfiguration(void)
567 int i
; /* Looping var */
568 cups_file_t
*fp
; /* Configuration file */
569 int status
; /* Return status */
570 char temp
[1024], /* Temporary buffer */
571 mimedir
[1024], /* MIME directory */
572 *slash
; /* Directory separator */
573 cups_lang_t
*language
; /* Language */
574 struct passwd
*user
; /* Default user */
575 struct group
*group
; /* Default group */
576 char *old_serverroot
, /* Old ServerRoot */
577 *old_requestroot
; /* Old RequestRoot */
578 int old_remote_port
; /* Old RemotePort */
579 const char *tmpdir
; /* TMPDIR environment variable */
580 struct stat tmpinfo
; /* Temporary directory info */
581 cupsd_policy_t
*p
; /* Policy */
585 * Save the old root paths...
588 old_serverroot
= NULL
;
589 cupsdSetString(&old_serverroot
, ServerRoot
);
590 old_requestroot
= NULL
;
591 cupsdSetString(&old_requestroot
, RequestRoot
);
594 * Reset the server configuration data...
597 cupsdDeleteAllLocations();
599 cupsdDeleteAllListeners();
601 old_remote_port
= RemotePort
;
608 cupsdFreeAliases(ServerAlias
);
611 cupsdClearString(&ServerName
);
612 cupsdClearString(&ServerAdmin
);
613 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
614 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
615 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
616 cupsdSetString(&DataDir
, CUPS_DATADIR
);
617 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
618 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
619 cupsdClearString(&ErrorLog
);
620 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
621 cupsdSetString(&PageLogFormat
,
622 "%p %u %j %T %P %C %{job-billing} "
623 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
624 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
625 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
626 cupsdSetString(&RemoteRoot
, "remroot");
627 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
629 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
631 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
632 PrintcapFormat
= PRINTCAP_SOLARIS
;
633 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
634 "/Library/Preferences/org.cups.printers.plist"))
635 PrintcapFormat
= PRINTCAP_PLIST
;
637 PrintcapFormat
= PRINTCAP_BSD
;
639 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
640 if ((slash
= strrchr(temp
, '/')) != NULL
)
643 cupsdSetString(&ServerRoot
, temp
);
645 cupsdClearString(&Classification
);
646 ClassifyOverride
= 0;
650 cupsdSetString(&ServerKeychain
, "ssl");
652 cupsdSetString(&ServerKeychain
, "/Library/Keychains/System.keychain");
653 # endif /* HAVE_GNUTLS */
655 _httpTLSSetOptions(0);
656 #endif /* HAVE_SSL */
658 language
= cupsLangDefault();
660 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
661 cupsdSetString(&DefaultLanguage
, "en");
663 cupsdSetString(&DefaultLanguage
, language
->language
);
665 cupsdClearString(&DefaultPaperSize
);
667 cupsdSetString(&RIPCache
, "128m");
669 cupsdSetString(&TempDir
, NULL
);
672 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
676 OM_uint32 minor_status
; /* Minor status code */
678 gss_release_cred(&minor_status
, &ServerCreds
);
683 ServerCreds
= GSS_C_NO_CREDENTIAL
;
684 #endif /* HAVE_GSSAPI */
687 * Find the default user...
690 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
695 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
696 * complement number...)
705 * Find the default group...
708 group
= getgrnam(CUPS_DEFAULT_GROUP
);
712 Group
= group
->gr_gid
;
716 * Fallback to group "nobody"...
719 group
= getgrnam("nobody");
723 Group
= group
->gr_gid
;
727 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
728 * complement number...)
739 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
740 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
741 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
742 default_auth_type
= CUPSD_AUTH_BASIC
;
744 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
745 #endif /* HAVE_SSL */
746 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
747 JobKillDelay
= DEFAULT_TIMEOUT
;
749 JobRetryInterval
= 300;
754 HostNameLookups
= FALSE
;
756 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
757 ListenBackLog
= SOMAXCONN
;
758 LogDebugHistory
= 200;
759 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
760 LogLevel
= CUPSD_LOG_WARN
;
761 LogTimeFormat
= CUPSD_TIME_STANDARD
;
763 MaxClientsPerHost
= 0;
764 MaxLogSize
= 1024 * 1024;
766 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
768 ReloadTimeout
= DEFAULT_KEEPALIVE
;
769 RootCertDuration
= 300;
770 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
771 StrictConformance
= FALSE
;
773 Timeout
= DEFAULT_TIMEOUT
;
774 WebInterface
= CUPS_DEFAULT_WEBIF
;
776 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
778 Browsing
= CUPS_DEFAULT_BROWSING
;
779 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
781 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
782 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
783 #endif /* HAVE_DNSSD || HAVE_AVAHI */
785 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
786 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
788 cupsdSetString(&ErrorPolicy
, "stop-printer");
790 JobHistory
= DEFAULT_HISTORY
;
791 JobFiles
= DEFAULT_FILES
;
797 MaxJobsPerPrinter
= 0;
798 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
799 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
801 cupsdDeleteAllPolicies();
802 cupsdClearString(&DefaultPolicy
);
804 #ifdef HAVE_AUTHORIZATION_H
805 cupsdSetString(&SystemGroupAuthKey
, CUPS_DEFAULT_SYSTEM_AUTHKEY
);
806 #endif /* HAVE_AUTHORIZATION_H */
808 MaxSubscriptions
= 100;
809 MaxSubscriptionsPerJob
= 0;
810 MaxSubscriptionsPerPrinter
= 0;
811 MaxSubscriptionsPerUser
= 0;
812 DefaultLeaseDuration
= 86400;
813 MaxLeaseDuration
= 0;
815 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
816 IdleExitTimeout
= 60;
817 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
820 * Setup environment variables...
826 * Read the cups-files.conf file...
829 if ((fp
= cupsFileOpen(CupsFilesFile
, "r")) != NULL
)
831 status
= read_cups_files_conf(fp
);
838 printf("\"%s\" contains errors.\n", CupsFilesFile
);
842 asl_object_t m
; /* Log message */
844 m
= asl_new(ASL_TYPE_MSG
);
845 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
846 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
849 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
850 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
852 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
853 #endif /* HAVE_ASL_H */
858 else if (errno
== ENOENT
)
859 cupsdLogMessage(CUPSD_LOG_INFO
, "No %s, using defaults.", CupsFilesFile
);
863 asl_object_t m
; /* Log message */
865 m
= asl_new(ASL_TYPE_MSG
);
866 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
867 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
870 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
871 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
873 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
874 #endif /* HAVE_ASL_H */
880 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
883 * Read the cupsd.conf file...
886 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
889 asl_object_t m
; /* Log message */
891 m
= asl_new(ASL_TYPE_MSG
);
892 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
893 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
895 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
896 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
898 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
899 #endif /* HAVE_ASL_H */
904 status
= read_cupsd_conf(fp
);
911 printf("\"%s\" contains errors.\n", ConfigurationFile
);
915 asl_object_t m
; /* Log message */
917 m
= asl_new(ASL_TYPE_MSG
);
918 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
919 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
922 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
923 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
925 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
926 #endif /* HAVE_ASL_H */
933 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
934 RemotePort
? "enabled" : "disabled");
937 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
940 * See if the ServerName is an IP address...
946 ServerAlias
= cupsArrayNew(NULL
, NULL
);
948 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
952 if (gethostname(temp
, sizeof(temp
)))
954 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
956 strlcpy(temp
, "localhost", sizeof(temp
));
959 cupsdSetString(&ServerName
, temp
);
962 ServerAlias
= cupsArrayNew(NULL
, NULL
);
964 cupsdAddAlias(ServerAlias
, temp
);
965 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
967 if (HostNameLookups
|| RemotePort
)
969 struct hostent
*host
; /* Host entry to get FQDN */
971 if ((host
= gethostbyname(temp
)) != NULL
)
973 if (_cups_strcasecmp(temp
, host
->h_name
))
975 cupsdSetString(&ServerName
, host
->h_name
);
976 cupsdAddAlias(ServerAlias
, host
->h_name
);
977 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
983 for (i
= 0; host
->h_aliases
[i
]; i
++)
984 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
986 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
987 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
995 * Make sure we have the base hostname added as an alias, too!
998 if ((slash
= strchr(temp
, '.')) != NULL
)
1001 cupsdAddAlias(ServerAlias
, temp
);
1002 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
1006 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
1008 ServerNameIsIP
= !*slash
;
1011 * Make sure ServerAdmin is initialized...
1015 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
1018 * Use the default system group if none was supplied in cupsd.conf...
1021 if (NumSystemGroups
== 0)
1023 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
1026 * Find the group associated with GID 0...
1029 group
= getgrgid(0);
1033 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
1035 cupsdSetString(&SystemGroups
[0], "unknown");
1037 SystemGroupIDs
[0] = 0;
1038 NumSystemGroups
= 1;
1043 * Make sure ConfigFilePerm and LogFilePerm have sane values...
1046 ConfigFilePerm
&= 0664;
1047 LogFilePerm
&= 0664;
1050 * Open the system log for cupsd if necessary...
1055 if (!strcmp(AccessLog
, "stderr"))
1056 cupsdSetString(&AccessLog
, "syslog");
1058 if (!strcmp(ErrorLog
, "stderr"))
1059 cupsdSetString(&ErrorLog
, "syslog");
1061 if (!strcmp(PageLog
, "stderr"))
1062 cupsdSetString(&PageLog
, "syslog");
1065 #if defined(HAVE_VSYSLOG) && !defined(HAVE_ASL_H) && !defined(HAVE_SYSTEMD_SD_JOURNAL_H)
1066 if (!strcmp(AccessLog
, "syslog") ||
1067 !strcmp(ErrorLog
, "syslog") ||
1068 !strcmp(PageLog
, "syslog"))
1069 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
1070 #endif /* HAVE_VSYSLOG && !HAVE_ASL_H && !HAVE_SYSTEMD_SD_JOURNAL_H */
1073 * Make sure each of the log files exists and gets rotated as necessary...
1076 if (strcmp(AccessLog
, "syslog"))
1077 cupsdCheckLogFile(&AccessFile
, AccessLog
);
1079 if (strcmp(ErrorLog
, "syslog"))
1080 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
1082 if (strcmp(PageLog
, "syslog"))
1083 cupsdCheckLogFile(&PageFile
, PageLog
);
1086 * Log the configuration file that was used...
1089 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
1093 * Validate the Group and SystemGroup settings - they cannot be the same,
1094 * otherwise the CGI programs will be able to authenticate as root without
1100 for (i
= 0; i
< NumSystemGroups
; i
++)
1101 if (Group
== SystemGroupIDs
[i
])
1104 if (i
< NumSystemGroups
)
1107 * Log the error and reset the group to a safe value...
1110 cupsdLogMessage(CUPSD_LOG_ERROR
,
1111 "Group and SystemGroup cannot use the same groups.");
1112 if (FatalErrors
& (CUPSD_FATAL_CONFIG
| CUPSD_FATAL_PERMISSIONS
))
1115 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
1117 group
= getgrnam("nobody");
1121 Group
= group
->gr_gid
;
1125 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
1126 * complement number...)
1135 * Check that we have at least one listen/port line; if not, report this
1136 * as an error and exit!
1139 if (cupsArrayCount(Listeners
) == 0)
1145 cupsdLogMessage(CUPSD_LOG_EMERG
,
1146 "No valid Listen or Port lines were found in the "
1147 "configuration file.");
1153 cupsdEndProcess(getpid(), 0);
1157 * Set the default locale using the language and charset...
1160 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1163 * Update all relative filenames to include the full path from ServerRoot...
1166 if (DocumentRoot
[0] != '/')
1167 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1169 if (RequestRoot
[0] != '/')
1170 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1172 if (ServerBin
[0] != '/')
1173 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1175 if (StateDir
[0] != '/')
1176 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1178 if (CacheDir
[0] != '/')
1179 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1182 if (ServerKeychain
[0] != '/')
1183 cupsdSetStringf(&ServerKeychain
, "%s/%s", ServerRoot
, ServerKeychain
);
1185 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Using keychain \"%s\" for server name \"%s\".", ServerKeychain
, ServerName
);
1186 cupsSetServerCredentials(ServerKeychain
, ServerName
, 1);
1187 #endif /* HAVE_SSL */
1190 * Make sure that directories and config files are owned and
1191 * writable by the user and group in the cupsd.conf file...
1194 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1196 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1198 cupsdCheckPermissions(CacheDir
, NULL
, 0770, RunUser
,
1200 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1202 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1204 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1205 SystemGroupIDs
[0], 1, 1) < 0 ||
1206 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1208 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1210 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1212 cupsdCheckPermissions(ConfigurationFile
, NULL
, ConfigFilePerm
, RunUser
,
1214 cupsdCheckPermissions(CupsFilesFile
, NULL
, ConfigFilePerm
, RunUser
,
1216 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1218 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1220 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1221 Group
, 0, 0) < 0) &&
1222 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1226 * Update TempDir to the default if it hasn't been set already...
1230 if (TempDir
&& !RunUser
&&
1231 (!strncmp(TempDir
, "/private/tmp", 12) || !strncmp(TempDir
, "/tmp", 4)))
1233 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot use %s for TempDir.", TempDir
);
1234 cupsdClearString(&TempDir
);
1236 #endif /* __APPLE__ */
1241 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1242 strncmp(tmpdir
, "/private/tmp", 12) && strncmp(tmpdir
, "/tmp", 4))
1244 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1245 #endif /* __APPLE__ */
1248 * TMPDIR is defined, see if it is OK for us to use...
1251 if (stat(tmpdir
, &tmpinfo
))
1252 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1253 tmpdir
, strerror(errno
));
1254 else if (!S_ISDIR(tmpinfo
.st_mode
))
1255 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1257 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1258 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1259 !(tmpinfo
.st_mode
& S_IWOTH
))
1260 cupsdLogMessage(CUPSD_LOG_ERROR
,
1261 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1263 cupsdSetString(&TempDir
, tmpdir
);
1269 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1271 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1274 setenv("TMPDIR", TempDir
, 1);
1277 * Make sure the temporary directory has the right permissions...
1280 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1284 * Update ownership and permissions if the CUPS temp directory
1285 * is under the spool directory or does not exist...
1288 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1289 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1294 * Update environment variables...
1300 * Validate the default error policy...
1303 if (strcmp(ErrorPolicy
, "retry-current-job") &&
1304 strcmp(ErrorPolicy
, "abort-job") &&
1305 strcmp(ErrorPolicy
, "retry-job") &&
1306 strcmp(ErrorPolicy
, "stop-printer"))
1308 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\", resetting to \"stop-printer\".", ErrorPolicy
);
1309 cupsdSetString(&ErrorPolicy
, "stop-printer");
1313 * Update default paper size setting as needed...
1316 if (!DefaultPaperSize
)
1318 #ifdef HAVE_LIBPAPER
1319 char *paper_result
; /* Paper size name from libpaper */
1321 if ((paper_result
= systempapername()) != NULL
)
1322 cupsdSetString(&DefaultPaperSize
, paper_result
);
1324 #endif /* HAVE_LIBPAPER */
1325 if (!DefaultLanguage
||
1326 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1327 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1328 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1329 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1330 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1331 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1332 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1335 * These are the only locales that will default to "letter" size...
1338 cupsdSetString(&DefaultPaperSize
, "Letter");
1341 cupsdSetString(&DefaultPaperSize
, "A4");
1345 * Update classification setting as needed...
1348 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1349 cupsdClearString(&Classification
);
1352 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1355 * Check the MaxClients setting, and then allocate memory for it...
1358 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1361 cupsdLogMessage(CUPSD_LOG_INFO
,
1362 "MaxClients limited to 1/3 (%d) of the file descriptor "
1364 MaxFDs
/ 3, MaxFDs
);
1366 MaxClients
= MaxFDs
/ 3;
1369 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1373 * Check the MaxActiveJobs setting; limit to 1/3 the available
1374 * file descriptors, since we need a pipe for each job...
1377 if (MaxActiveJobs
> (MaxFDs
/ 3))
1378 MaxActiveJobs
= MaxFDs
/ 3;
1381 * Update the MaxClientsPerHost value, as needed...
1384 if (MaxClientsPerHost
<= 0)
1385 MaxClientsPerHost
= MaxClients
;
1387 if (MaxClientsPerHost
> MaxClients
)
1388 MaxClientsPerHost
= MaxClients
;
1390 cupsdLogMessage(CUPSD_LOG_INFO
,
1391 "Allowing up to %d client connections per host.",
1395 * Update the default policy, as needed...
1399 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1401 DefaultPolicyPtr
= NULL
;
1403 if (!DefaultPolicyPtr
)
1405 cupsd_location_t
*po
; /* New policy operation */
1409 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1412 cupsdSetString(&DefaultPolicy
, "default");
1414 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1415 cupsdLogMessage(CUPSD_LOG_INFO
,
1416 "Using policy \"default\" as the default.");
1419 cupsdLogMessage(CUPSD_LOG_INFO
,
1420 "Creating CUPS default administrative policy:");
1422 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1424 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1426 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1427 cupsdAddString(&(p
->job_access
), "@OWNER");
1428 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1430 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1431 cupsdAddString(&(p
->job_attrs
), "job-name");
1432 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1433 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1434 cupsdAddString(&(p
->job_attrs
), "phone");
1436 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1437 cupsdAddString(&(p
->sub_access
), "@OWNER");
1438 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1440 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1441 cupsdAddString(&(p
->job_attrs
), "notify-events");
1442 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1443 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1444 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1445 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1447 cupsdLogMessage(CUPSD_LOG_INFO
,
1448 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1449 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1451 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1452 po
->order_type
= CUPSD_AUTH_ALLOW
;
1454 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1455 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1456 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1458 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1460 cupsdLogMessage(CUPSD_LOG_INFO
,
1461 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1462 "Release-Job Restart-Job Purge-Jobs "
1463 "Set-Job-Attributes Create-Job-Subscription "
1464 "Renew-Subscription Cancel-Subscription "
1465 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1466 "Suspend-Current-Job Resume-Job "
1467 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1468 "CUPS-Authenticate-Job CUPS-Get-Document>");
1469 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1471 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1472 po
->order_type
= CUPSD_AUTH_ALLOW
;
1473 po
->level
= CUPSD_AUTH_USER
;
1475 cupsdAddName(po
, "@OWNER");
1476 cupsdAddName(po
, "@SYSTEM");
1477 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1479 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1480 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1481 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1482 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1483 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1484 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1485 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1486 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1487 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1488 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1489 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1490 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1491 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1492 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1493 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1494 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1495 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1496 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1497 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1498 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1500 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1502 cupsdLogMessage(CUPSD_LOG_INFO
,
1503 "<Limit Pause-Printer Resume-Printer "
1504 "Set-Printer-Attributes Enable-Printer "
1505 "Disable-Printer Pause-Printer-After-Current-Job "
1506 "Hold-New-Jobs Release-Held-New-Jobs "
1507 "Deactivate-Printer Activate-Printer Restart-Printer "
1508 "Shutdown-Printer Startup-Printer Promote-Job "
1509 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1510 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1511 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1512 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1513 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1515 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1516 po
->order_type
= CUPSD_AUTH_ALLOW
;
1517 po
->type
= CUPSD_AUTH_DEFAULT
;
1518 po
->level
= CUPSD_AUTH_USER
;
1520 cupsdAddName(po
, "@SYSTEM");
1521 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1523 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1524 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1525 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1526 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1527 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1528 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1529 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1530 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1531 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1532 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1533 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1534 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1535 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1536 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1537 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1538 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1539 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1540 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1541 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1542 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1543 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1544 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1546 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1548 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1549 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1551 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1552 po
->order_type
= CUPSD_AUTH_ALLOW
;
1554 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1555 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1559 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1560 cupsArrayCount(Policies
));
1561 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1563 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1564 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1565 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1568 * If we are doing a full reload or the server root has changed, flush
1569 * the jobs, printers, etc. and start from scratch...
1572 if (NeedReload
== RELOAD_ALL
||
1573 old_remote_port
!= RemotePort
||
1574 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1575 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1577 mime_type_t
*type
; /* Current type */
1578 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1579 /* MIME type name */
1582 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1585 * Free all memory...
1588 cupsdDeleteAllSubscriptions();
1590 cupsdDeleteAllPrinters();
1592 DefaultPrinter
= NULL
;
1594 if (MimeDatabase
!= NULL
)
1595 mimeDelete(MimeDatabase
);
1599 for (i
= 0; i
< NumMimeTypes
; i
++)
1600 _cupsStrFree(MimeTypes
[i
]);
1606 * Read the MIME type and conversion database...
1609 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1610 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1612 MimeDatabase
= mimeNew();
1613 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1615 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1616 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1617 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1618 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1622 cupsdLogMessage(CUPSD_LOG_EMERG
,
1623 "Unable to load MIME database from \"%s\" or \"%s\".",
1624 mimedir
, ServerRoot
);
1625 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1629 cupsdLogMessage(CUPSD_LOG_INFO
,
1630 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1631 "%d filters...", mimedir
, ServerRoot
,
1632 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1635 * Create a list of MIME types for the document-format-supported
1639 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1640 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1643 if ((MimeTypes
= calloc((size_t)NumMimeTypes
, sizeof(const char *))) == NULL
)
1645 cupsdLogMessage(CUPSD_LOG_ERROR
,
1646 "Unable to allocate memory for %d MIME types.",
1652 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1654 i
++, type
= mimeNextType(MimeDatabase
))
1656 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1658 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1661 if (i
< NumMimeTypes
)
1662 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1665 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1667 mime_filter_t
*filter
; /* Current filter */
1670 for (type
= mimeFirstType(MimeDatabase
);
1672 type
= mimeNextType(MimeDatabase
))
1673 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1674 type
->super
, type
->type
);
1676 for (filter
= mimeFirstFilter(MimeDatabase
);
1678 filter
= mimeNextFilter(MimeDatabase
))
1679 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1680 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1681 filter
->src
->super
, filter
->src
->type
,
1682 filter
->dst
->super
, filter
->dst
->type
,
1683 filter
->cost
, filter
->filter
);
1690 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1691 cupsdLoadBanners(temp
);
1694 * Load printers and classes...
1697 cupsdLoadAllPrinters();
1698 cupsdLoadAllClasses();
1700 cupsdCreateCommonData();
1703 * Update the printcap file as needed...
1706 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1707 cupsdWritePrintcap();
1710 * Load queued jobs...
1716 * Load subscriptions...
1719 cupsdLoadAllSubscriptions();
1721 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1726 * Not a full reload, so recreate the common printer attributes...
1729 cupsdCreateCommonData();
1732 * Update all jobs as needed...
1738 * Update all printers as needed...
1741 cupsdUpdatePrinters();
1742 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1744 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1748 * Reset the reload state...
1751 NeedReload
= RELOAD_NONE
;
1753 cupsdClearString(&old_serverroot
);
1754 cupsdClearString(&old_requestroot
);
1761 * 'get_address()' - Get an address + port number from a line.
1764 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1765 get_address(const char *value
, /* I - Value string */
1766 int defport
) /* I - Default port */
1768 char buffer
[1024], /* Hostname + port number buffer */
1769 defpname
[255], /* Default port name */
1770 *hostname
, /* Hostname or IP */
1771 *portname
; /* Port number or name */
1772 http_addrlist_t
*addrlist
; /* Address list */
1776 * Check for an empty value...
1781 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1786 * Grab a hostname and port number; if there is no colon and the port name
1787 * is only digits, then we have a port number by itself...
1790 strlcpy(buffer
, value
, sizeof(buffer
));
1792 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1799 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1804 * Use the default port...
1807 sprintf(defpname
, "%d", defport
);
1808 portname
= defpname
;
1814 * The buffer contains just a port number...
1822 if (hostname
&& !strcmp(hostname
, "*"))
1826 * Now lookup the address using httpAddrGetList()...
1829 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1830 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1831 hostname
? hostname
: "(nil)");
1838 * 'get_addr_and_mask()' - Get an IP address and netmask.
1841 static int /* O - 1 on success, 0 on failure */
1842 get_addr_and_mask(const char *value
, /* I - String from config file */
1843 unsigned *ip
, /* O - Address value */
1844 unsigned *mask
) /* O - Mask value */
1846 int i
, j
, /* Looping vars */
1847 family
, /* Address family */
1848 ipcount
; /* Count of fields in address */
1849 unsigned ipval
; /* Value */
1850 const char *maskval
, /* Pointer to start of mask value */
1851 *ptr
, /* Pointer into value */
1856 * Get the address...
1859 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1860 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1862 if ((maskval
= strchr(value
, '/')) != NULL
)
1865 maskval
= value
+ strlen(value
);
1869 * Check for an IPv6 address...
1875 * Parse hexadecimal IPv6/IPv4 address...
1880 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1884 else if (!strncmp(ptr
, "::", 2))
1886 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1888 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1893 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1896 * Read IPv4 dotted quad...
1899 unsigned val
[4] = { 0, 0, 0, 0 };
1900 /* IPv4 address values */
1902 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1906 * Range check the IP numbers...
1909 for (i
= 0; i
< ipcount
; i
++)
1914 * Merge everything into a 32-bit IPv4 address in ip[3]...
1917 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1918 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1921 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1924 * If the leading words are all 0's then this is an IPv4 address...
1927 if (!val
[0] && !val
[1] && !val
[2])
1930 while (isdigit(*ptr
& 255) || *ptr
== '.')
1934 else if (isxdigit(*ptr
& 255))
1936 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1938 if (*ptr
== ':' && ptr
[1] != ':')
1947 ip
[i
/ 2] |= ipval
<< 16;
1958 if (*ptr
&& *ptr
!= '/')
1962 #endif /* AF_INET6 */
1965 * Parse dotted-decimal IPv4 address...
1968 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1972 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1975 * Range check the IP numbers...
1978 for (i
= 0; i
< ipcount
; i
++)
1983 * Merge everything into a 32-bit IPv4 address in ip[3]...
1986 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1987 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1990 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1996 * Get the netmask value(s)...
1999 memset(mask
, 0, sizeof(unsigned) * 4);
2001 if (strchr(maskval
, '.'))
2004 * Get dotted-decimal mask...
2007 if (family
!= AF_INET
)
2010 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
2014 mask
[3] |= (((((unsigned)mask
[0] << 8) | (unsigned)mask
[1]) << 8) |
2015 (unsigned)mask
[2]) << 8;
2016 mask
[0] = mask
[1] = mask
[2] = 0;
2021 * Get address/bits format...
2027 if (family
== AF_INET6
)
2035 mask
[0] = 0xffffffff;
2037 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
2040 mask
[1] = 0xffffffff;
2044 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
2047 mask
[2] = 0xffffffff;
2051 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
2054 mask
[3] = 0xffffffff;
2058 mask
[3] = (0xffffffff << i
) & 0xffffffff;
2061 #endif /* AF_INET6 */
2066 mask
[0] = 0xffffffff;
2067 mask
[1] = 0xffffffff;
2068 mask
[2] = 0xffffffff;
2071 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
2073 mask
[3] = 0xffffffff;
2078 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2079 "get_addr_and_mask(value=\"%s\", "
2080 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
2081 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
2085 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2088 if ((ip
[0] & ~mask
[0]) != 0 ||
2089 (ip
[1] & ~mask
[1]) != 0 ||
2090 (ip
[2] & ~mask
[2]) != 0 ||
2091 (ip
[3] & ~mask
[3]) != 0)
2099 * 'mime_error_cb()' - Log a MIME error.
2103 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
2104 const char *message
) /* I - Message */
2108 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
2113 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
2116 static int /* O - 1 on success, 0 on failure */
2117 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
2118 char *line
, /* I - Line from file */
2119 char *value
, /* I - Start of value data */
2120 int linenum
) /* I - Current line number */
2122 char *valptr
; /* Pointer into value */
2123 unsigned ip
[4], /* IP address components */
2124 mask
[4]; /* IP netmask components */
2127 if (!_cups_strcasecmp(line
, "Encryption"))
2130 * "Encryption xxx" - set required encryption level...
2133 if (!_cups_strcasecmp(value
, "never"))
2134 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
2135 else if (!_cups_strcasecmp(value
, "always"))
2137 cupsdLogMessage(CUPSD_LOG_ERROR
,
2138 "Encryption value \"%s\" on line %d of %s is invalid in this "
2139 "context. Using \"required\" instead.", value
, linenum
, ConfigurationFile
);
2141 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2143 else if (!_cups_strcasecmp(value
, "required"))
2144 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2145 else if (!_cups_strcasecmp(value
, "ifrequested"))
2146 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2149 cupsdLogMessage(CUPSD_LOG_ERROR
,
2150 "Unknown Encryption value %s on line %d of %s.", value
, linenum
, ConfigurationFile
);
2154 else if (!_cups_strcasecmp(line
, "Order"))
2157 * "Order Deny,Allow" or "Order Allow,Deny"...
2160 if (!_cups_strncasecmp(value
, "deny", 4))
2161 loc
->order_type
= CUPSD_AUTH_ALLOW
;
2162 else if (!_cups_strncasecmp(value
, "allow", 5))
2163 loc
->order_type
= CUPSD_AUTH_DENY
;
2166 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d of %s.",
2167 value
, linenum
, ConfigurationFile
);
2171 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2174 * Allow [From] host/ip...
2175 * Deny [From] host/ip...
2180 if (!_cups_strncasecmp(value
, "from", 4))
2183 * Strip leading "from"...
2188 while (_cups_isspace(*value
))
2196 * Find the end of the value...
2199 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2201 while (_cups_isspace(*valptr
))
2205 * Figure out what form the allow/deny address takes:
2216 * nnn.nnn.nnn.nnn/mm
2217 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2220 if (!_cups_strcasecmp(value
, "all"))
2226 if (!_cups_strcasecmp(line
, "Allow"))
2227 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2229 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2231 else if (!_cups_strcasecmp(value
, "none"))
2237 if (!_cups_strcasecmp(line
, "Allow"))
2238 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2240 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2243 else if (value
[0] == '*' || value
[0] == '.' ||
2244 (!isdigit(value
[0] & 255) && value
[0] != '['))
2246 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2247 #endif /* AF_INET6 */
2250 * Host or domain name...
2253 if (value
[0] == '*')
2256 if (!_cups_strcasecmp(line
, "Allow"))
2257 cupsdAddNameMask(&(loc
->allow
), value
);
2259 cupsdAddNameMask(&(loc
->deny
), value
);
2264 * One of many IP address forms...
2267 if (!get_addr_and_mask(value
, ip
, mask
))
2269 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d of %s.",
2270 value
, linenum
, ConfigurationFile
);
2274 if (!_cups_strcasecmp(line
, "Allow"))
2275 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2277 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2281 * Advance to next value...
2287 else if (!_cups_strcasecmp(line
, "AuthType"))
2290 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2293 if (!_cups_strcasecmp(value
, "none"))
2295 loc
->type
= CUPSD_AUTH_NONE
;
2296 loc
->level
= CUPSD_AUTH_ANON
;
2298 else if (!_cups_strcasecmp(value
, "basic"))
2300 loc
->type
= CUPSD_AUTH_BASIC
;
2302 if (loc
->level
== CUPSD_AUTH_ANON
)
2303 loc
->level
= CUPSD_AUTH_USER
;
2305 else if (!_cups_strcasecmp(value
, "default"))
2307 loc
->type
= CUPSD_AUTH_DEFAULT
;
2309 if (loc
->level
== CUPSD_AUTH_ANON
)
2310 loc
->level
= CUPSD_AUTH_USER
;
2313 else if (!_cups_strcasecmp(value
, "negotiate"))
2315 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2317 if (loc
->level
== CUPSD_AUTH_ANON
)
2318 loc
->level
= CUPSD_AUTH_USER
;
2320 #endif /* HAVE_GSSAPI */
2323 cupsdLogMessage(CUPSD_LOG_WARN
,
2324 "Unknown authorization type %s on line %d of %s.",
2325 value
, linenum
, ConfigurationFile
);
2329 else if (!_cups_strcasecmp(line
, "AuthClass"))
2332 * AuthClass anonymous, user, system, group
2335 if (!_cups_strcasecmp(value
, "anonymous"))
2337 loc
->type
= CUPSD_AUTH_NONE
;
2338 loc
->level
= CUPSD_AUTH_ANON
;
2340 cupsdLogMessage(CUPSD_LOG_WARN
,
2341 "\"AuthClass %s\" is deprecated; consider removing "
2345 else if (!_cups_strcasecmp(value
, "user"))
2347 loc
->level
= CUPSD_AUTH_USER
;
2349 cupsdLogMessage(CUPSD_LOG_WARN
,
2350 "\"AuthClass %s\" is deprecated; consider using "
2351 "\"Require valid-user\" on line %d of %s.",
2352 value
, linenum
, ConfigurationFile
);
2354 else if (!_cups_strcasecmp(value
, "group"))
2356 loc
->level
= CUPSD_AUTH_GROUP
;
2358 cupsdLogMessage(CUPSD_LOG_WARN
,
2359 "\"AuthClass %s\" is deprecated; consider using "
2360 "\"Require user @groupname\" on line %d of %s.",
2361 value
, linenum
, ConfigurationFile
);
2363 else if (!_cups_strcasecmp(value
, "system"))
2365 loc
->level
= CUPSD_AUTH_GROUP
;
2367 cupsdAddName(loc
, "@SYSTEM");
2369 cupsdLogMessage(CUPSD_LOG_WARN
,
2370 "\"AuthClass %s\" is deprecated; consider using "
2371 "\"Require user @SYSTEM\" on line %d of %s.",
2372 value
, linenum
, ConfigurationFile
);
2376 cupsdLogMessage(CUPSD_LOG_WARN
,
2377 "Unknown authorization class %s on line %d of %s.",
2378 value
, linenum
, ConfigurationFile
);
2382 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2384 cupsdAddName(loc
, value
);
2386 cupsdLogMessage(CUPSD_LOG_WARN
,
2387 "\"AuthGroupName %s\" directive is deprecated; consider "
2388 "using \"Require user @%s\" on line %d of %s.",
2389 value
, value
, linenum
, ConfigurationFile
);
2391 else if (!_cups_strcasecmp(line
, "Require"))
2394 * Apache synonym for AuthClass and AuthGroupName...
2398 * Require valid-user
2399 * Require group names
2400 * Require user names
2403 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2408 if (!_cups_strcasecmp(value
, "valid-user") ||
2409 !_cups_strcasecmp(value
, "user"))
2410 loc
->level
= CUPSD_AUTH_USER
;
2411 else if (!_cups_strcasecmp(value
, "group"))
2412 loc
->level
= CUPSD_AUTH_GROUP
;
2415 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d of %s.",
2416 value
, linenum
, ConfigurationFile
);
2421 * Get the list of names from the line...
2424 for (value
= valptr
; *value
;)
2426 while (_cups_isspace(*value
))
2429 #ifdef HAVE_AUTHORIZATION_H
2430 if (!strncmp(value
, "@AUTHKEY(", 9))
2433 * Grab "@AUTHKEY(name)" value...
2436 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2442 #endif /* HAVE_AUTHORIZATION_H */
2443 if (*value
== '\"' || *value
== '\'')
2446 * Grab quoted name...
2449 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2456 * Grab literal name.
2459 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2465 cupsdAddName(loc
, value
);
2467 for (value
= valptr
; _cups_isspace(*value
); value
++);
2470 else if (!_cups_strcasecmp(line
, "Satisfy"))
2472 if (!_cups_strcasecmp(value
, "all"))
2473 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2474 else if (!_cups_strcasecmp(value
, "any"))
2475 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2478 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d of %s.",
2479 value
, linenum
, ConfigurationFile
);
2491 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2494 static int /* O - FatalErrors bits */
2495 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2497 int fatal
; /* FatalErrors bits */
2498 char value
[1024], /* Value string */
2499 *valstart
, /* Pointer into value */
2500 *valend
; /* End of value */
2504 * Empty FatalErrors line yields NULL pointer...
2508 return (CUPSD_FATAL_NONE
);
2511 * Loop through the value string,...
2514 strlcpy(value
, s
, sizeof(value
));
2516 fatal
= CUPSD_FATAL_NONE
;
2518 for (valstart
= value
; *valstart
;)
2521 * Get the current space/comma-delimited kind name...
2524 for (valend
= valstart
; *valend
; valend
++)
2525 if (_cups_isspace(*valend
) || *valend
== ',')
2532 * Add the error to the bitmask...
2535 if (!_cups_strcasecmp(valstart
, "all"))
2536 fatal
= CUPSD_FATAL_ALL
;
2537 else if (!_cups_strcasecmp(valstart
, "browse"))
2538 fatal
|= CUPSD_FATAL_BROWSE
;
2539 else if (!_cups_strcasecmp(valstart
, "-browse"))
2540 fatal
&= ~CUPSD_FATAL_BROWSE
;
2541 else if (!_cups_strcasecmp(valstart
, "config"))
2542 fatal
|= CUPSD_FATAL_CONFIG
;
2543 else if (!_cups_strcasecmp(valstart
, "-config"))
2544 fatal
&= ~CUPSD_FATAL_CONFIG
;
2545 else if (!_cups_strcasecmp(valstart
, "listen"))
2546 fatal
|= CUPSD_FATAL_LISTEN
;
2547 else if (!_cups_strcasecmp(valstart
, "-listen"))
2548 fatal
&= ~CUPSD_FATAL_LISTEN
;
2549 else if (!_cups_strcasecmp(valstart
, "log"))
2550 fatal
|= CUPSD_FATAL_LOG
;
2551 else if (!_cups_strcasecmp(valstart
, "-log"))
2552 fatal
&= ~CUPSD_FATAL_LOG
;
2553 else if (!_cups_strcasecmp(valstart
, "permissions"))
2554 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2555 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2556 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2557 else if (_cups_strcasecmp(valstart
, "none"))
2558 cupsdLogMessage(CUPSD_LOG_ERROR
,
2559 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2561 for (valstart
= valend
; *valstart
; valstart
++)
2562 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2571 * 'parse_groups()' - Parse system group names in a string.
2574 static int /* O - 1 on success, 0 on failure */
2575 parse_groups(const char *s
) /* I - Space-delimited groups */
2577 int status
; /* Return status */
2578 char value
[1024], /* Value string */
2579 *valstart
, /* Pointer into value */
2580 *valend
, /* End of value */
2581 quote
; /* Quote character */
2582 struct group
*group
; /* Group */
2586 * Make a copy of the string and parse out the groups...
2589 strlcpy(value
, s
, sizeof(value
));
2594 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2596 if (*valstart
== '\'' || *valstart
== '\"')
2599 * Scan quoted name...
2602 quote
= *valstart
++;
2604 for (valend
= valstart
; *valend
; valend
++)
2605 if (*valend
== quote
)
2611 * Scan space or comma-delimited name...
2614 for (valend
= valstart
; *valend
; valend
++)
2615 if (_cups_isspace(*valend
) || *valend
== ',')
2622 group
= getgrnam(valstart
);
2625 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2626 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2637 while (*valstart
== ',' || _cups_isspace(*valstart
))
2646 * 'parse_protocols()' - Parse browse protocols in a string.
2649 static int /* O - Browse protocol bits */
2650 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2652 int protocols
; /* Browse protocol bits */
2653 char value
[1024], /* Value string */
2654 *valstart
, /* Pointer into value */
2655 *valend
; /* End of value */
2659 * Empty protocol line yields NULL pointer...
2666 * Loop through the value string,...
2669 strlcpy(value
, s
, sizeof(value
));
2673 for (valstart
= value
; *valstart
;)
2676 * Get the current space/comma-delimited protocol name...
2679 for (valend
= valstart
; *valend
; valend
++)
2680 if (_cups_isspace(*valend
) || *valend
== ',')
2687 * Add the protocol to the bitmask...
2690 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2691 !_cups_strcasecmp(valstart
, "dns-sd") ||
2692 !_cups_strcasecmp(valstart
, "bonjour"))
2693 protocols
|= BROWSE_DNSSD
;
2694 else if (!_cups_strcasecmp(valstart
, "all"))
2695 protocols
|= BROWSE_ALL
;
2696 else if (_cups_strcasecmp(valstart
, "none"))
2697 cupsdLogMessage(CUPSD_LOG_ERROR
,
2698 "Unknown browse protocol \"%s\" ignored.", valstart
);
2700 for (valstart
= valend
; *valstart
; valstart
++)
2701 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2710 * 'parse_variable()' - Parse a variable line.
2713 static int /* O - 1 on success, 0 on failure */
2715 const char *filename
, /* I - Name of configuration file */
2716 int linenum
, /* I - Line in configuration file */
2717 const char *line
, /* I - Line from configuration file */
2718 const char *value
, /* I - Value from configuration file */
2719 size_t num_vars
, /* I - Number of variables */
2720 const cupsd_var_t
*vars
) /* I - Variables */
2722 size_t i
; /* Looping var */
2723 const cupsd_var_t
*var
; /* Variables */
2724 char temp
[1024]; /* Temporary string */
2727 for (i
= num_vars
, var
= vars
; i
> 0; i
--, var
++)
2728 if (!_cups_strcasecmp(line
, var
->name
))
2734 * Unknown directive! Output an error message and continue...
2738 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d of %s.",
2739 line
, linenum
, filename
);
2741 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d of %s.",
2742 line
, linenum
, filename
);
2749 case CUPSD_VARTYPE_INTEGER
:
2752 cupsdLogMessage(CUPSD_LOG_ERROR
,
2753 "Missing integer value for %s on line %d of %s.",
2754 line
, linenum
, filename
);
2757 else if (!isdigit(*value
& 255))
2759 cupsdLogMessage(CUPSD_LOG_ERROR
,
2760 "Bad integer value for %s on line %d of %s.",
2761 line
, linenum
, filename
);
2767 char *units
; /* Units */
2769 n
= strtol(value
, &units
, 0);
2771 if (units
&& *units
)
2773 if (tolower(units
[0] & 255) == 'g')
2774 n
*= 1024 * 1024 * 1024;
2775 else if (tolower(units
[0] & 255) == 'm')
2777 else if (tolower(units
[0] & 255) == 'k')
2779 else if (tolower(units
[0] & 255) == 't')
2783 cupsdLogMessage(CUPSD_LOG_ERROR
,
2784 "Unknown integer value for %s on line %d of %s.",
2785 line
, linenum
, filename
);
2792 cupsdLogMessage(CUPSD_LOG_ERROR
,
2793 "Bad negative integer value for %s on line %d of "
2794 "%s.", line
, linenum
, filename
);
2799 *((int *)var
->ptr
) = n
;
2804 case CUPSD_VARTYPE_PERM
:
2807 cupsdLogMessage(CUPSD_LOG_ERROR
,
2808 "Missing permissions value for %s on line %d of %s.",
2809 line
, linenum
, filename
);
2812 else if (!isdigit(*value
& 255))
2814 /* TODO: Add chmod UGO syntax support */
2815 cupsdLogMessage(CUPSD_LOG_ERROR
,
2816 "Bad permissions value for %s on line %d of %s.",
2817 line
, linenum
, filename
);
2822 int n
= strtol(value
, NULL
, 8);
2823 /* Permissions value */
2827 cupsdLogMessage(CUPSD_LOG_ERROR
,
2828 "Bad negative permissions value for %s on line %d of "
2829 "%s.", line
, linenum
, filename
);
2834 *((mode_t
*)var
->ptr
) = (mode_t
)n
;
2839 case CUPSD_VARTYPE_TIME
:
2842 cupsdLogMessage(CUPSD_LOG_ERROR
,
2843 "Missing time interval value for %s on line %d of "
2844 "%s.", line
, linenum
, filename
);
2847 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
2848 (!_cups_strcasecmp(value
, "true") ||
2849 !_cups_strcasecmp(value
, "on") ||
2850 !_cups_strcasecmp(value
, "enabled") ||
2851 !_cups_strcasecmp(value
, "yes")))
2853 *((int *)var
->ptr
) = INT_MAX
;
2855 else if (!_cups_strcasecmp(value
, "false") ||
2856 !_cups_strcasecmp(value
, "off") ||
2857 !_cups_strcasecmp(value
, "disabled") ||
2858 !_cups_strcasecmp(value
, "no"))
2860 *((int *)var
->ptr
) = 0;
2862 else if (!isdigit(*value
& 255))
2864 cupsdLogMessage(CUPSD_LOG_ERROR
,
2865 "Unknown time interval value for %s on line %d of "
2866 "%s.", line
, linenum
, filename
);
2871 double n
; /* Number */
2872 char *units
; /* Units */
2874 n
= strtod(value
, &units
);
2876 if (units
&& *units
)
2878 if (tolower(units
[0] & 255) == 'w')
2879 n
*= 7 * 24 * 60 * 60;
2880 else if (tolower(units
[0] & 255) == 'd')
2882 else if (tolower(units
[0] & 255) == 'h')
2884 else if (tolower(units
[0] & 255) == 'm')
2888 cupsdLogMessage(CUPSD_LOG_ERROR
,
2889 "Unknown time interval value for %s on line "
2890 "%d of %s.", line
, linenum
, filename
);
2895 if (n
< 0.0 || n
> INT_MAX
)
2897 cupsdLogMessage(CUPSD_LOG_ERROR
,
2898 "Bad time value for %s on line %d of %s.",
2899 line
, linenum
, filename
);
2904 *((int *)var
->ptr
) = (int)n
;
2909 case CUPSD_VARTYPE_BOOLEAN
:
2912 cupsdLogMessage(CUPSD_LOG_ERROR
,
2913 "Missing boolean value for %s on line %d of %s.",
2914 line
, linenum
, filename
);
2917 else if (!_cups_strcasecmp(value
, "true") ||
2918 !_cups_strcasecmp(value
, "on") ||
2919 !_cups_strcasecmp(value
, "enabled") ||
2920 !_cups_strcasecmp(value
, "yes") ||
2923 *((int *)var
->ptr
) = TRUE
;
2925 else if (!_cups_strcasecmp(value
, "false") ||
2926 !_cups_strcasecmp(value
, "off") ||
2927 !_cups_strcasecmp(value
, "disabled") ||
2928 !_cups_strcasecmp(value
, "no") ||
2929 !_cups_strcasecmp(value
, "0"))
2931 *((int *)var
->ptr
) = FALSE
;
2935 cupsdLogMessage(CUPSD_LOG_ERROR
,
2936 "Unknown boolean value %s on line %d of %s.",
2937 value
, linenum
, filename
);
2942 case CUPSD_VARTYPE_PATHNAME
:
2945 cupsdLogMessage(CUPSD_LOG_ERROR
,
2946 "Missing pathname value for %s on line %d of %s.",
2947 line
, linenum
, filename
);
2951 if (value
[0] == '/')
2952 strlcpy(temp
, value
, sizeof(temp
));
2954 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
2956 if (access(temp
, 0))
2958 cupsdLogMessage(CUPSD_LOG_ERROR
,
2959 "File or directory for \"%s %s\" on line %d of %s "
2960 "does not exist.", line
, value
, linenum
, filename
);
2964 cupsdSetString((char **)var
->ptr
, temp
);
2967 case CUPSD_VARTYPE_STRING
:
2968 cupsdSetString((char **)var
->ptr
, value
);
2977 * 'read_cupsd_conf()' - Read the cupsd.conf configuration file.
2980 static int /* O - 1 on success, 0 on failure */
2981 read_cupsd_conf(cups_file_t
*fp
) /* I - File to read from */
2983 int linenum
; /* Current line number */
2984 char line
[HTTP_MAX_BUFFER
],
2985 /* Line from file */
2986 temp
[HTTP_MAX_BUFFER
],
2987 /* Temporary buffer for value */
2988 *value
, /* Pointer to value */
2989 *valueptr
; /* Pointer into value */
2990 int valuelen
; /* Length of value */
2991 http_addrlist_t
*addrlist
, /* Address list */
2992 *addr
; /* Current address */
2993 cups_file_t
*incfile
; /* Include file */
2994 char incname
[1024]; /* Include filename */
2998 * Loop through each line in the file...
3003 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3006 * Decode the directive...
3009 if (!_cups_strcasecmp(line
, "Include") && value
)
3015 if (value
[0] == '/')
3016 strlcpy(incname
, value
, sizeof(incname
));
3018 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
3020 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
3021 cupsdLogMessage(CUPSD_LOG_ERROR
,
3022 "Unable to include config file \"%s\" - %s",
3023 incname
, strerror(errno
));
3026 read_cupsd_conf(incfile
);
3027 cupsFileClose(incfile
);
3030 else if (!_cups_strcasecmp(line
, "<Location") && value
)
3036 linenum
= read_location(fp
, value
, linenum
);
3040 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
3046 linenum
= read_policy(fp
, value
, linenum
);
3050 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
3052 JobRetryInterval
= atoi(value
);
3053 cupsdLogMessage(CUPSD_LOG_WARN
,
3054 "FaxRetryInterval is deprecated; use "
3055 "JobRetryInterval on line %d of %s.", linenum
, ConfigurationFile
);
3057 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
3059 JobRetryLimit
= atoi(value
);
3060 cupsdLogMessage(CUPSD_LOG_WARN
,
3061 "FaxRetryLimit is deprecated; use "
3062 "JobRetryLimit on line %d of %s.", linenum
, ConfigurationFile
);
3065 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3068 * SSLOptions [AllowRC4] [AllowSSL3] [None]
3071 int options
= 0; /* SSL/TLS options */
3075 char *start
, /* Start of option */
3076 *end
; /* End of option */
3078 for (start
= value
; *start
; start
= end
)
3081 * Find end of keyword...
3085 while (*end
&& !_cups_isspace(*end
))
3095 if (!_cups_strcasecmp(start
, "AllowRC4"))
3096 options
|= _HTTP_TLS_ALLOW_RC4
;
3097 else if (!_cups_strcasecmp(start
, "AllowSSL3"))
3098 options
|= _HTTP_TLS_ALLOW_SSL3
;
3099 else if (!_cups_strcasecmp(start
, "None"))
3101 else if (_cups_strcasecmp(start
, "NoEmptyFragments"))
3102 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown SSL option %s at line %d.", start
, linenum
);
3106 _httpTLSSetOptions(options
);
3108 #endif /* HAVE_SSL */
3109 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
3111 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
3112 #endif /* HAVE_SSL */
3116 * Add listening address(es) to the list...
3119 cupsd_listener_t
*lis
; /* New listeners array */
3123 * Get the address list...
3126 addrlist
= get_address(value
, IPP_PORT
);
3130 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
3136 * Add each address...
3139 for (addr
= addrlist
; addr
; addr
= addr
->next
)
3142 * See if this address is already present...
3145 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
3147 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
3148 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
3149 httpAddrPort(&(addr
->addr
)) == httpAddrPort(&(lis
->address
)))
3154 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
3155 if (!lis
->on_demand
)
3156 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
3158 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3159 cupsdLogMessage(CUPSD_LOG_WARN
,
3160 "Duplicate listen address \"%s\" ignored.", temp
);
3167 * Allocate another listener...
3171 Listeners
= cupsArrayNew(NULL
, NULL
);
3175 cupsdLogMessage(CUPSD_LOG_ERROR
,
3176 "Unable to allocate %s at line %d - %s.",
3177 line
, linenum
, strerror(errno
));
3181 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
3183 cupsdLogMessage(CUPSD_LOG_ERROR
,
3184 "Unable to allocate %s at line %d - %s.",
3185 line
, linenum
, strerror(errno
));
3189 cupsArrayAdd(Listeners
, lis
);
3192 * Copy the current address and log it...
3195 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
3199 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
3200 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
3201 #endif /* HAVE_SSL */
3203 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3206 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
3207 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
3209 #endif /* AF_LOCAL */
3210 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
3211 httpAddrPort(&(lis
->address
)),
3212 httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
3214 if (!httpAddrLocalhost(&(lis
->address
)))
3215 RemotePort
= httpAddrPort(&(lis
->address
));
3222 httpAddrFreeList(addrlist
);
3224 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
3225 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
3228 * "BrowseProtocols name [... name]"
3229 * "BrowseLocalProtocols name [... name]"
3232 int protocols
= parse_protocols(value
);
3236 cupsdLogMessage(CUPSD_LOG_ERROR
,
3237 "Unknown browse protocol \"%s\" on line %d of %s.",
3238 value
, linenum
, ConfigurationFile
);
3242 BrowseLocalProtocols
= protocols
;
3244 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
3247 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3250 if (!_cups_strcasecmp(value
, "none"))
3251 default_auth_type
= CUPSD_AUTH_NONE
;
3252 else if (!_cups_strcasecmp(value
, "basic"))
3253 default_auth_type
= CUPSD_AUTH_BASIC
;
3255 else if (!_cups_strcasecmp(value
, "negotiate"))
3256 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
3257 #endif /* HAVE_GSSAPI */
3258 else if (!_cups_strcasecmp(value
, "auto"))
3259 default_auth_type
= CUPSD_AUTH_AUTO
;
3262 cupsdLogMessage(CUPSD_LOG_WARN
,
3263 "Unknown default authorization type %s on line %d of %s.",
3264 value
, linenum
, ConfigurationFile
);
3265 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3270 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
3273 * DefaultEncryption {Never,IfRequested,Required}
3276 if (!value
|| !_cups_strcasecmp(value
, "never"))
3277 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3278 else if (!_cups_strcasecmp(value
, "required"))
3279 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3280 else if (!_cups_strcasecmp(value
, "ifrequested"))
3281 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3284 cupsdLogMessage(CUPSD_LOG_WARN
,
3285 "Unknown default encryption %s on line %d of %s.",
3286 value
, linenum
, ConfigurationFile
);
3287 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3291 #endif /* HAVE_SSL */
3292 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
3295 * Do hostname lookups?
3298 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
3299 !_cups_strcasecmp(value
, "false"))
3300 HostNameLookups
= 0;
3301 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
3302 !_cups_strcasecmp(value
, "true"))
3303 HostNameLookups
= 1;
3304 else if (!_cups_strcasecmp(value
, "double"))
3305 HostNameLookups
= 2;
3307 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d of %s.",
3308 value
, linenum
, ConfigurationFile
);
3310 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
3313 * Amount of logging to do to access log...
3316 if (!_cups_strcasecmp(value
, "all"))
3317 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3318 else if (!_cups_strcasecmp(value
, "actions"))
3319 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3320 else if (!_cups_strcasecmp(value
, "config"))
3321 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3322 else if (!_cups_strcasecmp(value
, "none"))
3323 AccessLogLevel
= CUPSD_ACCESSLOG_NONE
;
3325 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d of %s.",
3326 value
, linenum
, ConfigurationFile
);
3328 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
3331 * Amount of logging to do to error log...
3334 if (!_cups_strcasecmp(value
, "debug2"))
3335 LogLevel
= CUPSD_LOG_DEBUG2
;
3336 else if (!_cups_strcasecmp(value
, "debug"))
3337 LogLevel
= CUPSD_LOG_DEBUG
;
3338 else if (!_cups_strcasecmp(value
, "info"))
3339 LogLevel
= CUPSD_LOG_INFO
;
3340 else if (!_cups_strcasecmp(value
, "notice"))
3341 LogLevel
= CUPSD_LOG_NOTICE
;
3342 else if (!_cups_strcasecmp(value
, "warn"))
3343 LogLevel
= CUPSD_LOG_WARN
;
3344 else if (!_cups_strcasecmp(value
, "error"))
3345 LogLevel
= CUPSD_LOG_ERROR
;
3346 else if (!_cups_strcasecmp(value
, "crit"))
3347 LogLevel
= CUPSD_LOG_CRIT
;
3348 else if (!_cups_strcasecmp(value
, "alert"))
3349 LogLevel
= CUPSD_LOG_ALERT
;
3350 else if (!_cups_strcasecmp(value
, "emerg"))
3351 LogLevel
= CUPSD_LOG_EMERG
;
3352 else if (!_cups_strcasecmp(value
, "none"))
3353 LogLevel
= CUPSD_LOG_NONE
;
3355 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d of %s.",
3356 value
, linenum
, ConfigurationFile
);
3358 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
3361 * Amount of logging to do to error log...
3364 if (!_cups_strcasecmp(value
, "standard"))
3365 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3366 else if (!_cups_strcasecmp(value
, "usecs"))
3367 LogTimeFormat
= CUPSD_TIME_USECS
;
3369 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d of %s.",
3370 value
, linenum
, ConfigurationFile
);
3372 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
3375 * Set the string used for the Server header...
3378 struct utsname plat
; /* Platform info */
3383 if (!_cups_strcasecmp(value
, "ProductOnly"))
3384 cupsdSetString(&ServerHeader
, "CUPS IPP");
3385 else if (!_cups_strcasecmp(value
, "Major"))
3386 cupsdSetStringf(&ServerHeader
, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR
);
3387 else if (!_cups_strcasecmp(value
, "Minor"))
3388 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
3389 CUPS_VERSION_MINOR
);
3390 else if (!_cups_strcasecmp(value
, "Minimal"))
3391 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
" IPP/2.1");
3392 else if (!_cups_strcasecmp(value
, "OS"))
3393 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s) IPP/2.1",
3394 plat
.sysname
, plat
.release
);
3395 else if (!_cups_strcasecmp(value
, "Full"))
3396 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s; %s) IPP/2.1",
3397 plat
.sysname
, plat
.release
, plat
.machine
);
3398 else if (!_cups_strcasecmp(value
, "None"))
3399 cupsdClearString(&ServerHeader
);
3401 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d of %s.",
3402 value
, linenum
, ConfigurationFile
);
3404 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3407 * PassEnv variable [... variable]
3412 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3413 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3416 if (value
[valuelen
])
3418 value
[valuelen
] = '\0';
3422 cupsdSetEnv(value
, NULL
);
3424 for (value
+= valuelen
; *value
; value
++)
3425 if (!_cups_isspace(*value
) || *value
!= ',')
3429 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3432 * ServerAlias name [... name]
3436 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3440 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3441 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3444 if (value
[valuelen
])
3446 value
[valuelen
] = '\0';
3450 cupsdAddAlias(ServerAlias
, value
);
3452 for (value
+= valuelen
; *value
; value
++)
3453 if (!_cups_isspace(*value
) || *value
!= ',')
3457 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3460 * SetEnv variable value
3463 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3471 while (isspace(*valueptr
& 255))
3474 cupsdSetEnv(value
, valueptr
);
3477 cupsdLogMessage(CUPSD_LOG_ERROR
,
3478 "Missing value for SetEnv directive on line %d of %s.",
3479 linenum
, ConfigurationFile
);
3481 else if (!_cups_strcasecmp(line
, "AccessLog") ||
3482 !_cups_strcasecmp(line
, "CacheDir") ||
3483 !_cups_strcasecmp(line
, "ConfigFilePerm") ||
3484 !_cups_strcasecmp(line
, "DataDir") ||
3485 !_cups_strcasecmp(line
, "DocumentRoot") ||
3486 !_cups_strcasecmp(line
, "ErrorLog") ||
3487 !_cups_strcasecmp(line
, "FatalErrors") ||
3488 !_cups_strcasecmp(line
, "FileDevice") ||
3489 !_cups_strcasecmp(line
, "FontPath") ||
3490 !_cups_strcasecmp(line
, "Group") ||
3491 !_cups_strcasecmp(line
, "LogFilePerm") ||
3492 !_cups_strcasecmp(line
, "LPDConfigFile") ||
3493 !_cups_strcasecmp(line
, "PageLog") ||
3494 !_cups_strcasecmp(line
, "Printcap") ||
3495 !_cups_strcasecmp(line
, "PrintcapFormat") ||
3496 !_cups_strcasecmp(line
, "RemoteRoot") ||
3497 !_cups_strcasecmp(line
, "RequestRoot") ||
3498 !_cups_strcasecmp(line
, "ServerBin") ||
3499 !_cups_strcasecmp(line
, "ServerCertificate") ||
3500 !_cups_strcasecmp(line
, "ServerKey") ||
3501 !_cups_strcasecmp(line
, "ServerKeychain") ||
3502 !_cups_strcasecmp(line
, "ServerRoot") ||
3503 !_cups_strcasecmp(line
, "SMBConfigFile") ||
3504 !_cups_strcasecmp(line
, "StateDir") ||
3505 !_cups_strcasecmp(line
, "SystemGroup") ||
3506 !_cups_strcasecmp(line
, "SystemGroupAuthKey") ||
3507 !_cups_strcasecmp(line
, "TempDir") ||
3508 !_cups_strcasecmp(line
, "User"))
3510 cupsdLogMessage(CUPSD_LOG_INFO
,
3511 "Please move \"%s%s%s\" on line %d of %s to the %s file; "
3512 "this will become an error in a future release.",
3513 line
, value
? " " : "", value
? value
: "", linenum
,
3514 ConfigurationFile
, CupsFilesFile
);
3517 parse_variable(ConfigurationFile
, linenum
, line
, value
,
3518 sizeof(cupsd_vars
) / sizeof(cupsd_vars
[0]), cupsd_vars
);
3526 * 'read_cups_files_conf()' - Read the cups-files.conf configuration file.
3529 static int /* O - 1 on success, 0 on failure */
3530 read_cups_files_conf(cups_file_t
*fp
) /* I - File to read from */
3532 int linenum
; /* Current line number */
3533 char line
[HTTP_MAX_BUFFER
], /* Line from file */
3534 *value
; /* Value from line */
3535 struct group
*group
; /* Group */
3539 * Loop through each line in the file...
3544 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3546 if (!_cups_strcasecmp(line
, "FatalErrors"))
3547 FatalErrors
= parse_fatal_errors(value
);
3548 else if (!_cups_strcasecmp(line
, "Group") && value
)
3551 * Group ID to run as...
3554 if (isdigit(value
[0]))
3555 Group
= (gid_t
)atoi(value
);
3559 group
= getgrnam(value
);
3562 Group
= group
->gr_gid
;
3565 cupsdLogMessage(CUPSD_LOG_ERROR
,
3566 "Unknown Group \"%s\" on line %d of %s.", value
,
3567 linenum
, CupsFilesFile
);
3568 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3573 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
3576 * Format of printcap file?
3579 if (!_cups_strcasecmp(value
, "bsd"))
3580 PrintcapFormat
= PRINTCAP_BSD
;
3581 else if (!_cups_strcasecmp(value
, "plist"))
3582 PrintcapFormat
= PRINTCAP_PLIST
;
3583 else if (!_cups_strcasecmp(value
, "solaris"))
3584 PrintcapFormat
= PRINTCAP_SOLARIS
;
3587 cupsdLogMessage(CUPSD_LOG_ERROR
,
3588 "Unknown PrintcapFormat \"%s\" on line %d of %s.",
3589 value
, linenum
, CupsFilesFile
);
3590 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3594 else if (!_cups_strcasecmp(line
, "Sandboxing") && value
)
3597 * Level of sandboxing?
3600 if (!_cups_strcasecmp(value
, "off") && getuid())
3602 Sandboxing
= CUPSD_SANDBOXING_OFF
;
3603 cupsdLogMessage(CUPSD_LOG_WARN
, "Disabling sandboxing is not recommended (line %d of %s)", linenum
, CupsFilesFile
);
3605 else if (!_cups_strcasecmp(value
, "relaxed"))
3606 Sandboxing
= CUPSD_SANDBOXING_RELAXED
;
3607 else if (!_cups_strcasecmp(value
, "strict"))
3608 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
3611 cupsdLogMessage(CUPSD_LOG_ERROR
,
3612 "Unknown Sandboxing \"%s\" on line %d of %s.",
3613 value
, linenum
, CupsFilesFile
);
3614 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3618 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
3621 * SystemGroup (admin) group(s)...
3624 if (!parse_groups(value
))
3626 cupsdLogMessage(CUPSD_LOG_ERROR
,
3627 "Unknown SystemGroup \"%s\" on line %d of %s.", value
,
3628 linenum
, CupsFilesFile
);
3629 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3633 else if (!_cups_strcasecmp(line
, "User") && value
)
3636 * User ID to run as...
3639 if (isdigit(value
[0] & 255))
3641 int uid
= atoi(value
);
3645 cupsdLogMessage(CUPSD_LOG_ERROR
,
3646 "Will not use User 0 as specified on line %d of %s "
3647 "for security reasons. You must use a non-"
3648 "privileged account instead.",
3649 linenum
, CupsFilesFile
);
3650 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3654 User
= (uid_t
)atoi(value
);
3658 struct passwd
*p
; /* Password information */
3661 p
= getpwnam(value
);
3667 cupsdLogMessage(CUPSD_LOG_ERROR
,
3668 "Will not use User %s (UID=0) as specified on line "
3669 "%d of %s for security reasons. You must use a "
3670 "non-privileged account instead.",
3671 value
, linenum
, CupsFilesFile
);
3672 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3680 cupsdLogMessage(CUPSD_LOG_ERROR
,
3681 "Unknown User \"%s\" on line %d of %s.",
3682 value
, linenum
, CupsFilesFile
);
3683 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3688 else if (!_cups_strcasecmp(line
, "ServerCertificate") ||
3689 !_cups_strcasecmp(line
, "ServerKey"))
3691 cupsdLogMessage(CUPSD_LOG_INFO
,
3692 "The \"%s\" directive on line %d of %s is no longer "
3693 "supported; this will become an error in a future "
3695 line
, linenum
, CupsFilesFile
);
3697 else if (!parse_variable(CupsFilesFile
, linenum
, line
, value
,
3698 sizeof(cupsfiles_vars
) / sizeof(cupsfiles_vars
[0]),
3700 (FatalErrors
& CUPSD_FATAL_CONFIG
))
3709 * 'read_location()' - Read a <Location path> definition.
3712 static int /* O - New line number or 0 on error */
3713 read_location(cups_file_t
*fp
, /* I - Configuration file */
3714 char *location
, /* I - Location name/path */
3715 int linenum
) /* I - Current line number */
3717 cupsd_location_t
*loc
, /* New location */
3718 *parent
; /* Parent location */
3719 char line
[HTTP_MAX_BUFFER
],
3721 *value
, /* Value for directive */
3722 *valptr
; /* Pointer into value */
3725 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3726 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d of %s.",
3727 location
, linenum
, ConfigurationFile
);
3728 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3732 cupsdAddLocation(parent
);
3734 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3739 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3742 * Decode the directive...
3745 if (!_cups_strcasecmp(line
, "</Location>"))
3747 else if (!_cups_strcasecmp(line
, "<Limit") ||
3748 !_cups_strcasecmp(line
, "<LimitExcept"))
3752 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3753 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3759 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3762 cupsdAddLocation(loc
);
3767 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3772 if (!strcmp(value
, "ALL"))
3773 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3774 else if (!strcmp(value
, "GET"))
3775 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3776 else if (!strcmp(value
, "HEAD"))
3777 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3778 else if (!strcmp(value
, "OPTIONS"))
3779 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3780 else if (!strcmp(value
, "POST"))
3781 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3782 else if (!strcmp(value
, "PUT"))
3783 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3784 else if (!strcmp(value
, "TRACE"))
3785 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3787 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d of %s.",
3788 value
, linenum
, ConfigurationFile
);
3790 for (value
= valptr
; isspace(*value
& 255); value
++);
3793 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3794 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3796 parent
->limit
&= ~loc
->limit
;
3798 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3799 !_cups_strcasecmp(line
, "</LimitExcept>"))
3803 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3804 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3807 else if (!parse_aaa(loc
, line
, value
, linenum
))
3809 cupsdLogMessage(CUPSD_LOG_ERROR
,
3810 "Unknown Location directive %s on line %d of %s.",
3811 line
, linenum
, ConfigurationFile
);
3812 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3817 cupsdLogMessage(CUPSD_LOG_ERROR
,
3818 "Unexpected end-of-file at line %d while reading location.",
3821 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3826 * 'read_policy()' - Read a <Policy name> definition.
3829 static int /* O - New line number or 0 on error */
3830 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3831 char *policy
, /* I - Location name/path */
3832 int linenum
) /* I - Current line number */
3834 int i
; /* Looping var */
3835 cupsd_policy_t
*pol
; /* Policy */
3836 cupsd_location_t
*op
; /* Policy operation */
3837 int num_ops
; /* Number of IPP operations */
3838 ipp_op_t ops
[100]; /* Operations */
3839 char line
[HTTP_MAX_BUFFER
],
3841 *value
, /* Value for directive */
3842 *valptr
; /* Pointer into value */
3846 * Create the policy...
3849 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3850 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d of %s.",
3851 policy
, linenum
, ConfigurationFile
);
3852 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3856 * Read from the file...
3862 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3865 * Decode the directive...
3868 if (!_cups_strcasecmp(line
, "</Policy>"))
3871 cupsdLogMessage(CUPSD_LOG_WARN
,
3872 "Missing </Limit> before </Policy> on line %d of %s.",
3873 linenum
, ConfigurationFile
);
3875 set_policy_defaults(pol
);
3879 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3883 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3884 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3891 * Scan for IPP operation names...
3898 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3903 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3905 if (!_cups_strcasecmp(value
, "All"))
3906 ops
[num_ops
] = IPP_ANY_OPERATION
;
3907 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3908 cupsdLogMessage(CUPSD_LOG_ERROR
,
3909 "Bad IPP operation name \"%s\" on line %d of %s.",
3910 value
, linenum
, ConfigurationFile
);
3915 cupsdLogMessage(CUPSD_LOG_ERROR
,
3916 "Too many operations listed on line %d of %s.",
3917 linenum
, ConfigurationFile
);
3919 for (value
= valptr
; isspace(*value
& 255); value
++);
3923 * If none are specified, apply the policy to all operations...
3928 ops
[0] = IPP_ANY_OPERATION
;
3933 * Add a new policy for the first operation...
3936 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3938 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3941 * Finish the current operation limit...
3947 * Copy the policy to the other operations...
3950 for (i
= 1; i
< num_ops
; i
++)
3951 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3958 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3959 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3962 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3963 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3964 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3965 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3969 cupsdLogMessage(CUPSD_LOG_ERROR
,
3970 "%s directive must appear outside <Limit>...</Limit> "
3971 "on line %d of %s.", line
, linenum
, ConfigurationFile
);
3972 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3978 * Pull out whitespace-delimited values...
3984 * Find the end of the current value...
3987 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3993 * Save it appropriately...
3996 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3999 * JobPrivateAccess {all|default|user/group list|@@ACL}
4002 if (!_cups_strcasecmp(value
, "default"))
4004 cupsdAddString(&(pol
->job_access
), "@OWNER");
4005 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4008 cupsdAddString(&(pol
->job_access
), value
);
4010 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
4013 * JobPrivateValues {all|none|default|attribute list}
4016 if (!_cups_strcasecmp(value
, "default"))
4018 cupsdAddString(&(pol
->job_attrs
), "job-name");
4019 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4020 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4021 cupsdAddString(&(pol
->job_attrs
), "phone");
4024 cupsdAddString(&(pol
->job_attrs
), value
);
4026 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
4029 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
4032 if (!_cups_strcasecmp(value
, "default"))
4034 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4035 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4038 cupsdAddString(&(pol
->sub_access
), value
);
4040 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
4043 * SubscriptionPrivateValues {all|none|default|attribute list}
4046 if (!_cups_strcasecmp(value
, "default"))
4048 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4049 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4050 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4051 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4052 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
4055 cupsdAddString(&(pol
->sub_attrs
), value
);
4059 * Find the next string on the line...
4062 for (value
= valptr
; isspace(*value
& 255); value
++);
4068 cupsdLogMessage(CUPSD_LOG_ERROR
,
4069 "Missing <Limit ops> directive before %s on line %d of %s.",
4070 line
, linenum
, ConfigurationFile
);
4071 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4074 else if (!parse_aaa(op
, line
, value
, linenum
))
4076 cupsdLogMessage(CUPSD_LOG_ERROR
,
4077 "Unknown Policy Limit directive %s on line %d of %s.",
4078 line
, linenum
, ConfigurationFile
);
4080 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4085 cupsdLogMessage(CUPSD_LOG_ERROR
,
4086 "Unexpected end-of-file at line %d while reading policy "
4087 "\"%s\".", linenum
, policy
);
4089 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
4094 * 'set_policy_defaults()' - Set default policy values as needed.
4098 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
4100 cupsd_location_t
*op
; /* Policy operation */
4104 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
4105 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
4106 * upgrades do not introduce new security issues...
4109 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
4110 op
->op
== IPP_ANY_OPERATION
)
4112 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
4113 op
->op
!= IPP_ANY_OPERATION
)
4116 * Add a new limit for Validate-Job using the Print-Job limit as a
4120 cupsdLogMessage(CUPSD_LOG_WARN
,
4121 "No limit for Validate-Job defined in policy %s "
4122 "- using Print-Job's policy.", pol
->name
);
4124 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
4127 cupsdLogMessage(CUPSD_LOG_WARN
,
4128 "No limit for Validate-Job defined in policy %s "
4129 "and no suitable template found.", pol
->name
);
4132 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
4133 op
->op
== IPP_ANY_OPERATION
)
4135 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
4136 op
->op
!= IPP_ANY_OPERATION
)
4139 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
4143 cupsdLogMessage(CUPSD_LOG_WARN
,
4144 "No limit for Cancel-Jobs defined in policy %s "
4145 "- using Pause-Printer's policy.", pol
->name
);
4147 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
4150 cupsdLogMessage(CUPSD_LOG_WARN
,
4151 "No limit for Cancel-Jobs defined in policy %s "
4152 "and no suitable template found.", pol
->name
);
4155 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
4156 op
->op
== IPP_ANY_OPERATION
)
4158 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4159 op
->op
!= IPP_ANY_OPERATION
)
4162 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
4166 cupsdLogMessage(CUPSD_LOG_WARN
,
4167 "No limit for Cancel-My-Jobs defined in policy %s "
4168 "- using Send-Document's policy.", pol
->name
);
4170 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
4173 cupsdLogMessage(CUPSD_LOG_WARN
,
4174 "No limit for Cancel-My-Jobs defined in policy %s "
4175 "and no suitable template found.", pol
->name
);
4178 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
4179 op
->op
== IPP_ANY_OPERATION
)
4181 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4182 op
->op
!= IPP_ANY_OPERATION
)
4185 * Add a new limit for Close-Job using the Send-Document limit as a
4189 cupsdLogMessage(CUPSD_LOG_WARN
,
4190 "No limit for Close-Job defined in policy %s "
4191 "- using Send-Document's policy.", pol
->name
);
4193 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
4196 cupsdLogMessage(CUPSD_LOG_WARN
,
4197 "No limit for Close-Job defined in policy %s "
4198 "and no suitable template found.", pol
->name
);
4201 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
4202 op
->op
== IPP_ANY_OPERATION
)
4204 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4205 op
->op
!= IPP_ANY_OPERATION
)
4208 * Add a new limit for CUPS-Get-Document using the Send-Document
4209 * limit as a template...
4212 cupsdLogMessage(CUPSD_LOG_WARN
,
4213 "No limit for CUPS-Get-Document defined in policy %s "
4214 "- using Send-Document's policy.", pol
->name
);
4216 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
4219 cupsdLogMessage(CUPSD_LOG_WARN
,
4220 "No limit for CUPS-Get-Document defined in policy %s "
4221 "and no suitable template found.", pol
->name
);
4225 * Verify we have JobPrivateAccess, JobPrivateValues,
4226 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4229 if (!pol
->job_access
)
4231 cupsdLogMessage(CUPSD_LOG_WARN
,
4232 "No JobPrivateAccess defined in policy %s "
4233 "- using defaults.", pol
->name
);
4234 cupsdAddString(&(pol
->job_access
), "@OWNER");
4235 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4238 if (!pol
->job_attrs
)
4240 cupsdLogMessage(CUPSD_LOG_WARN
,
4241 "No JobPrivateValues defined in policy %s "
4242 "- using defaults.", pol
->name
);
4243 cupsdAddString(&(pol
->job_attrs
), "job-name");
4244 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4245 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4246 cupsdAddString(&(pol
->job_attrs
), "phone");
4249 if (!pol
->sub_access
)
4251 cupsdLogMessage(CUPSD_LOG_WARN
,
4252 "No SubscriptionPrivateAccess defined in policy %s "
4253 "- using defaults.", pol
->name
);
4254 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4255 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4258 if (!pol
->sub_attrs
)
4260 cupsdLogMessage(CUPSD_LOG_WARN
,
4261 "No SubscriptionPrivateValues defined in policy %s "
4262 "- using defaults.", pol
->name
);
4263 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4264 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4265 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4266 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4267 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");