4 * Configuration routines for the CUPS scheduler.
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
23 #include <sys/utsname.h>
28 #endif /* HAVE_LIBPAPER */
32 * Possibly missing network definitions...
36 # define INADDR_NONE 0xffffffff
37 #endif /* !INADDR_NONE */
41 * Configuration variable structure...
46 CUPSD_VARTYPE_INTEGER
, /* Integer option */
47 CUPSD_VARTYPE_TIME
, /* Time interval option */
48 CUPSD_VARTYPE_STRING
, /* String option */
49 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
50 CUPSD_VARTYPE_PATHNAME
, /* File/directory name option */
51 CUPSD_VARTYPE_PERM
/* File/directory permissions */
56 const char *name
; /* Name of variable */
57 void *ptr
; /* Pointer to variable */
58 cupsd_vartype_t type
; /* Type (int, string, address) */
66 static const cupsd_var_t cupsd_vars
[] =
68 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
69 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
70 { "BrowseDNSSDSubTypes", &DNSSDSubTypes
, CUPSD_VARTYPE_STRING
},
71 #endif /* HAVE_DNSSD || HAVE_AVAHI */
72 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
73 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
74 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
75 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
76 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
77 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_TIME
},
78 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
79 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
80 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
81 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_TIME
},
82 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
83 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
84 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
86 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
87 #endif /* HAVE_GSSAPI */
88 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
89 { "IdleExitTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
90 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
91 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_TIME
},
92 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
93 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_TIME
},
94 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_TIME
},
95 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
97 { "LaunchdTimeout", &IdleExitTimeout
, CUPSD_VARTYPE_TIME
},
98 #endif /* HAVE_LAUNCHD */
99 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
100 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
101 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
102 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
103 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
104 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
105 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
106 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
107 { "MaxHoldTime", &MaxHoldTime
, CUPSD_VARTYPE_TIME
},
108 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
109 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
110 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
111 { "MaxJobTime", &MaxJobTime
, CUPSD_VARTYPE_TIME
},
112 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_TIME
},
113 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
114 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
115 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
116 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
117 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
118 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
119 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_TIME
},
120 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
121 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_TIME
},
122 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_TIME
},
123 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_TIME
},
124 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
125 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_TIME
},
126 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
127 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
128 { "StrictConformance", &StrictConformance
, CUPSD_VARTYPE_BOOLEAN
},
129 { "Timeout", &Timeout
, CUPSD_VARTYPE_TIME
},
130 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
132 static const cupsd_var_t cupsfiles_vars
[] =
134 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
135 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
136 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_PERM
},
137 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
138 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
139 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
140 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
141 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
142 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_PERM
},
143 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
144 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
145 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
146 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
147 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
148 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
150 { "ServerKeychain", &ServerKeychain
, CUPSD_VARTYPE_PATHNAME
},
151 #endif /* HAVE_SSL */
152 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
153 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
154 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
155 { "SyncOnClose", &SyncOnClose
, CUPSD_VARTYPE_BOOLEAN
},
156 #ifdef HAVE_AUTHORIZATION_H
157 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
158 #endif /* HAVE_AUTHORIZATION_H */
159 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
}
162 static int default_auth_type
= CUPSD_AUTH_AUTO
;
163 /* Default AuthType, if not specified */
165 static const unsigned ones
[4] =
167 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
169 static const unsigned zeros
[4] =
171 0x00000000, 0x00000000, 0x00000000, 0x00000000
179 static http_addrlist_t
*get_address(const char *value
, int defport
);
180 static int get_addr_and_mask(const char *value
, unsigned *ip
,
182 static void mime_error_cb(void *ctx
, const char *message
);
183 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
184 char *value
, int linenum
);
185 static int parse_fatal_errors(const char *s
);
186 static int parse_groups(const char *s
);
187 static int parse_protocols(const char *s
);
188 static int parse_variable(const char *filename
, int linenum
,
189 const char *line
, const char *value
,
191 const cupsd_var_t
*vars
);
192 static int read_cupsd_conf(cups_file_t
*fp
);
193 static int read_cups_files_conf(cups_file_t
*fp
);
194 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
195 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
196 static void set_policy_defaults(cupsd_policy_t
*pol
);
200 * 'cupsdAddAlias()' - Add a host alias.
204 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
205 const char *name
) /* I - Name to add */
207 cupsd_alias_t
*a
; /* New alias */
208 size_t namelen
; /* Length of name */
211 namelen
= strlen(name
);
213 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
216 a
->namelen
= namelen
;
217 memcpy(a
->name
, name
, namelen
+ 1); /* OK since a->name is allocated */
219 cupsArrayAdd(aliases
, a
);
224 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
227 int /* O - 0 on success, -1 on error, 1 on warning */
228 cupsdCheckPermissions(
229 const char *filename
, /* I - File/directory name */
230 const char *suffix
, /* I - Additional file/directory name */
231 mode_t mode
, /* I - Permissions */
232 uid_t user
, /* I - Owner */
233 gid_t group
, /* I - Group */
234 int is_dir
, /* I - 1 = directory, 0 = file */
235 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
237 int dir_created
= 0; /* Did we create a directory? */
238 char pathname
[1024]; /* File name with prefix */
239 struct stat fileinfo
; /* Stat buffer */
240 int is_symlink
; /* Is "filename" a symlink? */
244 * Prepend the given root to the filename before testing it...
249 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
254 * See if we can stat the file/directory...
257 if (lstat(filename
, &fileinfo
))
259 if (errno
== ENOENT
&& create_dir
)
262 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
265 if (mkdir(filename
, mode
))
268 cupsdLogMessage(CUPSD_LOG_ERROR
,
269 "Unable to create directory \"%s\" - %s", filename
,
272 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
279 fileinfo
.st_mode
= mode
| S_IFDIR
;
282 return (create_dir
? -1 : 1);
285 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
287 if (stat(filename
, &fileinfo
))
289 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
290 filename
, strerror(errno
));
296 * Make sure it's a regular file or a directory as needed...
299 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
301 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
305 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
308 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
310 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
316 * If the filename is a symlink, do not change permissions (STR #2937)...
323 * Fix owner, group, and mode as needed...
326 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
329 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
332 if (chown(filename
, user
, group
) && !getuid())
335 cupsdLogMessage(CUPSD_LOG_ERROR
,
336 "Unable to change ownership of \"%s\" - %s", filename
,
339 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
346 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
349 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
352 if (chmod(filename
, mode
))
355 cupsdLogMessage(CUPSD_LOG_ERROR
,
356 "Unable to change permissions of \"%s\" - %s", filename
,
359 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
367 * Everything is OK...
375 * 'cupsdDefaultAuthType()' - Get the default AuthType.
377 * When the default_auth_type is "auto", this function tries to get the GSS
378 * credentials for the server. If that succeeds we use Kerberos authentication,
379 * otherwise we do a fallback to Basic authentication against the local user
383 int /* O - Default AuthType value */
384 cupsdDefaultAuthType(void)
387 OM_uint32 major_status
, /* Major status code */
388 minor_status
; /* Minor status code */
389 gss_name_t server_name
; /* Server name */
390 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
391 /* Service name token */
392 char buf
[1024]; /* Service name buffer */
393 #endif /* HAVE_GSSAPI */
397 * If we have already determined the correct default AuthType, use it...
400 if (default_auth_type
!= CUPSD_AUTH_AUTO
)
401 return (default_auth_type
);
406 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
410 if (gss_init_sec_context
== NULL
)
411 return (default_auth_type
= CUPSD_AUTH_BASIC
);
412 # endif /* __APPLE__ */
415 * Try to obtain the server's GSS credentials (GSSServiceName@servername). If
416 * that fails we must use Basic...
419 snprintf(buf
, sizeof(buf
), "%s@%s", GSSServiceName
, ServerName
);
422 token
.length
= strlen(buf
);
423 server_name
= GSS_C_NO_NAME
;
424 major_status
= gss_import_name(&minor_status
, &token
,
425 GSS_C_NT_HOSTBASED_SERVICE
,
428 memset(&token
, 0, sizeof(token
));
430 if (GSS_ERROR(major_status
))
432 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
433 "cupsdDefaultAuthType: gss_import_name(%s) failed", buf
);
434 return (default_auth_type
= CUPSD_AUTH_BASIC
);
437 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
439 if (GSS_ERROR(major_status
))
441 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
442 "cupsdDefaultAuthType: gss_display_name(%s) failed",
444 return (default_auth_type
= CUPSD_AUTH_BASIC
);
447 cupsdLogMessage(CUPSD_LOG_DEBUG
,
448 "cupsdDefaultAuthType: Attempting to acquire Kerberos "
449 "credentials for %s...", (char *)token
.value
);
451 ServerCreds
= GSS_C_NO_CREDENTIAL
;
452 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
453 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
454 &ServerCreds
, NULL
, NULL
);
455 if (GSS_ERROR(major_status
))
457 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
458 "cupsdDefaultAuthType: gss_acquire_cred(%s) failed",
459 (char *)token
.value
);
460 gss_release_name(&minor_status
, &server_name
);
461 gss_release_buffer(&minor_status
, &token
);
462 return (default_auth_type
= CUPSD_AUTH_BASIC
);
465 cupsdLogMessage(CUPSD_LOG_DEBUG
,
466 "cupsdDefaultAuthType: Kerberos credentials acquired "
467 "successfully for %s.", (char *)token
.value
);
469 gss_release_name(&minor_status
, &server_name
);
470 gss_release_buffer(&minor_status
, &token
);
474 return (default_auth_type
= CUPSD_AUTH_NEGOTIATE
);
478 * No Kerberos support compiled in so just use Basic all the time...
481 return (default_auth_type
= CUPSD_AUTH_BASIC
);
482 #endif /* HAVE_GSSAPI */
487 * 'cupsdFreeAliases()' - Free all of the alias entries.
491 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
493 cupsd_alias_t
*a
; /* Current alias */
496 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
498 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
501 cupsArrayDelete(aliases
);
506 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
509 int /* O - 1 on success, 0 otherwise */
510 cupsdReadConfiguration(void)
512 int i
; /* Looping var */
513 cups_file_t
*fp
; /* Configuration file */
514 int status
; /* Return status */
515 char temp
[1024], /* Temporary buffer */
516 mimedir
[1024], /* MIME directory */
517 *slash
; /* Directory separator */
518 cups_lang_t
*language
; /* Language */
519 struct passwd
*user
; /* Default user */
520 struct group
*group
; /* Default group */
521 char *old_serverroot
, /* Old ServerRoot */
522 *old_requestroot
; /* Old RequestRoot */
523 int old_remote_port
; /* Old RemotePort */
524 const char *tmpdir
; /* TMPDIR environment variable */
525 struct stat tmpinfo
; /* Temporary directory info */
526 cupsd_policy_t
*p
; /* Policy */
530 * Save the old root paths...
533 old_serverroot
= NULL
;
534 cupsdSetString(&old_serverroot
, ServerRoot
);
535 old_requestroot
= NULL
;
536 cupsdSetString(&old_requestroot
, RequestRoot
);
539 * Reset the server configuration data...
542 cupsdDeleteAllLocations();
544 cupsdDeleteAllListeners();
546 old_remote_port
= RemotePort
;
553 cupsdFreeAliases(ServerAlias
);
556 cupsdClearString(&ServerName
);
557 cupsdClearString(&ServerAdmin
);
558 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
559 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
560 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
561 cupsdSetString(&DataDir
, CUPS_DATADIR
);
562 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
563 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
564 cupsdClearString(&ErrorLog
);
565 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
566 cupsdSetString(&PageLogFormat
,
567 "%p %u %j %T %P %C %{job-billing} "
568 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
569 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
570 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
571 cupsdSetString(&RemoteRoot
, "remroot");
572 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
574 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
576 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
577 PrintcapFormat
= PRINTCAP_SOLARIS
;
578 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
579 "/Library/Preferences/org.cups.printers.plist"))
580 PrintcapFormat
= PRINTCAP_PLIST
;
582 PrintcapFormat
= PRINTCAP_BSD
;
584 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
585 if ((slash
= strrchr(temp
, '/')) != NULL
)
588 cupsdSetString(&ServerRoot
, temp
);
590 cupsdClearString(&Classification
);
591 ClassifyOverride
= 0;
595 cupsdSetString(&ServerKeychain
, "ssl");
597 cupsdSetString(&ServerKeychain
, "/Library/Keychains/System.keychain");
598 # endif /* HAVE_GNUTLS */
599 #endif /* HAVE_SSL */
601 language
= cupsLangDefault();
603 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
604 cupsdSetString(&DefaultLanguage
, "en");
606 cupsdSetString(&DefaultLanguage
, language
->language
);
608 cupsdClearString(&DefaultPaperSize
);
610 cupsdSetString(&RIPCache
, "128m");
612 cupsdSetString(&TempDir
, NULL
);
615 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
619 OM_uint32 minor_status
; /* Minor status code */
621 gss_release_cred(&minor_status
, &ServerCreds
);
626 ServerCreds
= GSS_C_NO_CREDENTIAL
;
627 #endif /* HAVE_GSSAPI */
630 * Find the default user...
633 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
638 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
639 * complement number...)
648 * Find the default group...
651 group
= getgrnam(CUPS_DEFAULT_GROUP
);
655 Group
= group
->gr_gid
;
659 * Fallback to group "nobody"...
662 group
= getgrnam("nobody");
666 Group
= group
->gr_gid
;
670 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
671 * complement number...)
682 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
683 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
684 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
685 default_auth_type
= CUPSD_AUTH_BASIC
;
687 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
688 #endif /* HAVE_SSL */
689 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
690 JobKillDelay
= DEFAULT_TIMEOUT
;
692 JobRetryInterval
= 300;
697 HostNameLookups
= FALSE
;
699 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
700 ListenBackLog
= SOMAXCONN
;
701 LogDebugHistory
= 200;
702 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
703 LogLevel
= CUPSD_LOG_WARN
;
704 LogTimeFormat
= CUPSD_TIME_STANDARD
;
706 MaxClientsPerHost
= 0;
707 MaxLogSize
= 1024 * 1024;
709 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
711 ReloadTimeout
= DEFAULT_KEEPALIVE
;
712 RootCertDuration
= 300;
713 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
714 StrictConformance
= FALSE
;
716 Timeout
= DEFAULT_TIMEOUT
;
717 WebInterface
= CUPS_DEFAULT_WEBIF
;
719 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
721 Browsing
= CUPS_DEFAULT_BROWSING
;
722 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
724 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
725 cupsdSetString(&DNSSDSubTypes
, "_cups,_print");
726 #endif /* HAVE_DNSSD || HAVE_AVAHI */
728 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
729 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
731 cupsdSetString(&ErrorPolicy
, "stop-printer");
733 JobHistory
= DEFAULT_HISTORY
;
734 JobFiles
= DEFAULT_FILES
;
740 MaxJobsPerPrinter
= 0;
741 MaxJobTime
= 3 * 60 * 60; /* 3 hours */
742 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
744 cupsdDeleteAllPolicies();
745 cupsdClearString(&DefaultPolicy
);
747 #ifdef HAVE_AUTHORIZATION_H
748 cupsdSetString(&SystemGroupAuthKey
, CUPS_DEFAULT_SYSTEM_AUTHKEY
);
749 #endif /* HAVE_AUTHORIZATION_H */
751 MaxSubscriptions
= 100;
752 MaxSubscriptionsPerJob
= 0;
753 MaxSubscriptionsPerPrinter
= 0;
754 MaxSubscriptionsPerUser
= 0;
755 DefaultLeaseDuration
= 86400;
756 MaxLeaseDuration
= 0;
758 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
759 IdleExitTimeout
= 60;
760 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
763 * Setup environment variables...
769 * Read the cups-files.conf file...
772 if ((fp
= cupsFileOpen(CupsFilesFile
, "r")) != NULL
)
774 status
= read_cups_files_conf(fp
);
781 printf("\"%s\" contains errors.\n", CupsFilesFile
);
783 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.",
789 else if (errno
== ENOENT
)
790 cupsdLogMessage(CUPSD_LOG_INFO
, "No %s, using defaults.", CupsFilesFile
);
793 syslog(LOG_LPR
, "Unable to open \"%s\": %s", CupsFilesFile
,
799 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
802 * Read the cupsd.conf file...
805 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
807 syslog(LOG_LPR
, "Unable to open \"%s\": %s", ConfigurationFile
,
812 status
= read_cupsd_conf(fp
);
819 printf("\"%s\" contains errors.\n", ConfigurationFile
);
821 syslog(LOG_LPR
, "Unable to read \"%s\" due to errors.",
829 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
830 RemotePort
? "enabled" : "disabled");
833 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
836 * See if the ServerName is an IP address...
842 ServerAlias
= cupsArrayNew(NULL
, NULL
);
844 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
848 if (gethostname(temp
, sizeof(temp
)))
850 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
852 strlcpy(temp
, "localhost", sizeof(temp
));
855 cupsdSetString(&ServerName
, temp
);
858 ServerAlias
= cupsArrayNew(NULL
, NULL
);
860 cupsdAddAlias(ServerAlias
, temp
);
861 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
863 if (HostNameLookups
|| RemotePort
)
865 struct hostent
*host
; /* Host entry to get FQDN */
867 if ((host
= gethostbyname(temp
)) != NULL
)
869 if (_cups_strcasecmp(temp
, host
->h_name
))
871 cupsdSetString(&ServerName
, host
->h_name
);
872 cupsdAddAlias(ServerAlias
, host
->h_name
);
873 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
879 for (i
= 0; host
->h_aliases
[i
]; i
++)
880 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
882 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
883 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
891 * Make sure we have the base hostname added as an alias, too!
894 if ((slash
= strchr(temp
, '.')) != NULL
)
897 cupsdAddAlias(ServerAlias
, temp
);
898 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
902 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
904 ServerNameIsIP
= !*slash
;
907 * Make sure ServerAdmin is initialized...
911 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
914 * Use the default system group if none was supplied in cupsd.conf...
917 if (NumSystemGroups
== 0)
919 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
922 * Find the group associated with GID 0...
929 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
931 cupsdSetString(&SystemGroups
[0], "unknown");
933 SystemGroupIDs
[0] = 0;
939 * Make sure ConfigFilePerm and LogFilePerm have sane values...
942 ConfigFilePerm
&= 0664;
946 * Open the system log for cupsd if necessary...
950 if (!strcmp(AccessLog
, "syslog") ||
951 !strcmp(ErrorLog
, "syslog") ||
952 !strcmp(PageLog
, "syslog"))
953 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
954 #endif /* HAVE_VSYSLOG */
957 * Make sure each of the log files exists and gets rotated as necessary...
960 if (strcmp(AccessLog
, "syslog"))
961 cupsdCheckLogFile(&AccessFile
, AccessLog
);
963 if (strcmp(ErrorLog
, "syslog"))
964 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
966 if (strcmp(PageLog
, "syslog"))
967 cupsdCheckLogFile(&PageFile
, PageLog
);
970 * Log the configuration file that was used...
973 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
977 * Validate the Group and SystemGroup settings - they cannot be the same,
978 * otherwise the CGI programs will be able to authenticate as root without
984 for (i
= 0; i
< NumSystemGroups
; i
++)
985 if (Group
== SystemGroupIDs
[i
])
988 if (i
< NumSystemGroups
)
991 * Log the error and reset the group to a safe value...
994 cupsdLogMessage(CUPSD_LOG_NOTICE
,
995 "Group and SystemGroup cannot use the same groups.");
996 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
998 group
= getgrnam("nobody");
1002 Group
= group
->gr_gid
;
1006 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
1007 * complement number...)
1016 * Check that we have at least one listen/port line; if not, report this
1017 * as an error and exit!
1020 if (cupsArrayCount(Listeners
) == 0)
1026 cupsdLogMessage(CUPSD_LOG_EMERG
,
1027 "No valid Listen or Port lines were found in the "
1028 "configuration file.");
1034 cupsdEndProcess(getpid(), 0);
1038 * Set the default locale using the language and charset...
1041 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
1044 * Update all relative filenames to include the full path from ServerRoot...
1047 if (DocumentRoot
[0] != '/')
1048 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
1050 if (RequestRoot
[0] != '/')
1051 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
1053 if (ServerBin
[0] != '/')
1054 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
1056 if (StateDir
[0] != '/')
1057 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
1059 if (CacheDir
[0] != '/')
1060 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
1063 if (ServerKeychain
[0] != '/')
1064 cupsdSetStringf(&ServerKeychain
, "%s/%s", ServerRoot
, ServerKeychain
);
1066 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Using keychain \"%s\" for server name \"%s\".", ServerKeychain
, ServerName
);
1067 cupsSetServerCredentials(ServerKeychain
, ServerName
, 1);
1068 #endif /* HAVE_SSL */
1071 * Make sure that directories and config files are owned and
1072 * writable by the user and group in the cupsd.conf file...
1075 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
1077 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
1079 cupsdCheckPermissions(CacheDir
, NULL
, 0770, RunUser
,
1081 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
1083 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
1085 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
1086 SystemGroupIDs
[0], 1, 1) < 0 ||
1087 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
1089 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
1091 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
1093 cupsdCheckPermissions(ConfigurationFile
, NULL
, ConfigFilePerm
, RunUser
,
1095 cupsdCheckPermissions(CupsFilesFile
, NULL
, ConfigFilePerm
, RunUser
,
1097 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1099 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1101 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1102 Group
, 0, 0) < 0) &&
1103 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1107 * Update TempDir to the default if it hasn't been set already...
1111 if (TempDir
&& !RunUser
&&
1112 (!strncmp(TempDir
, "/private/tmp", 12) || !strncmp(TempDir
, "/tmp", 4)))
1114 cupsdLogMessage(CUPSD_LOG_ERROR
, "Cannot use %s for TempDir.", TempDir
);
1115 cupsdClearString(&TempDir
);
1117 #endif /* __APPLE__ */
1122 if ((tmpdir
= getenv("TMPDIR")) != NULL
&&
1123 strncmp(tmpdir
, "/private/tmp", 12) && strncmp(tmpdir
, "/tmp", 4))
1125 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1126 #endif /* __APPLE__ */
1129 * TMPDIR is defined, see if it is OK for us to use...
1132 if (stat(tmpdir
, &tmpinfo
))
1133 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1134 tmpdir
, strerror(errno
));
1135 else if (!S_ISDIR(tmpinfo
.st_mode
))
1136 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1138 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1139 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1140 !(tmpinfo
.st_mode
& S_IWOTH
))
1141 cupsdLogMessage(CUPSD_LOG_ERROR
,
1142 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1144 cupsdSetString(&TempDir
, tmpdir
);
1150 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1152 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1155 setenv("TMPDIR", TempDir
, 1);
1158 * Make sure the temporary directory has the right permissions...
1161 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1165 * Update ownership and permissions if the CUPS temp directory
1166 * is under the spool directory or does not exist...
1169 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1170 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1175 * Update environment variables...
1181 * Update default paper size setting as needed...
1184 if (!DefaultPaperSize
)
1186 #ifdef HAVE_LIBPAPER
1187 char *paper_result
; /* Paper size name from libpaper */
1189 if ((paper_result
= systempapername()) != NULL
)
1190 cupsdSetString(&DefaultPaperSize
, paper_result
);
1192 #endif /* HAVE_LIBPAPER */
1193 if (!DefaultLanguage
||
1194 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1195 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1196 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1197 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1198 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1199 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1200 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1203 * These are the only locales that will default to "letter" size...
1206 cupsdSetString(&DefaultPaperSize
, "Letter");
1209 cupsdSetString(&DefaultPaperSize
, "A4");
1213 * Update classification setting as needed...
1216 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1217 cupsdClearString(&Classification
);
1220 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1223 * Check the MaxClients setting, and then allocate memory for it...
1226 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1229 cupsdLogMessage(CUPSD_LOG_INFO
,
1230 "MaxClients limited to 1/3 (%d) of the file descriptor "
1232 MaxFDs
/ 3, MaxFDs
);
1234 MaxClients
= MaxFDs
/ 3;
1237 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1241 * Check the MaxActiveJobs setting; limit to 1/3 the available
1242 * file descriptors, since we need a pipe for each job...
1245 if (MaxActiveJobs
> (MaxFDs
/ 3))
1246 MaxActiveJobs
= MaxFDs
/ 3;
1249 * Update the MaxClientsPerHost value, as needed...
1252 if (MaxClientsPerHost
<= 0)
1253 MaxClientsPerHost
= MaxClients
;
1255 if (MaxClientsPerHost
> MaxClients
)
1256 MaxClientsPerHost
= MaxClients
;
1258 cupsdLogMessage(CUPSD_LOG_INFO
,
1259 "Allowing up to %d client connections per host.",
1263 * Update the default policy, as needed...
1267 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1269 DefaultPolicyPtr
= NULL
;
1271 if (!DefaultPolicyPtr
)
1273 cupsd_location_t
*po
; /* New policy operation */
1277 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1280 cupsdSetString(&DefaultPolicy
, "default");
1282 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1283 cupsdLogMessage(CUPSD_LOG_INFO
,
1284 "Using policy \"default\" as the default.");
1287 cupsdLogMessage(CUPSD_LOG_INFO
,
1288 "Creating CUPS default administrative policy:");
1290 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1292 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1294 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1295 cupsdAddString(&(p
->job_access
), "@OWNER");
1296 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1298 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1299 cupsdAddString(&(p
->job_attrs
), "job-name");
1300 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1301 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1302 cupsdAddString(&(p
->job_attrs
), "phone");
1304 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1305 cupsdAddString(&(p
->sub_access
), "@OWNER");
1306 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1308 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1309 cupsdAddString(&(p
->job_attrs
), "notify-events");
1310 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1311 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1312 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1313 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1315 cupsdLogMessage(CUPSD_LOG_INFO
,
1316 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1317 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1319 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1320 po
->order_type
= CUPSD_AUTH_ALLOW
;
1322 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1323 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1324 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1326 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1328 cupsdLogMessage(CUPSD_LOG_INFO
,
1329 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1330 "Release-Job Restart-Job Purge-Jobs "
1331 "Set-Job-Attributes Create-Job-Subscription "
1332 "Renew-Subscription Cancel-Subscription "
1333 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1334 "Suspend-Current-Job Resume-Job "
1335 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1336 "CUPS-Authenticate-Job CUPS-Get-Document>");
1337 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1339 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1340 po
->order_type
= CUPSD_AUTH_ALLOW
;
1341 po
->level
= CUPSD_AUTH_USER
;
1343 cupsdAddName(po
, "@OWNER");
1344 cupsdAddName(po
, "@SYSTEM");
1345 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1347 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1348 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1349 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1350 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1351 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1352 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1353 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1354 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1355 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1356 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1357 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1358 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1359 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1360 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1361 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1362 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1363 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1364 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1365 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1366 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1368 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1370 cupsdLogMessage(CUPSD_LOG_INFO
,
1371 "<Limit Pause-Printer Resume-Printer "
1372 "Set-Printer-Attributes Enable-Printer "
1373 "Disable-Printer Pause-Printer-After-Current-Job "
1374 "Hold-New-Jobs Release-Held-New-Jobs "
1375 "Deactivate-Printer Activate-Printer Restart-Printer "
1376 "Shutdown-Printer Startup-Printer Promote-Job "
1377 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1378 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1379 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1380 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1381 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1383 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1384 po
->order_type
= CUPSD_AUTH_ALLOW
;
1385 po
->type
= CUPSD_AUTH_DEFAULT
;
1386 po
->level
= CUPSD_AUTH_USER
;
1388 cupsdAddName(po
, "@SYSTEM");
1389 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1391 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1392 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1393 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1394 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1395 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1396 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1397 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1398 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1399 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1400 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1401 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1402 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1403 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1404 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1405 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1406 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1407 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1408 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1409 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1410 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1411 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1412 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1414 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1416 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1417 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1419 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1420 po
->order_type
= CUPSD_AUTH_ALLOW
;
1422 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1423 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1427 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1428 cupsArrayCount(Policies
));
1429 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1431 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1432 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1433 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1436 * If we are doing a full reload or the server root has changed, flush
1437 * the jobs, printers, etc. and start from scratch...
1440 if (NeedReload
== RELOAD_ALL
||
1441 old_remote_port
!= RemotePort
||
1442 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1443 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1445 mime_type_t
*type
; /* Current type */
1446 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1447 /* MIME type name */
1450 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1453 * Free all memory...
1456 cupsdDeleteAllSubscriptions();
1458 cupsdDeleteAllPrinters();
1460 DefaultPrinter
= NULL
;
1462 if (MimeDatabase
!= NULL
)
1463 mimeDelete(MimeDatabase
);
1467 for (i
= 0; i
< NumMimeTypes
; i
++)
1468 _cupsStrFree(MimeTypes
[i
]);
1474 * Read the MIME type and conversion database...
1477 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1478 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1480 MimeDatabase
= mimeNew();
1481 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1483 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1484 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1485 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1486 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1490 cupsdLogMessage(CUPSD_LOG_EMERG
,
1491 "Unable to load MIME database from \"%s\" or \"%s\".",
1492 mimedir
, ServerRoot
);
1493 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1497 cupsdLogMessage(CUPSD_LOG_INFO
,
1498 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1499 "%d filters...", mimedir
, ServerRoot
,
1500 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1503 * Create a list of MIME types for the document-format-supported
1507 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1508 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1511 if ((MimeTypes
= calloc((size_t)NumMimeTypes
, sizeof(const char *))) == NULL
)
1513 cupsdLogMessage(CUPSD_LOG_ERROR
,
1514 "Unable to allocate memory for %d MIME types.",
1520 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1522 i
++, type
= mimeNextType(MimeDatabase
))
1524 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1526 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1529 if (i
< NumMimeTypes
)
1530 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1533 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1535 mime_filter_t
*filter
; /* Current filter */
1538 for (type
= mimeFirstType(MimeDatabase
);
1540 type
= mimeNextType(MimeDatabase
))
1541 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1542 type
->super
, type
->type
);
1544 for (filter
= mimeFirstFilter(MimeDatabase
);
1546 filter
= mimeNextFilter(MimeDatabase
))
1547 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1548 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1549 filter
->src
->super
, filter
->src
->type
,
1550 filter
->dst
->super
, filter
->dst
->type
,
1551 filter
->cost
, filter
->filter
);
1558 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1559 cupsdLoadBanners(temp
);
1562 * Load printers and classes...
1565 cupsdLoadAllPrinters();
1566 cupsdLoadAllClasses();
1568 cupsdCreateCommonData();
1571 * Update the printcap file as needed...
1574 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1575 cupsdWritePrintcap();
1578 * Load queued jobs...
1584 * Load subscriptions...
1587 cupsdLoadAllSubscriptions();
1589 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1594 * Not a full reload, so recreate the common printer attributes...
1597 cupsdCreateCommonData();
1600 * Update all jobs as needed...
1606 * Update all printers as needed...
1609 cupsdUpdatePrinters();
1610 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1612 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1616 * Reset the reload state...
1619 NeedReload
= RELOAD_NONE
;
1621 cupsdClearString(&old_serverroot
);
1622 cupsdClearString(&old_requestroot
);
1629 * 'get_address()' - Get an address + port number from a line.
1632 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1633 get_address(const char *value
, /* I - Value string */
1634 int defport
) /* I - Default port */
1636 char buffer
[1024], /* Hostname + port number buffer */
1637 defpname
[255], /* Default port name */
1638 *hostname
, /* Hostname or IP */
1639 *portname
; /* Port number or name */
1640 http_addrlist_t
*addrlist
; /* Address list */
1644 * Check for an empty value...
1649 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1654 * Grab a hostname and port number; if there is no colon and the port name
1655 * is only digits, then we have a port number by itself...
1658 strlcpy(buffer
, value
, sizeof(buffer
));
1660 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1667 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1672 * Use the default port...
1675 sprintf(defpname
, "%d", defport
);
1676 portname
= defpname
;
1682 * The buffer contains just a port number...
1690 if (hostname
&& !strcmp(hostname
, "*"))
1694 * Now lookup the address using httpAddrGetList()...
1697 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1698 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1699 hostname
? hostname
: "(nil)");
1706 * 'get_addr_and_mask()' - Get an IP address and netmask.
1709 static int /* O - 1 on success, 0 on failure */
1710 get_addr_and_mask(const char *value
, /* I - String from config file */
1711 unsigned *ip
, /* O - Address value */
1712 unsigned *mask
) /* O - Mask value */
1714 int i
, j
, /* Looping vars */
1715 family
, /* Address family */
1716 ipcount
; /* Count of fields in address */
1717 unsigned ipval
; /* Value */
1718 const char *maskval
, /* Pointer to start of mask value */
1719 *ptr
, /* Pointer into value */
1724 * Get the address...
1727 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1728 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1730 if ((maskval
= strchr(value
, '/')) != NULL
)
1733 maskval
= value
+ strlen(value
);
1737 * Check for an IPv6 address...
1743 * Parse hexadecimal IPv6/IPv4 address...
1748 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1752 else if (!strncmp(ptr
, "::", 2))
1754 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1756 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1761 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1764 * Read IPv4 dotted quad...
1767 unsigned val
[4] = { 0, 0, 0, 0 };
1768 /* IPv4 address values */
1770 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1774 * Range check the IP numbers...
1777 for (i
= 0; i
< ipcount
; i
++)
1782 * Merge everything into a 32-bit IPv4 address in ip[3]...
1785 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1786 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1789 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1792 * If the leading words are all 0's then this is an IPv4 address...
1795 if (!val
[0] && !val
[1] && !val
[2])
1798 while (isdigit(*ptr
& 255) || *ptr
== '.')
1802 else if (isxdigit(*ptr
& 255))
1804 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1806 if (*ptr
== ':' && ptr
[1] != ':')
1815 ip
[i
/ 2] |= ipval
<< 16;
1826 if (*ptr
&& *ptr
!= '/')
1830 #endif /* AF_INET6 */
1833 * Parse dotted-decimal IPv4 address...
1836 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1840 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1843 * Range check the IP numbers...
1846 for (i
= 0; i
< ipcount
; i
++)
1851 * Merge everything into a 32-bit IPv4 address in ip[3]...
1854 ip
[3] = ((((((unsigned)val
[0] << 8) | (unsigned)val
[1]) << 8) |
1855 (unsigned)val
[2]) << 8) | (unsigned)val
[3];
1858 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1864 * Get the netmask value(s)...
1867 memset(mask
, 0, sizeof(unsigned) * 4);
1869 if (strchr(maskval
, '.'))
1872 * Get dotted-decimal mask...
1875 if (family
!= AF_INET
)
1878 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1882 mask
[3] |= (((((unsigned)mask
[0] << 8) | (unsigned)mask
[1]) << 8) |
1883 (unsigned)mask
[2]) << 8;
1884 mask
[0] = mask
[1] = mask
[2] = 0;
1889 * Get address/bits format...
1895 if (family
== AF_INET6
)
1903 mask
[0] = 0xffffffff;
1905 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1908 mask
[1] = 0xffffffff;
1912 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1915 mask
[2] = 0xffffffff;
1919 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1922 mask
[3] = 0xffffffff;
1926 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1929 #endif /* AF_INET6 */
1934 mask
[0] = 0xffffffff;
1935 mask
[1] = 0xffffffff;
1936 mask
[2] = 0xffffffff;
1939 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1941 mask
[3] = 0xffffffff;
1946 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1947 "get_addr_and_mask(value=\"%s\", "
1948 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1949 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1953 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1956 if ((ip
[0] & ~mask
[0]) != 0 ||
1957 (ip
[1] & ~mask
[1]) != 0 ||
1958 (ip
[2] & ~mask
[2]) != 0 ||
1959 (ip
[3] & ~mask
[3]) != 0)
1967 * 'mime_error_cb()' - Log a MIME error.
1971 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
1972 const char *message
) /* I - Message */
1976 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
1981 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1984 static int /* O - 1 on success, 0 on failure */
1985 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1986 char *line
, /* I - Line from file */
1987 char *value
, /* I - Start of value data */
1988 int linenum
) /* I - Current line number */
1990 char *valptr
; /* Pointer into value */
1991 unsigned ip
[4], /* IP address components */
1992 mask
[4]; /* IP netmask components */
1995 if (!_cups_strcasecmp(line
, "Encryption"))
1998 * "Encryption xxx" - set required encryption level...
2001 if (!_cups_strcasecmp(value
, "never"))
2002 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
2003 else if (!_cups_strcasecmp(value
, "always"))
2005 cupsdLogMessage(CUPSD_LOG_ERROR
,
2006 "Encryption value \"%s\" on line %d is invalid in this "
2007 "context. Using \"required\" instead.", value
, linenum
);
2009 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2011 else if (!_cups_strcasecmp(value
, "required"))
2012 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
2013 else if (!_cups_strcasecmp(value
, "ifrequested"))
2014 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2017 cupsdLogMessage(CUPSD_LOG_ERROR
,
2018 "Unknown Encryption value %s on line %d.", value
, linenum
);
2022 else if (!_cups_strcasecmp(line
, "Order"))
2025 * "Order Deny,Allow" or "Order Allow,Deny"...
2028 if (!_cups_strncasecmp(value
, "deny", 4))
2029 loc
->order_type
= CUPSD_AUTH_ALLOW
;
2030 else if (!_cups_strncasecmp(value
, "allow", 5))
2031 loc
->order_type
= CUPSD_AUTH_DENY
;
2034 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
2039 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
2042 * Allow [From] host/ip...
2043 * Deny [From] host/ip...
2048 if (!_cups_strncasecmp(value
, "from", 4))
2051 * Strip leading "from"...
2056 while (_cups_isspace(*value
))
2064 * Find the end of the value...
2067 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
2069 while (_cups_isspace(*valptr
))
2073 * Figure out what form the allow/deny address takes:
2084 * nnn.nnn.nnn.nnn/mm
2085 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2088 if (!_cups_strcasecmp(value
, "all"))
2094 if (!_cups_strcasecmp(line
, "Allow"))
2095 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
2097 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
2099 else if (!_cups_strcasecmp(value
, "none"))
2105 if (!_cups_strcasecmp(line
, "Allow"))
2106 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2108 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2111 else if (value
[0] == '*' || value
[0] == '.' ||
2112 (!isdigit(value
[0] & 255) && value
[0] != '['))
2114 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2115 #endif /* AF_INET6 */
2118 * Host or domain name...
2121 if (value
[0] == '*')
2124 if (!_cups_strcasecmp(line
, "Allow"))
2125 cupsdAddNameMask(&(loc
->allow
), value
);
2127 cupsdAddNameMask(&(loc
->deny
), value
);
2132 * One of many IP address forms...
2135 if (!get_addr_and_mask(value
, ip
, mask
))
2137 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2142 if (!_cups_strcasecmp(line
, "Allow"))
2143 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2145 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2149 * Advance to next value...
2155 else if (!_cups_strcasecmp(line
, "AuthType"))
2158 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2161 if (!_cups_strcasecmp(value
, "none"))
2163 loc
->type
= CUPSD_AUTH_NONE
;
2164 loc
->level
= CUPSD_AUTH_ANON
;
2166 else if (!_cups_strcasecmp(value
, "basic"))
2168 loc
->type
= CUPSD_AUTH_BASIC
;
2170 if (loc
->level
== CUPSD_AUTH_ANON
)
2171 loc
->level
= CUPSD_AUTH_USER
;
2173 else if (!_cups_strcasecmp(value
, "default"))
2175 loc
->type
= CUPSD_AUTH_DEFAULT
;
2177 if (loc
->level
== CUPSD_AUTH_ANON
)
2178 loc
->level
= CUPSD_AUTH_USER
;
2181 else if (!_cups_strcasecmp(value
, "negotiate"))
2183 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2185 if (loc
->level
== CUPSD_AUTH_ANON
)
2186 loc
->level
= CUPSD_AUTH_USER
;
2188 #endif /* HAVE_GSSAPI */
2191 cupsdLogMessage(CUPSD_LOG_WARN
,
2192 "Unknown authorization type %s on line %d.",
2197 else if (!_cups_strcasecmp(line
, "AuthClass"))
2200 * AuthClass anonymous, user, system, group
2203 if (!_cups_strcasecmp(value
, "anonymous"))
2205 loc
->type
= CUPSD_AUTH_NONE
;
2206 loc
->level
= CUPSD_AUTH_ANON
;
2208 cupsdLogMessage(CUPSD_LOG_WARN
,
2209 "\"AuthClass %s\" is deprecated; consider removing "
2213 else if (!_cups_strcasecmp(value
, "user"))
2215 loc
->level
= CUPSD_AUTH_USER
;
2217 cupsdLogMessage(CUPSD_LOG_WARN
,
2218 "\"AuthClass %s\" is deprecated; consider using "
2219 "\"Require valid-user\" on line %d.",
2222 else if (!_cups_strcasecmp(value
, "group"))
2224 loc
->level
= CUPSD_AUTH_GROUP
;
2226 cupsdLogMessage(CUPSD_LOG_WARN
,
2227 "\"AuthClass %s\" is deprecated; consider using "
2228 "\"Require user @groupname\" on line %d.",
2231 else if (!_cups_strcasecmp(value
, "system"))
2233 loc
->level
= CUPSD_AUTH_GROUP
;
2235 cupsdAddName(loc
, "@SYSTEM");
2237 cupsdLogMessage(CUPSD_LOG_WARN
,
2238 "\"AuthClass %s\" is deprecated; consider using "
2239 "\"Require user @SYSTEM\" on line %d.",
2244 cupsdLogMessage(CUPSD_LOG_WARN
,
2245 "Unknown authorization class %s on line %d.",
2250 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2252 cupsdAddName(loc
, value
);
2254 cupsdLogMessage(CUPSD_LOG_WARN
,
2255 "\"AuthGroupName %s\" directive is deprecated; consider "
2256 "using \"Require user @%s\" on line %d.",
2257 value
, value
, linenum
);
2259 else if (!_cups_strcasecmp(line
, "Require"))
2262 * Apache synonym for AuthClass and AuthGroupName...
2266 * Require valid-user
2267 * Require group names
2268 * Require user names
2271 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2276 if (!_cups_strcasecmp(value
, "valid-user") ||
2277 !_cups_strcasecmp(value
, "user"))
2278 loc
->level
= CUPSD_AUTH_USER
;
2279 else if (!_cups_strcasecmp(value
, "group"))
2280 loc
->level
= CUPSD_AUTH_GROUP
;
2283 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2289 * Get the list of names from the line...
2292 for (value
= valptr
; *value
;)
2294 while (_cups_isspace(*value
))
2297 #ifdef HAVE_AUTHORIZATION_H
2298 if (!strncmp(value
, "@AUTHKEY(", 9))
2301 * Grab "@AUTHKEY(name)" value...
2304 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2310 #endif /* HAVE_AUTHORIZATION_H */
2311 if (*value
== '\"' || *value
== '\'')
2314 * Grab quoted name...
2317 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2324 * Grab literal name.
2327 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2333 cupsdAddName(loc
, value
);
2335 for (value
= valptr
; _cups_isspace(*value
); value
++);
2338 else if (!_cups_strcasecmp(line
, "Satisfy"))
2340 if (!_cups_strcasecmp(value
, "all"))
2341 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2342 else if (!_cups_strcasecmp(value
, "any"))
2343 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2346 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2359 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2362 static int /* O - FatalErrors bits */
2363 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2365 int fatal
; /* FatalErrors bits */
2366 char value
[1024], /* Value string */
2367 *valstart
, /* Pointer into value */
2368 *valend
; /* End of value */
2372 * Empty FatalErrors line yields NULL pointer...
2376 return (CUPSD_FATAL_NONE
);
2379 * Loop through the value string,...
2382 strlcpy(value
, s
, sizeof(value
));
2384 fatal
= CUPSD_FATAL_NONE
;
2386 for (valstart
= value
; *valstart
;)
2389 * Get the current space/comma-delimited kind name...
2392 for (valend
= valstart
; *valend
; valend
++)
2393 if (_cups_isspace(*valend
) || *valend
== ',')
2400 * Add the error to the bitmask...
2403 if (!_cups_strcasecmp(valstart
, "all"))
2404 fatal
= CUPSD_FATAL_ALL
;
2405 else if (!_cups_strcasecmp(valstart
, "browse"))
2406 fatal
|= CUPSD_FATAL_BROWSE
;
2407 else if (!_cups_strcasecmp(valstart
, "-browse"))
2408 fatal
&= ~CUPSD_FATAL_BROWSE
;
2409 else if (!_cups_strcasecmp(valstart
, "config"))
2410 fatal
|= CUPSD_FATAL_CONFIG
;
2411 else if (!_cups_strcasecmp(valstart
, "-config"))
2412 fatal
&= ~CUPSD_FATAL_CONFIG
;
2413 else if (!_cups_strcasecmp(valstart
, "listen"))
2414 fatal
|= CUPSD_FATAL_LISTEN
;
2415 else if (!_cups_strcasecmp(valstart
, "-listen"))
2416 fatal
&= ~CUPSD_FATAL_LISTEN
;
2417 else if (!_cups_strcasecmp(valstart
, "log"))
2418 fatal
|= CUPSD_FATAL_LOG
;
2419 else if (!_cups_strcasecmp(valstart
, "-log"))
2420 fatal
&= ~CUPSD_FATAL_LOG
;
2421 else if (!_cups_strcasecmp(valstart
, "permissions"))
2422 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2423 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2424 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2425 else if (_cups_strcasecmp(valstart
, "none"))
2426 cupsdLogMessage(CUPSD_LOG_ERROR
,
2427 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2429 for (valstart
= valend
; *valstart
; valstart
++)
2430 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2439 * 'parse_groups()' - Parse system group names in a string.
2442 static int /* O - 1 on success, 0 on failure */
2443 parse_groups(const char *s
) /* I - Space-delimited groups */
2445 int status
; /* Return status */
2446 char value
[1024], /* Value string */
2447 *valstart
, /* Pointer into value */
2448 *valend
, /* End of value */
2449 quote
; /* Quote character */
2450 struct group
*group
; /* Group */
2454 * Make a copy of the string and parse out the groups...
2457 strlcpy(value
, s
, sizeof(value
));
2462 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2464 if (*valstart
== '\'' || *valstart
== '\"')
2467 * Scan quoted name...
2470 quote
= *valstart
++;
2472 for (valend
= valstart
; *valend
; valend
++)
2473 if (*valend
== quote
)
2479 * Scan space or comma-delimited name...
2482 for (valend
= valstart
; *valend
; valend
++)
2483 if (_cups_isspace(*valend
) || *valend
== ',')
2490 group
= getgrnam(valstart
);
2493 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2494 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2505 while (*valstart
== ',' || _cups_isspace(*valstart
))
2514 * 'parse_protocols()' - Parse browse protocols in a string.
2517 static int /* O - Browse protocol bits */
2518 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2520 int protocols
; /* Browse protocol bits */
2521 char value
[1024], /* Value string */
2522 *valstart
, /* Pointer into value */
2523 *valend
; /* End of value */
2527 * Empty protocol line yields NULL pointer...
2534 * Loop through the value string,...
2537 strlcpy(value
, s
, sizeof(value
));
2541 for (valstart
= value
; *valstart
;)
2544 * Get the current space/comma-delimited protocol name...
2547 for (valend
= valstart
; *valend
; valend
++)
2548 if (_cups_isspace(*valend
) || *valend
== ',')
2555 * Add the protocol to the bitmask...
2558 if (!_cups_strcasecmp(valstart
, "dnssd") ||
2559 !_cups_strcasecmp(valstart
, "dns-sd") ||
2560 !_cups_strcasecmp(valstart
, "bonjour"))
2561 protocols
|= BROWSE_DNSSD
;
2562 else if (!_cups_strcasecmp(valstart
, "all"))
2563 protocols
|= BROWSE_ALL
;
2564 else if (_cups_strcasecmp(valstart
, "none"))
2565 cupsdLogMessage(CUPSD_LOG_ERROR
,
2566 "Unknown browse protocol \"%s\" ignored.", valstart
);
2568 for (valstart
= valend
; *valstart
; valstart
++)
2569 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2578 * 'parse_variable()' - Parse a variable line.
2581 static int /* O - 1 on success, 0 on failure */
2583 const char *filename
, /* I - Name of configuration file */
2584 int linenum
, /* I - Line in configuration file */
2585 const char *line
, /* I - Line from configuration file */
2586 const char *value
, /* I - Value from configuration file */
2587 size_t num_vars
, /* I - Number of variables */
2588 const cupsd_var_t
*vars
) /* I - Variables */
2590 size_t i
; /* Looping var */
2591 const cupsd_var_t
*var
; /* Variables */
2592 char temp
[1024]; /* Temporary string */
2595 for (i
= num_vars
, var
= vars
; i
> 0; i
--, var
++)
2596 if (!_cups_strcasecmp(line
, var
->name
))
2602 * Unknown directive! Output an error message and continue...
2606 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d of %s.",
2607 line
, linenum
, filename
);
2609 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d of %s.",
2610 line
, linenum
, filename
);
2617 case CUPSD_VARTYPE_INTEGER
:
2620 cupsdLogMessage(CUPSD_LOG_ERROR
,
2621 "Missing integer value for %s on line %d of %s.",
2622 line
, linenum
, filename
);
2625 else if (!isdigit(*value
& 255))
2627 cupsdLogMessage(CUPSD_LOG_ERROR
,
2628 "Bad integer value for %s on line %d of %s.",
2629 line
, linenum
, filename
);
2635 char *units
; /* Units */
2637 n
= strtol(value
, &units
, 0);
2639 if (units
&& *units
)
2641 if (tolower(units
[0] & 255) == 'g')
2642 n
*= 1024 * 1024 * 1024;
2643 else if (tolower(units
[0] & 255) == 'm')
2645 else if (tolower(units
[0] & 255) == 'k')
2647 else if (tolower(units
[0] & 255) == 't')
2651 cupsdLogMessage(CUPSD_LOG_ERROR
,
2652 "Unknown integer value for %s on line %d of %s.",
2653 line
, linenum
, filename
);
2660 cupsdLogMessage(CUPSD_LOG_ERROR
,
2661 "Bad negative integer value for %s on line %d of "
2662 "%s.", line
, linenum
, filename
);
2667 *((int *)var
->ptr
) = n
;
2672 case CUPSD_VARTYPE_PERM
:
2675 cupsdLogMessage(CUPSD_LOG_ERROR
,
2676 "Missing permissions value for %s on line %d of %s.",
2677 line
, linenum
, filename
);
2680 else if (!isdigit(*value
& 255))
2682 /* TODO: Add chmod UGO syntax support */
2683 cupsdLogMessage(CUPSD_LOG_ERROR
,
2684 "Bad permissions value for %s on line %d of %s.",
2685 line
, linenum
, filename
);
2690 int n
= strtol(value
, NULL
, 8);
2691 /* Permissions value */
2695 cupsdLogMessage(CUPSD_LOG_ERROR
,
2696 "Bad negative permissions value for %s on line %d of "
2697 "%s.", line
, linenum
, filename
);
2702 *((mode_t
*)var
->ptr
) = (mode_t
)n
;
2707 case CUPSD_VARTYPE_TIME
:
2710 cupsdLogMessage(CUPSD_LOG_ERROR
,
2711 "Missing time interval value for %s on line %d of "
2712 "%s.", line
, linenum
, filename
);
2715 else if (!_cups_strncasecmp(line
, "PreserveJob", 11) &&
2716 (!_cups_strcasecmp(value
, "true") ||
2717 !_cups_strcasecmp(value
, "on") ||
2718 !_cups_strcasecmp(value
, "enabled") ||
2719 !_cups_strcasecmp(value
, "yes")))
2721 *((int *)var
->ptr
) = INT_MAX
;
2723 else if (!_cups_strcasecmp(value
, "false") ||
2724 !_cups_strcasecmp(value
, "off") ||
2725 !_cups_strcasecmp(value
, "disabled") ||
2726 !_cups_strcasecmp(value
, "no"))
2728 *((int *)var
->ptr
) = 0;
2730 else if (!isdigit(*value
& 255))
2732 cupsdLogMessage(CUPSD_LOG_ERROR
,
2733 "Unknown time interval value for %s on line %d of "
2734 "%s.", line
, linenum
, filename
);
2739 double n
; /* Number */
2740 char *units
; /* Units */
2742 n
= strtod(value
, &units
);
2744 if (units
&& *units
)
2746 if (tolower(units
[0] & 255) == 'w')
2747 n
*= 7 * 24 * 60 * 60;
2748 else if (tolower(units
[0] & 255) == 'd')
2750 else if (tolower(units
[0] & 255) == 'h')
2752 else if (tolower(units
[0] & 255) == 'm')
2756 cupsdLogMessage(CUPSD_LOG_ERROR
,
2757 "Unknown time interval value for %s on line "
2758 "%d of %s.", line
, linenum
, filename
);
2763 if (n
< 0.0 || n
> INT_MAX
)
2765 cupsdLogMessage(CUPSD_LOG_ERROR
,
2766 "Bad time value for %s on line %d of %s.",
2767 line
, linenum
, filename
);
2772 *((int *)var
->ptr
) = (int)n
;
2777 case CUPSD_VARTYPE_BOOLEAN
:
2780 cupsdLogMessage(CUPSD_LOG_ERROR
,
2781 "Missing boolean value for %s on line %d of %s.",
2782 line
, linenum
, filename
);
2785 else if (!_cups_strcasecmp(value
, "true") ||
2786 !_cups_strcasecmp(value
, "on") ||
2787 !_cups_strcasecmp(value
, "enabled") ||
2788 !_cups_strcasecmp(value
, "yes") ||
2791 *((int *)var
->ptr
) = TRUE
;
2793 else if (!_cups_strcasecmp(value
, "false") ||
2794 !_cups_strcasecmp(value
, "off") ||
2795 !_cups_strcasecmp(value
, "disabled") ||
2796 !_cups_strcasecmp(value
, "no") ||
2797 !_cups_strcasecmp(value
, "0"))
2799 *((int *)var
->ptr
) = FALSE
;
2803 cupsdLogMessage(CUPSD_LOG_ERROR
,
2804 "Unknown boolean value %s on line %d of %s.",
2805 value
, linenum
, filename
);
2810 case CUPSD_VARTYPE_PATHNAME
:
2813 cupsdLogMessage(CUPSD_LOG_ERROR
,
2814 "Missing pathname value for %s on line %d of %s.",
2815 line
, linenum
, filename
);
2819 if (value
[0] == '/')
2820 strlcpy(temp
, value
, sizeof(temp
));
2822 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
2824 if (access(temp
, 0))
2826 cupsdLogMessage(CUPSD_LOG_ERROR
,
2827 "File or directory for \"%s %s\" on line %d of %s "
2828 "does not exist.", line
, value
, linenum
, filename
);
2832 cupsdSetString((char **)var
->ptr
, temp
);
2835 case CUPSD_VARTYPE_STRING
:
2836 cupsdSetString((char **)var
->ptr
, value
);
2845 * 'read_cupsd_conf()' - Read the cupsd.conf configuration file.
2848 static int /* O - 1 on success, 0 on failure */
2849 read_cupsd_conf(cups_file_t
*fp
) /* I - File to read from */
2851 int linenum
; /* Current line number */
2852 char line
[HTTP_MAX_BUFFER
],
2853 /* Line from file */
2854 temp
[HTTP_MAX_BUFFER
],
2855 /* Temporary buffer for value */
2856 *value
, /* Pointer to value */
2857 *valueptr
; /* Pointer into value */
2858 int valuelen
; /* Length of value */
2859 http_addrlist_t
*addrlist
, /* Address list */
2860 *addr
; /* Current address */
2861 cups_file_t
*incfile
; /* Include file */
2862 char incname
[1024]; /* Include filename */
2866 * Loop through each line in the file...
2871 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2874 * Decode the directive...
2877 if (!_cups_strcasecmp(line
, "Include") && value
)
2883 if (value
[0] == '/')
2884 strlcpy(incname
, value
, sizeof(incname
));
2886 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2888 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2889 cupsdLogMessage(CUPSD_LOG_ERROR
,
2890 "Unable to include config file \"%s\" - %s",
2891 incname
, strerror(errno
));
2894 read_cupsd_conf(incfile
);
2895 cupsFileClose(incfile
);
2898 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2904 linenum
= read_location(fp
, value
, linenum
);
2908 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2914 linenum
= read_policy(fp
, value
, linenum
);
2918 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2920 JobRetryInterval
= atoi(value
);
2921 cupsdLogMessage(CUPSD_LOG_WARN
,
2922 "FaxRetryInterval is deprecated; use "
2923 "JobRetryInterval on line %d.", linenum
);
2925 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2927 JobRetryLimit
= atoi(value
);
2928 cupsdLogMessage(CUPSD_LOG_WARN
,
2929 "FaxRetryLimit is deprecated; use "
2930 "JobRetryLimit on line %d.", linenum
);
2932 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
2934 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
2935 #endif /* HAVE_SSL */
2939 * Add listening address(es) to the list...
2942 cupsd_listener_t
*lis
; /* New listeners array */
2946 * Get the address list...
2949 addrlist
= get_address(value
, IPP_PORT
);
2953 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2959 * Add each address...
2962 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2965 * See if this address is already present...
2968 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2970 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2971 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2972 httpAddrPort(&(addr
->addr
)) == httpAddrPort(&(lis
->address
)))
2977 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2978 cupsdLogMessage(CUPSD_LOG_WARN
,
2979 "Duplicate listen address \"%s\" ignored.", temp
);
2984 * Allocate another listener...
2988 Listeners
= cupsArrayNew(NULL
, NULL
);
2992 cupsdLogMessage(CUPSD_LOG_ERROR
,
2993 "Unable to allocate %s at line %d - %s.",
2994 line
, linenum
, strerror(errno
));
2998 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
3000 cupsdLogMessage(CUPSD_LOG_ERROR
,
3001 "Unable to allocate %s at line %d - %s.",
3002 line
, linenum
, strerror(errno
));
3006 cupsArrayAdd(Listeners
, lis
);
3009 * Copy the current address and log it...
3012 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
3016 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
3017 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
3018 #endif /* HAVE_SSL */
3020 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
3023 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
3024 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
3026 #endif /* AF_LOCAL */
3027 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
3028 httpAddrPort(&(lis
->address
)),
3029 httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
3031 if (!httpAddrLocalhost(&(lis
->address
)))
3032 RemotePort
= httpAddrPort(&(lis
->address
));
3039 httpAddrFreeList(addrlist
);
3041 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
3042 !_cups_strcasecmp(line
, "BrowseLocalProtocols"))
3045 * "BrowseProtocols name [... name]"
3046 * "BrowseLocalProtocols name [... name]"
3049 int protocols
= parse_protocols(value
);
3053 cupsdLogMessage(CUPSD_LOG_ERROR
,
3054 "Unknown browse protocol \"%s\" on line %d.",
3059 BrowseLocalProtocols
= protocols
;
3061 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
3064 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3067 if (!_cups_strcasecmp(value
, "none"))
3068 default_auth_type
= CUPSD_AUTH_NONE
;
3069 else if (!_cups_strcasecmp(value
, "basic"))
3070 default_auth_type
= CUPSD_AUTH_BASIC
;
3072 else if (!_cups_strcasecmp(value
, "negotiate"))
3073 default_auth_type
= CUPSD_AUTH_NEGOTIATE
;
3074 #endif /* HAVE_GSSAPI */
3075 else if (!_cups_strcasecmp(value
, "auto"))
3076 default_auth_type
= CUPSD_AUTH_AUTO
;
3079 cupsdLogMessage(CUPSD_LOG_WARN
,
3080 "Unknown default authorization type %s on line %d.",
3082 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3087 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
3090 * DefaultEncryption {Never,IfRequested,Required}
3093 if (!value
|| !_cups_strcasecmp(value
, "never"))
3094 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3095 else if (!_cups_strcasecmp(value
, "required"))
3096 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3097 else if (!_cups_strcasecmp(value
, "ifrequested"))
3098 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3101 cupsdLogMessage(CUPSD_LOG_WARN
,
3102 "Unknown default encryption %s on line %d.",
3104 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3108 #endif /* HAVE_SSL */
3109 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
3112 * Do hostname lookups?
3115 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
3116 !_cups_strcasecmp(value
, "false"))
3117 HostNameLookups
= 0;
3118 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
3119 !_cups_strcasecmp(value
, "true"))
3120 HostNameLookups
= 1;
3121 else if (!_cups_strcasecmp(value
, "double"))
3122 HostNameLookups
= 2;
3124 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3127 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
3130 * Amount of logging to do to access log...
3133 if (!_cups_strcasecmp(value
, "all"))
3134 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3135 else if (!_cups_strcasecmp(value
, "actions"))
3136 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3137 else if (!_cups_strcasecmp(value
, "config"))
3138 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3139 else if (!_cups_strcasecmp(value
, "none"))
3140 AccessLogLevel
= CUPSD_ACCESSLOG_NONE
;
3142 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3145 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
3148 * Amount of logging to do to error log...
3151 if (!_cups_strcasecmp(value
, "debug2"))
3152 LogLevel
= CUPSD_LOG_DEBUG2
;
3153 else if (!_cups_strcasecmp(value
, "debug"))
3154 LogLevel
= CUPSD_LOG_DEBUG
;
3155 else if (!_cups_strcasecmp(value
, "info"))
3156 LogLevel
= CUPSD_LOG_INFO
;
3157 else if (!_cups_strcasecmp(value
, "notice"))
3158 LogLevel
= CUPSD_LOG_NOTICE
;
3159 else if (!_cups_strcasecmp(value
, "warn"))
3160 LogLevel
= CUPSD_LOG_WARN
;
3161 else if (!_cups_strcasecmp(value
, "error"))
3162 LogLevel
= CUPSD_LOG_ERROR
;
3163 else if (!_cups_strcasecmp(value
, "crit"))
3164 LogLevel
= CUPSD_LOG_CRIT
;
3165 else if (!_cups_strcasecmp(value
, "alert"))
3166 LogLevel
= CUPSD_LOG_ALERT
;
3167 else if (!_cups_strcasecmp(value
, "emerg"))
3168 LogLevel
= CUPSD_LOG_EMERG
;
3169 else if (!_cups_strcasecmp(value
, "none"))
3170 LogLevel
= CUPSD_LOG_NONE
;
3172 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3175 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
3178 * Amount of logging to do to error log...
3181 if (!_cups_strcasecmp(value
, "standard"))
3182 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3183 else if (!_cups_strcasecmp(value
, "usecs"))
3184 LogTimeFormat
= CUPSD_TIME_USECS
;
3186 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3189 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
3192 * Set the string used for the Server header...
3195 struct utsname plat
; /* Platform info */
3200 if (!_cups_strcasecmp(value
, "ProductOnly"))
3201 cupsdSetString(&ServerHeader
, "CUPS IPP");
3202 else if (!_cups_strcasecmp(value
, "Major"))
3203 cupsdSetStringf(&ServerHeader
, "CUPS/%d IPP/2", CUPS_VERSION_MAJOR
);
3204 else if (!_cups_strcasecmp(value
, "Minor"))
3205 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d IPP/2.1", CUPS_VERSION_MAJOR
,
3206 CUPS_VERSION_MINOR
);
3207 else if (!_cups_strcasecmp(value
, "Minimal"))
3208 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
" IPP/2.1");
3209 else if (!_cups_strcasecmp(value
, "OS"))
3210 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s) IPP/2.1",
3211 plat
.sysname
, plat
.release
);
3212 else if (!_cups_strcasecmp(value
, "Full"))
3213 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s %s; %s) IPP/2.1",
3214 plat
.sysname
, plat
.release
, plat
.machine
);
3215 else if (!_cups_strcasecmp(value
, "None"))
3216 cupsdClearString(&ServerHeader
);
3218 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3221 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3224 * PassEnv variable [... variable]
3229 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3230 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3233 if (value
[valuelen
])
3235 value
[valuelen
] = '\0';
3239 cupsdSetEnv(value
, NULL
);
3241 for (value
+= valuelen
; *value
; value
++)
3242 if (!_cups_isspace(*value
) || *value
!= ',')
3246 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3249 * ServerAlias name [... name]
3253 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3257 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3258 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3261 if (value
[valuelen
])
3263 value
[valuelen
] = '\0';
3267 cupsdAddAlias(ServerAlias
, value
);
3269 for (value
+= valuelen
; *value
; value
++)
3270 if (!_cups_isspace(*value
) || *value
!= ',')
3274 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3277 * SetEnv variable value
3280 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3288 while (isspace(*valueptr
& 255))
3291 cupsdSetEnv(value
, valueptr
);
3294 cupsdLogMessage(CUPSD_LOG_ERROR
,
3295 "Missing value for SetEnv directive on line %d.",
3298 else if (!_cups_strcasecmp(line
, "AccessLog") ||
3299 !_cups_strcasecmp(line
, "CacheDir") ||
3300 !_cups_strcasecmp(line
, "ConfigFilePerm") ||
3301 !_cups_strcasecmp(line
, "DataDir") ||
3302 !_cups_strcasecmp(line
, "DocumentRoot") ||
3303 !_cups_strcasecmp(line
, "ErrorLog") ||
3304 !_cups_strcasecmp(line
, "FatalErrors") ||
3305 !_cups_strcasecmp(line
, "FileDevice") ||
3306 !_cups_strcasecmp(line
, "FontPath") ||
3307 !_cups_strcasecmp(line
, "Group") ||
3308 !_cups_strcasecmp(line
, "LogFilePerm") ||
3309 !_cups_strcasecmp(line
, "LPDConfigFile") ||
3310 !_cups_strcasecmp(line
, "PageLog") ||
3311 !_cups_strcasecmp(line
, "Printcap") ||
3312 !_cups_strcasecmp(line
, "PrintcapFormat") ||
3313 !_cups_strcasecmp(line
, "RemoteRoot") ||
3314 !_cups_strcasecmp(line
, "RequestRoot") ||
3315 !_cups_strcasecmp(line
, "ServerBin") ||
3316 !_cups_strcasecmp(line
, "ServerCertificate") ||
3317 !_cups_strcasecmp(line
, "ServerKey") ||
3318 !_cups_strcasecmp(line
, "ServerKeychain") ||
3319 !_cups_strcasecmp(line
, "ServerRoot") ||
3320 !_cups_strcasecmp(line
, "SMBConfigFile") ||
3321 !_cups_strcasecmp(line
, "StateDir") ||
3322 !_cups_strcasecmp(line
, "SystemGroup") ||
3323 !_cups_strcasecmp(line
, "SystemGroupAuthKey") ||
3324 !_cups_strcasecmp(line
, "TempDir") ||
3325 !_cups_strcasecmp(line
, "User"))
3327 cupsdLogMessage(CUPSD_LOG_INFO
,
3328 "Please move \"%s%s%s\" on line %d of %s to the %s file; "
3329 "this will become an error in a future release.",
3330 line
, value
? " " : "", value
? value
: "", linenum
,
3331 ConfigurationFile
, CupsFilesFile
);
3334 parse_variable(ConfigurationFile
, linenum
, line
, value
,
3335 sizeof(cupsd_vars
) / sizeof(cupsd_vars
[0]), cupsd_vars
);
3343 * 'read_cups_files_conf()' - Read the cups-files.conf configuration file.
3346 static int /* O - 1 on success, 0 on failure */
3347 read_cups_files_conf(cups_file_t
*fp
) /* I - File to read from */
3349 int linenum
; /* Current line number */
3350 char line
[HTTP_MAX_BUFFER
], /* Line from file */
3351 *value
; /* Value from line */
3352 struct group
*group
; /* Group */
3356 * Loop through each line in the file...
3361 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3363 if (!_cups_strcasecmp(line
, "FatalErrors"))
3364 FatalErrors
= parse_fatal_errors(value
);
3365 else if (!_cups_strcasecmp(line
, "Group") && value
)
3368 * Group ID to run as...
3371 if (isdigit(value
[0]))
3372 Group
= (gid_t
)atoi(value
);
3376 group
= getgrnam(value
);
3379 Group
= group
->gr_gid
;
3382 cupsdLogMessage(CUPSD_LOG_ERROR
,
3383 "Unknown Group \"%s\" on line %d of %s.", value
,
3384 linenum
, CupsFilesFile
);
3385 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3390 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
3393 * Format of printcap file?
3396 if (!_cups_strcasecmp(value
, "bsd"))
3397 PrintcapFormat
= PRINTCAP_BSD
;
3398 else if (!_cups_strcasecmp(value
, "plist"))
3399 PrintcapFormat
= PRINTCAP_PLIST
;
3400 else if (!_cups_strcasecmp(value
, "solaris"))
3401 PrintcapFormat
= PRINTCAP_SOLARIS
;
3404 cupsdLogMessage(CUPSD_LOG_ERROR
,
3405 "Unknown PrintcapFormat \"%s\" on line %d of %s.",
3406 value
, linenum
, CupsFilesFile
);
3407 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3411 else if (!_cups_strcasecmp(line
, "Sandboxing") && value
)
3414 * Level of sandboxing?
3417 if (!_cups_strcasecmp(value
, "off"))
3419 Sandboxing
= CUPSD_SANDBOXING_OFF
;
3420 cupsdLogMessage(CUPSD_LOG_WARN
, "Disabling sandboxing is not recommended (line %d of %s)", linenum
, CupsFilesFile
);
3422 else if (!_cups_strcasecmp(value
, "relaxed"))
3423 Sandboxing
= CUPSD_SANDBOXING_RELAXED
;
3424 else if (!_cups_strcasecmp(value
, "strict"))
3425 Sandboxing
= CUPSD_SANDBOXING_STRICT
;
3428 cupsdLogMessage(CUPSD_LOG_ERROR
,
3429 "Unknown Sandboxing \"%s\" on line %d of %s.",
3430 value
, linenum
, CupsFilesFile
);
3431 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3435 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
3438 * SystemGroup (admin) group(s)...
3441 if (!parse_groups(value
))
3443 cupsdLogMessage(CUPSD_LOG_ERROR
,
3444 "Unknown SystemGroup \"%s\" on line %d of %s.", value
,
3445 linenum
, CupsFilesFile
);
3446 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3450 else if (!_cups_strcasecmp(line
, "User") && value
)
3453 * User ID to run as...
3456 if (isdigit(value
[0] & 255))
3458 int uid
= atoi(value
);
3462 cupsdLogMessage(CUPSD_LOG_ERROR
,
3463 "Will not use User 0 as specified on line %d of %s "
3464 "for security reasons. You must use a non-"
3465 "privileged account instead.",
3466 linenum
, CupsFilesFile
);
3467 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3471 User
= (uid_t
)atoi(value
);
3475 struct passwd
*p
; /* Password information */
3478 p
= getpwnam(value
);
3484 cupsdLogMessage(CUPSD_LOG_ERROR
,
3485 "Will not use User %s (UID=0) as specified on line "
3486 "%d of %s for security reasons. You must use a "
3487 "non-privileged account instead.",
3488 value
, linenum
, CupsFilesFile
);
3489 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3497 cupsdLogMessage(CUPSD_LOG_ERROR
,
3498 "Unknown User \"%s\" on line %d of %s.",
3499 value
, linenum
, CupsFilesFile
);
3500 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3505 else if (!_cups_strcasecmp(line
, "ServerCertificate") ||
3506 !_cups_strcasecmp(line
, "ServerKey"))
3508 cupsdLogMessage(CUPSD_LOG_INFO
,
3509 "The \"%s\" directive on line %d of %s is no longer "
3510 "supported; this will become an error in a future "
3512 line
, linenum
, CupsFilesFile
);
3514 else if (!parse_variable(CupsFilesFile
, linenum
, line
, value
,
3515 sizeof(cupsfiles_vars
) / sizeof(cupsfiles_vars
[0]),
3517 (FatalErrors
& CUPSD_FATAL_CONFIG
))
3526 * 'read_location()' - Read a <Location path> definition.
3529 static int /* O - New line number or 0 on error */
3530 read_location(cups_file_t
*fp
, /* I - Configuration file */
3531 char *location
, /* I - Location name/path */
3532 int linenum
) /* I - Current line number */
3534 cupsd_location_t
*loc
, /* New location */
3535 *parent
; /* Parent location */
3536 char line
[HTTP_MAX_BUFFER
],
3538 *value
, /* Value for directive */
3539 *valptr
; /* Pointer into value */
3542 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3543 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d.",
3545 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3549 cupsdAddLocation(parent
);
3551 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3556 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3559 * Decode the directive...
3562 if (!_cups_strcasecmp(line
, "</Location>"))
3564 else if (!_cups_strcasecmp(line
, "<Limit") ||
3565 !_cups_strcasecmp(line
, "<LimitExcept"))
3569 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3570 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3576 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3579 cupsdAddLocation(loc
);
3584 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3589 if (!strcmp(value
, "ALL"))
3590 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3591 else if (!strcmp(value
, "GET"))
3592 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3593 else if (!strcmp(value
, "HEAD"))
3594 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3595 else if (!strcmp(value
, "OPTIONS"))
3596 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3597 else if (!strcmp(value
, "POST"))
3598 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3599 else if (!strcmp(value
, "PUT"))
3600 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3601 else if (!strcmp(value
, "TRACE"))
3602 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3604 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d.",
3607 for (value
= valptr
; isspace(*value
& 255); value
++);
3610 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3611 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3613 parent
->limit
&= ~loc
->limit
;
3615 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3616 !_cups_strcasecmp(line
, "</LimitExcept>"))
3620 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3621 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3624 else if (!parse_aaa(loc
, line
, value
, linenum
))
3626 cupsdLogMessage(CUPSD_LOG_ERROR
,
3627 "Unknown Location directive %s on line %d.",
3629 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3634 cupsdLogMessage(CUPSD_LOG_ERROR
,
3635 "Unexpected end-of-file at line %d while reading location.",
3638 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3643 * 'read_policy()' - Read a <Policy name> definition.
3646 static int /* O - New line number or 0 on error */
3647 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3648 char *policy
, /* I - Location name/path */
3649 int linenum
) /* I - Current line number */
3651 int i
; /* Looping var */
3652 cupsd_policy_t
*pol
; /* Policy */
3653 cupsd_location_t
*op
; /* Policy operation */
3654 int num_ops
; /* Number of IPP operations */
3655 ipp_op_t ops
[100]; /* Operations */
3656 char line
[HTTP_MAX_BUFFER
],
3658 *value
, /* Value for directive */
3659 *valptr
; /* Pointer into value */
3663 * Create the policy...
3666 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3667 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d.",
3669 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3673 * Read from the file...
3679 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3682 * Decode the directive...
3685 if (!_cups_strcasecmp(line
, "</Policy>"))
3688 cupsdLogMessage(CUPSD_LOG_WARN
,
3689 "Missing </Limit> before </Policy> on line %d.",
3692 set_policy_defaults(pol
);
3696 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3700 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3701 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3708 * Scan for IPP operation names...
3715 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3720 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3722 if (!_cups_strcasecmp(value
, "All"))
3723 ops
[num_ops
] = IPP_ANY_OPERATION
;
3724 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3725 cupsdLogMessage(CUPSD_LOG_ERROR
,
3726 "Bad IPP operation name \"%s\" on line %d.",
3732 cupsdLogMessage(CUPSD_LOG_ERROR
,
3733 "Too many operations listed on line %d.",
3736 for (value
= valptr
; isspace(*value
& 255); value
++);
3740 * If none are specified, apply the policy to all operations...
3745 ops
[0] = IPP_ANY_OPERATION
;
3750 * Add a new policy for the first operation...
3753 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3755 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3758 * Finish the current operation limit...
3764 * Copy the policy to the other operations...
3767 for (i
= 1; i
< num_ops
; i
++)
3768 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3775 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3776 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3779 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3780 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3781 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3782 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3786 cupsdLogMessage(CUPSD_LOG_ERROR
,
3787 "%s directive must appear outside <Limit>...</Limit> "
3788 "on line %d.", line
, linenum
);
3789 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3795 * Pull out whitespace-delimited values...
3801 * Find the end of the current value...
3804 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3810 * Save it appropriately...
3813 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3816 * JobPrivateAccess {all|default|user/group list|@@ACL}
3819 if (!_cups_strcasecmp(value
, "default"))
3821 cupsdAddString(&(pol
->job_access
), "@OWNER");
3822 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3825 cupsdAddString(&(pol
->job_access
), value
);
3827 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3830 * JobPrivateValues {all|none|default|attribute list}
3833 if (!_cups_strcasecmp(value
, "default"))
3835 cupsdAddString(&(pol
->job_attrs
), "job-name");
3836 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3837 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3838 cupsdAddString(&(pol
->job_attrs
), "phone");
3841 cupsdAddString(&(pol
->job_attrs
), value
);
3843 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3846 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3849 if (!_cups_strcasecmp(value
, "default"))
3851 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3852 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3855 cupsdAddString(&(pol
->sub_access
), value
);
3857 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3860 * SubscriptionPrivateValues {all|none|default|attribute list}
3863 if (!_cups_strcasecmp(value
, "default"))
3865 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3866 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3867 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3868 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3869 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3872 cupsdAddString(&(pol
->sub_attrs
), value
);
3876 * Find the next string on the line...
3879 for (value
= valptr
; isspace(*value
& 255); value
++);
3885 cupsdLogMessage(CUPSD_LOG_ERROR
,
3886 "Missing <Limit ops> directive before %s on line %d.",
3888 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3891 else if (!parse_aaa(op
, line
, value
, linenum
))
3893 cupsdLogMessage(CUPSD_LOG_ERROR
,
3894 "Unknown Policy Limit directive %s on line %d.",
3897 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3902 cupsdLogMessage(CUPSD_LOG_ERROR
,
3903 "Unexpected end-of-file at line %d while reading policy "
3904 "\"%s\".", linenum
, policy
);
3906 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3911 * 'set_policy_defaults()' - Set default policy values as needed.
3915 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
3917 cupsd_location_t
*op
; /* Policy operation */
3921 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
3922 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
3923 * upgrades do not introduce new security issues...
3926 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
3927 op
->op
== IPP_ANY_OPERATION
)
3929 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
3930 op
->op
!= IPP_ANY_OPERATION
)
3933 * Add a new limit for Validate-Job using the Print-Job limit as a
3937 cupsdLogMessage(CUPSD_LOG_WARN
,
3938 "No limit for Validate-Job defined in policy %s "
3939 "- using Print-Job's policy.", pol
->name
);
3941 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
3944 cupsdLogMessage(CUPSD_LOG_WARN
,
3945 "No limit for Validate-Job defined in policy %s "
3946 "and no suitable template found.", pol
->name
);
3949 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
3950 op
->op
== IPP_ANY_OPERATION
)
3952 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
3953 op
->op
!= IPP_ANY_OPERATION
)
3956 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
3960 cupsdLogMessage(CUPSD_LOG_WARN
,
3961 "No limit for Cancel-Jobs defined in policy %s "
3962 "- using Pause-Printer's policy.", pol
->name
);
3964 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
3967 cupsdLogMessage(CUPSD_LOG_WARN
,
3968 "No limit for Cancel-Jobs defined in policy %s "
3969 "and no suitable template found.", pol
->name
);
3972 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
3973 op
->op
== IPP_ANY_OPERATION
)
3975 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3976 op
->op
!= IPP_ANY_OPERATION
)
3979 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
3983 cupsdLogMessage(CUPSD_LOG_WARN
,
3984 "No limit for Cancel-My-Jobs defined in policy %s "
3985 "- using Send-Document's policy.", pol
->name
);
3987 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
3990 cupsdLogMessage(CUPSD_LOG_WARN
,
3991 "No limit for Cancel-My-Jobs defined in policy %s "
3992 "and no suitable template found.", pol
->name
);
3995 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
3996 op
->op
== IPP_ANY_OPERATION
)
3998 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3999 op
->op
!= IPP_ANY_OPERATION
)
4002 * Add a new limit for Close-Job using the Send-Document limit as a
4006 cupsdLogMessage(CUPSD_LOG_WARN
,
4007 "No limit for Close-Job defined in policy %s "
4008 "- using Send-Document's policy.", pol
->name
);
4010 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
4013 cupsdLogMessage(CUPSD_LOG_WARN
,
4014 "No limit for Close-Job defined in policy %s "
4015 "and no suitable template found.", pol
->name
);
4018 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
4019 op
->op
== IPP_ANY_OPERATION
)
4021 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4022 op
->op
!= IPP_ANY_OPERATION
)
4025 * Add a new limit for CUPS-Get-Document using the Send-Document
4026 * limit as a template...
4029 cupsdLogMessage(CUPSD_LOG_WARN
,
4030 "No limit for CUPS-Get-Document defined in policy %s "
4031 "- using Send-Document's policy.", pol
->name
);
4033 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
4036 cupsdLogMessage(CUPSD_LOG_WARN
,
4037 "No limit for CUPS-Get-Document defined in policy %s "
4038 "and no suitable template found.", pol
->name
);
4042 * Verify we have JobPrivateAccess, JobPrivateValues,
4043 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4046 if (!pol
->job_access
)
4048 cupsdLogMessage(CUPSD_LOG_WARN
,
4049 "No JobPrivateAccess defined in policy %s "
4050 "- using defaults.", pol
->name
);
4051 cupsdAddString(&(pol
->job_access
), "@OWNER");
4052 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4055 if (!pol
->job_attrs
)
4057 cupsdLogMessage(CUPSD_LOG_WARN
,
4058 "No JobPrivateValues defined in policy %s "
4059 "- using defaults.", pol
->name
);
4060 cupsdAddString(&(pol
->job_attrs
), "job-name");
4061 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4062 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4063 cupsdAddString(&(pol
->job_attrs
), "phone");
4066 if (!pol
->sub_access
)
4068 cupsdLogMessage(CUPSD_LOG_WARN
,
4069 "No SubscriptionPrivateAccess defined in policy %s "
4070 "- using defaults.", pol
->name
);
4071 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4072 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4075 if (!pol
->sub_attrs
)
4077 cupsdLogMessage(CUPSD_LOG_WARN
,
4078 "No SubscriptionPrivateValues defined in policy %s "
4079 "- using defaults.", pol
->name
);
4080 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4081 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4082 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4083 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4084 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");