2 * "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $"
4 * Configuration routines for the CUPS scheduler.
6 * Copyright 2007-2011 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 * cupsdAddAlias() - Add a host alias.
18 * cupsdCheckPermissions() - Fix the mode and ownership of a file or
20 * cupsdFreeAliases() - Free all of the alias entries.
21 * cupsdReadConfiguration() - Read the cupsd.conf file.
22 * get_address() - Get an address + port number from a line.
23 * get_addr_and_mask() - Get an IP address and netmask.
24 * mime_error_cb() - Log a MIME error.
25 * parse_aaa() - Parse authentication, authorization, and access
27 * parse_fatal_errors() - Parse FatalErrors values in a string.
28 * parse_groups() - Parse system group names in a string.
29 * parse_protocols() - Parse browse protocols in a string.
30 * read_configuration() - Read a configuration file.
31 * read_location() - Read a <Location path> definition.
32 * read_policy() - Read a <Policy name> definition.
33 * set_policy_defaults() - Set default policy values as needed.
37 * Include necessary headers...
43 #include <sys/utsname.h>
48 #endif /* HAVE_LIBPAPER */
52 * Possibly missing network definitions...
56 # define INADDR_NONE 0xffffffff
57 #endif /* !INADDR_NONE */
61 * Configuration variable structure...
66 CUPSD_VARTYPE_INTEGER
, /* Integer option */
67 CUPSD_VARTYPE_STRING
, /* String option */
68 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
69 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
74 char *name
; /* Name of variable */
75 void *ptr
; /* Pointer to variable */
76 cupsd_vartype_t type
; /* Type (int, string, address) */
84 static const cupsd_var_t variables
[] =
86 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
87 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
89 { "BrowseDNSSDRegType", &DNSSDRegType
, CUPSD_VARTYPE_STRING
},
90 #endif /* HAVE_DNSSD */
91 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
93 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
95 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_PATHNAME
},
96 # endif /* HAVE_LDAP_SSL */
97 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
98 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
99 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
100 #endif /* HAVE_LDAP */
101 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
102 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
103 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
104 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
105 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
106 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
107 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
108 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
109 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
110 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
111 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
112 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
113 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
114 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
115 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
116 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
117 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
118 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
119 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
120 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
121 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
122 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
123 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
124 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
125 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
126 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
127 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
128 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
129 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_INTEGER
},
130 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
131 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
132 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
133 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
135 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
136 #endif /* HAVE_LAUNCHD */
137 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
138 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
139 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
140 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
141 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
142 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
151 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
152 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
153 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
154 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
155 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
156 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
157 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
158 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
159 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
160 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
161 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
162 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
163 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
164 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
165 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
166 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
167 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
168 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
169 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
170 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
172 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
173 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
174 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
175 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
176 #endif /* HAVE_SSL */
177 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
178 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
179 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
180 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
181 #ifdef HAVE_AUTHORIZATION_H
182 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
183 #endif /* HAVE_AUTHORIZATION_H */
184 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
185 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
186 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
},
187 { "WebInterface", &WebInterface
, CUPSD_VARTYPE_BOOLEAN
}
189 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
192 static const unsigned ones
[4] =
194 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
196 static const unsigned zeros
[4] =
198 0x00000000, 0x00000000, 0x00000000, 0x00000000
206 static http_addrlist_t
*get_address(const char *value
, int defport
);
207 static int get_addr_and_mask(const char *value
, unsigned *ip
,
209 static void mime_error_cb(void *ctx
, const char *message
);
210 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
211 char *value
, int linenum
);
212 static int parse_fatal_errors(const char *s
);
213 static int parse_groups(const char *s
);
214 static int parse_protocols(const char *s
);
215 static int read_configuration(cups_file_t
*fp
);
216 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
217 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
218 static void set_policy_defaults(cupsd_policy_t
*pol
);
222 * 'cupsdAddAlias()' - Add a host alias.
226 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
227 const char *name
) /* I - Name to add */
229 cupsd_alias_t
*a
; /* New alias */
230 size_t namelen
; /* Length of name */
233 namelen
= strlen(name
);
235 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
238 a
->namelen
= namelen
;
239 strcpy(a
->name
, name
); /* OK since a->name is allocated */
241 cupsArrayAdd(aliases
, a
);
246 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
249 int /* O - 0 on success, -1 on error, 1 on warning */
250 cupsdCheckPermissions(
251 const char *filename
, /* I - File/directory name */
252 const char *suffix
, /* I - Additional file/directory name */
253 int mode
, /* I - Permissions */
254 int user
, /* I - Owner */
255 int group
, /* I - Group */
256 int is_dir
, /* I - 1 = directory, 0 = file */
257 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
259 int dir_created
= 0; /* Did we create a directory? */
260 char pathname
[1024]; /* File name with prefix */
261 struct stat fileinfo
; /* Stat buffer */
262 int is_symlink
; /* Is "filename" a symlink? */
266 * Prepend the given root to the filename before testing it...
271 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
276 * See if we can stat the file/directory...
279 if (lstat(filename
, &fileinfo
))
281 if (errno
== ENOENT
&& create_dir
)
284 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
287 if (mkdir(filename
, mode
))
290 cupsdLogMessage(CUPSD_LOG_ERROR
,
291 "Unable to create directory \"%s\" - %s", filename
,
294 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
301 fileinfo
.st_mode
= mode
| S_IFDIR
;
304 return (create_dir
? -1 : 1);
307 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
309 if (stat(filename
, &fileinfo
))
311 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
312 filename
, strerror(errno
));
318 * Make sure it's a regular file or a directory as needed...
321 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
323 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file.", filename
);
327 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
330 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory.", filename
);
332 syslog(LOG_ERR
, "\"%s\" is not a directory.", filename
);
338 * If the filename is a symlink, do not change permissions (STR #2937)...
345 * Fix owner, group, and mode as needed...
348 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
351 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
354 if (chown(filename
, user
, group
) && !getuid())
357 cupsdLogMessage(CUPSD_LOG_ERROR
,
358 "Unable to change ownership of \"%s\" - %s", filename
,
361 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
368 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
371 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
374 if (chmod(filename
, mode
))
377 cupsdLogMessage(CUPSD_LOG_ERROR
,
378 "Unable to change permissions of \"%s\" - %s", filename
,
381 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
389 * Everything is OK...
397 * 'cupsdFreeAliases()' - Free all of the alias entries.
401 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
403 cupsd_alias_t
*a
; /* Current alias */
406 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
408 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
411 cupsArrayDelete(aliases
);
416 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
419 int /* O - 1 on success, 0 otherwise */
420 cupsdReadConfiguration(void)
422 int i
; /* Looping var */
423 cups_file_t
*fp
; /* Configuration file */
424 int status
; /* Return status */
425 char temp
[1024], /* Temporary buffer */
426 mimedir
[1024], /* MIME directory */
427 *slash
; /* Directory separator */
428 cups_lang_t
*language
; /* Language */
429 struct passwd
*user
; /* Default user */
430 struct group
*group
; /* Default group */
431 char *old_serverroot
, /* Old ServerRoot */
432 *old_requestroot
; /* Old RequestRoot */
433 int old_remote_port
; /* Old RemotePort */
434 const char *tmpdir
; /* TMPDIR environment variable */
435 struct stat tmpinfo
; /* Temporary directory info */
436 cupsd_policy_t
*p
; /* Policy */
440 * Save the old root paths...
443 old_serverroot
= NULL
;
444 cupsdSetString(&old_serverroot
, ServerRoot
);
445 old_requestroot
= NULL
;
446 cupsdSetString(&old_requestroot
, RequestRoot
);
449 * Reset the server configuration data...
452 cupsdDeleteAllLocations();
471 for (i
= 0; i
< NumRelays
; i
++)
472 cupsArrayDelete(Relays
[i
].from
);
479 cupsdDeleteAllListeners();
481 old_remote_port
= RemotePort
;
488 cupsdFreeAliases(ServerAlias
);
491 cupsdClearString(&ServerName
);
492 cupsdClearString(&ServerAdmin
);
493 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
494 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
495 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
496 cupsdSetString(&DataDir
, CUPS_DATADIR
);
497 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
498 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
499 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
500 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
501 cupsdSetString(&PageLogFormat
,
502 "%p %u %j %T %P %C %{job-billing} "
503 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
504 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
505 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
506 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
507 cupsdSetString(&RemoteRoot
, "remroot");
508 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
510 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
512 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
513 PrintcapFormat
= PRINTCAP_SOLARIS
;
514 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
515 "/Library/Preferences/org.cups.printers.plist"))
516 PrintcapFormat
= PRINTCAP_PLIST
;
518 PrintcapFormat
= PRINTCAP_BSD
;
520 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
521 if ((slash
= strrchr(temp
, '/')) != NULL
)
524 cupsdSetString(&ServerRoot
, temp
);
526 cupsdClearString(&Classification
);
527 ClassifyOverride
= 0;
531 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
533 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
534 cupsdSetString(&ServerKey
, "ssl/server.key");
535 # endif /* HAVE_CDSASSL */
536 #endif /* HAVE_SSL */
538 language
= cupsLangDefault();
540 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
541 cupsdSetString(&DefaultLanguage
, "en");
543 cupsdSetString(&DefaultLanguage
, language
->language
);
545 cupsdClearString(&DefaultPaperSize
);
547 cupsdSetString(&RIPCache
, "128m");
549 cupsdSetString(&TempDir
, NULL
);
552 * Find the default user...
555 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
560 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
561 * complement number...)
570 * Find the default group...
573 group
= getgrnam(CUPS_DEFAULT_GROUP
);
577 Group
= group
->gr_gid
;
581 * Fallback to group "nobody"...
584 group
= getgrnam("nobody");
588 Group
= group
->gr_gid
;
592 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
593 * complement number...)
604 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
605 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
606 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
607 DefaultAuthType
= CUPSD_AUTH_BASIC
;
609 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
610 SSLOptions
= CUPSD_SSL_NONE
;
611 #endif /* HAVE_SSL */
612 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
613 JobKillDelay
= DEFAULT_TIMEOUT
;
615 JobRetryInterval
= 300;
620 HostNameLookups
= FALSE
;
621 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
622 ImplicitAnyClasses
= FALSE
;
623 HideImplicitMembers
= TRUE
;
625 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
626 ListenBackLog
= SOMAXCONN
;
627 LogDebugHistory
= 200;
628 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
629 LogLevel
= CUPSD_LOG_WARN
;
630 LogTimeFormat
= CUPSD_TIME_STANDARD
;
632 MaxClientsPerHost
= 0;
633 MaxLogSize
= 1024 * 1024;
635 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
636 ReloadTimeout
= DEFAULT_KEEPALIVE
;
637 RootCertDuration
= 300;
638 Timeout
= DEFAULT_TIMEOUT
;
640 WebInterface
= CUPS_DEFAULT_WEBIF
;
642 BrowseInterval
= DEFAULT_INTERVAL
;
643 BrowsePort
= ippPort();
644 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
645 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
646 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
647 BrowseTimeout
= DEFAULT_TIMEOUT
;
649 Browsing
= CUPS_DEFAULT_BROWSING
;
650 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
653 cupsdSetString(&DNSSDRegType
, "_ipp._tcp,_cups");
654 #endif /* HAVE_DNSSD */
656 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
657 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
659 cupsdClearString(&BrowseLocalOptions
);
660 cupsdClearString(&BrowseRemoteOptions
);
662 cupsdSetString(&ErrorPolicy
, "stop-printer");
665 cupsdClearString(&BrowseLDAPBindDN
);
666 cupsdClearString(&BrowseLDAPDN
);
667 cupsdClearString(&BrowseLDAPPassword
);
668 cupsdClearString(&BrowseLDAPServer
);
669 # ifdef HAVE_LDAP_SSL
670 cupsdClearString(&BrowseLDAPCACertFile
);
671 # endif /* HAVE_LDAP_SSL */
672 #endif /* HAVE_LDAP */
674 JobHistory
= DEFAULT_HISTORY
;
675 JobFiles
= DEFAULT_FILES
;
680 MaxJobsPerPrinter
= 0;
681 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
683 cupsdDeleteAllPolicies();
684 cupsdClearString(&DefaultPolicy
);
686 #ifdef HAVE_AUTHORIZATION_H
687 cupsdClearString(&SystemGroupAuthKey
);
688 #endif /* HAVE_AUTHORIZATION_H */
690 MaxSubscriptions
= 100;
691 MaxSubscriptionsPerJob
= 0;
692 MaxSubscriptionsPerPrinter
= 0;
693 MaxSubscriptionsPerUser
= 0;
694 DefaultLeaseDuration
= 86400;
695 MaxLeaseDuration
= 0;
698 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
699 #endif /* HAVE_LAUNCHD */
702 * Setup environment variables...
708 * Read the configuration file...
711 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
714 status
= read_configuration(fp
);
723 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
724 RemotePort
? "enabled" : "disabled");
727 BrowseLocalProtocols
= 0; /* Disable sharing - no remote access */
730 * See if the ServerName is an IP address...
736 ServerAlias
= cupsArrayNew(NULL
, NULL
);
738 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
742 if (gethostname(temp
, sizeof(temp
)))
744 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
746 strlcpy(temp
, "localhost", sizeof(temp
));
749 cupsdSetString(&ServerName
, temp
);
752 ServerAlias
= cupsArrayNew(NULL
, NULL
);
754 cupsdAddAlias(ServerAlias
, temp
);
755 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
757 if (HostNameLookups
|| RemotePort
)
759 struct hostent
*host
; /* Host entry to get FQDN */
761 if ((host
= gethostbyname(temp
)) != NULL
)
763 if (_cups_strcasecmp(temp
, host
->h_name
))
765 cupsdSetString(&ServerName
, host
->h_name
);
766 cupsdAddAlias(ServerAlias
, host
->h_name
);
767 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
773 for (i
= 0; host
->h_aliases
[i
]; i
++)
774 if (_cups_strcasecmp(temp
, host
->h_aliases
[i
]))
776 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
777 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
785 * Make sure we have the base hostname added as an alias, too!
788 if ((slash
= strchr(temp
, '.')) != NULL
)
791 cupsdAddAlias(ServerAlias
, temp
);
792 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
796 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
798 ServerNameIsIP
= !*slash
;
801 * Make sure ServerAdmin is initialized...
805 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
808 * Use the default system group if none was supplied in cupsd.conf...
811 if (NumSystemGroups
== 0)
813 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
816 * Find the group associated with GID 0...
823 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
825 cupsdSetString(&SystemGroups
[0], "unknown");
827 SystemGroupIDs
[0] = 0;
833 * Get the access control list for browsing...
836 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
839 * Open the system log for cupsd if necessary...
843 if (!strcmp(AccessLog
, "syslog") ||
844 !strcmp(ErrorLog
, "syslog") ||
845 !strcmp(PageLog
, "syslog"))
846 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
847 #endif /* HAVE_VSYSLOG */
850 * Make sure each of the log files exists and gets rotated as necessary...
853 if (strcmp(AccessLog
, "syslog"))
854 cupsdCheckLogFile(&AccessFile
, AccessLog
);
856 if (strcmp(ErrorLog
, "syslog"))
857 cupsdCheckLogFile(&ErrorFile
, ErrorLog
);
859 if (strcmp(PageLog
, "syslog"))
860 cupsdCheckLogFile(&PageFile
, PageLog
);
863 * Log the configuration file that was used...
866 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
870 * Validate the Group and SystemGroup settings - they cannot be the same,
871 * otherwise the CGI programs will be able to authenticate as root without
877 for (i
= 0; i
< NumSystemGroups
; i
++)
878 if (Group
== SystemGroupIDs
[i
])
881 if (i
< NumSystemGroups
)
884 * Log the error and reset the group to a safe value...
887 cupsdLogMessage(CUPSD_LOG_NOTICE
,
888 "Group and SystemGroup cannot use the same groups.");
889 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
891 group
= getgrnam("nobody");
895 Group
= group
->gr_gid
;
899 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
900 * complement number...)
909 * Check that we have at least one listen/port line; if not, report this
910 * as an error and exit!
913 if (cupsArrayCount(Listeners
) == 0)
919 cupsdLogMessage(CUPSD_LOG_EMERG
,
920 "No valid Listen or Port lines were found in the "
921 "configuration file.");
927 cupsdEndProcess(getpid(), 0);
931 * Set the default locale using the language and charset...
934 cupsdSetStringf(&DefaultLocale
, "%s.UTF-8", DefaultLanguage
);
937 * Update all relative filenames to include the full path from ServerRoot...
940 if (DocumentRoot
[0] != '/')
941 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
943 if (RequestRoot
[0] != '/')
944 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
946 if (ServerBin
[0] != '/')
947 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
949 if (StateDir
[0] != '/')
950 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
952 if (CacheDir
[0] != '/')
953 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
956 if (ServerCertificate
[0] != '/')
957 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
959 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
960 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
962 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
965 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
966 if (ServerKey
[0] != '/')
967 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
969 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
970 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
971 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
973 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
974 #endif /* HAVE_SSL */
977 * Make sure that directories and config files are owned and
978 * writable by the user and group in the cupsd.conf file...
981 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
983 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
985 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
987 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
989 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
991 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
992 SystemGroupIDs
[0], 1, 1) < 0 ||
993 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
995 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
997 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
999 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
1001 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
1003 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
1005 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
1006 Group
, 0, 0) < 0) &&
1007 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1011 * Update TempDir to the default if it hasn't been set already...
1016 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
1019 * TMPDIR is defined, see if it is OK for us to use...
1022 if (stat(tmpdir
, &tmpinfo
))
1023 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1024 tmpdir
, strerror(errno
));
1025 else if (!S_ISDIR(tmpinfo
.st_mode
))
1026 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory.",
1028 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1029 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1030 !(tmpinfo
.st_mode
& S_IWOTH
))
1031 cupsdLogMessage(CUPSD_LOG_ERROR
,
1032 "TMPDIR (%s) has the wrong permissions.", tmpdir
);
1034 cupsdSetString(&TempDir
, tmpdir
);
1039 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1041 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1046 * Make sure the temporary directory has the right permissions...
1049 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1053 * Update ownership and permissions if the CUPS temp directory
1054 * is under the spool directory or does not exist...
1057 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1058 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1063 * Update environment variables...
1069 * Update default paper size setting as needed...
1072 if (!DefaultPaperSize
)
1074 #ifdef HAVE_LIBPAPER
1075 char *paper_result
; /* Paper size name from libpaper */
1077 if ((paper_result
= systempapername()) != NULL
)
1078 cupsdSetString(&DefaultPaperSize
, paper_result
);
1080 #endif /* HAVE_LIBPAPER */
1081 if (!DefaultLanguage
||
1082 !_cups_strcasecmp(DefaultLanguage
, "C") ||
1083 !_cups_strcasecmp(DefaultLanguage
, "POSIX") ||
1084 !_cups_strcasecmp(DefaultLanguage
, "en") ||
1085 !_cups_strncasecmp(DefaultLanguage
, "en.", 3) ||
1086 !_cups_strncasecmp(DefaultLanguage
, "en_US", 5) ||
1087 !_cups_strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1088 !_cups_strncasecmp(DefaultLanguage
, "fr_CA", 5))
1091 * These are the only locales that will default to "letter" size...
1094 cupsdSetString(&DefaultPaperSize
, "Letter");
1097 cupsdSetString(&DefaultPaperSize
, "A4");
1101 * Update classification setting as needed...
1104 if (Classification
&& !_cups_strcasecmp(Classification
, "none"))
1105 cupsdClearString(&Classification
);
1108 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1111 * Check the MaxClients setting, and then allocate memory for it...
1114 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1117 cupsdLogMessage(CUPSD_LOG_INFO
,
1118 "MaxClients limited to 1/3 (%d) of the file descriptor "
1120 MaxFDs
/ 3, MaxFDs
);
1122 MaxClients
= MaxFDs
/ 3;
1125 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1129 * Check the MaxActiveJobs setting; limit to 1/3 the available
1130 * file descriptors, since we need a pipe for each job...
1133 if (MaxActiveJobs
> (MaxFDs
/ 3))
1134 MaxActiveJobs
= MaxFDs
/ 3;
1137 * Update the MaxClientsPerHost value, as needed...
1140 if (MaxClientsPerHost
<= 0)
1141 MaxClientsPerHost
= MaxClients
;
1143 if (MaxClientsPerHost
> MaxClients
)
1144 MaxClientsPerHost
= MaxClients
;
1146 cupsdLogMessage(CUPSD_LOG_INFO
,
1147 "Allowing up to %d client connections per host.",
1151 * Make sure that BrowseTimeout is at least twice the interval...
1154 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1156 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d.",
1160 BrowseTimeout
= BrowseInterval
* 2;
1162 BrowseTimeout
= DEFAULT_TIMEOUT
;
1164 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d.",
1169 * Update the default policy, as needed...
1173 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1175 DefaultPolicyPtr
= NULL
;
1177 if (!DefaultPolicyPtr
)
1179 cupsd_location_t
*po
; /* New policy operation */
1183 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found.",
1186 cupsdSetString(&DefaultPolicy
, "default");
1188 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1189 cupsdLogMessage(CUPSD_LOG_INFO
,
1190 "Using policy \"default\" as the default.");
1193 cupsdLogMessage(CUPSD_LOG_INFO
,
1194 "Creating CUPS default administrative policy:");
1196 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1198 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1200 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateAccess default");
1201 cupsdAddString(&(p
->job_access
), "@OWNER");
1202 cupsdAddString(&(p
->job_access
), "@SYSTEM");
1204 cupsdLogMessage(CUPSD_LOG_INFO
, "JobPrivateValues default");
1205 cupsdAddString(&(p
->job_attrs
), "job-name");
1206 cupsdAddString(&(p
->job_attrs
), "job-originating-host-name");
1207 cupsdAddString(&(p
->job_attrs
), "job-originating-user-name");
1209 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateAccess default");
1210 cupsdAddString(&(p
->sub_access
), "@OWNER");
1211 cupsdAddString(&(p
->sub_access
), "@SYSTEM");
1213 cupsdLogMessage(CUPSD_LOG_INFO
, "SubscriptionPrivateValues default");
1214 cupsdAddString(&(p
->job_attrs
), "notify-events");
1215 cupsdAddString(&(p
->job_attrs
), "notify-pull-method");
1216 cupsdAddString(&(p
->job_attrs
), "notify-recipient-uri");
1217 cupsdAddString(&(p
->job_attrs
), "notify-subscriber-user-name");
1218 cupsdAddString(&(p
->job_attrs
), "notify-user-data");
1220 cupsdLogMessage(CUPSD_LOG_INFO
,
1221 "<Limit Create-Job Print-Job Print-URI Validate-Job>");
1222 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1224 po
= cupsdAddPolicyOp(p
, NULL
, IPP_CREATE_JOB
);
1225 po
->order_type
= CUPSD_AUTH_ALLOW
;
1227 cupsdAddPolicyOp(p
, po
, IPP_PRINT_JOB
);
1228 cupsdAddPolicyOp(p
, po
, IPP_PRINT_URI
);
1229 cupsdAddPolicyOp(p
, po
, IPP_VALIDATE_JOB
);
1231 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1233 cupsdLogMessage(CUPSD_LOG_INFO
,
1234 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1235 "Release-Job Restart-Job Purge-Jobs "
1236 "Set-Job-Attributes Create-Job-Subscription "
1237 "Renew-Subscription Cancel-Subscription "
1238 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1239 "Suspend-Current-Job Resume-Job "
1240 "Cancel-My-Jobs Close-Job CUPS-Move-Job "
1241 "CUPS-Authenticate-Job CUPS-Get-Document>");
1242 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1244 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1245 po
->order_type
= CUPSD_AUTH_ALLOW
;
1246 po
->level
= CUPSD_AUTH_USER
;
1248 cupsdAddName(po
, "@OWNER");
1249 cupsdAddName(po
, "@SYSTEM");
1250 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1252 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1253 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1254 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1255 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1256 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1257 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1258 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1259 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1260 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1261 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1262 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1263 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1264 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1265 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1266 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1267 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_MY_JOBS
);
1268 cupsdAddPolicyOp(p
, po
, IPP_CLOSE_JOB
);
1269 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1270 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1271 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1273 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1275 cupsdLogMessage(CUPSD_LOG_INFO
,
1276 "<Limit Pause-Printer Resume-Printer "
1277 "Set-Printer-Attributes Enable-Printer "
1278 "Disable-Printer Pause-Printer-After-Current-Job "
1279 "Hold-New-Jobs Release-Held-New-Jobs "
1280 "Deactivate-Printer Activate-Printer Restart-Printer "
1281 "Shutdown-Printer Startup-Printer Promote-Job "
1282 "Schedule-Job-After Cancel-Jobs CUPS-Add-Printer "
1283 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1284 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1285 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1286 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1288 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1289 po
->order_type
= CUPSD_AUTH_ALLOW
;
1290 po
->type
= CUPSD_AUTH_DEFAULT
;
1291 po
->level
= CUPSD_AUTH_USER
;
1293 cupsdAddName(po
, "@SYSTEM");
1294 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1296 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1297 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1298 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1299 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1300 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1301 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1302 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1303 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1304 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1305 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1306 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1307 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1308 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1309 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1310 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOBS
);
1311 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1312 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1313 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1314 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1315 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1316 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1317 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1319 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1321 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1322 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1324 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1325 po
->order_type
= CUPSD_AUTH_ALLOW
;
1327 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1328 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1332 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1333 cupsArrayCount(Policies
));
1334 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1336 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1337 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1338 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1341 * If we are doing a full reload or the server root has changed, flush
1342 * the jobs, printers, etc. and start from scratch...
1345 if (NeedReload
== RELOAD_ALL
||
1346 old_remote_port
!= RemotePort
||
1347 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1348 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1350 mime_type_t
*type
; /* Current type */
1351 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1352 /* MIME type name */
1355 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1358 * Free all memory...
1361 cupsdDeleteAllSubscriptions();
1363 cupsdDeleteAllPrinters();
1365 DefaultPrinter
= NULL
;
1367 if (MimeDatabase
!= NULL
)
1368 mimeDelete(MimeDatabase
);
1372 for (i
= 0; i
< NumMimeTypes
; i
++)
1373 _cupsStrFree(MimeTypes
[i
]);
1379 * Read the MIME type and conversion database...
1382 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1383 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1385 MimeDatabase
= mimeNew();
1386 mimeSetErrorCallback(MimeDatabase
, mime_error_cb
, NULL
);
1388 MimeDatabase
= mimeLoadTypes(MimeDatabase
, mimedir
);
1389 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1390 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1391 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1395 cupsdLogMessage(CUPSD_LOG_EMERG
,
1396 "Unable to load MIME database from \"%s\" or \"%s\".",
1397 mimedir
, ServerRoot
);
1398 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1402 cupsdLogMessage(CUPSD_LOG_INFO
,
1403 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1404 "%d filters...", mimedir
, ServerRoot
,
1405 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1408 * Create a list of MIME types for the document-format-supported
1412 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1413 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1416 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1418 cupsdLogMessage(CUPSD_LOG_ERROR
,
1419 "Unable to allocate memory for %d MIME types.",
1425 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1427 i
++, type
= mimeNextType(MimeDatabase
))
1429 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1431 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1434 if (i
< NumMimeTypes
)
1435 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1438 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1440 mime_filter_t
*filter
; /* Current filter */
1443 for (type
= mimeFirstType(MimeDatabase
);
1445 type
= mimeNextType(MimeDatabase
))
1446 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1447 type
->super
, type
->type
);
1449 for (filter
= mimeFirstFilter(MimeDatabase
);
1451 filter
= mimeNextFilter(MimeDatabase
))
1452 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1453 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1454 filter
->src
->super
, filter
->src
->type
,
1455 filter
->dst
->super
, filter
->dst
->type
,
1456 filter
->cost
, filter
->filter
);
1463 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1464 cupsdLoadBanners(temp
);
1467 * Load printers and classes...
1470 cupsdLoadAllPrinters();
1471 cupsdLoadAllClasses();
1472 cupsdLoadRemoteCache();
1474 cupsdCreateCommonData();
1477 * Update the printcap file as needed...
1480 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1481 cupsdWritePrintcap();
1484 * Load queued jobs...
1490 * Load subscriptions...
1493 cupsdLoadAllSubscriptions();
1495 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1500 * Not a full reload, so recreate the common printer attributes...
1503 cupsdCreateCommonData();
1506 * Update all printers as needed...
1509 cupsdUpdatePrinters();
1510 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1512 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1516 * Reset the reload state...
1519 NeedReload
= RELOAD_NONE
;
1521 cupsdClearString(&old_serverroot
);
1522 cupsdClearString(&old_requestroot
);
1529 * 'get_address()' - Get an address + port number from a line.
1532 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1533 get_address(const char *value
, /* I - Value string */
1534 int defport
) /* I - Default port */
1536 char buffer
[1024], /* Hostname + port number buffer */
1537 defpname
[255], /* Default port name */
1538 *hostname
, /* Hostname or IP */
1539 *portname
; /* Port number or name */
1540 http_addrlist_t
*addrlist
; /* Address list */
1544 * Check for an empty value...
1549 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address.");
1554 * Grab a hostname and port number; if there is no colon and the port name
1555 * is only digits, then we have a port number by itself...
1558 strlcpy(buffer
, value
, sizeof(buffer
));
1560 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1567 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1572 * Use the default port...
1575 sprintf(defpname
, "%d", defport
);
1576 portname
= defpname
;
1582 * The buffer contains just a port number...
1590 if (hostname
&& !strcmp(hostname
, "*"))
1594 * Now lookup the address using httpAddrGetList()...
1597 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1598 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed.",
1599 hostname
? hostname
: "(nil)");
1606 * 'get_addr_and_mask()' - Get an IP address and netmask.
1609 static int /* O - 1 on success, 0 on failure */
1610 get_addr_and_mask(const char *value
, /* I - String from config file */
1611 unsigned *ip
, /* O - Address value */
1612 unsigned *mask
) /* O - Mask value */
1614 int i
, j
, /* Looping vars */
1615 family
, /* Address family */
1616 ipcount
; /* Count of fields in address */
1617 unsigned ipval
; /* Value */
1618 const char *maskval
, /* Pointer to start of mask value */
1619 *ptr
, /* Pointer into value */
1624 * Get the address...
1627 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1628 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1630 if ((maskval
= strchr(value
, '/')) != NULL
)
1633 maskval
= value
+ strlen(value
);
1637 * Check for an IPv6 address...
1643 * Parse hexadecimal IPv6/IPv4 address...
1648 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1652 else if (!strncmp(ptr
, "::", 2))
1654 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1656 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1661 else if (isdigit(*ptr
& 255) && strchr(ptr
+ 1, '.') && i
>= 6)
1664 * Read IPv4 dotted quad...
1667 unsigned val
[4] = { 0, 0, 0, 0 };
1668 /* IPv4 address values */
1670 ipcount
= sscanf(ptr
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2,
1674 * Range check the IP numbers...
1677 for (i
= 0; i
< ipcount
; i
++)
1682 * Merge everything into a 32-bit IPv4 address in ip[3]...
1685 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1688 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1691 * If the leading words are all 0's then this is an IPv4 address...
1694 if (!val
[0] && !val
[1] && !val
[2])
1697 while (isdigit(*ptr
& 255) || *ptr
== '.')
1701 else if (isxdigit(*ptr
& 255))
1703 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1705 if (*ptr
== ':' && ptr
[1] != ':')
1714 ip
[i
/ 2] |= ipval
<< 16;
1725 if (*ptr
&& *ptr
!= '/')
1729 #endif /* AF_INET6 */
1732 * Parse dotted-decimal IPv4 address...
1735 unsigned val
[4] = { 0, 0, 0, 0 }; /* IPv4 address values */
1739 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1742 * Range check the IP numbers...
1745 for (i
= 0; i
< ipcount
; i
++)
1750 * Merge everything into a 32-bit IPv4 address in ip[3]...
1753 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1756 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1762 * Get the netmask value(s)...
1765 memset(mask
, 0, sizeof(unsigned) * 4);
1767 if (strchr(maskval
, '.'))
1770 * Get dotted-decimal mask...
1773 if (family
!= AF_INET
)
1776 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2,
1780 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1781 mask
[0] = mask
[1] = mask
[2] = 0;
1786 * Get address/bits format...
1792 if (family
== AF_INET6
)
1800 mask
[0] = 0xffffffff;
1802 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1805 mask
[1] = 0xffffffff;
1809 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1812 mask
[2] = 0xffffffff;
1816 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1819 mask
[3] = 0xffffffff;
1823 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1826 #endif /* AF_INET6 */
1831 mask
[0] = 0xffffffff;
1832 mask
[1] = 0xffffffff;
1833 mask
[2] = 0xffffffff;
1836 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1838 mask
[3] = 0xffffffff;
1843 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1844 "get_addr_and_mask(value=\"%s\", "
1845 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1846 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1850 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1853 if ((ip
[0] & ~mask
[0]) != 0 ||
1854 (ip
[1] & ~mask
[1]) != 0 ||
1855 (ip
[2] & ~mask
[2]) != 0 ||
1856 (ip
[3] & ~mask
[3]) != 0)
1864 * 'mime_error_cb()' - Log a MIME error.
1868 mime_error_cb(void *ctx
, /* I - Context pointer (unused) */
1869 const char *message
) /* I - Message */
1873 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", message
);
1878 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1881 static int /* O - 1 on success, 0 on failure */
1882 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1883 char *line
, /* I - Line from file */
1884 char *value
, /* I - Start of value data */
1885 int linenum
) /* I - Current line number */
1887 char *valptr
; /* Pointer into value */
1888 unsigned ip
[4], /* IP address components */
1889 mask
[4]; /* IP netmask components */
1892 if (!_cups_strcasecmp(line
, "Encryption"))
1895 * "Encryption xxx" - set required encryption level...
1898 if (!_cups_strcasecmp(value
, "never"))
1899 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1900 else if (!_cups_strcasecmp(value
, "always"))
1902 cupsdLogMessage(CUPSD_LOG_ERROR
,
1903 "Encryption value \"%s\" on line %d is invalid in this "
1904 "context. Using \"required\" instead.", value
, linenum
);
1906 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1908 else if (!_cups_strcasecmp(value
, "required"))
1909 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1910 else if (!_cups_strcasecmp(value
, "ifrequested"))
1911 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1914 cupsdLogMessage(CUPSD_LOG_ERROR
,
1915 "Unknown Encryption value %s on line %d.", value
, linenum
);
1919 else if (!_cups_strcasecmp(line
, "Order"))
1922 * "Order Deny,Allow" or "Order Allow,Deny"...
1925 if (!_cups_strncasecmp(value
, "deny", 4))
1926 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1927 else if (!_cups_strncasecmp(value
, "allow", 5))
1928 loc
->order_type
= CUPSD_AUTH_DENY
;
1931 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1936 else if (!_cups_strcasecmp(line
, "Allow") || !_cups_strcasecmp(line
, "Deny"))
1939 * Allow [From] host/ip...
1940 * Deny [From] host/ip...
1945 if (!_cups_strncasecmp(value
, "from", 4))
1948 * Strip leading "from"...
1953 while (_cups_isspace(*value
))
1961 * Find the end of the value...
1964 for (valptr
= value
; *valptr
&& !_cups_isspace(*valptr
); valptr
++);
1966 while (_cups_isspace(*valptr
))
1970 * Figure out what form the allow/deny address takes:
1981 * nnn.nnn.nnn.nnn/mm
1982 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1985 if (!_cups_strcasecmp(value
, "all"))
1991 if (!_cups_strcasecmp(line
, "Allow"))
1992 cupsdAddIPMask(&(loc
->allow
), zeros
, zeros
);
1994 cupsdAddIPMask(&(loc
->deny
), zeros
, zeros
);
1996 else if (!_cups_strcasecmp(value
, "none"))
2002 if (!_cups_strcasecmp(line
, "Allow"))
2003 cupsdAddIPMask(&(loc
->allow
), ones
, zeros
);
2005 cupsdAddIPMask(&(loc
->deny
), ones
, zeros
);
2008 else if (value
[0] == '*' || value
[0] == '.' ||
2009 (!isdigit(value
[0] & 255) && value
[0] != '['))
2011 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2012 #endif /* AF_INET6 */
2015 * Host or domain name...
2018 if (value
[0] == '*')
2021 if (!_cups_strcasecmp(line
, "Allow"))
2022 cupsdAddNameMask(&(loc
->allow
), value
);
2024 cupsdAddNameMask(&(loc
->deny
), value
);
2029 * One of many IP address forms...
2032 if (!get_addr_and_mask(value
, ip
, mask
))
2034 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2039 if (!_cups_strcasecmp(line
, "Allow"))
2040 cupsdAddIPMask(&(loc
->allow
), ip
, mask
);
2042 cupsdAddIPMask(&(loc
->deny
), ip
, mask
);
2046 * Advance to next value...
2052 else if (!_cups_strcasecmp(line
, "AuthType"))
2055 * AuthType {none,basic,digest,basicdigest,negotiate,default}
2058 if (!_cups_strcasecmp(value
, "none"))
2060 loc
->type
= CUPSD_AUTH_NONE
;
2061 loc
->level
= CUPSD_AUTH_ANON
;
2063 else if (!_cups_strcasecmp(value
, "basic"))
2065 loc
->type
= CUPSD_AUTH_BASIC
;
2067 if (loc
->level
== CUPSD_AUTH_ANON
)
2068 loc
->level
= CUPSD_AUTH_USER
;
2070 else if (!_cups_strcasecmp(value
, "digest"))
2072 loc
->type
= CUPSD_AUTH_DIGEST
;
2074 if (loc
->level
== CUPSD_AUTH_ANON
)
2075 loc
->level
= CUPSD_AUTH_USER
;
2077 else if (!_cups_strcasecmp(value
, "basicdigest"))
2079 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
2081 if (loc
->level
== CUPSD_AUTH_ANON
)
2082 loc
->level
= CUPSD_AUTH_USER
;
2084 else if (!_cups_strcasecmp(value
, "default"))
2086 loc
->type
= CUPSD_AUTH_DEFAULT
;
2088 if (loc
->level
== CUPSD_AUTH_ANON
)
2089 loc
->level
= CUPSD_AUTH_USER
;
2092 else if (!_cups_strcasecmp(value
, "negotiate"))
2094 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
2096 if (loc
->level
== CUPSD_AUTH_ANON
)
2097 loc
->level
= CUPSD_AUTH_USER
;
2099 #endif /* HAVE_GSSAPI */
2102 cupsdLogMessage(CUPSD_LOG_WARN
,
2103 "Unknown authorization type %s on line %d.",
2108 else if (!_cups_strcasecmp(line
, "AuthClass"))
2111 * AuthClass anonymous, user, system, group
2114 if (!_cups_strcasecmp(value
, "anonymous"))
2116 loc
->type
= CUPSD_AUTH_NONE
;
2117 loc
->level
= CUPSD_AUTH_ANON
;
2119 cupsdLogMessage(CUPSD_LOG_WARN
,
2120 "\"AuthClass %s\" is deprecated; consider removing "
2124 else if (!_cups_strcasecmp(value
, "user"))
2126 loc
->level
= CUPSD_AUTH_USER
;
2128 cupsdLogMessage(CUPSD_LOG_WARN
,
2129 "\"AuthClass %s\" is deprecated; consider using "
2130 "\"Require valid-user\" on line %d.",
2133 else if (!_cups_strcasecmp(value
, "group"))
2135 loc
->level
= CUPSD_AUTH_GROUP
;
2137 cupsdLogMessage(CUPSD_LOG_WARN
,
2138 "\"AuthClass %s\" is deprecated; consider using "
2139 "\"Require user @groupname\" on line %d.",
2142 else if (!_cups_strcasecmp(value
, "system"))
2144 loc
->level
= CUPSD_AUTH_GROUP
;
2146 cupsdAddName(loc
, "@SYSTEM");
2148 cupsdLogMessage(CUPSD_LOG_WARN
,
2149 "\"AuthClass %s\" is deprecated; consider using "
2150 "\"Require user @SYSTEM\" on line %d.",
2155 cupsdLogMessage(CUPSD_LOG_WARN
,
2156 "Unknown authorization class %s on line %d.",
2161 else if (!_cups_strcasecmp(line
, "AuthGroupName"))
2163 cupsdAddName(loc
, value
);
2165 cupsdLogMessage(CUPSD_LOG_WARN
,
2166 "\"AuthGroupName %s\" directive is deprecated; consider "
2167 "using \"Require user @%s\" on line %d.",
2168 value
, value
, linenum
);
2170 else if (!_cups_strcasecmp(line
, "Require"))
2173 * Apache synonym for AuthClass and AuthGroupName...
2177 * Require valid-user
2178 * Require group names
2179 * Require user names
2182 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2187 if (!_cups_strcasecmp(value
, "valid-user") ||
2188 !_cups_strcasecmp(value
, "user"))
2189 loc
->level
= CUPSD_AUTH_USER
;
2190 else if (!_cups_strcasecmp(value
, "group"))
2191 loc
->level
= CUPSD_AUTH_GROUP
;
2194 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2200 * Get the list of names from the line...
2203 for (value
= valptr
; *value
;)
2205 while (_cups_isspace(*value
))
2208 #ifdef HAVE_AUTHORIZATION_H
2209 if (!strncmp(value
, "@AUTHKEY(", 9))
2212 * Grab "@AUTHKEY(name)" value...
2215 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2221 #endif /* HAVE_AUTHORIZATION_H */
2222 if (*value
== '\"' || *value
== '\'')
2225 * Grab quoted name...
2228 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2235 * Grab literal name.
2238 for (valptr
= value
; !_cups_isspace(*valptr
) && *valptr
; valptr
++);
2244 cupsdAddName(loc
, value
);
2246 for (value
= valptr
; _cups_isspace(*value
); value
++);
2249 else if (!_cups_strcasecmp(line
, "Satisfy"))
2251 if (!_cups_strcasecmp(value
, "all"))
2252 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2253 else if (!_cups_strcasecmp(value
, "any"))
2254 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2257 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2270 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2273 static int /* O - FatalErrors bits */
2274 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2276 int fatal
; /* FatalErrors bits */
2277 char value
[1024], /* Value string */
2278 *valstart
, /* Pointer into value */
2279 *valend
; /* End of value */
2283 * Empty FatalErrors line yields NULL pointer...
2287 return (CUPSD_FATAL_NONE
);
2290 * Loop through the value string,...
2293 strlcpy(value
, s
, sizeof(value
));
2295 fatal
= CUPSD_FATAL_NONE
;
2297 for (valstart
= value
; *valstart
;)
2300 * Get the current space/comma-delimited kind name...
2303 for (valend
= valstart
; *valend
; valend
++)
2304 if (_cups_isspace(*valend
) || *valend
== ',')
2311 * Add the error to the bitmask...
2314 if (!_cups_strcasecmp(valstart
, "all"))
2315 fatal
= CUPSD_FATAL_ALL
;
2316 else if (!_cups_strcasecmp(valstart
, "browse"))
2317 fatal
|= CUPSD_FATAL_BROWSE
;
2318 else if (!_cups_strcasecmp(valstart
, "-browse"))
2319 fatal
&= ~CUPSD_FATAL_BROWSE
;
2320 else if (!_cups_strcasecmp(valstart
, "config"))
2321 fatal
|= CUPSD_FATAL_CONFIG
;
2322 else if (!_cups_strcasecmp(valstart
, "-config"))
2323 fatal
&= ~CUPSD_FATAL_CONFIG
;
2324 else if (!_cups_strcasecmp(valstart
, "listen"))
2325 fatal
|= CUPSD_FATAL_LISTEN
;
2326 else if (!_cups_strcasecmp(valstart
, "-listen"))
2327 fatal
&= ~CUPSD_FATAL_LISTEN
;
2328 else if (!_cups_strcasecmp(valstart
, "log"))
2329 fatal
|= CUPSD_FATAL_LOG
;
2330 else if (!_cups_strcasecmp(valstart
, "-log"))
2331 fatal
&= ~CUPSD_FATAL_LOG
;
2332 else if (!_cups_strcasecmp(valstart
, "permissions"))
2333 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2334 else if (!_cups_strcasecmp(valstart
, "-permissions"))
2335 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2336 else if (_cups_strcasecmp(valstart
, "none"))
2337 cupsdLogMessage(CUPSD_LOG_ERROR
,
2338 "Unknown FatalErrors kind \"%s\" ignored.", valstart
);
2340 for (valstart
= valend
; *valstart
; valstart
++)
2341 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2350 * 'parse_groups()' - Parse system group names in a string.
2353 static int /* O - 1 on success, 0 on failure */
2354 parse_groups(const char *s
) /* I - Space-delimited groups */
2356 int status
; /* Return status */
2357 char value
[1024], /* Value string */
2358 *valstart
, /* Pointer into value */
2359 *valend
, /* End of value */
2360 quote
; /* Quote character */
2361 struct group
*group
; /* Group */
2365 * Make a copy of the string and parse out the groups...
2368 strlcpy(value
, s
, sizeof(value
));
2373 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2375 if (*valstart
== '\'' || *valstart
== '\"')
2378 * Scan quoted name...
2381 quote
= *valstart
++;
2383 for (valend
= valstart
; *valend
; valend
++)
2384 if (*valend
== quote
)
2390 * Scan space or comma-delimited name...
2393 for (valend
= valstart
; *valend
; valend
++)
2394 if (_cups_isspace(*valend
) || *valend
== ',')
2401 group
= getgrnam(valstart
);
2404 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2405 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2416 while (*valstart
== ',' || _cups_isspace(*valstart
))
2425 * 'parse_protocols()' - Parse browse protocols in a string.
2428 static int /* O - Browse protocol bits */
2429 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2431 int protocols
; /* Browse protocol bits */
2432 char value
[1024], /* Value string */
2433 *valstart
, /* Pointer into value */
2434 *valend
; /* End of value */
2438 * Empty protocol line yields NULL pointer...
2445 * Loop through the value string,...
2448 strlcpy(value
, s
, sizeof(value
));
2452 for (valstart
= value
; *valstart
;)
2455 * Get the current space/comma-delimited protocol name...
2458 for (valend
= valstart
; *valend
; valend
++)
2459 if (_cups_isspace(*valend
) || *valend
== ',')
2466 * Add the protocol to the bitmask...
2469 if (!_cups_strcasecmp(valstart
, "cups"))
2470 protocols
|= BROWSE_CUPS
;
2471 else if (!_cups_strcasecmp(valstart
, "slp"))
2472 protocols
|= BROWSE_SLP
;
2473 else if (!_cups_strcasecmp(valstart
, "ldap"))
2474 protocols
|= BROWSE_LDAP
;
2475 else if (!_cups_strcasecmp(valstart
, "dnssd") ||
2476 !_cups_strcasecmp(valstart
, "dns-sd") ||
2477 !_cups_strcasecmp(valstart
, "bonjour"))
2478 protocols
|= BROWSE_DNSSD
;
2479 else if (!_cups_strcasecmp(valstart
, "lpd"))
2480 protocols
|= BROWSE_LPD
;
2481 else if (!_cups_strcasecmp(valstart
, "smb"))
2482 protocols
|= BROWSE_SMB
;
2483 else if (!_cups_strcasecmp(valstart
, "all"))
2484 protocols
|= BROWSE_ALL
;
2485 else if (_cups_strcasecmp(valstart
, "none"))
2486 cupsdLogMessage(CUPSD_LOG_ERROR
,
2487 "Unknown browse protocol \"%s\" ignored.", valstart
);
2489 for (valstart
= valend
; *valstart
; valstart
++)
2490 if (!_cups_isspace(*valstart
) || *valstart
!= ',')
2499 * 'read_configuration()' - Read a configuration file.
2502 static int /* O - 1 on success, 0 on failure */
2503 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2505 int i
; /* Looping var */
2506 int linenum
; /* Current line number */
2507 char line
[HTTP_MAX_BUFFER
],
2508 /* Line from file */
2509 temp
[HTTP_MAX_BUFFER
],
2510 /* Temporary buffer for value */
2511 *ptr
, /* Pointer into line/temp */
2512 *value
, /* Pointer to value */
2513 *valueptr
; /* Pointer into value */
2514 int valuelen
; /* Length of value */
2515 cupsd_var_t
const *var
; /* Current variable */
2516 http_addrlist_t
*addrlist
, /* Address list */
2517 *addr
; /* Current address */
2518 unsigned ip
[4], /* Address value */
2519 mask
[4]; /* Netmask value */
2520 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2521 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2522 cupsd_location_t
*location
; /* Browse location */
2523 cups_file_t
*incfile
; /* Include file */
2524 char incname
[1024]; /* Include filename */
2525 struct group
*group
; /* Group */
2529 * Loop through each line in the file...
2534 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2537 * Decode the directive...
2540 if (!_cups_strcasecmp(line
, "Include") && value
)
2546 if (value
[0] == '/')
2547 strlcpy(incname
, value
, sizeof(incname
));
2549 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2551 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2552 cupsdLogMessage(CUPSD_LOG_ERROR
,
2553 "Unable to include config file \"%s\" - %s",
2554 incname
, strerror(errno
));
2557 read_configuration(incfile
);
2558 cupsFileClose(incfile
);
2561 else if (!_cups_strcasecmp(line
, "<Location") && value
)
2567 linenum
= read_location(fp
, value
, linenum
);
2571 else if (!_cups_strcasecmp(line
, "<Policy") && value
)
2577 linenum
= read_policy(fp
, value
, linenum
);
2581 else if (!_cups_strcasecmp(line
, "FatalErrors"))
2582 FatalErrors
= parse_fatal_errors(value
);
2583 else if (!_cups_strcasecmp(line
, "FaxRetryInterval") && value
)
2585 JobRetryInterval
= atoi(value
);
2586 cupsdLogMessage(CUPSD_LOG_WARN
,
2587 "FaxRetryInterval is deprecated; use "
2588 "JobRetryInterval on line %d.", linenum
);
2590 else if (!_cups_strcasecmp(line
, "FaxRetryLimit") && value
)
2592 JobRetryLimit
= atoi(value
);
2593 cupsdLogMessage(CUPSD_LOG_WARN
,
2594 "FaxRetryLimit is deprecated; use "
2595 "JobRetryLimit on line %d.", linenum
);
2597 else if ((!_cups_strcasecmp(line
, "Port") || !_cups_strcasecmp(line
, "Listen")
2599 || !_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen")
2600 #endif /* HAVE_SSL */
2604 * Add listening address(es) to the list...
2607 cupsd_listener_t
*lis
; /* New listeners array */
2611 * Get the address list...
2614 addrlist
= get_address(value
, IPP_PORT
);
2618 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2624 * Add each address...
2627 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2630 * See if this address is already present...
2633 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2635 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2636 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2637 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2642 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2643 cupsdLogMessage(CUPSD_LOG_WARN
,
2644 "Duplicate listen address \"%s\" ignored.", temp
);
2649 * Allocate another listener...
2653 Listeners
= cupsArrayNew(NULL
, NULL
);
2657 cupsdLogMessage(CUPSD_LOG_ERROR
,
2658 "Unable to allocate %s at line %d - %s.",
2659 line
, linenum
, strerror(errno
));
2663 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2665 cupsdLogMessage(CUPSD_LOG_ERROR
,
2666 "Unable to allocate %s at line %d - %s.",
2667 line
, linenum
, strerror(errno
));
2671 cupsArrayAdd(Listeners
, lis
);
2674 * Copy the current address and log it...
2677 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2681 if (!_cups_strcasecmp(line
, "SSLPort") || !_cups_strcasecmp(line
, "SSLListen"))
2682 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2683 #endif /* HAVE_SSL */
2685 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2688 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2689 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2691 #endif /* AF_LOCAL */
2692 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv%d)", temp
,
2693 _httpAddrPort(&(lis
->address
)),
2694 _httpAddrFamily(&(lis
->address
)) == AF_INET
? 4 : 6);
2696 if (!httpAddrLocalhost(&(lis
->address
)))
2697 RemotePort
= _httpAddrPort(&(lis
->address
));
2704 httpAddrFreeList(addrlist
);
2706 else if (!_cups_strcasecmp(line
, "BrowseAddress") && value
)
2709 * Add a browse address to the list...
2712 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2715 if (NumBrowsers
== 0)
2716 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2718 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2722 cupsdLogMessage(CUPSD_LOG_ERROR
,
2723 "Unable to allocate BrowseAddress at line %d - %s.",
2724 linenum
, strerror(errno
));
2729 dira
+= NumBrowsers
;
2731 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2733 if (!_cups_strcasecmp(value
, "@LOCAL"))
2736 * Send browse data to all local interfaces...
2739 strcpy(dira
->iface
, "*");
2742 else if (!_cups_strncasecmp(value
, "@IF(", 4))
2745 * Send browse data to the named interface...
2748 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2750 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2756 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2759 * Only IPv4 addresses are supported...
2762 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2763 if (_httpAddrFamily(&(addr
->addr
)) == AF_INET
)
2768 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2769 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2771 cupsdLogMessage(CUPSD_LOG_INFO
,
2772 "Sending browsing info to %s:%d (IPv4)",
2773 temp
, _httpAddrPort(&(dira
->to
)));
2778 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2781 httpAddrFreeList(addrlist
);
2784 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2787 else if (!_cups_strcasecmp(line
, "BrowseOrder") && value
)
2790 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2793 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2794 if ((location
= cupsdNewLocation("CUPS_INTERNAL_BROWSE_ACL")) != NULL
)
2795 cupsdAddLocation(location
);
2797 if (location
== NULL
)
2798 cupsdLogMessage(CUPSD_LOG_ERROR
,
2799 "Unable to initialize browse access control list.");
2800 else if (!_cups_strncasecmp(value
, "deny", 4))
2801 location
->order_type
= CUPSD_AUTH_ALLOW
;
2802 else if (!_cups_strncasecmp(value
, "allow", 5))
2803 location
->order_type
= CUPSD_AUTH_DENY
;
2805 cupsdLogMessage(CUPSD_LOG_ERROR
,
2806 "Unknown BrowseOrder value %s on line %d.",
2809 else if (!_cups_strcasecmp(line
, "BrowseProtocols") ||
2810 !_cups_strcasecmp(line
, "BrowseLocalProtocols") ||
2811 !_cups_strcasecmp(line
, "BrowseRemoteProtocols"))
2814 * "BrowseProtocols name [... name]"
2815 * "BrowseLocalProtocols name [... name]"
2816 * "BrowseRemoteProtocols name [... name]"
2819 int protocols
= parse_protocols(value
);
2823 cupsdLogMessage(CUPSD_LOG_ERROR
,
2824 "Unknown browse protocol \"%s\" on line %d.",
2829 if (_cups_strcasecmp(line
, "BrowseLocalProtocols"))
2830 BrowseRemoteProtocols
= protocols
;
2831 if (_cups_strcasecmp(line
, "BrowseRemoteProtocols"))
2832 BrowseLocalProtocols
= protocols
;
2834 else if ((!_cups_strcasecmp(line
, "BrowseAllow") ||
2835 !_cups_strcasecmp(line
, "BrowseDeny")) && value
)
2838 * BrowseAllow [From] host/ip...
2839 * BrowseDeny [From] host/ip...
2842 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2843 if ((location
= cupsdNewLocation("CUPS_INTERNAL_BROWSE_ACL")) != NULL
)
2844 cupsdAddLocation(location
);
2847 if (location
== NULL
)
2848 cupsdLogMessage(CUPSD_LOG_ERROR
,
2849 "Unable to initialize browse access control list.");
2852 if (!_cups_strncasecmp(value
, "from", 4))
2855 * Skip leading "from"...
2864 * Skip leading whitespace...
2867 while (_cups_isspace(*value
))
2874 * Find the end of the value...
2877 for (valueptr
= value
;
2878 *valueptr
&& !_cups_isspace(*valueptr
);
2881 while (_cups_isspace(*valueptr
))
2885 * Figure out what form the allow/deny address takes:
2896 * nnn.nnn.nnn.nnn/mm
2897 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2900 if (!_cups_strcasecmp(value
, "all"))
2906 if (!_cups_strcasecmp(line
, "BrowseAllow"))
2907 cupsdAddIPMask(&(location
->allow
), zeros
, zeros
);
2909 cupsdAddIPMask(&(location
->deny
), zeros
, zeros
);
2911 else if (!_cups_strcasecmp(value
, "none"))
2917 if (!_cups_strcasecmp(line
, "BrowseAllow"))
2918 cupsdAddIPMask(&(location
->allow
), ones
, zeros
);
2920 cupsdAddIPMask(&(location
->deny
), ones
, zeros
);
2923 else if (value
[0] == '*' || value
[0] == '.' ||
2924 (!isdigit(value
[0] & 255) && value
[0] != '['))
2926 else if (value
[0] == '*' || value
[0] == '.' ||
2927 !isdigit(value
[0] & 255))
2928 #endif /* AF_INET6 */
2931 * Host or domain name...
2934 if (!_cups_strcasecmp(line
, "BrowseAllow"))
2935 cupsdAddNameMask(&(location
->allow
), value
);
2937 cupsdAddNameMask(&(location
->deny
), value
);
2942 * One of many IP address forms...
2945 if (!get_addr_and_mask(value
, ip
, mask
))
2947 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2952 if (!_cups_strcasecmp(line
, "BrowseAllow"))
2953 cupsdAddIPMask(&(location
->allow
), ip
, mask
);
2955 cupsdAddIPMask(&(location
->deny
), ip
, mask
);
2959 * Advance to next value...
2966 else if (!_cups_strcasecmp(line
, "BrowseRelay") && value
)
2969 * BrowseRelay [from] source [to] destination
2973 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2975 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2979 cupsdLogMessage(CUPSD_LOG_ERROR
,
2980 "Unable to allocate BrowseRelay at line %d - %s.",
2981 linenum
, strerror(errno
));
2988 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2990 if (!_cups_strncasecmp(value
, "from ", 5))
2993 * Skip leading "from"...
2999 * Skip leading whitespace...
3002 while (_cups_isspace(*value
))
3007 * Find the end of the from value...
3010 for (valueptr
= value
;
3011 *valueptr
&& !_cups_isspace(*valueptr
);
3014 while (_cups_isspace(*valueptr
))
3018 * Figure out what form the from address takes:
3027 * nnn.nnn.nnn.nnn/mm
3028 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
3032 if (value
[0] == '*' || value
[0] == '.' ||
3033 (!isdigit(value
[0] & 255) && value
[0] != '['))
3035 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
3036 #endif /* AF_INET6 */
3039 * Host or domain name...
3042 if (!cupsdAddNameMask(&(relay
->from
), value
))
3044 cupsdLogMessage(CUPSD_LOG_ERROR
,
3045 "Unable to allocate BrowseRelay name at line %d - %s.",
3046 linenum
, strerror(errno
));
3053 * One of many IP address forms...
3056 if (!get_addr_and_mask(value
, ip
, mask
))
3058 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
3063 if (!cupsdAddIPMask(&(relay
->from
), ip
, mask
))
3065 cupsdLogMessage(CUPSD_LOG_ERROR
,
3066 "Unable to allocate BrowseRelay IP at line %d - %s.",
3067 linenum
, strerror(errno
));
3073 * Get "to" address and port...
3076 if (!_cups_strncasecmp(valueptr
, "to ", 3))
3079 * Strip leading "to"...
3084 while (_cups_isspace(*valueptr
))
3088 if ((addrlist
= get_address(valueptr
, BrowsePort
)) != NULL
)
3091 * Only IPv4 addresses are supported...
3094 for (addr
= addrlist
; addr
; addr
= addr
->next
)
3095 if (addr
->addr
.addr
.sa_family
== AF_INET
)
3100 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
3102 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
3104 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
3105 value
, temp
, _httpAddrPort(&(relay
->to
)));
3111 cupsArrayDelete(relay
->from
);
3114 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3118 httpAddrFreeList(addrlist
);
3122 cupsArrayDelete(relay
->from
);
3125 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3129 else if (!_cups_strcasecmp(line
, "BrowsePoll") && value
)
3132 * BrowsePoll address[:port]
3135 char *portname
; /* Port name */
3136 int portnum
; /* Port number */
3137 struct servent
*service
; /* Service */
3141 * Extract the port name from the address...
3144 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
3148 if (isdigit(*portname
& 255))
3149 portnum
= atoi(portname
);
3150 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
3151 portnum
= ntohs(service
->s_port
);
3154 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed.",
3160 portnum
= ippPort();
3163 * Add the poll entry...
3167 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
3169 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
3173 cupsdLogMessage(CUPSD_LOG_ERROR
,
3174 "Unable to allocate BrowsePoll at line %d - %s.",
3175 linenum
, strerror(errno
));
3183 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
3185 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
3186 pollp
->port
= portnum
;
3188 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
3191 else if (!_cups_strcasecmp(line
, "DefaultAuthType") && value
)
3194 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3197 if (!_cups_strcasecmp(value
, "none"))
3198 DefaultAuthType
= CUPSD_AUTH_NONE
;
3199 else if (!_cups_strcasecmp(value
, "basic"))
3200 DefaultAuthType
= CUPSD_AUTH_BASIC
;
3201 else if (!_cups_strcasecmp(value
, "digest"))
3202 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
3203 else if (!_cups_strcasecmp(value
, "basicdigest"))
3204 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
3206 else if (!_cups_strcasecmp(value
, "negotiate"))
3207 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
3208 #endif /* HAVE_GSSAPI */
3211 cupsdLogMessage(CUPSD_LOG_WARN
,
3212 "Unknown default authorization type %s on line %d.",
3214 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3219 else if (!_cups_strcasecmp(line
, "DefaultEncryption"))
3222 * DefaultEncryption {Never,IfRequested,Required}
3225 if (!value
|| !_cups_strcasecmp(value
, "never"))
3226 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3227 else if (!_cups_strcasecmp(value
, "required"))
3228 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3229 else if (!_cups_strcasecmp(value
, "ifrequested"))
3230 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3233 cupsdLogMessage(CUPSD_LOG_WARN
,
3234 "Unknown default encryption %s on line %d.",
3236 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3240 #endif /* HAVE_SSL */
3241 else if (!_cups_strcasecmp(line
, "User") && value
)
3244 * User ID to run as...
3247 if (isdigit(value
[0] & 255))
3249 int uid
= atoi(value
);
3252 cupsdLogMessage(CUPSD_LOG_ERROR
,
3253 "Will not use User 0 as specified on line %d "
3254 "for security reasons. You must use a non-"
3255 "privileged account instead.",
3262 struct passwd
*p
; /* Password information */
3265 p
= getpwnam(value
);
3270 cupsdLogMessage(CUPSD_LOG_ERROR
,
3271 "Will not use User %s (UID=0) as specified on line "
3272 "%d for security reasons. You must use a non-"
3273 "privileged account instead.",
3279 cupsdLogMessage(CUPSD_LOG_ERROR
,
3280 "Unknown User \"%s\" on line %d, ignoring.",
3284 else if (!_cups_strcasecmp(line
, "Group") && value
)
3287 * Group ID to run as...
3290 if (isdigit(value
[0]))
3291 Group
= atoi(value
);
3295 group
= getgrnam(value
);
3298 Group
= group
->gr_gid
;
3300 cupsdLogMessage(CUPSD_LOG_ERROR
,
3301 "Unknown Group \"%s\" on line %d, ignoring.",
3305 else if (!_cups_strcasecmp(line
, "SystemGroup") && value
)
3308 * SystemGroup (admin) group(s)...
3311 if (!parse_groups(value
))
3312 cupsdLogMessage(CUPSD_LOG_ERROR
,
3313 "Unknown SystemGroup \"%s\" on line %d, ignoring.",
3316 else if (!_cups_strcasecmp(line
, "HostNameLookups") && value
)
3319 * Do hostname lookups?
3322 if (!_cups_strcasecmp(value
, "off") || !_cups_strcasecmp(value
, "no") ||
3323 !_cups_strcasecmp(value
, "false"))
3324 HostNameLookups
= 0;
3325 else if (!_cups_strcasecmp(value
, "on") || !_cups_strcasecmp(value
, "yes") ||
3326 !_cups_strcasecmp(value
, "true"))
3327 HostNameLookups
= 1;
3328 else if (!_cups_strcasecmp(value
, "double"))
3329 HostNameLookups
= 2;
3331 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3334 else if (!_cups_strcasecmp(line
, "AccessLogLevel") && value
)
3337 * Amount of logging to do to access log...
3340 if (!_cups_strcasecmp(value
, "all"))
3341 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3342 else if (!_cups_strcasecmp(value
, "actions"))
3343 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3344 else if (!_cups_strcasecmp(value
, "config"))
3345 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3347 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3350 else if (!_cups_strcasecmp(line
, "LogLevel") && value
)
3353 * Amount of logging to do to error log...
3356 if (!_cups_strcasecmp(value
, "debug2"))
3357 LogLevel
= CUPSD_LOG_DEBUG2
;
3358 else if (!_cups_strcasecmp(value
, "debug"))
3359 LogLevel
= CUPSD_LOG_DEBUG
;
3360 else if (!_cups_strcasecmp(value
, "info"))
3361 LogLevel
= CUPSD_LOG_INFO
;
3362 else if (!_cups_strcasecmp(value
, "notice"))
3363 LogLevel
= CUPSD_LOG_NOTICE
;
3364 else if (!_cups_strcasecmp(value
, "warn"))
3365 LogLevel
= CUPSD_LOG_WARN
;
3366 else if (!_cups_strcasecmp(value
, "error"))
3367 LogLevel
= CUPSD_LOG_ERROR
;
3368 else if (!_cups_strcasecmp(value
, "crit"))
3369 LogLevel
= CUPSD_LOG_CRIT
;
3370 else if (!_cups_strcasecmp(value
, "alert"))
3371 LogLevel
= CUPSD_LOG_ALERT
;
3372 else if (!_cups_strcasecmp(value
, "emerg"))
3373 LogLevel
= CUPSD_LOG_EMERG
;
3374 else if (!_cups_strcasecmp(value
, "none"))
3375 LogLevel
= CUPSD_LOG_NONE
;
3377 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3380 else if (!_cups_strcasecmp(line
, "LogTimeFormat") && value
)
3383 * Amount of logging to do to error log...
3386 if (!_cups_strcasecmp(value
, "standard"))
3387 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3388 else if (!_cups_strcasecmp(value
, "usecs"))
3389 LogTimeFormat
= CUPSD_TIME_USECS
;
3391 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3394 else if (!_cups_strcasecmp(line
, "PrintcapFormat") && value
)
3397 * Format of printcap file?
3400 if (!_cups_strcasecmp(value
, "bsd"))
3401 PrintcapFormat
= PRINTCAP_BSD
;
3402 else if (!_cups_strcasecmp(value
, "plist"))
3403 PrintcapFormat
= PRINTCAP_PLIST
;
3404 else if (!_cups_strcasecmp(value
, "solaris"))
3405 PrintcapFormat
= PRINTCAP_SOLARIS
;
3407 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3410 else if (!_cups_strcasecmp(line
, "ServerTokens") && value
)
3413 * Set the string used for the Server header...
3416 struct utsname plat
; /* Platform info */
3421 if (!_cups_strcasecmp(value
, "ProductOnly"))
3422 cupsdSetString(&ServerHeader
, "CUPS");
3423 else if (!_cups_strcasecmp(value
, "Major"))
3424 cupsdSetStringf(&ServerHeader
, "CUPS/%d", CUPS_VERSION_MAJOR
);
3425 else if (!_cups_strcasecmp(value
, "Minor"))
3426 cupsdSetStringf(&ServerHeader
, "CUPS/%d.%d", CUPS_VERSION_MAJOR
,
3427 CUPS_VERSION_MINOR
);
3428 else if (!_cups_strcasecmp(value
, "Minimal"))
3429 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3430 else if (!_cups_strcasecmp(value
, "OS"))
3431 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3432 else if (!_cups_strcasecmp(value
, "Full"))
3433 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/2.1",
3435 else if (!_cups_strcasecmp(value
, "None"))
3436 cupsdClearString(&ServerHeader
);
3438 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3441 else if (!_cups_strcasecmp(line
, "PassEnv") && value
)
3444 * PassEnv variable [... variable]
3449 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3450 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3453 if (value
[valuelen
])
3455 value
[valuelen
] = '\0';
3459 cupsdSetEnv(value
, NULL
);
3461 for (value
+= valuelen
; *value
; value
++)
3462 if (!_cups_isspace(*value
) || *value
!= ',')
3466 else if (!_cups_strcasecmp(line
, "ServerAlias") && value
)
3469 * ServerAlias name [... name]
3473 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3477 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3478 if (_cups_isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3481 if (value
[valuelen
])
3483 value
[valuelen
] = '\0';
3487 cupsdAddAlias(ServerAlias
, value
);
3489 for (value
+= valuelen
; *value
; value
++)
3490 if (!_cups_isspace(*value
) || *value
!= ',')
3494 else if (!_cups_strcasecmp(line
, "SetEnv") && value
)
3497 * SetEnv variable value
3500 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3508 while (isspace(*valueptr
& 255))
3511 cupsdSetEnv(value
, valueptr
);
3514 cupsdLogMessage(CUPSD_LOG_ERROR
,
3515 "Missing value for SetEnv directive on line %d.",
3519 else if (!_cups_strcasecmp(line
, "SSLOptions"))
3522 * SSLOptions options
3525 if (!value
|| !_cups_strcasecmp(value
, "none"))
3526 SSLOptions
= CUPSD_SSL_NONE
;
3527 else if (!_cups_strcasecmp(value
, "noemptyfragments"))
3528 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3530 cupsdLogMessage(CUPSD_LOG_ERROR
,
3531 "Unknown value \"%s\" for SSLOptions directive on "
3532 "line %d.", value
, linenum
);
3534 #endif /* HAVE_SSL */
3538 * Find a simple variable in the list...
3541 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3542 if (!_cups_strcasecmp(line
, var
->name
))
3548 * Unknown directive! Output an error message and continue...
3552 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3555 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3562 case CUPSD_VARTYPE_INTEGER
:
3564 cupsdLogMessage(CUPSD_LOG_ERROR
,
3565 "Missing integer value for %s on line %d.",
3570 char *units
; /* Units */
3573 n
= strtol(value
, &units
, 0);
3575 if (units
&& *units
)
3577 if (tolower(units
[0] & 255) == 'g')
3578 n
*= 1024 * 1024 * 1024;
3579 else if (tolower(units
[0] & 255) == 'm')
3581 else if (tolower(units
[0] & 255) == 'k')
3583 else if (tolower(units
[0] & 255) == 't')
3588 cupsdLogMessage(CUPSD_LOG_ERROR
,
3589 "Bad negative integer value for %s on line %d.",
3592 *((int *)var
->ptr
) = n
;
3596 case CUPSD_VARTYPE_BOOLEAN
:
3598 cupsdLogMessage(CUPSD_LOG_ERROR
,
3599 "Missing boolean value for %s on line %d.",
3601 else if (!_cups_strcasecmp(value
, "true") ||
3602 !_cups_strcasecmp(value
, "on") ||
3603 !_cups_strcasecmp(value
, "enabled") ||
3604 !_cups_strcasecmp(value
, "yes") ||
3606 *((int *)var
->ptr
) = TRUE
;
3607 else if (!_cups_strcasecmp(value
, "false") ||
3608 !_cups_strcasecmp(value
, "off") ||
3609 !_cups_strcasecmp(value
, "disabled") ||
3610 !_cups_strcasecmp(value
, "no") ||
3611 !_cups_strcasecmp(value
, "0"))
3612 *((int *)var
->ptr
) = FALSE
;
3614 cupsdLogMessage(CUPSD_LOG_ERROR
,
3615 "Unknown boolean value %s on line %d.",
3619 case CUPSD_VARTYPE_PATHNAME
:
3622 cupsdLogMessage(CUPSD_LOG_ERROR
,
3623 "Missing pathname value for %s on line %d.",
3628 if (value
[0] == '/')
3629 strlcpy(temp
, value
, sizeof(temp
));
3631 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3633 if (access(temp
, 0))
3635 cupsdLogMessage(CUPSD_LOG_ERROR
,
3636 "File or directory for \"%s %s\" on line %d "
3637 "does not exist.", line
, value
, linenum
);
3641 case CUPSD_VARTYPE_STRING
:
3642 cupsdSetString((char **)var
->ptr
, value
);
3653 * 'read_location()' - Read a <Location path> definition.
3656 static int /* O - New line number or 0 on error */
3657 read_location(cups_file_t
*fp
, /* I - Configuration file */
3658 char *location
, /* I - Location name/path */
3659 int linenum
) /* I - Current line number */
3661 cupsd_location_t
*loc
, /* New location */
3662 *parent
; /* Parent location */
3663 char line
[HTTP_MAX_BUFFER
],
3665 *value
, /* Value for directive */
3666 *valptr
; /* Pointer into value */
3669 if ((parent
= cupsdFindLocation(location
)) != NULL
)
3670 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Location %s> on line %d.",
3672 else if ((parent
= cupsdNewLocation(location
)) == NULL
)
3676 cupsdAddLocation(parent
);
3678 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3683 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3686 * Decode the directive...
3689 if (!_cups_strcasecmp(line
, "</Location>"))
3691 else if (!_cups_strcasecmp(line
, "<Limit") ||
3692 !_cups_strcasecmp(line
, "<LimitExcept"))
3696 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3697 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3703 if ((loc
= cupsdCopyLocation(parent
)) == NULL
)
3706 cupsdAddLocation(loc
);
3711 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3716 if (!strcmp(value
, "ALL"))
3717 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3718 else if (!strcmp(value
, "GET"))
3719 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3720 else if (!strcmp(value
, "HEAD"))
3721 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3722 else if (!strcmp(value
, "OPTIONS"))
3723 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3724 else if (!strcmp(value
, "POST"))
3725 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3726 else if (!strcmp(value
, "PUT"))
3727 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3728 else if (!strcmp(value
, "TRACE"))
3729 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3731 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d.",
3734 for (value
= valptr
; isspace(*value
& 255); value
++);
3737 if (!_cups_strcasecmp(line
, "<LimitExcept"))
3738 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3740 parent
->limit
&= ~loc
->limit
;
3742 else if (!_cups_strcasecmp(line
, "</Limit>") ||
3743 !_cups_strcasecmp(line
, "</LimitExcept>"))
3747 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3748 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3751 else if (!parse_aaa(loc
, line
, value
, linenum
))
3753 cupsdLogMessage(CUPSD_LOG_ERROR
,
3754 "Unknown Location directive %s on line %d.",
3756 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3761 cupsdLogMessage(CUPSD_LOG_ERROR
,
3762 "Unexpected end-of-file at line %d while reading location.",
3765 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3770 * 'read_policy()' - Read a <Policy name> definition.
3773 static int /* O - New line number or 0 on error */
3774 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3775 char *policy
, /* I - Location name/path */
3776 int linenum
) /* I - Current line number */
3778 int i
; /* Looping var */
3779 cupsd_policy_t
*pol
; /* Policy */
3780 cupsd_location_t
*op
; /* Policy operation */
3781 int num_ops
; /* Number of IPP operations */
3782 ipp_op_t ops
[100]; /* Operations */
3783 char line
[HTTP_MAX_BUFFER
],
3785 *value
, /* Value for directive */
3786 *valptr
; /* Pointer into value */
3790 * Create the policy...
3793 if ((pol
= cupsdFindPolicy(policy
)) != NULL
)
3794 cupsdLogMessage(CUPSD_LOG_WARN
, "Duplicate <Policy %s> on line %d.",
3796 else if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3800 * Read from the file...
3806 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3809 * Decode the directive...
3812 if (!_cups_strcasecmp(line
, "</Policy>"))
3815 cupsdLogMessage(CUPSD_LOG_WARN
,
3816 "Missing </Limit> before </Policy> on line %d.",
3819 set_policy_defaults(pol
);
3823 else if (!_cups_strcasecmp(line
, "<Limit") && !op
)
3827 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3828 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3835 * Scan for IPP operation names...
3842 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3847 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3849 if (!_cups_strcasecmp(value
, "All"))
3850 ops
[num_ops
] = IPP_ANY_OPERATION
;
3851 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3852 cupsdLogMessage(CUPSD_LOG_ERROR
,
3853 "Bad IPP operation name \"%s\" on line %d.",
3859 cupsdLogMessage(CUPSD_LOG_ERROR
,
3860 "Too many operations listed on line %d.",
3863 for (value
= valptr
; isspace(*value
& 255); value
++);
3867 * If none are specified, apply the policy to all operations...
3872 ops
[0] = IPP_ANY_OPERATION
;
3877 * Add a new policy for the first operation...
3880 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3882 else if (!_cups_strcasecmp(line
, "</Limit>") && op
)
3885 * Finish the current operation limit...
3891 * Copy the policy to the other operations...
3894 for (i
= 1; i
< num_ops
; i
++)
3895 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3902 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value on line %d.", linenum
);
3903 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3906 else if (!_cups_strcasecmp(line
, "JobPrivateAccess") ||
3907 !_cups_strcasecmp(line
, "JobPrivateValues") ||
3908 !_cups_strcasecmp(line
, "SubscriptionPrivateAccess") ||
3909 !_cups_strcasecmp(line
, "SubscriptionPrivateValues"))
3913 cupsdLogMessage(CUPSD_LOG_ERROR
,
3914 "%s directive must appear outside <Limit>...</Limit> "
3915 "on line %d.", line
, linenum
);
3916 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3922 * Pull out whitespace-delimited values...
3928 * Find the end of the current value...
3931 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3937 * Save it appropriately...
3940 if (!_cups_strcasecmp(line
, "JobPrivateAccess"))
3943 * JobPrivateAccess {all|default|user/group list|@@ACL}
3946 if (!_cups_strcasecmp(value
, "default"))
3948 cupsdAddString(&(pol
->job_access
), "@OWNER");
3949 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
3952 cupsdAddString(&(pol
->job_access
), value
);
3954 else if (!_cups_strcasecmp(line
, "JobPrivateValues"))
3957 * JobPrivateValues {all|none|default|attribute list}
3960 if (!_cups_strcasecmp(value
, "default"))
3962 cupsdAddString(&(pol
->job_attrs
), "job-name");
3963 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
3964 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
3967 cupsdAddString(&(pol
->job_attrs
), value
);
3969 else if (!_cups_strcasecmp(line
, "SubscriptionPrivateAccess"))
3972 * SubscriptionPrivateAccess {all|default|user/group list|@@ACL}
3975 if (!_cups_strcasecmp(value
, "default"))
3977 cupsdAddString(&(pol
->sub_access
), "@OWNER");
3978 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
3981 cupsdAddString(&(pol
->sub_access
), value
);
3983 else /* if (!_cups_strcasecmp(line, "SubscriptionPrivateValues")) */
3986 * SubscriptionPrivateValues {all|none|default|attribute list}
3989 if (!_cups_strcasecmp(value
, "default"))
3991 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
3992 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
3993 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
3994 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
3995 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
3998 cupsdAddString(&(pol
->sub_attrs
), value
);
4002 * Find the next string on the line...
4005 for (value
= valptr
; isspace(*value
& 255); value
++);
4011 cupsdLogMessage(CUPSD_LOG_ERROR
,
4012 "Missing <Limit ops> directive before %s on line %d.",
4014 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4017 else if (!parse_aaa(op
, line
, value
, linenum
))
4019 cupsdLogMessage(CUPSD_LOG_ERROR
,
4020 "Unknown Policy Limit directive %s on line %d.",
4023 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
4028 cupsdLogMessage(CUPSD_LOG_ERROR
,
4029 "Unexpected end-of-file at line %d while reading policy "
4030 "\"%s\".", linenum
, policy
);
4032 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
4037 * 'set_policy_defaults()' - Set default policy values as needed.
4041 set_policy_defaults(cupsd_policy_t
*pol
)/* I - Policy */
4043 cupsd_location_t
*op
; /* Policy operation */
4047 * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
4048 * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
4049 * upgrades do not introduce new security issues...
4052 if ((op
= cupsdFindPolicyOp(pol
, IPP_VALIDATE_JOB
)) == NULL
||
4053 op
->op
== IPP_ANY_OPERATION
)
4055 if ((op
= cupsdFindPolicyOp(pol
, IPP_PRINT_JOB
)) != NULL
&&
4056 op
->op
!= IPP_ANY_OPERATION
)
4059 * Add a new limit for Validate-Job using the Print-Job limit as a
4063 cupsdLogMessage(CUPSD_LOG_WARN
,
4064 "No limit for Validate-Job defined in policy %s "
4065 "- using Print-Job's policy.", pol
->name
);
4067 cupsdAddPolicyOp(pol
, op
, IPP_VALIDATE_JOB
);
4070 cupsdLogMessage(CUPSD_LOG_WARN
,
4071 "No limit for Validate-Job defined in policy %s "
4072 "and no suitable template found.", pol
->name
);
4075 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_JOBS
)) == NULL
||
4076 op
->op
== IPP_ANY_OPERATION
)
4078 if ((op
= cupsdFindPolicyOp(pol
, IPP_PAUSE_PRINTER
)) != NULL
&&
4079 op
->op
!= IPP_ANY_OPERATION
)
4082 * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
4086 cupsdLogMessage(CUPSD_LOG_WARN
,
4087 "No limit for Cancel-Jobs defined in policy %s "
4088 "- using Pause-Printer's policy.", pol
->name
);
4090 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_JOBS
);
4093 cupsdLogMessage(CUPSD_LOG_WARN
,
4094 "No limit for Cancel-Jobs defined in policy %s "
4095 "and no suitable template found.", pol
->name
);
4098 if ((op
= cupsdFindPolicyOp(pol
, IPP_CANCEL_MY_JOBS
)) == NULL
||
4099 op
->op
== IPP_ANY_OPERATION
)
4101 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4102 op
->op
!= IPP_ANY_OPERATION
)
4105 * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
4109 cupsdLogMessage(CUPSD_LOG_WARN
,
4110 "No limit for Cancel-My-Jobs defined in policy %s "
4111 "- using Send-Document's policy.", pol
->name
);
4113 cupsdAddPolicyOp(pol
, op
, IPP_CANCEL_MY_JOBS
);
4116 cupsdLogMessage(CUPSD_LOG_WARN
,
4117 "No limit for Cancel-My-Jobs defined in policy %s "
4118 "and no suitable template found.", pol
->name
);
4121 if ((op
= cupsdFindPolicyOp(pol
, IPP_CLOSE_JOB
)) == NULL
||
4122 op
->op
== IPP_ANY_OPERATION
)
4124 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4125 op
->op
!= IPP_ANY_OPERATION
)
4128 * Add a new limit for Close-Job using the Send-Document limit as a
4132 cupsdLogMessage(CUPSD_LOG_WARN
,
4133 "No limit for Close-Job defined in policy %s "
4134 "- using Send-Document's policy.", pol
->name
);
4136 cupsdAddPolicyOp(pol
, op
, IPP_CLOSE_JOB
);
4139 cupsdLogMessage(CUPSD_LOG_WARN
,
4140 "No limit for Close-Job defined in policy %s "
4141 "and no suitable template found.", pol
->name
);
4144 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
4145 op
->op
== IPP_ANY_OPERATION
)
4147 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
4148 op
->op
!= IPP_ANY_OPERATION
)
4151 * Add a new limit for CUPS-Get-Document using the Send-Document
4152 * limit as a template...
4155 cupsdLogMessage(CUPSD_LOG_WARN
,
4156 "No limit for CUPS-Get-Document defined in policy %s "
4157 "- using Send-Document's policy.", pol
->name
);
4159 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
4162 cupsdLogMessage(CUPSD_LOG_WARN
,
4163 "No limit for CUPS-Get-Document defined in policy %s "
4164 "and no suitable template found.", pol
->name
);
4168 * Verify we have JobPrivateAccess, JobPrivateValues,
4169 * SubscriptionPrivateAccess, and SubscriptionPrivateValues in the policy.
4172 if (!pol
->job_access
)
4174 cupsdLogMessage(CUPSD_LOG_WARN
,
4175 "No JobPrivateAccess defined in policy %s "
4176 "- using defaults.", pol
->name
);
4177 cupsdAddString(&(pol
->job_access
), "@OWNER");
4178 cupsdAddString(&(pol
->job_access
), "@SYSTEM");
4181 if (!pol
->job_attrs
)
4183 cupsdLogMessage(CUPSD_LOG_WARN
,
4184 "No JobPrivateValues defined in policy %s "
4185 "- using defaults.", pol
->name
);
4186 cupsdAddString(&(pol
->job_attrs
), "job-name");
4187 cupsdAddString(&(pol
->job_attrs
), "job-originating-host-name");
4188 cupsdAddString(&(pol
->job_attrs
), "job-originating-user-name");
4191 if (!pol
->sub_access
)
4193 cupsdLogMessage(CUPSD_LOG_WARN
,
4194 "No SubscriptionPrivateAccess defined in policy %s "
4195 "- using defaults.", pol
->name
);
4196 cupsdAddString(&(pol
->sub_access
), "@OWNER");
4197 cupsdAddString(&(pol
->sub_access
), "@SYSTEM");
4200 if (!pol
->sub_attrs
)
4202 cupsdLogMessage(CUPSD_LOG_WARN
,
4203 "No SubscriptionPrivateValues defined in policy %s "
4204 "- using defaults.", pol
->name
);
4205 cupsdAddString(&(pol
->sub_attrs
), "notify-events");
4206 cupsdAddString(&(pol
->sub_attrs
), "notify-pull-method");
4207 cupsdAddString(&(pol
->sub_attrs
), "notify-recipient-uri");
4208 cupsdAddString(&(pol
->sub_attrs
), "notify-subscriber-user-name");
4209 cupsdAddString(&(pol
->sub_attrs
), "notify-user-data");
4215 * End of "$Id: conf.c 9352 2010-11-06 04:55:26Z mike $".