2 * Configuration routines for the CUPS scheduler.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
21 #include <sys/utsname.h>
24 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
25 # define SD_JOURNAL_SUPPRESS_LOCATION
26 # include <systemd/sd-journal.h>
27 #endif /* HAVE_ASL_H */
32 #endif /* HAVE_LIBPAPER */
36 * Possibly missing network definitions...
40 # define INADDR_NONE 0xffffffff
41 #endif /* !INADDR_NONE */
45 * Configuration variable structure...
50 CUPSD_VARTYPE_INTEGER
, /* Integer option */
51 CUPSD_VARTYPE_TIME
, /* Time interval option */
52 CUPSD_VARTYPE_STRING
, /* String option */
53 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
54 CUPSD_VARTYPE_PATHNAME
, /* File/directory name option */
55 CUPSD_VARTYPE_PERM
/* File/directory permissions */
60 const char *name
; /* Name of variable */
61 void *ptr
; /* Pointer to variable */
62 cupsd_vartype_t type
; /* Type (int, string, address) */
70 static const cupsd_var_t cupsd_vars
[] =
72 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
73 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
74 { "BrowseDNSSDSubTypes", &DNSSDSubTypes
, CUPSD_VARTYPE_STRING
},
75 #endif /* HAVE_DNSSD || HAVE_AVAHI */
76 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
77 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
78 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
79 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
80 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
81 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_TIME
},
82 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
83 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
84 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
85 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_TIME
},
86 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
87 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
88 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
90 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
91 #endif /* HAVE_GSSAPI */
93 { "IdleExitTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
94 #endif /* HAVE_ONDEMAND */
95 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_TIME
},
96 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
97 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_TIME
},
98 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_TIME
},
99 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
101 { "LaunchdTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
102 #endif /* HAVE_LAUNCHD */
103 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
104 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
105 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
106 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
107 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
108 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
109 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
110 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
111 { "MaxHoldTime", &MaxHoldTime
, CUPSD_VARTYPE_TIME
},
112 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
113 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
114 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
115 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_TIME
},
116 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_TIME
},
117 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
118 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
119 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
120 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
121 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
122 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
123 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_TIME
},
124 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
125 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_TIME
},
126 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_TIME
},
127 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_TIME
},
128 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
129 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_TIME
},
130 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
131 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
132 { "StrictConformance", &StrictConformance
, CUPSD_VARTYPE_BOOLEAN
},
133 { "Timeout", &Timeout
, CUPSD_VARTYPE_TIME
},
134 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
136 static const cupsd_var_t cupsfiles_vars
[] =
138 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
139 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
140 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_PERM
},
142 { "CreateSelfSignedCerts", &CreateSelfSignedCerts
, CUPSD_VARTYPE_BOOLEAN
},
143 #endif /* HAVE_SSL */
144 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
145 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
146 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
147 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
148 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
149 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_PERM
},
150 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
151 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
152 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
153 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
154 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
155 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
157 { "ServerKeychain", &ServerKeychain
, CUPSD_VARTYPE_PATHNAME
},
158 #endif /* HAVE_SSL */
159 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
160 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
161 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
162 { "SyncOnClose", &SyncOnClose
, CUPSD_VARTYPE_BOOLEAN
},
163 #ifdef HAVE_AUTHORIZATION_H
164 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
165 #endif /* HAVE_AUTHORIZATION_H */
166 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
}
169 static int default_auth_type
= CUPSD_AUTH_AUTO
;
170 /* Default AuthType, if not specified */
172 static const unsigned ones
[4] =
174 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
176 static const unsigned zeros
[4] =
178 0x00000000, 0x00000000, 0x00000000, 0x00000000
186 static http_addrlist_t
*get_address(const char *value
, int defport
);
187 static int get_addr_and_mask(const char *value
, unsigned *ip
,
189 static void mime_error_cb(void *ctx
, const char *message
);
190 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
191 char *value
, int linenum
);
192 static int parse_fatal_errors(const char *s
);
193 static int parse_groups(const char *s
);
194 static int parse_protocols(const char *s
);
195 static int parse_variable(const char *filename
, int linenum
,
196 const char *line
, const char *value
,
198 const cupsd_var_t
*vars
);
199 static int read_cupsd_conf(cups_file_t
*fp
);
200 static int read_cups_files_conf(cups_file_t
*fp
);
201 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
202 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
203 static void set_policy_defaults(cupsd_policy_t
*pol
);
207 * 'cupsdAddAlias()' - Add a host alias.
211 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
212 const char *name
) /* I - Name to add */
214 cupsd_alias_t
*a
; /* New alias */
215 size_t namelen
; /* Length of name */
218 namelen
= strlen(name
);
220 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
223 a
->namelen
= namelen
;
224 memcpy(a
->name
, name
, namelen
+ 1); /* OK since a->name is allocated */
226 cupsArrayAdd(aliases
, a
);
231 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
234 int /* O - 0 on success, -1 on error, 1 on warning */
235 cupsdCheckPermissions(
236 const char *filename
, /* I - File/directory name */
237 const char *suffix
, /* I - Additional file/directory name */
238 mode_t mode
, /* I - Permissions */
239 uid_t user
, /* I - Owner */
240 gid_t group
, /* I - Group */
241 int is_dir
, /* I - 1 = directory, 0 = file */
242 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
244 int dir_created
= 0; /* Did we create a directory? */
245 char pathname
[1024]; /* File name with prefix */
246 struct stat fileinfo
; /* Stat buffer */
247 int is_symlink
; /* Is "filename" a symlink? */
251 * Prepend the given root to the filename before testing it...
256 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
261 * See if we can stat the file/directory...
264 if (lstat(filename
, &fileinfo
))
266 if (errno
== ENOENT
&& create_dir
)
269 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
272 if (mkdir(filename
, mode
))
275 cupsdLogMessage(CUPSD_LOG_ERROR
,
276 "Unable to create directory \"%s\" - %s", filename
,
281 asl_object_t m
; /* Log message */
283 m
= asl_new(ASL_TYPE_MSG
);
284 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
285 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
288 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
289 sd_journal_print(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
291 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
, strerror(errno
));
292 #endif /* HAVE_ASL_H */
298 fileinfo
.st_mode
= mode
| S_IFDIR
;
301 return (create_dir
? -1 : 1);
304 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
306 if (stat(filename
, &fileinfo
))
308 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
309 filename
, strerror(errno
));
315 * Make sure it's a regular file or a directory as needed...
318 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
320 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
324 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
327 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
331 asl_object_t m
; /* Log message */
333 m
= asl_new(ASL_TYPE_MSG
);
334 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
335 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "\"%s\" is not a directory.", filename
);
338 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
339 sd_journal_print(LOG_ERR
, "\"%s\" is not a directory.", filename
);
341 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
342 #endif /* HAVE_ASL_H */
348 * If the filename is a symlink, do not change permissions (STR #2937)...
355 * Fix owner, group, and mode as needed...
358 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
361 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
364 if (chown(filename
, user
, group
) && !getuid())
367 cupsdLogMessage(CUPSD_LOG_ERROR
,
368 "Unable to change ownership of \"%s\" - %s", filename
,
373 asl_object_t m
; /* Log message */
375 m
= asl_new(ASL_TYPE_MSG
);
376 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
377 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
380 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
381 sd_journal_print(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
383 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
, strerror(errno
));
384 #endif /* HAVE_ASL_H */
390 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
393 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
396 if (chmod(filename
, mode
))
399 cupsdLogMessage(CUPSD_LOG_ERROR
,
400 "Unable to change permissions of \"%s\" - %s", filename
,
405 asl_object_t m
; /* Log message */
407 m
= asl_new(ASL_TYPE_MSG
);
408 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
409 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
412 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
413 sd_journal_print(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
415 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
, strerror(errno
));
416 #endif /* HAVE_ASL_H */
423 * Everything is OK...
431 * 'cupsdDefaultAuthType()' - Get the default AuthType.
433 * When the default_auth_type is "auto", this function tries to get the GSS
434 * credentials for the server. If that succeeds we use Kerberos authentication,
435 * otherwise we do a fallback to Basic authentication against the local user
439 int /* O - Default AuthType value */
440 cupsdDefaultAuthType(void)
443 OM_uint32 major_status
, /* Major status code */
444 minor_status
; /* Minor status code */
445 gss_name_t server_name
; /* Server name */
446 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
447 /* Service name token */
448 char buf
[1024]; /* Service name buffer */
449 #endif /* HAVE_GSSAPI */
453 * If we have already determined the correct default AuthType, use it...
456 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
457 return (default_auth_type
);
462 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
466 if (&gss_init_sec_context
== NULL
)
467 return (default_auth_type
= CUPSD_AUTH_BASIC
);
468 # endif /* __APPLE__ */
471 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
472 * that fails we must use Basic...
475 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
478 token
.length
= strlen(buf
);
479 server_name
= GSS_C_NO_NAME
;
480 major_status
= gss_import_name(&minor_status
, &token
,
481 GSS_C_NT_HOSTBASED_SERVICE
,
484 memset(&token
, 0, sizeof(token
));
486 if (GSS_ERROR(major_status
))
488 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
489 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
490 return (default_auth_type
= CUPSD_AUTH_BASIC
);
493 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
495 if (GSS_ERROR(major_status
))
497 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
498 "cupsdDefaultAuthType: gss_display_name(%s) failed",
500 return (default_auth_type
= CUPSD_AUTH_BASIC
);
503 cupsdLogMessage(CUPSD_LOG_DEBUG
,
504 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
505 "credentials for %s...", (char *)token
.value
);
507 ServerCreds
= GSS_C_NO_CREDENTIAL
;
508 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
509 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
510 &ServerCreds
, NULL
, NULL
);
511 if (GSS_ERROR(major_status
))
513 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
514 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
515 (char *)token
.value
);
516 gss_release_name(&minor_status
, &server_name
);
517 gss_release_buffer(&minor_status
, &token
);
518 return (default_auth_type
= CUPSD_AUTH_BASIC
);
521 cupsdLogMessage(CUPSD_LOG_DEBUG
,
522 "cupsdDefaultAuthType: Kerberos credentials acquired "
523 "successfully for %s.", (char *)token
.value
);
525 gss_release_name(&minor_status
, &server_name
);
526 gss_release_buffer(&minor_status
, &token
);
530 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
534 * No Kerberos support compiled in so just use Basic all the time...
537 return (default_auth_type
= CUPSD_AUTH_BASIC
);
538 #endif /* HAVE_GSSAPI */
543 * 'cupsdFreeAliases()' - Free all of the alias entries.
547 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
549 cupsd_alias_t
*a
; /* Current alias */
552 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
554 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
557 cupsArrayDelete(aliases
);
562 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
565 int /* O - 1 on success, 0 otherwise */
566 cupsdReadConfiguration(void)
568 int i
; /* Looping var */
569 cups_file_t
*fp
; /* Configuration file */
570 int status
; /* Return status */
571 char temp
[1024], /* Temporary buffer */
572 mimedir
[1024], /* MIME directory */
573 *slash
; /* Directory separator */
574 cups_lang_t
*language
; /* Language */
575 struct passwd
*user
; /* Default user */
576 struct group
*group
; /* Default group */
577 char *old_serverroot
, /* Old ServerRoot */
578 *old_requestroot
; /* Old RequestRoot */
579 int old_remote_port
; /* Old RemotePort */
580 const char *tmpdir
; /* TMPDIR environment variable */
581 struct stat tmpinfo
; /* Temporary directory info */
582 cupsd_policy_t
*p
; /* Policy */
586 * Save the old root paths...
589 old_serverroot
= NULL
;
590 cupsdSetString(&old_serverroot
, ServerRoot
);
591 old_requestroot
= NULL
;
592 cupsdSetString(&old_requestroot
, RequestRoot
);
595 * Reset the server configuration data...
598 cupsdDeleteAllLocations();
600 cupsdDeleteAllListeners();
602 old_remote_port
= RemotePort
;
609 cupsdFreeAliases(ServerAlias
);
612 cupsdClearString(&ServerName
);
613 cupsdClearString(&ServerAdmin
);
614 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
615 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
616 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
617 cupsdSetString(&DataDir
, CUPS_DATADIR
);
618 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
619 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
620 cupsdClearString(&ErrorLog
);
621 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
622 cupsdSetString(&PageLogFormat
,
623 "%p %u %j %T %P %C %{job-billing} "
624 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
625 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
626 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
627 cupsdSetString(&RemoteRoot
, "remroot");
628 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
630 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
632 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
633 PrintcapFormat
= PRINTCAP_SOLARIS
;
634 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
635 "/Library/Preferences/org.cups.printers.plist"))
636 PrintcapFormat
= PRINTCAP_PLIST
;
638 PrintcapFormat
= PRINTCAP_BSD
;
640 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
641 if ((slash
= strrchr(temp
, '/')) != NULL
)
644 cupsdSetString(&ServerRoot
, temp
);
646 cupsdClearString(&Classification
);
647 ClassifyOverride
= 0;
651 cupsdSetString(&ServerKeychain
, "ssl");
653 cupsdSetString(&ServerKeychain
, "/Library/Keychains/System.keychain");
654 # endif /* HAVE_GNUTLS */
656 _httpTLSSetOptions(0);
657 #endif /* HAVE_SSL */
659 language
= cupsLangDefault();
661 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
662 cupsdSetString(&DefaultLanguage
, "en");
664 cupsdSetString(&DefaultLanguage
, language
->language
);
666 cupsdClearString(&DefaultPaperSize
);
668 cupsdSetString(&RIPCache
, "128m");
670 cupsdSetString(&TempDir
, NULL
);
673 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
677 OM_uint32 minor_status
; /* Minor status code */
679 gss_release_cred(&minor_status
, &ServerCreds
);
684 ServerCreds
= GSS_C_NO_CREDENTIAL
;
685 #endif /* HAVE_GSSAPI */
688 * Find the default user...
691 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
696 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
697 * complement number...)
706 * Find the default group...
709 group
= getgrnam(CUPS_DEFAULT_GROUP
);
713 Group
= group
->gr_gid
;
717 * Fallback to group "nobody"...
720 group
= getgrnam("nobody");
724 Group
= group
->gr_gid
;
728 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
729 * complement number...)
740 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
741 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
742 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
743 default_auth_type
= CUPSD_AUTH_BASIC
;
745 CreateSelfSignedCerts
= TRUE
;
746 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
747 #endif /* HAVE_SSL */
748 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
749 JobKillDelay
= DEFAULT_TIMEOUT
;
751 JobRetryInterval
= 300;
756 HostNameLookups
= FALSE
;
758 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
759 ListenBackLog
= SOMAXCONN
;
760 LogDebugHistory
= 200;
761 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
762 LogLevel
= CUPSD_LOG_WARN
;
763 LogTimeFormat
= CUPSD_TIME_STANDARD
;
765 MaxClientsPerHost
= 0;
766 MaxLogSize
= 1024 * 1024;
768 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
770 ReloadTimeout
= DEFAULT_KEEPALIVE
;
771 RootCertDuration
= 300;
772 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
773 StrictConformance
= FALSE
;
775 Timeout
= DEFAULT_TIMEOUT
;
776 WebInterface
= CUPS_DEFAULT_WEBIF
;
778 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
780 Browsing
= CUPS_DEFAULT_BROWSING
;
781 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
783 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
784 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
785 #endif /* HAVE_DNSSD || HAVE_AVAHI */
787 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
788 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
790 cupsdSetString(&ErrorPolicy
, "stop-printer");
792 JobHistory
= DEFAULT_HISTORY
;
793 JobFiles
= DEFAULT_FILES
;
799 MaxJobsPerPrinter
= 0;
800 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
801 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
803 cupsdDeleteAllPolicies();
804 cupsdClearString(&DefaultPolicy
);
806 #ifdef HAVE_AUTHORIZATION_H
807 cupsdSetString(&SystemGroupAuthKey
, CUPS_DEFAULT_SYSTEM_AUTHKEY
);
808 #endif /* HAVE_AUTHORIZATION_H */
810 MaxSubscriptions
= 100;
811 MaxSubscriptionsPerJob
= 0;
812 MaxSubscriptionsPerPrinter
= 0;
813 MaxSubscriptionsPerUser
= 0;
814 DefaultLeaseDuration
= 86400;
815 MaxLeaseDuration
= 0;
818 IdleExitTimeout
= 60;
819 #endif /* HAVE_ONDEMAND */
822 * Setup environment variables...
828 * Read the cups-files.conf file...
831 if ((fp
= cupsFileOpen(CupsFilesFile
, "r")) != NULL
)
833 status
= read_cups_files_conf(fp
);
840 printf("\"%s\" contains errors.\n", CupsFilesFile
);
844 asl_object_t m
; /* Log message */
846 m
= asl_new(ASL_TYPE_MSG
);
847 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
848 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
851 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
852 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
854 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", CupsFilesFile
);
855 #endif /* HAVE_ASL_H */
860 else if (errno
== ENOENT
)
861 cupsdLogMessage(CUPSD_LOG_INFO
, "No %s, using defaults.", CupsFilesFile
);
865 asl_object_t m
; /* Log message */
867 m
= asl_new(ASL_TYPE_MSG
);
868 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
869 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
872 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
873 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
875 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", CupsFilesFile
, strerror(errno
));
876 #endif /* HAVE_ASL_H */
882 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
885 * Read the cupsd.conf file...
888 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
891 asl_object_t m
; /* Log message */
893 m
= asl_new(ASL_TYPE_MSG
);
894 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
895 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
897 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
898 sd_journal_print(LOG_ERR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
900 syslog(LOG_LPR
, "Unable to open \"%s\" - %s", ConfigurationFile
, strerror(errno
));
901 #endif /* HAVE_ASL_H */
906 status
= read_cupsd_conf(fp
);
913 printf("\"%s\" contains errors.\n", ConfigurationFile
);
917 asl_object_t m
; /* Log message */
919 m
= asl_new(ASL_TYPE_MSG
);
920 asl_set(m
, ASL_KEY_FACILITY
, "org.cups.cupsd");
921 asl_log(NULL
, m
, ASL_LEVEL_ERR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
924 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
925 sd_journal_print(LOG_ERR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
927 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.", ConfigurationFile
);
928 #endif /* HAVE_ASL_H */
935 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
936 RemotePort
? "enabled" : "disabled");
939 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
942 * See if the ServerName is an IP address...
948 ServerAlias
= cupsArrayNew(NULL
, NULL
);
950 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
954 if (gethostname(temp
, sizeof(temp
)))
956 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
958 strlcpy(temp
, "localhost", sizeof(temp
));
961 cupsdSetString(&ServerName
, temp
);
964 ServerAlias
= cupsArrayNew(NULL
, NULL
);
966 cupsdAddAlias(ServerAlias
, temp
);
967 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
969 if (HostNameLookups
|| RemotePort
)
971 struct hostent
*host
; /* Host entry to get FQDN */
973 if ((host
= gethostbyname(temp
)) != NULL
)
975 if (_cups_strcasecmp(temp
, host
->h_name
))
977 cupsdSetString(&ServerName
, host
->h_name
);
978 cupsdAddAlias(ServerAlias
, host
->h_name
);
979 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
985 for (i
= 0; host
->h_aliases
[i
]; i
++)
986 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
988 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
989 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
997 * Make sure we have the base hostname added as an alias, too!
1000 if ((slash
= strchr(temp
, '.')) != NULL
)
1003 cupsdAddAlias(ServerAlias
, temp
);
1004 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
1008 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
1010 ServerNameIsIP
= !*slash
;
1013 * Make sure ServerAdmin is initialized...
1017 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
1020 * Use the default system group if none was supplied in cupsd.conf...
1023 if (NumSystemGroups
== 0)
1025 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
1028 * Find the group associated with GID 0...
1031 group
= getgrgid(0);
1035 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
1037 cupsdSetString(&SystemGroups
[0], "unknown");
1039 SystemGroupIDs
[0] = 0;
1040 NumSystemGroups
= 1;
1045 * Make sure ConfigFilePerm and LogFilePerm have sane values...
1048 ConfigFilePerm
&= 0664;
1049 LogFilePerm
&= 0664;
1052 * Open the system log for cupsd if necessary...
1057 if (!strcmp(AccessLog
, "stderr"))
1058 cupsdSetString(&AccessLog
, "syslog");
1060 if (!strcmp(ErrorLog
, "stderr"))
1061 cupsdSetString(&ErrorLog
, "syslog");
1063 if (!strcmp(PageLog
, "stderr"))
1064 cupsdSetString(&PageLog
, "syslog");
1067 #if defined(HAVE_VSYSLOG) && !defined(HAVE_ASL_H) && !defined(HAVE_SYSTEMD_SD_JOURNAL_H)
1068 if (!strcmp(AccessLog
, "syslog") ||
1069 !strcmp(ErrorLog
, "syslog") ||
1070 !strcmp(PageLog
, "syslog"))
1071 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
1072 #endif /* HAVE_VSYSLOG && !HAVE_ASL_H && !HAVE_SYSTEMD_SD_JOURNAL_H */
1075 * Make sure each of the log files exists and gets rotated as necessary...
1078 if (strcmp(AccessLog
, "syslog"))
1079 cupsdCheckLogFile(&AccessFile
, AccessLog
);
1081 if (strcmp(ErrorLog
, "syslog"))
1082 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
1084 if (strcmp(PageLog
, "syslog"))
1085 cupsdCheckLogFile(&PageFile
, PageLog
);
1088 * Log the configuration file that was used...
1091 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
1095 * Validate the Group and SystemGroup settings - they cannot be the same,
1096 * otherwise the CGI programs will be able to authenticate as root without
1102 for (i
= 0; i
< NumSystemGroups
; i
++)
1103 if (Group
== SystemGroupIDs
[i
])
1106 if (i
< NumSystemGroups
)
1109 * Log the error and reset the group to a safe value...
1112 cupsdLogMessage(CUPSD_LOG_ERROR
,
1113 "Group and SystemGroup cannot use the same groups.");
1114 if (FatalErrors
& (CUPSD_FATAL_CONFIG
| CUPSD_FATAL_PERMISSIONS
))
1117 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
1119 group
= getgrnam("nobody");
1123 Group
= group
->gr_gid
;
1127 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
1128 * complement number...)
1137 * Check that we have at least one listen/port line; if not, report this
1138 * as an error and exit!
1141 if (cupsArrayCount(Listeners
) == 0)
1147 cupsdLogMessage(CUPSD_LOG_EMERG
,
1148 "No valid Listen or Port lines were found in the "
1149 "configuration file.");
1155 cupsdEndProcess(getpid(), 0);
1159 * Set the default locale using the language and charset...
1162 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1165 * Update all relative filenames to include the full path from ServerRoot...
1168 if (DocumentRoot
[0] != '/')
1169 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1171 if (RequestRoot
[0] != '/')
1172 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1174 if (ServerBin
[0] != '/')
1175 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1177 if (StateDir
[0] != '/')
1178 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1180 if (CacheDir
[0] != '/')
1181 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1184 if (ServerKeychain
[0] != '/')
1185 cupsdSetStringf(&ServerKeychain
, "%s/%s", ServerRoot
, ServerKeychain
);
1187 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Using keychain \"%s\" for server name \"%s\".", ServerKeychain
, ServerName
);
1188 if (!CreateSelfSignedCerts
)
1189 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Self-signed TLS certificate generation is disabled.");
1190 cupsSetServerCredentials(ServerKeychain
, ServerName
, CreateSelfSignedCerts
);
1191 #endif /* HAVE_SSL */
1194 * Make sure that directories and config files are owned and
1195 * writable by the user and group in the cupsd.conf file...
1198 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1200 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1202 cupsdCheckPermissions(CacheDir
, NULL
, 0770, RunUser
,
1204 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1206 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1208 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1209 SystemGroupIDs
[0], 1, 1) < 0 ||
1210 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1212 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1214 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1216 cupsdCheckPermissions(ConfigurationFile
, NULL
, ConfigFilePerm
, RunUser
,
1218 cupsdCheckPermissions(CupsFilesFile
, NULL
, ConfigFilePerm
, RunUser
,
1220 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1222 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1224 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1225 Group
, 0, 0) < 0) &&
1226 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1230 * Update TempDir to the default if it hasn't been set already...
1234 if (TempDir
&& !RunUser
&&
1235 (!strncmp(TempDir
, "/private/tmp", 12) || !strncmp(TempDir
, "/tmp", 4)))
1237 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot use %s for TempDir.", TempDir
);
1238 cupsdClearString(&TempDir
);
1240 #endif /* __APPLE__ */
1245 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1246 strncmp(tmpdir
, "/private/tmp", 12) && strncmp(tmpdir
, "/tmp", 4))
1248 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1249 #endif /* __APPLE__ */
1252 * TMPDIR is defined, see if it is OK for us to use...
1255 if (stat(tmpdir
, &tmpinfo
))
1256 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1257 tmpdir
, strerror(errno
));
1258 else if (!S_ISDIR(tmpinfo
.st_mode
))
1259 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1261 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1262 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1263 !(tmpinfo
.st_mode
& S_IWOTH
))
1264 cupsdLogMessage(CUPSD_LOG_ERROR
,
1265 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1267 cupsdSetString(&TempDir
, tmpdir
);
1273 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1275 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1278 setenv("TMPDIR", TempDir
, 1);
1281 * Make sure the temporary directory has the right permissions...
1284 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1288 * Update ownership and permissions if the CUPS temp directory
1289 * is under the spool directory or does not exist...
1292 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1293 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1298 * Update environment variables...
1304 * Validate the default error policy...
1307 if (strcmp(ErrorPolicy
, "retry-current-job") &&
1308 strcmp(ErrorPolicy
, "abort-job") &&
1309 strcmp(ErrorPolicy
, "retry-job") &&
1310 strcmp(ErrorPolicy
, "stop-printer"))
1312 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\", resetting to \"stop-printer\".", ErrorPolicy
);
1313 cupsdSetString(&ErrorPolicy
, "stop-printer");
1317 * Update default paper size setting as needed...
1320 if (!DefaultPaperSize
)
1322 #ifdef HAVE_LIBPAPER
1323 char *paper_result
; /* Paper size name from libpaper */
1325 if ((paper_result
= systempapername()) != NULL
)
1326 cupsdSetString(&DefaultPaperSize
, paper_result
);
1328 #endif /* HAVE_LIBPAPER */
1329 if (!DefaultLanguage
||
1330 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1331 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1332 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1333 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1334 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1335 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1336 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1339 * These are the only locales that will default to "letter" size...
1342 cupsdSetString(&DefaultPaperSize
, "Letter");
1345 cupsdSetString(&DefaultPaperSize
, "A4");
1349 * Update classification setting as needed...
1352 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1353 cupsdClearString(&Classification
);
1356 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1359 * Check the MaxClients setting, and then allocate memory for it...
1362 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1365 cupsdLogMessage(CUPSD_LOG_INFO
,
1366 "MaxClients limited to 1/3 (%d) of the file descriptor "
1368 MaxFDs
/ 3, MaxFDs
);
1370 MaxClients
= MaxFDs
/ 3;
1373 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1377 * Check the MaxActiveJobs setting; limit to 1/3 the available
1378 * file descriptors, since we need a pipe for each job...
1381 if (MaxActiveJobs
> (MaxFDs
/ 3))
1382 MaxActiveJobs
= MaxFDs
/ 3;
1385 * Update the MaxClientsPerHost value, as needed...
1388 if (MaxClientsPerHost
<= 0)
1389 MaxClientsPerHost
= MaxClients
;
1391 if (MaxClientsPerHost
> MaxClients
)
1392 MaxClientsPerHost
= MaxClients
;
1394 cupsdLogMessage(CUPSD_LOG_INFO
,
1395 "Allowing up to %d client connections per host.",
1399 * Update the default policy, as needed...
1403 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1405 DefaultPolicyPtr
= NULL
;
1407 if (!DefaultPolicyPtr
)
1409 cupsd_location_t
*po
; /* New policy operation */
1413 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1416 cupsdSetString(&DefaultPolicy
, "default");
1418 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1419 cupsdLogMessage(CUPSD_LOG_INFO
,
1420 "Using policy \"default\" as the default.");
1423 cupsdLogMessage(CUPSD_LOG_INFO
,
1424 "Creating CUPS default administrative policy:");
1426 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1428 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1430 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1431 cupsdAddString(&(p
->job_access
), "@OWNER");
1432 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1434 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1435 cupsdAddString(&(p
->job_attrs
), "job-name");
1436 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1437 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1438 cupsdAddString(&(p
->job_attrs
), "phone");
1440 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1441 cupsdAddString(&(p
->sub_access
), "@OWNER");
1442 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1444 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1445 cupsdAddString(&(p
->job_attrs
), "notify-events");
1446 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1447 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1448 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1449 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1451 cupsdLogMessage(CUPSD_LOG_INFO
,
1452 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1453 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1455 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1456 po
->order_type
= CUPSD_AUTH_ALLOW
;
1458 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1459 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1460 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1462 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1464 cupsdLogMessage(CUPSD_LOG_INFO
,
1465 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1466 "Release-Job Restart-Job Purge-Jobs "
1467 "Set-Job-Attributes Create-Job-Subscription "
1468 "Renew-Subscription Cancel-Subscription "
1469 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1470 "Suspend-Current-Job Resume-Job "
1471 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1472 "CUPS-Authenticate-Job CUPS-Get-Document>");
1473 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1475 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1476 po
->order_type
= CUPSD_AUTH_ALLOW
;
1477 po
->level
= CUPSD_AUTH_USER
;
1479 cupsdAddName(po
, "@OWNER");
1480 cupsdAddName(po
, "@SYSTEM");
1481 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1483 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1484 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1485 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1486 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1487 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1488 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1489 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1490 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1491 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1492 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1493 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1494 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1495 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1496 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1497 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1498 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1499 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1500 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1501 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1502 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1504 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1506 cupsdLogMessage(CUPSD_LOG_INFO
,
1507 "<Limit Pause-Printer Resume-Printer "
1508 "Set-Printer-Attributes Enable-Printer "
1509 "Disable-Printer Pause-Printer-After-Current-Job "
1510 "Hold-New-Jobs Release-Held-New-Jobs "
1511 "Deactivate-Printer Activate-Printer Restart-Printer "
1512 "Shutdown-Printer Startup-Printer Promote-Job "
1513 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1514 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1515 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1516 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1517 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1519 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1520 po
->order_type
= CUPSD_AUTH_ALLOW
;
1521 po
->type
= CUPSD_AUTH_DEFAULT
;
1522 po
->level
= CUPSD_AUTH_USER
;
1524 cupsdAddName(po
, "@SYSTEM");
1525 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1527 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1528 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1529 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1530 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1531 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1532 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1533 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1534 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1535 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1536 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1537 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1538 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1539 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1540 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1541 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1542 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1543 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1544 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1545 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1546 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1547 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1548 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1550 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1552 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1553 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1555 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1556 po
->order_type
= CUPSD_AUTH_ALLOW
;
1558 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1559 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1563 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1564 cupsArrayCount(Policies
));
1565 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1567 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1568 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1569 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1572 * If we are doing a full reload or the server root has changed, flush
1573 * the jobs, printers, etc. and start from scratch...
1576 if (NeedReload
== RELOAD_ALL
||
1577 old_remote_port
!= RemotePort
||
1578 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1579 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1581 mime_type_t
*type
; /* Current type */
1582 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1583 /* MIME type name */
1586 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1589 * Free all memory...
1592 cupsdDeleteAllSubscriptions();
1594 cupsdDeleteAllPrinters();
1596 DefaultPrinter
= NULL
;
1598 if (MimeDatabase
!= NULL
)
1599 mimeDelete(MimeDatabase
);
1603 for (i
= 0; i
< NumMimeTypes
; i
++)
1604 _cupsStrFree(MimeTypes
[i
]);
1610 * Read the MIME type and conversion database...
1613 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1614 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1616 MimeDatabase
= mimeNew();
1617 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1619 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1620 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1621 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1622 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1626 cupsdLogMessage(CUPSD_LOG_EMERG
,
1627 "Unable to load MIME database from \"%s\" or \"%s\".",
1628 mimedir
, ServerRoot
);
1629 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1633 cupsdLogMessage(CUPSD_LOG_INFO
,
1634 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1635 "%d filters...", mimedir
, ServerRoot
,
1636 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1639 * Create a list of MIME types for the document-format-supported
1643 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1644 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1647 if ((MimeTypes
= calloc((size_t)NumMimeTypes
, sizeof(const char *))) == NULL
)
1649 cupsdLogMessage(CUPSD_LOG_ERROR
,
1650 "Unable to allocate memory for %d MIME types.",
1656 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1658 i
++, type
= mimeNextType(MimeDatabase
))
1660 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1662 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1665 if (i
< NumMimeTypes
)
1666 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1669 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1671 mime_filter_t
*filter
; /* Current filter */
1674 for (type
= mimeFirstType(MimeDatabase
);
1676 type
= mimeNextType(MimeDatabase
))
1677 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1678 type
->super
, type
->type
);
1680 for (filter
= mimeFirstFilter(MimeDatabase
);
1682 filter
= mimeNextFilter(MimeDatabase
))
1683 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1684 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1685 filter
->src
->super
, filter
->src
->type
,
1686 filter
->dst
->super
, filter
->dst
->type
,
1687 filter
->cost
, filter
->filter
);
1694 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1695 cupsdLoadBanners(temp
);
1698 * Load printers and classes...
1701 cupsdLoadAllPrinters();
1702 cupsdLoadAllClasses();
1704 cupsdCreateCommonData();
1707 * Update the printcap file as needed...
1710 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1711 cupsdWritePrintcap();
1714 * Load queued jobs...
1720 * Load subscriptions...
1723 cupsdLoadAllSubscriptions();
1725 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1730 * Not a full reload, so recreate the common printer attributes...
1733 cupsdCreateCommonData();
1736 * Update all jobs as needed...
1742 * Update all printers as needed...
1745 cupsdUpdatePrinters();
1746 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1748 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1752 * Reset the reload state...
1755 NeedReload
= RELOAD_NONE
;
1757 cupsdClearString(&old_serverroot
);
1758 cupsdClearString(&old_requestroot
);
1765 * 'get_address()' - Get an address + port number from a line.
1768 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1769 get_address(const char *value
, /* I - Value string */
1770 int defport
) /* I - Default port */
1772 char buffer
[1024], /* Hostname + port number buffer */
1773 defpname
[255], /* Default port name */
1774 *hostname
, /* Hostname or IP */
1775 *portname
; /* Port number or name */
1776 http_addrlist_t
*addrlist
; /* Address list */
1780 * Check for an empty value...
1785 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1790 * Grab a hostname and port number; if there is no colon and the port name
1791 * is only digits, then we have a port number by itself...
1794 strlcpy(buffer
, value
, sizeof(buffer
));
1796 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1803 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1808 * Use the default port...
1811 sprintf(defpname
, "%d", defport
);
1812 portname
= defpname
;
1818 * The buffer contains just a port number...
1826 if (hostname
&& !strcmp(hostname
, "*"))
1830 * Now lookup the address using httpAddrGetList()...
1833 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1834 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1835 hostname
? hostname
: "(nil)");
1842 * 'get_addr_and_mask()' - Get an IP address and netmask.
1845 static int /* O - 1 on success, 0 on failure */
1846 get_addr_and_mask(const char *value
, /* I - String from config file */
1847 unsigned *ip
, /* O - Address value */
1848 unsigned *mask
) /* O - Mask value */
1850 int i
, j
, /* Looping vars */
1851 family
, /* Address family */
1852 ipcount
; /* Count of fields in address */
1853 unsigned ipval
; /* Value */
1854 const char *maskval
, /* Pointer to start of mask value */
1855 *ptr
, /* Pointer into value */
1860 * Get the address...
1863 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1864 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1866 if ((maskval
= strchr(value
, '/')) != NULL
)
1869 maskval
= value
+ strlen(value
);
1873 * Check for an IPv6 address...
1879 * Parse hexadecimal IPv6/IPv4 address...
1884 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1888 else if (!strncmp(ptr
, "::", 2))
1890 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1892 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1897 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1900 * Read IPv4 dotted quad...
1903 unsigned val
[4] = { 0, 0, 0, 0 };
1904 /* IPv4 address values */
1906 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1910 * Range check the IP numbers...
1913 for (i
= 0; i
< ipcount
; i
++)
1918 * Merge everything into a 32-bit IPv4 address in ip[3]...
1921 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1922 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1925 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1928 * If the leading words are all 0's then this is an IPv4 address...
1931 if (!val
[0] && !val
[1] && !val
[2])
1934 while (isdigit(*ptr
& 255) || *ptr
== '.')
1938 else if (isxdigit(*ptr
& 255))
1940 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1942 if (*ptr
== ':' && ptr
[1] != ':')
1951 ip
[i
/ 2] |= ipval
<< 16;
1962 if (*ptr
&& *ptr
!= '/')
1966 #endif /* AF_INET6 */
1969 * Parse dotted-decimal IPv4 address...
1972 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1976 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1979 * Range check the IP numbers...
1982 for (i
= 0; i
< ipcount
; i
++)
1987 * Merge everything into a 32-bit IPv4 address in ip[3]...
1990 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1991 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1994 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
2000 * Get the netmask value(s)...
2003 memset(mask
, 0, sizeof(unsigned) * 4);
2005 if (strchr(maskval
, '.'))
2008 * Get dotted-decimal mask...
2011 if (family
!= AF_INET
)
2014 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
2018 mask
[3] |= (((((unsigned)mask
[0] << 8) | (unsigned)mask
[1]) << 8) |
2019 (unsigned)mask
[2]) << 8;
2020 mask
[0] = mask
[1] = mask
[2] = 0;
2025 * Get address/bits format...
2031 if (family
== AF_INET6
)
2039 mask
[0] = 0xffffffff;
2041 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
2044 mask
[1] = 0xffffffff;
2048 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
2051 mask
[2] = 0xffffffff;
2055 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
2058 mask
[3] = 0xffffffff;
2062 mask
[3] = (0xffffffff << i
) & 0xffffffff;
2065 #endif /* AF_INET6 */
2070 mask
[0] = 0xffffffff;
2071 mask
[1] = 0xffffffff;
2072 mask
[2] = 0xffffffff;
2075 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
2077 mask
[3] = 0xffffffff;
2082 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2083 "get_addr_and_mask(value=\"%s\", "
2084 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
2085 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
2089 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2092 if ((ip
[0] & ~mask
[0]) != 0 ||
2093 (ip
[1] & ~mask
[1]) != 0 ||
2094 (ip
[2] & ~mask
[2]) != 0 ||
2095 (ip
[3] & ~mask
[3]) != 0)
2103 * 'mime_error_cb()' - Log a MIME error.
2107 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
2108 const char *message
) /* I - Message */
2112 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
2117 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
2120 static int /* O - 1 on success, 0 on failure */
2121 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
2122 char *line
, /* I - Line from file */
2123 char *value
, /* I - Start of value data */
2124 int linenum
) /* I - Current line number */
2126 char *valptr
; /* Pointer into value */
2127 unsigned ip
[4], /* IP address components */
2128 mask
[4]; /* IP netmask components */
2131 if (!_cups_strcasecmp(line
, "Encryption"))
2134 * "Encryption xxx" - set required encryption level...
2137 if (!_cups_strcasecmp(value
, "never"))
2138 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
2139 else if (!_cups_strcasecmp(value
, "always"))
2141 cupsdLogMessage(CUPSD_LOG_ERROR
,
2142 "Encryption value \"%s\" on line %d of %s is invalid in this "
2143 "context. Using \"required\" instead.", value
, linenum
, ConfigurationFile
);
2145 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2147 else if (!_cups_strcasecmp(value
, "required"))
2148 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2149 else if (!_cups_strcasecmp(value
, "ifrequested"))
2150 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2153 cupsdLogMessage(CUPSD_LOG_ERROR
,
2154 "Unknown Encryption value %s on line %d of %s.", value
, linenum
, ConfigurationFile
);
2158 else if (!_cups_strcasecmp(line
, "Order"))
2161 * "Order Deny,Allow" or "Order Allow,Deny"...
2164 if (!_cups_strncasecmp(value
, "deny", 4))
2165 loc
->order_type
= CUPSD_AUTH_ALLOW
;
2166 else if (!_cups_strncasecmp(value
, "allow", 5))
2167 loc
->order_type
= CUPSD_AUTH_DENY
;
2170 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d of %s.",
2171 value
, linenum
, ConfigurationFile
);
2175 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2178 * Allow [From] host/ip...
2179 * Deny [From] host/ip...
2184 if (!_cups_strncasecmp(value
, "from", 4))
2187 * Strip leading "from"...
2192 while (_cups_isspace(*value
))
2200 * Find the end of the value...
2203 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2205 while (_cups_isspace(*valptr
))
2209 * Figure out what form the allow/deny address takes:
2220 * nnn.nnn.nnn.nnn/mm
2221 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2224 if (!_cups_strcasecmp(value
, "all"))
2230 if (!_cups_strcasecmp(line
, "Allow"))
2231 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2233 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2235 else if (!_cups_strcasecmp(value
, "none"))
2241 if (!_cups_strcasecmp(line
, "Allow"))
2242 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2244 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2247 else if (value
[0] == '*' || value
[0] == '.' ||
2248 (!isdigit(value
[0] & 255) && value
[0] != '['))
2250 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2251 #endif /* AF_INET6 */
2254 * Host or domain name...
2257 if (value
[0] == '*')
2260 if (!_cups_strcasecmp(line
, "Allow"))
2261 cupsdAddNameMask(&(loc
->allow
), value
);
2263 cupsdAddNameMask(&(loc
->deny
), value
);
2268 * One of many IP address forms...
2271 if (!get_addr_and_mask(value
, ip
, mask
))
2273 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d of %s.",
2274 value
, linenum
, ConfigurationFile
);
2278 if (!_cups_strcasecmp(line
, "Allow"))
2279 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2281 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2285 * Advance to next value...
2291 else if (!_cups_strcasecmp(line
, "AuthType"))
2294 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2297 if (!_cups_strcasecmp(value
, "none"))
2299 loc
->type
= CUPSD_AUTH_NONE
;
2300 loc
->level
= CUPSD_AUTH_ANON
;
2302 else if (!_cups_strcasecmp(value
, "basic"))
2304 loc
->type
= CUPSD_AUTH_BASIC
;
2306 if (loc
->level
== CUPSD_AUTH_ANON
)
2307 loc
->level
= CUPSD_AUTH_USER
;
2309 else if (!_cups_strcasecmp(value
, "default"))
2311 loc
->type
= CUPSD_AUTH_DEFAULT
;
2313 if (loc
->level
== CUPSD_AUTH_ANON
)
2314 loc
->level
= CUPSD_AUTH_USER
;
2317 else if (!_cups_strcasecmp(value
, "negotiate"))
2319 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2321 if (loc
->level
== CUPSD_AUTH_ANON
)
2322 loc
->level
= CUPSD_AUTH_USER
;
2324 #endif /* HAVE_GSSAPI */
2327 cupsdLogMessage(CUPSD_LOG_WARN
,
2328 "Unknown authorization type %s on line %d of %s.",
2329 value
, linenum
, ConfigurationFile
);
2333 else if (!_cups_strcasecmp(line
, "AuthClass"))
2336 * AuthClass anonymous, user, system, group
2339 if (!_cups_strcasecmp(value
, "anonymous"))
2341 loc
->type
= CUPSD_AUTH_NONE
;
2342 loc
->level
= CUPSD_AUTH_ANON
;
2344 cupsdLogMessage(CUPSD_LOG_WARN
,
2345 "\"AuthClass %s\" is deprecated; consider removing "
2349 else if (!_cups_strcasecmp(value
, "user"))
2351 loc
->level
= CUPSD_AUTH_USER
;
2353 cupsdLogMessage(CUPSD_LOG_WARN
,
2354 "\"AuthClass %s\" is deprecated; consider using "
2355 "\"Require valid-user\" on line %d of %s.",
2356 value
, linenum
, ConfigurationFile
);
2358 else if (!_cups_strcasecmp(value
, "group"))
2360 loc
->level
= CUPSD_AUTH_GROUP
;
2362 cupsdLogMessage(CUPSD_LOG_WARN
,
2363 "\"AuthClass %s\" is deprecated; consider using "
2364 "\"Require user @groupname\" on line %d of %s.",
2365 value
, linenum
, ConfigurationFile
);
2367 else if (!_cups_strcasecmp(value
, "system"))
2369 loc
->level
= CUPSD_AUTH_GROUP
;
2371 cupsdAddName(loc
, "@SYSTEM");
2373 cupsdLogMessage(CUPSD_LOG_WARN
,
2374 "\"AuthClass %s\" is deprecated; consider using "
2375 "\"Require user @SYSTEM\" on line %d of %s.",
2376 value
, linenum
, ConfigurationFile
);
2380 cupsdLogMessage(CUPSD_LOG_WARN
,
2381 "Unknown authorization class %s on line %d of %s.",
2382 value
, linenum
, ConfigurationFile
);
2386 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2388 cupsdAddName(loc
, value
);
2390 cupsdLogMessage(CUPSD_LOG_WARN
,
2391 "\"AuthGroupName %s\" directive is deprecated; consider "
2392 "using \"Require user @%s\" on line %d of %s.",
2393 value
, value
, linenum
, ConfigurationFile
);
2395 else if (!_cups_strcasecmp(line
, "Require"))
2398 * Apache synonym for AuthClass and AuthGroupName...
2402 * Require valid-user
2403 * Require group names
2404 * Require user names
2407 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2412 if (!_cups_strcasecmp(value
, "valid-user") ||
2413 !_cups_strcasecmp(value
, "user"))
2414 loc
->level
= CUPSD_AUTH_USER
;
2415 else if (!_cups_strcasecmp(value
, "group"))
2416 loc
->level
= CUPSD_AUTH_GROUP
;
2419 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d of %s.",
2420 value
, linenum
, ConfigurationFile
);
2425 * Get the list of names from the line...
2428 for (value
= valptr
; *value
;)
2430 while (_cups_isspace(*value
))
2433 #ifdef HAVE_AUTHORIZATION_H
2434 if (!strncmp(value
, "@AUTHKEY(", 9))
2437 * Grab "@AUTHKEY(name)" value...
2440 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2446 #endif /* HAVE_AUTHORIZATION_H */
2447 if (*value
== '\"' || *value
== '\'')
2450 * Grab quoted name...
2453 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2460 * Grab literal name.
2463 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2469 cupsdAddName(loc
, value
);
2471 for (value
= valptr
; _cups_isspace(*value
); value
++);
2474 else if (!_cups_strcasecmp(line
, "Satisfy"))
2476 if (!_cups_strcasecmp(value
, "all"))
2477 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2478 else if (!_cups_strcasecmp(value
, "any"))
2479 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2482 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d of %s.",
2483 value
, linenum
, ConfigurationFile
);
2495 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2498 static int /* O - FatalErrors bits */
2499 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2501 int fatal
; /* FatalErrors bits */
2502 char value
[1024], /* Value string */
2503 *valstart
, /* Pointer into value */
2504 *valend
; /* End of value */
2508 * Empty FatalErrors line yields NULL pointer...
2512 return (CUPSD_FATAL_NONE
);
2515 * Loop through the value string,...
2518 strlcpy(value
, s
, sizeof(value
));
2520 fatal
= CUPSD_FATAL_NONE
;
2522 for (valstart
= value
; *valstart
;)
2525 * Get the current space/comma-delimited kind name...
2528 for (valend
= valstart
; *valend
; valend
++)
2529 if (_cups_isspace(*valend
) || *valend
== ',')
2536 * Add the error to the bitmask...
2539 if (!_cups_strcasecmp(valstart
, "all"))
2540 fatal
= CUPSD_FATAL_ALL
;
2541 else if (!_cups_strcasecmp(valstart
, "browse"))
2542 fatal
|= CUPSD_FATAL_BROWSE
;
2543 else if (!_cups_strcasecmp(valstart
, "-browse"))
2544 fatal
&= ~CUPSD_FATAL_BROWSE
;
2545 else if (!_cups_strcasecmp(valstart
, "config"))
2546 fatal
|= CUPSD_FATAL_CONFIG
;
2547 else if (!_cups_strcasecmp(valstart
, "-config"))
2548 fatal
&= ~CUPSD_FATAL_CONFIG
;
2549 else if (!_cups_strcasecmp(valstart
, "listen"))
2550 fatal
|= CUPSD_FATAL_LISTEN
;
2551 else if (!_cups_strcasecmp(valstart
, "-listen"))
2552 fatal
&= ~CUPSD_FATAL_LISTEN
;
2553 else if (!_cups_strcasecmp(valstart
, "log"))
2554 fatal
|= CUPSD_FATAL_LOG
;
2555 else if (!_cups_strcasecmp(valstart
, "-log"))
2556 fatal
&= ~CUPSD_FATAL_LOG
;
2557 else if (!_cups_strcasecmp(valstart
, "permissions"))
2558 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2559 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2560 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2561 else if (_cups_strcasecmp(valstart
, "none"))
2562 cupsdLogMessage(CUPSD_LOG_ERROR
,
2563 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2565 for (valstart
= valend
; *valstart
; valstart
++)
2566 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2575 * 'parse_groups()' - Parse system group names in a string.
2578 static int /* O - 1 on success, 0 on failure */
2579 parse_groups(const char *s
) /* I - Space-delimited groups */
2581 int status
; /* Return status */
2582 char value
[1024], /* Value string */
2583 *valstart
, /* Pointer into value */
2584 *valend
, /* End of value */
2585 quote
; /* Quote character */
2586 struct group
*group
; /* Group */
2590 * Make a copy of the string and parse out the groups...
2593 strlcpy(value
, s
, sizeof(value
));
2598 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2600 if (*valstart
== '\'' || *valstart
== '\"')
2603 * Scan quoted name...
2606 quote
= *valstart
++;
2608 for (valend
= valstart
; *valend
; valend
++)
2609 if (*valend
== quote
)
2615 * Scan space or comma-delimited name...
2618 for (valend
= valstart
; *valend
; valend
++)
2619 if (_cups_isspace(*valend
) || *valend
== ',')
2626 group
= getgrnam(valstart
);
2629 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2630 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2641 while (*valstart
== ',' || _cups_isspace(*valstart
))
2650 * 'parse_protocols()' - Parse browse protocols in a string.
2653 static int /* O - Browse protocol bits */
2654 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2656 int protocols
; /* Browse protocol bits */
2657 char value
[1024], /* Value string */
2658 *valstart
, /* Pointer into value */
2659 *valend
; /* End of value */
2663 * Empty protocol line yields NULL pointer...
2670 * Loop through the value string,...
2673 strlcpy(value
, s
, sizeof(value
));
2677 for (valstart
= value
; *valstart
;)
2680 * Get the current space/comma-delimited protocol name...
2683 for (valend
= valstart
; *valend
; valend
++)
2684 if (_cups_isspace(*valend
) || *valend
== ',')
2691 * Add the protocol to the bitmask...
2694 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2695 !_cups_strcasecmp(valstart
, "dns-sd") ||
2696 !_cups_strcasecmp(valstart
, "bonjour"))
2697 protocols
|= BROWSE_DNSSD
;
2698 else if (!_cups_strcasecmp(valstart
, "all"))
2699 protocols
|= BROWSE_ALL
;
2700 else if (_cups_strcasecmp(valstart
, "none"))
2701 cupsdLogMessage(CUPSD_LOG_ERROR
,
2702 "Unknown browse protocol \"%s\" ignored.", valstart
);
2704 for (valstart
= valend
; *valstart
; valstart
++)
2705 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2714 * 'parse_variable()' - Parse a variable line.
2717 static int /* O - 1 on success, 0 on failure */
2719 const char *filename
, /* I - Name of configuration file */
2720 int linenum
, /* I - Line in configuration file */
2721 const char *line
, /* I - Line from configuration file */
2722 const char *value
, /* I - Value from configuration file */
2723 size_t num_vars
, /* I - Number of variables */
2724 const cupsd_var_t
*vars
) /* I - Variables */
2726 size_t i
; /* Looping var */
2727 const cupsd_var_t
*var
; /* Variables */
2728 char temp
[1024]; /* Temporary string */
2731 for (i
= num_vars
, var
= vars
; i
> 0; i
--, var
++)
2732 if (!_cups_strcasecmp(line
, var
->name
))
2738 * Unknown directive! Output an error message and continue...
2742 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d of %s.",
2743 line
, linenum
, filename
);
2745 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d of %s.",
2746 line
, linenum
, filename
);
2753 case CUPSD_VARTYPE_INTEGER
:
2756 cupsdLogMessage(CUPSD_LOG_ERROR
,
2757 "Missing integer value for %s on line %d of %s.",
2758 line
, linenum
, filename
);
2761 else if (!isdigit(*value
& 255))
2763 cupsdLogMessage(CUPSD_LOG_ERROR
,
2764 "Bad integer value for %s on line %d of %s.",
2765 line
, linenum
, filename
);
2771 char *units
; /* Units */
2773 n
= strtol(value
, &units
, 0);
2775 if (units
&& *units
)
2777 if (tolower(units
[0] & 255) == 'g')
2778 n
*= 1024 * 1024 * 1024;
2779 else if (tolower(units
[0] & 255) == 'm')
2781 else if (tolower(units
[0] & 255) == 'k')
2783 else if (tolower(units
[0] & 255) == 't')
2787 cupsdLogMessage(CUPSD_LOG_ERROR
,
2788 "Unknown integer value for %s on line %d of %s.",
2789 line
, linenum
, filename
);
2796 cupsdLogMessage(CUPSD_LOG_ERROR
,
2797 "Bad negative integer value for %s on line %d of "
2798 "%s.", line
, linenum
, filename
);
2803 *((int *)var
->ptr
) = n
;
2808 case CUPSD_VARTYPE_PERM
:
2811 cupsdLogMessage(CUPSD_LOG_ERROR
,
2812 "Missing permissions value for %s on line %d of %s.",
2813 line
, linenum
, filename
);
2816 else if (!isdigit(*value
& 255))
2818 /* TODO: Add chmod UGO syntax support */
2819 cupsdLogMessage(CUPSD_LOG_ERROR
,
2820 "Bad permissions value for %s on line %d of %s.",
2821 line
, linenum
, filename
);
2826 int n
= strtol(value
, NULL
, 8);
2827 /* Permissions value */
2831 cupsdLogMessage(CUPSD_LOG_ERROR
,
2832 "Bad negative permissions value for %s on line %d of "
2833 "%s.", line
, linenum
, filename
);
2838 *((mode_t
*)var
->ptr
) = (mode_t
)n
;
2843 case CUPSD_VARTYPE_TIME
:
2846 cupsdLogMessage(CUPSD_LOG_ERROR
,
2847 "Missing time interval value for %s on line %d of "
2848 "%s.", line
, linenum
, filename
);
2851 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
2852 (!_cups_strcasecmp(value
, "true") ||
2853 !_cups_strcasecmp(value
, "on") ||
2854 !_cups_strcasecmp(value
, "enabled") ||
2855 !_cups_strcasecmp(value
, "yes")))
2857 *((int *)var
->ptr
) = INT_MAX
;
2859 else if (!_cups_strcasecmp(value
, "false") ||
2860 !_cups_strcasecmp(value
, "off") ||
2861 !_cups_strcasecmp(value
, "disabled") ||
2862 !_cups_strcasecmp(value
, "no"))
2864 *((int *)var
->ptr
) = 0;
2866 else if (!isdigit(*value
& 255))
2868 cupsdLogMessage(CUPSD_LOG_ERROR
,
2869 "Unknown time interval value for %s on line %d of "
2870 "%s.", line
, linenum
, filename
);
2875 double n
; /* Number */
2876 char *units
; /* Units */
2878 n
= strtod(value
, &units
);
2880 if (units
&& *units
)
2882 if (tolower(units
[0] & 255) == 'w')
2883 n
*= 7 * 24 * 60 * 60;
2884 else if (tolower(units
[0] & 255) == 'd')
2886 else if (tolower(units
[0] & 255) == 'h')
2888 else if (tolower(units
[0] & 255) == 'm')
2892 cupsdLogMessage(CUPSD_LOG_ERROR
,
2893 "Unknown time interval value for %s on line "
2894 "%d of %s.", line
, linenum
, filename
);
2899 if (n
< 0.0 || n
> INT_MAX
)
2901 cupsdLogMessage(CUPSD_LOG_ERROR
,
2902 "Bad time value for %s on line %d of %s.",
2903 line
, linenum
, filename
);
2908 *((int *)var
->ptr
) = (int)n
;
2913 case CUPSD_VARTYPE_BOOLEAN
:
2916 cupsdLogMessage(CUPSD_LOG_ERROR
,
2917 "Missing boolean value for %s on line %d of %s.",
2918 line
, linenum
, filename
);
2921 else if (!_cups_strcasecmp(value
, "true") ||
2922 !_cups_strcasecmp(value
, "on") ||
2923 !_cups_strcasecmp(value
, "enabled") ||
2924 !_cups_strcasecmp(value
, "yes") ||
2927 *((int *)var
->ptr
) = TRUE
;
2929 else if (!_cups_strcasecmp(value
, "false") ||
2930 !_cups_strcasecmp(value
, "off") ||
2931 !_cups_strcasecmp(value
, "disabled") ||
2932 !_cups_strcasecmp(value
, "no") ||
2933 !_cups_strcasecmp(value
, "0"))
2935 *((int *)var
->ptr
) = FALSE
;
2939 cupsdLogMessage(CUPSD_LOG_ERROR
,
2940 "Unknown boolean value %s on line %d of %s.",
2941 value
, linenum
, filename
);
2946 case CUPSD_VARTYPE_PATHNAME
:
2949 cupsdLogMessage(CUPSD_LOG_ERROR
,
2950 "Missing pathname value for %s on line %d of %s.",
2951 line
, linenum
, filename
);
2955 if (value
[0] == '/')
2956 strlcpy(temp
, value
, sizeof(temp
));
2958 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
2960 if (access(temp
, 0))
2962 cupsdLogMessage(CUPSD_LOG_ERROR
,
2963 "File or directory for \"%s %s\" on line %d of %s "
2964 "does not exist.", line
, value
, linenum
, filename
);
2968 cupsdSetString((char **)var
->ptr
, temp
);
2971 case CUPSD_VARTYPE_STRING
:
2972 cupsdSetString((char **)var
->ptr
, value
);
2981 * 'read_cupsd_conf()' - Read the cupsd.conf configuration file.
2984 static int /* O - 1 on success, 0 on failure */
2985 read_cupsd_conf(cups_file_t
*fp
) /* I - File to read from */
2987 int linenum
; /* Current line number */
2988 char line
[HTTP_MAX_BUFFER
],
2989 /* Line from file */
2990 temp
[HTTP_MAX_BUFFER
],
2991 /* Temporary buffer for value */
2992 *value
, /* Pointer to value */
2993 *valueptr
; /* Pointer into value */
2994 int valuelen
; /* Length of value */
2995 http_addrlist_t
*addrlist
, /* Address list */
2996 *addr
; /* Current address */
2997 cups_file_t
*incfile
; /* Include file */
2998 char incname
[1024]; /* Include filename */
3002 * Loop through each line in the file...
3007 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3010 * Decode the directive...
3013 if (!_cups_strcasecmp(line
, "Include") && value
)
3019 if (value
[0] == '/')
3020 strlcpy(incname
, value
, sizeof(incname
));
3022 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
3024 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
3025 cupsdLogMessage(CUPSD_LOG_ERROR
,
3026 "Unable to include config file \"%s\" - %s",
3027 incname
, strerror(errno
));
3030 read_cupsd_conf(incfile
);
3031 cupsFileClose(incfile
);
3034 else if (!_cups_strcasecmp(line
, "<Location") && value
)
3040 linenum
= read_location(fp
, value
, linenum
);
3044 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
3050 linenum
= read_policy(fp
, value
, linenum
);
3054 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
3056 JobRetryInterval
= atoi(value
);
3057 cupsdLogMessage(CUPSD_LOG_WARN
,
3058 "FaxRetryInterval is deprecated; use "
3059 "JobRetryInterval on line %d of %s.", linenum
, ConfigurationFile
);
3061 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
3063 JobRetryLimit
= atoi(value
);
3064 cupsdLogMessage(CUPSD_LOG_WARN
,
3065 "FaxRetryLimit is deprecated; use "
3066 "JobRetryLimit on line %d of %s.", linenum
, ConfigurationFile
);
3069 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3072 * SSLOptions [AllowRC4] [AllowSSL3] [None]
3075 int options
= 0; /* SSL/TLS options */
3079 char *start
, /* Start of option */
3080 *end
; /* End of option */
3082 for (start
= value
; *start
; start
= end
)
3085 * Find end of keyword...
3089 while (*end
&& !_cups_isspace(*end
))
3099 if (!_cups_strcasecmp(start
, "AllowRC4"))
3100 options
|= _HTTP_TLS_ALLOW_RC4
;
3101 else if (!_cups_strcasecmp(start
, "AllowSSL3"))
3102 options
|= _HTTP_TLS_ALLOW_SSL3
;
3103 else if (!_cups_strcasecmp(start
, "None"))
3105 else if (_cups_strcasecmp(start
, "NoEmptyFragments"))
3106 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown SSL option %s at line %d.", start
, linenum
);
3110 _httpTLSSetOptions(options
);
3112 #endif /* HAVE_SSL */
3113 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
3115 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
3116 #endif /* HAVE_SSL */
3120 * Add listening address(es) to the list...
3123 cupsd_listener_t
*lis
; /* New listeners array */
3127 * Get the address list...
3130 addrlist
= get_address(value
, IPP_PORT
);
3134 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
3140 * Add each address...
3143 for (addr
= addrlist
; addr
; addr
= addr
->next
)
3146 * See if this address is already present...
3149 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
3151 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
3152 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
3153 httpAddrPort(&(addr
->addr
)) == httpAddrPort(&(lis
->address
)))
3158 #ifdef HAVE_ONDEMAND
3159 if (!lis
->on_demand
)
3160 #endif /* HAVE_ONDEMAND */
3162 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3163 cupsdLogMessage(CUPSD_LOG_WARN
,
3164 "Duplicate listen address \"%s\" ignored.", temp
);
3171 * Allocate another listener...
3175 Listeners
= cupsArrayNew(NULL
, NULL
);
3179 cupsdLogMessage(CUPSD_LOG_ERROR
,
3180 "Unable to allocate %s at line %d - %s.",
3181 line
, linenum
, strerror(errno
));
3185 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
3187 cupsdLogMessage(CUPSD_LOG_ERROR
,
3188 "Unable to allocate %s at line %d - %s.",
3189 line
, linenum
, strerror(errno
));
3193 cupsArrayAdd(Listeners
, lis
);
3196 * Copy the current address and log it...
3199 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
3203 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
3204 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
3205 #endif /* HAVE_SSL */
3207 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3210 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
3211 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
3213 #endif /* AF_LOCAL */
3214 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
3215 httpAddrPort(&(lis
->address
)),
3216 httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
3218 if (!httpAddrLocalhost(&(lis
->address
)))
3219 RemotePort
= httpAddrPort(&(lis
->address
));
3226 httpAddrFreeList(addrlist
);
3228 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
3229 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
3232 * "BrowseProtocols name [... name]"
3233 * "BrowseLocalProtocols name [... name]"
3236 int protocols
= parse_protocols(value
);
3240 cupsdLogMessage(CUPSD_LOG_ERROR
,
3241 "Unknown browse protocol \"%s\" on line %d of %s.",
3242 value
, linenum
, ConfigurationFile
);
3246 BrowseLocalProtocols
= protocols
;
3248 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
3251 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3254 if (!_cups_strcasecmp(value
, "none"))
3255 default_auth_type
= CUPSD_AUTH_NONE
;
3256 else if (!_cups_strcasecmp(value
, "basic"))
3257 default_auth_type
= CUPSD_AUTH_BASIC
;
3259 else if (!_cups_strcasecmp(value
, "negotiate"))
3260 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
3261 #endif /* HAVE_GSSAPI */
3262 else if (!_cups_strcasecmp(value
, "auto"))
3263 default_auth_type
= CUPSD_AUTH_AUTO
;
3266 cupsdLogMessage(CUPSD_LOG_WARN
,
3267 "Unknown default authorization type %s on line %d of %s.",
3268 value
, linenum
, ConfigurationFile
);
3269 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3274 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
3277 * DefaultEncryption {Never,IfRequested,Required}
3280 if (!value
|| !_cups_strcasecmp(value
, "never"))
3281 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3282 else if (!_cups_strcasecmp(value
, "required"))
3283 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3284 else if (!_cups_strcasecmp(value
, "ifrequested"))
3285 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3288 cupsdLogMessage(CUPSD_LOG_WARN
,
3289 "Unknown default encryption %s on line %d of %s.",
3290 value
, linenum
, ConfigurationFile
);
3291 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3295 #endif /* HAVE_SSL */
3296 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
3299 * Do hostname lookups?
3302 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
3303 !_cups_strcasecmp(value
, "false"))
3304 HostNameLookups
= 0;
3305 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
3306 !_cups_strcasecmp(value
, "true"))
3307 HostNameLookups
= 1;
3308 else if (!_cups_strcasecmp(value
, "double"))
3309 HostNameLookups
= 2;
3311 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d of %s.",
3312 value
, linenum
, ConfigurationFile
);
3314 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
3317 * Amount of logging to do to access log...
3320 if (!_cups_strcasecmp(value
, "all"))
3321 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3322 else if (!_cups_strcasecmp(value
, "actions"))
3323 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3324 else if (!_cups_strcasecmp(value
, "config"))
3325 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3326 else if (!_cups_strcasecmp(value
, "none"))
3327 AccessLogLevel
= CUPSD_ACCESSLOG_NONE
;
3329 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d of %s.",
3330 value
, linenum
, ConfigurationFile
);
3332 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
3335 * Amount of logging to do to error log...
3338 if (!_cups_strcasecmp(value
, "debug2"))
3339 LogLevel
= CUPSD_LOG_DEBUG2
;
3340 else if (!_cups_strcasecmp(value
, "debug"))
3341 LogLevel
= CUPSD_LOG_DEBUG
;
3342 else if (!_cups_strcasecmp(value
, "info"))
3343 LogLevel
= CUPSD_LOG_INFO
;
3344 else if (!_cups_strcasecmp(value
, "notice"))
3345 LogLevel
= CUPSD_LOG_NOTICE
;
3346 else if (!_cups_strcasecmp(value
, "warn"))
3347 LogLevel
= CUPSD_LOG_WARN
;
3348 else if (!_cups_strcasecmp(value
, "error"))
3349 LogLevel
= CUPSD_LOG_ERROR
;
3350 else if (!_cups_strcasecmp(value
, "crit"))
3351 LogLevel
= CUPSD_LOG_CRIT
;
3352 else if (!_cups_strcasecmp(value
, "alert"))
3353 LogLevel
= CUPSD_LOG_ALERT
;
3354 else if (!_cups_strcasecmp(value
, "emerg"))
3355 LogLevel
= CUPSD_LOG_EMERG
;
3356 else if (!_cups_strcasecmp(value
, "none"))
3357 LogLevel
= CUPSD_LOG_NONE
;
3359 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d of %s.",
3360 value
, linenum
, ConfigurationFile
);
3362 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
3365 * Amount of logging to do to error log...
3368 if (!_cups_strcasecmp(value
, "standard"))
3369 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3370 else if (!_cups_strcasecmp(value
, "usecs"))
3371 LogTimeFormat
= CUPSD_TIME_USECS
;
3373 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d of %s.",
3374 value
, linenum
, ConfigurationFile
);
3376 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
3379 * Set the string used for the Server header...
3382 struct utsname plat
; /* Platform info */
3387 if (!_cups_strcasecmp(value
, "ProductOnly"))
3388 cupsdSetString(&ServerHeader
, "CUPS IPP");
3389 else if (!_cups_strcasecmp(value
, "Major"))
3390 cupsdSetStringf(&ServerHeader
, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR
);
3391 else if (!_cups_strcasecmp(value
, "Minor"))
3392 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
3393 CUPS_VERSION_MINOR
);
3394 else if (!_cups_strcasecmp(value
, "Minimal"))
3395 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
" IPP/2.1");
3396 else if (!_cups_strcasecmp(value
, "OS"))
3397 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s) IPP/2.1",
3398 plat
.sysname
, plat
.release
);
3399 else if (!_cups_strcasecmp(value
, "Full"))
3400 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s; %s) IPP/2.1",
3401 plat
.sysname
, plat
.release
, plat
.machine
);
3402 else if (!_cups_strcasecmp(value
, "None"))
3403 cupsdClearString(&ServerHeader
);
3405 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d of %s.",
3406 value
, linenum
, ConfigurationFile
);
3408 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3411 * PassEnv variable [... variable]
3416 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3417 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3420 if (value
[valuelen
])
3422 value
[valuelen
] = '\0';
3426 cupsdSetEnv(value
, NULL
);
3428 for (value
+= valuelen
; *value
; value
++)
3429 if (!_cups_isspace(*value
) || *value
!= ',')
3433 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3436 * ServerAlias name [... name]
3440 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3444 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3445 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3448 if (value
[valuelen
])
3450 value
[valuelen
] = '\0';
3454 cupsdAddAlias(ServerAlias
, value
);
3456 for (value
+= valuelen
; *value
; value
++)
3457 if (!_cups_isspace(*value
) || *value
!= ',')
3461 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3464 * SetEnv variable value
3467 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3475 while (isspace(*valueptr
& 255))
3478 cupsdSetEnv(value
, valueptr
);
3481 cupsdLogMessage(CUPSD_LOG_ERROR
,
3482 "Missing value for SetEnv directive on line %d of %s.",
3483 linenum
, ConfigurationFile
);
3485 else if (!_cups_strcasecmp(line
, "AccessLog") ||
3486 !_cups_strcasecmp(line
, "CacheDir") ||
3487 !_cups_strcasecmp(line
, "ConfigFilePerm") ||
3488 !_cups_strcasecmp(line
, "DataDir") ||
3489 !_cups_strcasecmp(line
, "DocumentRoot") ||
3490 !_cups_strcasecmp(line
, "ErrorLog") ||
3491 !_cups_strcasecmp(line
, "FatalErrors") ||
3492 !_cups_strcasecmp(line
, "FileDevice") ||
3493 !_cups_strcasecmp(line
, "FontPath") ||
3494 !_cups_strcasecmp(line
, "Group") ||
3495 !_cups_strcasecmp(line
, "LogFilePerm") ||
3496 !_cups_strcasecmp(line
, "LPDConfigFile") ||
3497 !_cups_strcasecmp(line
, "PageLog") ||
3498 !_cups_strcasecmp(line
, "Printcap") ||
3499 !_cups_strcasecmp(line
, "PrintcapFormat") ||
3500 !_cups_strcasecmp(line
, "RemoteRoot") ||
3501 !_cups_strcasecmp(line
, "RequestRoot") ||
3502 !_cups_strcasecmp(line
, "ServerBin") ||
3503 !_cups_strcasecmp(line
, "ServerCertificate") ||
3504 !_cups_strcasecmp(line
, "ServerKey") ||
3505 !_cups_strcasecmp(line
, "ServerKeychain") ||
3506 !_cups_strcasecmp(line
, "ServerRoot") ||
3507 !_cups_strcasecmp(line
, "SMBConfigFile") ||
3508 !_cups_strcasecmp(line
, "StateDir") ||
3509 !_cups_strcasecmp(line
, "SystemGroup") ||
3510 !_cups_strcasecmp(line
, "SystemGroupAuthKey") ||
3511 !_cups_strcasecmp(line
, "TempDir") ||
3512 !_cups_strcasecmp(line
, "User"))
3514 cupsdLogMessage(CUPSD_LOG_INFO
,
3515 "Please move \"%s%s%s\" on line %d of %s to the %s file; "
3516 "this will become an error in a future release.",
3517 line
, value
? " " : "", value
? value
: "", linenum
,
3518 ConfigurationFile
, CupsFilesFile
);
3521 parse_variable(ConfigurationFile
, linenum
, line
, value
,
3522 sizeof(cupsd_vars
) / sizeof(cupsd_vars
[0]), cupsd_vars
);
3530 * 'read_cups_files_conf()' - Read the cups-files.conf configuration file.
3533 static int /* O - 1 on success, 0 on failure */
3534 read_cups_files_conf(cups_file_t
*fp
) /* I - File to read from */
3536 int linenum
; /* Current line number */
3537 char line
[HTTP_MAX_BUFFER
], /* Line from file */
3538 *value
; /* Value from line */
3539 struct group
*group
; /* Group */
3543 * Loop through each line in the file...
3548 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3550 if (!_cups_strcasecmp(line
, "FatalErrors"))
3551 FatalErrors
= parse_fatal_errors(value
);
3552 else if (!_cups_strcasecmp(line
, "Group") && value
)
3555 * Group ID to run as...
3558 if (isdigit(value
[0]))
3559 Group
= (gid_t
)atoi(value
);
3563 group
= getgrnam(value
);
3566 Group
= group
->gr_gid
;
3569 cupsdLogMessage(CUPSD_LOG_ERROR
,
3570 "Unknown Group \"%s\" on line %d of %s.", value
,
3571 linenum
, CupsFilesFile
);
3572 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3577 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
3580 * Format of printcap file?
3583 if (!_cups_strcasecmp(value
, "bsd"))
3584 PrintcapFormat
= PRINTCAP_BSD
;
3585 else if (!_cups_strcasecmp(value
, "plist"))
3586 PrintcapFormat
= PRINTCAP_PLIST
;
3587 else if (!_cups_strcasecmp(value
, "solaris"))
3588 PrintcapFormat
= PRINTCAP_SOLARIS
;
3591 cupsdLogMessage(CUPSD_LOG_ERROR
,
3592 "Unknown PrintcapFormat \"%s\" on line %d of %s.",
3593 value
, linenum
, CupsFilesFile
);
3594 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3598 else if (!_cups_strcasecmp(line
, "Sandboxing") && value
)
3601 * Level of sandboxing?
3604 if (!_cups_strcasecmp(value
, "off") && getuid())
3606 Sandboxing
= CUPSD_SANDBOXING_OFF
;
3607 cupsdLogMessage(CUPSD_LOG_WARN
, "Disabling sandboxing is not recommended (line %d of %s)", linenum
, CupsFilesFile
);
3609 else if (!_cups_strcasecmp(value
, "relaxed"))
3610 Sandboxing
= CUPSD_SANDBOXING_RELAXED
;
3611 else if (!_cups_strcasecmp(value
, "strict"))
3612 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
3615 cupsdLogMessage(CUPSD_LOG_ERROR
,
3616 "Unknown Sandboxing \"%s\" on line %d of %s.",
3617 value
, linenum
, CupsFilesFile
);
3618 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3622 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
3625 * SystemGroup (admin) group(s)...
3628 if (!parse_groups(value
))
3630 cupsdLogMessage(CUPSD_LOG_ERROR
,
3631 "Unknown SystemGroup \"%s\" on line %d of %s.", value
,
3632 linenum
, CupsFilesFile
);
3633 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3637 else if (!_cups_strcasecmp(line
, "User") && value
)
3640 * User ID to run as...
3643 if (isdigit(value
[0] & 255))
3645 int uid
= atoi(value
);
3649 cupsdLogMessage(CUPSD_LOG_ERROR
,
3650 "Will not use User 0 as specified on line %d of %s "
3651 "for security reasons. You must use a non-"
3652 "privileged account instead.",
3653 linenum
, CupsFilesFile
);
3654 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3658 User
= (uid_t
)atoi(value
);
3662 struct passwd
*p
; /* Password information */
3665 p
= getpwnam(value
);
3671 cupsdLogMessage(CUPSD_LOG_ERROR
,
3672 "Will not use User %s (UID=0) as specified on line "
3673 "%d of %s for security reasons. You must use a "
3674 "non-privileged account instead.",
3675 value
, linenum
, CupsFilesFile
);
3676 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3684 cupsdLogMessage(CUPSD_LOG_ERROR
,
3685 "Unknown User \"%s\" on line %d of %s.",
3686 value
, linenum
, CupsFilesFile
);
3687 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3692 else if (!_cups_strcasecmp(line
, "ServerCertificate") ||
3693 !_cups_strcasecmp(line
, "ServerKey"))
3695 cupsdLogMessage(CUPSD_LOG_INFO
,
3696 "The \"%s\" directive on line %d of %s is no longer "
3697 "supported; this will become an error in a future "
3699 line
, linenum
, CupsFilesFile
);
3701 else if (!parse_variable(CupsFilesFile
, linenum
, line
, value
,
3702 sizeof(cupsfiles_vars
) / sizeof(cupsfiles_vars
[0]),
3704 (FatalErrors
& CUPSD_FATAL_CONFIG
))
3713 * 'read_location()' - Read a <Location path> definition.
3716 static int /* O - New line number or 0 on error */
3717 read_location(cups_file_t
*fp
, /* I - Configuration file */
3718 char *location
, /* I - Location name/path */
3719 int linenum
) /* I - Current line number */
3721 cupsd_location_t
*loc
, /* New location */
3722 *parent
; /* Parent location */
3723 char line
[HTTP_MAX_BUFFER
],
3725 *value
, /* Value for directive */
3726 *valptr
; /* Pointer into value */
3729 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3730 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d of %s.",
3731 location
, linenum
, ConfigurationFile
);
3732 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3736 cupsdAddLocation(parent
);
3738 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3743 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3746 * Decode the directive...
3749 if (!_cups_strcasecmp(line
, "</Location>"))
3751 else if (!_cups_strcasecmp(line
, "<Limit") ||
3752 !_cups_strcasecmp(line
, "<LimitExcept"))
3756 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3757 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3763 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3766 cupsdAddLocation(loc
);
3771 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3776 if (!strcmp(value
, "ALL"))
3777 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3778 else if (!strcmp(value
, "GET"))
3779 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3780 else if (!strcmp(value
, "HEAD"))
3781 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3782 else if (!strcmp(value
, "OPTIONS"))
3783 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3784 else if (!strcmp(value
, "POST"))
3785 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3786 else if (!strcmp(value
, "PUT"))
3787 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3788 else if (!strcmp(value
, "TRACE"))
3789 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3791 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d of %s.",
3792 value
, linenum
, ConfigurationFile
);
3794 for (value
= valptr
; isspace(*value
& 255); value
++);
3797 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3798 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3800 parent
->limit
&= ~loc
->limit
;
3802 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3803 !_cups_strcasecmp(line
, "</LimitExcept>"))
3807 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3808 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3811 else if (!parse_aaa(loc
, line
, value
, linenum
))
3813 cupsdLogMessage(CUPSD_LOG_ERROR
,
3814 "Unknown Location directive %s on line %d of %s.",
3815 line
, linenum
, ConfigurationFile
);
3816 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3821 cupsdLogMessage(CUPSD_LOG_ERROR
,
3822 "Unexpected end-of-file at line %d while reading location.",
3825 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3830 * 'read_policy()' - Read a <Policy name> definition.
3833 static int /* O - New line number or 0 on error */
3834 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3835 char *policy
, /* I - Location name/path */
3836 int linenum
) /* I - Current line number */
3838 int i
; /* Looping var */
3839 cupsd_policy_t
*pol
; /* Policy */
3840 cupsd_location_t
*op
; /* Policy operation */
3841 int num_ops
; /* Number of IPP operations */
3842 ipp_op_t ops
[100]; /* Operations */
3843 char line
[HTTP_MAX_BUFFER
],
3845 *value
, /* Value for directive */
3846 *valptr
; /* Pointer into value */
3850 * Create the policy...
3853 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3854 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d of %s.",
3855 policy
, linenum
, ConfigurationFile
);
3856 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3860 * Read from the file...
3866 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3869 * Decode the directive...
3872 if (!_cups_strcasecmp(line
, "</Policy>"))
3875 cupsdLogMessage(CUPSD_LOG_WARN
,
3876 "Missing </Limit> before </Policy> on line %d of %s.",
3877 linenum
, ConfigurationFile
);
3879 set_policy_defaults(pol
);
3883 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3887 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of %s.", linenum
, ConfigurationFile
);
3888 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3895 * Scan for IPP operation names...
3902 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3907 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3909 if (!_cups_strcasecmp(value
, "All"))
3910 ops
[num_ops
] = IPP_ANY_OPERATION
;
3911 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3912 cupsdLogMessage(CUPSD_LOG_ERROR
,
3913 "Bad IPP operation name \"%s\" on line %d of %s.",
3914 value
, linenum
, ConfigurationFile
);
3919 cupsdLogMessage(CUPSD_LOG_ERROR
,
3920 "Too many operations listed on line %d of %s.",
3921 linenum
, ConfigurationFile
);
3923 for (value
= valptr
; isspace(*value
& 255); value
++);
3927 * If none are specified, apply the policy to all operations...
3932 ops
[0] = IPP_ANY_OPERATION
;
3937 * Add a new policy for the first operation...
3940 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3942 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3945 * Finish the current operation limit...
3951 * Copy the policy to the other operations...
3954 for (i
= 1; i
< num_ops
; i
++)
3955 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3962 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d of %s.", linenum
, ConfigurationFile
);
3963 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3966 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3967 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3968 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3969 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3973 cupsdLogMessage(CUPSD_LOG_ERROR
,
3974 "%s directive must appear outside <Limit>...</Limit> "
3975 "on line %d of %s.", line
, linenum
, ConfigurationFile
);
3976 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3982 * Pull out whitespace-delimited values...
3988 * Find the end of the current value...
3991 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3997 * Save it appropriately...
4000 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
4003 * JobPrivateAccess {all|default|user/group list|@@ACL}
4006 if (!_cups_strcasecmp(value
, "default"))
4008 cupsdAddString(&(pol
->job_access
), "@OWNER");
4009 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4012 cupsdAddString(&(pol
->job_access
), value
);
4014 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
4017 * JobPrivateValues {all|none|default|attribute list}
4020 if (!_cups_strcasecmp(value
, "default"))
4022 cupsdAddString(&(pol
->job_attrs
), "job-name");
4023 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4024 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4025 cupsdAddString(&(pol
->job_attrs
), "phone");
4028 cupsdAddString(&(pol
->job_attrs
), value
);
4030 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
4033 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
4036 if (!_cups_strcasecmp(value
, "default"))
4038 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4039 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4042 cupsdAddString(&(pol
->sub_access
), value
);
4044 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
4047 * SubscriptionPrivateValues {all|none|default|attribute list}
4050 if (!_cups_strcasecmp(value
, "default"))
4052 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4053 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4054 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4055 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4056 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
4059 cupsdAddString(&(pol
->sub_attrs
), value
);
4063 * Find the next string on the line...
4066 for (value
= valptr
; isspace(*value
& 255); value
++);
4072 cupsdLogMessage(CUPSD_LOG_ERROR
,
4073 "Missing <Limit ops> directive before %s on line %d of %s.",
4074 line
, linenum
, ConfigurationFile
);
4075 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4078 else if (!parse_aaa(op
, line
, value
, linenum
))
4080 cupsdLogMessage(CUPSD_LOG_ERROR
,
4081 "Unknown Policy Limit directive %s on line %d of %s.",
4082 line
, linenum
, ConfigurationFile
);
4084 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4089 cupsdLogMessage(CUPSD_LOG_ERROR
,
4090 "Unexpected end-of-file at line %d while reading policy "
4091 "\"%s\".", linenum
, policy
);
4093 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
4098 * 'set_policy_defaults()' - Set default policy values as needed.
4102 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
4104 cupsd_location_t
*op
; /* Policy operation */
4108 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
4109 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
4110 * upgrades do not introduce new security issues...
4112 * CUPS STR #4659: Allow a lone <Limit All> policy.
4115 if (cupsArrayCount(pol
->ops
) > 1)
4117 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
4118 op
->op
== IPP_ANY_OPERATION
)
4120 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
4121 op
->op
!= IPP_ANY_OPERATION
)
4124 * Add a new limit for Validate-Job using the Print-Job limit as a
4128 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s - using Print-Job's policy.", pol
->name
);
4130 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
4133 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Validate-Job defined in policy %s and no suitable template found.", pol
->name
);
4136 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
4137 op
->op
== IPP_ANY_OPERATION
)
4139 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
4140 op
->op
!= IPP_ANY_OPERATION
)
4143 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
4147 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s - using Pause-Printer's policy.", pol
->name
);
4149 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
4152 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-Jobs defined in policy %s 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
, "No limit for Cancel-My-Jobs defined in policy %s - using Send-Document's policy.", pol
->name
);
4168 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
4171 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Cancel-My-Jobs defined in policy %s and no suitable template found.", pol
->name
);
4174 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
4175 op
->op
== IPP_ANY_OPERATION
)
4177 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4178 op
->op
!= IPP_ANY_OPERATION
)
4181 * Add a new limit for Close-Job using the Send-Document limit as a
4185 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s - using Send-Document's policy.", pol
->name
);
4187 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
4190 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for Close-Job defined in policy %s and no suitable template found.", pol
->name
);
4193 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
4194 op
->op
== IPP_ANY_OPERATION
)
4196 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4197 op
->op
!= IPP_ANY_OPERATION
)
4200 * Add a new limit for CUPS-Get-Document using the Send-Document
4201 * limit as a template...
4204 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s - using Send-Document's policy.", pol
->name
);
4206 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
4209 cupsdLogMessage(CUPSD_LOG_WARN
, "No limit for CUPS-Get-Document defined in policy %s and no suitable template found.", pol
->name
);
4214 * Verify we have JobPrivateAccess, JobPrivateValues,
4215 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4218 if (!pol
->job_access
)
4220 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4221 cupsdAddString(&(pol
->job_access
), "@OWNER");
4222 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4225 if (!pol
->job_attrs
)
4227 cupsdLogMessage(CUPSD_LOG_WARN
, "No JobPrivateValues defined in policy %s - using defaults.", pol
->name
);
4228 cupsdAddString(&(pol
->job_attrs
), "job-name");
4229 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4230 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4231 cupsdAddString(&(pol
->job_attrs
), "phone");
4234 if (!pol
->sub_access
)
4236 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateAccess defined in policy %s - using defaults.", pol
->name
);
4237 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4238 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4241 if (!pol
->sub_attrs
)
4243 cupsdLogMessage(CUPSD_LOG_WARN
, "No SubscriptionPrivateValues defined in policy %s - using defaults.", pol
->name
);
4244 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4245 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4246 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4247 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4248 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");