2 * "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2009 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 * parse_aaa() - Parse authentication, authorization, and access
26 * parse_fatal_errors() - Parse FatalErrors values in a string.
27 * parse_groups() - Parse system group names in a string.
28 * parse_protocols() - Parse browse protocols in a string.
29 * read_configuration() - Read a configuration file.
30 * read_location() - Read a <Location path> definition.
31 * read_policy() - Read a <Policy name> definition.
35 * Include necessary headers...
41 #include <sys/utsname.h>
46 #endif /* HAVE_LIBPAPER */
50 * Possibly missing network definitions...
54 # define INADDR_NONE 0xffffffff
55 #endif /* !INADDR_NONE */
59 * Configuration variable structure...
64 CUPSD_VARTYPE_INTEGER
, /* Integer option */
65 CUPSD_VARTYPE_STRING
, /* String option */
66 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
67 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
72 char *name
; /* Name of variable */
73 void *ptr
; /* Pointer to variable */
74 cupsd_vartype_t type
; /* Type (int, string, address) */
82 static const cupsd_var_t variables
[] =
84 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
86 { "AppleQuotas", &AppleQuotas
, CUPSD_VARTYPE_BOOLEAN
},
87 #endif /* __APPLE__ */
88 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
89 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
91 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
93 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_PATHNAME
},
94 # endif /* HAVE_LDAP_SSL */
95 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
96 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
97 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
98 #endif /* HAVE_LDAP */
99 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
100 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
101 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
102 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
103 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
104 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
105 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
106 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
107 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
108 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
109 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
110 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
111 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
112 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
113 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
114 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
115 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
116 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
117 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
118 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
119 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
120 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
121 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
122 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
123 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
124 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
125 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
126 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
127 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
128 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_INTEGER
},
129 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
130 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
131 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
132 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
134 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
135 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
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 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
153 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
154 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
155 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
156 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
157 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
158 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
159 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
160 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
161 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
162 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
163 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
164 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
165 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
166 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
167 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
168 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
169 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
170 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
171 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
173 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
174 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
175 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
176 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
177 #endif /* HAVE_SSL */
178 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
179 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
180 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
181 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
182 #ifdef HAVE_AUTHORIZATION_H
183 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
184 #endif /* HAVE_AUTHORIZATION_H */
185 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
186 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
187 { "UseNetworkDefault", &UseNetworkDefault
, 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 int parse_aaa(cupsd_location_t
*loc
, char *line
,
210 char *value
, int linenum
);
211 static int parse_fatal_errors(const char *s
);
212 static int parse_groups(const char *s
);
213 static int parse_protocols(const char *s
);
214 static int read_configuration(cups_file_t
*fp
);
215 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
216 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
220 * 'cupsdAddAlias()' - Add a host alias.
224 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
225 const char *name
) /* I - Name to add */
227 cupsd_alias_t
*a
; /* New alias */
228 size_t namelen
; /* Length of name */
231 namelen
= strlen(name
);
233 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
236 a
->namelen
= namelen
;
237 strcpy(a
->name
, name
); /* OK since a->name is allocated */
239 cupsArrayAdd(aliases
, a
);
244 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
247 int /* O - 0 on success, -1 on error, 1 on warning */
248 cupsdCheckPermissions(
249 const char *filename
, /* I - File/directory name */
250 const char *suffix
, /* I - Additional file/directory name */
251 int mode
, /* I - Permissions */
252 int user
, /* I - Owner */
253 int group
, /* I - Group */
254 int is_dir
, /* I - 1 = directory, 0 = file */
255 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
257 int dir_created
= 0; /* Did we create a directory? */
258 char pathname
[1024]; /* File name with prefix */
259 struct stat fileinfo
; /* Stat buffer */
260 int is_symlink
; /* Is "filename" a symlink? */
264 * Prepend the given root to the filename before testing it...
269 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
274 * See if we can stat the file/directory...
277 if (lstat(filename
, &fileinfo
))
279 if (errno
== ENOENT
&& create_dir
)
282 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
285 if (mkdir(filename
, mode
))
288 cupsdLogMessage(CUPSD_LOG_ERROR
,
289 "Unable to create directory \"%s\" - %s", filename
,
292 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
299 fileinfo
.st_mode
= mode
| S_IFDIR
;
302 return (create_dir
? -1 : 1);
305 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
307 if (stat(filename
, &fileinfo
))
309 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
310 filename
, strerror(errno
));
316 * Make sure it's a regular file or a directory as needed...
319 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
321 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
325 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
328 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
330 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
336 * If the filename is a symlink, do not change permissions (STR #2937)...
343 * Fix owner, group, and mode as needed...
346 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
349 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
352 if (chown(filename
, user
, group
) && !getuid())
355 cupsdLogMessage(CUPSD_LOG_ERROR
,
356 "Unable to change ownership of \"%s\" - %s", filename
,
359 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
366 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
369 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
372 if (chmod(filename
, mode
))
375 cupsdLogMessage(CUPSD_LOG_ERROR
,
376 "Unable to change permissions of \"%s\" - %s", filename
,
379 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
387 * Everything is OK...
395 * 'cupsdFreeAliases()' - Free all of the alias entries.
399 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
401 cupsd_alias_t
*a
; /* Current alias */
404 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
406 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
409 cupsArrayDelete(aliases
);
414 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
417 int /* O - 1 on success, 0 otherwise */
418 cupsdReadConfiguration(void)
420 int i
; /* Looping var */
421 cups_file_t
*fp
; /* Configuration file */
422 int status
; /* Return status */
423 char temp
[1024], /* Temporary buffer */
424 mimedir
[1024], /* MIME directory */
425 *slash
; /* Directory separator */
426 cups_lang_t
*language
; /* Language */
427 struct passwd
*user
; /* Default user */
428 struct group
*group
; /* Default group */
429 char *old_serverroot
, /* Old ServerRoot */
430 *old_requestroot
; /* Old RequestRoot */
431 int old_remote_port
; /* Old RemotePort */
432 const char *tmpdir
; /* TMPDIR environment variable */
433 struct stat tmpinfo
; /* Temporary directory info */
434 cupsd_policy_t
*p
; /* Policy */
438 * Save the old root paths...
441 old_serverroot
= NULL
;
442 cupsdSetString(&old_serverroot
, ServerRoot
);
443 old_requestroot
= NULL
;
444 cupsdSetString(&old_requestroot
, RequestRoot
);
447 * Reset the server configuration data...
450 cupsdDeleteAllLocations();
469 for (i
= 0; i
< NumRelays
; i
++)
470 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
471 free(Relays
[i
].from
.mask
.name
.name
);
478 cupsdDeleteAllListeners();
480 old_remote_port
= RemotePort
;
487 cupsdFreeAliases(ServerAlias
);
490 cupsdClearString(&ServerName
);
491 cupsdClearString(&ServerAdmin
);
492 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
493 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
494 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
495 cupsdSetString(&DataDir
, CUPS_DATADIR
);
496 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
497 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
498 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
499 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
500 cupsdSetString(&PageLogFormat
,
501 "%p %j %u %T %P %C %{job-billing} "
502 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
503 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
504 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
505 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
506 cupsdSetString(&RemoteRoot
, "remroot");
507 cupsdSetString(&ServerHeader
, "CUPS/1.4");
508 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
510 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
511 PrintcapFormat
= PRINTCAP_SOLARIS
;
512 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
513 "/Library/Preferences/org.cups.printers.plist"))
514 PrintcapFormat
= PRINTCAP_PLIST
;
516 PrintcapFormat
= PRINTCAP_BSD
;
518 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
519 if ((slash
= strrchr(temp
, '/')) != NULL
)
522 cupsdSetString(&ServerRoot
, temp
);
524 cupsdClearString(&Classification
);
525 ClassifyOverride
= 0;
529 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
531 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
532 cupsdSetString(&ServerKey
, "ssl/server.key");
533 # endif /* HAVE_CDSASSL */
534 #endif /* HAVE_SSL */
536 language
= cupsLangDefault();
538 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
539 cupsdSetString(&DefaultLanguage
, "en");
541 cupsdSetString(&DefaultLanguage
, language
->language
);
543 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
545 cupsdClearString(&DefaultPaperSize
);
547 cupsdSetString(&RIPCache
, "8m");
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;
634 MaxPrinterHistory
= 10;
636 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
637 ReloadTimeout
= DEFAULT_KEEPALIVE
;
638 RootCertDuration
= 300;
639 Timeout
= DEFAULT_TIMEOUT
;
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
;
652 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
653 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
655 cupsdClearString(&BrowseLocalOptions
);
656 cupsdClearString(&BrowseRemoteOptions
);
658 cupsdSetString(&ErrorPolicy
, "stop-printer");
661 cupsdClearString(&BrowseLDAPBindDN
);
662 cupsdClearString(&BrowseLDAPDN
);
663 cupsdClearString(&BrowseLDAPPassword
);
664 cupsdClearString(&BrowseLDAPServer
);
665 # ifdef HAVE_LDAP_SSL
666 cupsdClearString(&BrowseLDAPCACertFile
);
667 # endif /* HAVE_LDAP_SSL */
668 #endif /* HAVE_LDAP */
670 JobHistory
= DEFAULT_HISTORY
;
671 JobFiles
= DEFAULT_FILES
;
676 MaxJobsPerPrinter
= 0;
677 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
679 cupsdDeleteAllPolicies();
680 cupsdClearString(&DefaultPolicy
);
682 #ifdef HAVE_AUTHORIZATION_H
683 cupsdClearString(&SystemGroupAuthKey
);
684 #endif /* HAVE_AUTHORIZATION_H */
686 MaxSubscriptions
= 100;
687 MaxSubscriptionsPerJob
= 0;
688 MaxSubscriptionsPerPrinter
= 0;
689 MaxSubscriptionsPerUser
= 0;
690 DefaultLeaseDuration
= 86400;
691 MaxLeaseDuration
= 0;
694 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
695 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
696 #endif /* HAVE_LAUNCHD */
700 #endif /* __APPLE__ */
703 * Read the configuration file...
706 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
709 status
= read_configuration(fp
);
718 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
719 RemotePort
? "enabled" : "disabled");
722 * See if the ServerName is an IP address...
728 ServerAlias
= cupsArrayNew(NULL
, NULL
);
730 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
734 if (gethostname(temp
, sizeof(temp
)))
736 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
738 strlcpy(temp
, "localhost", sizeof(temp
));
741 cupsdSetString(&ServerName
, temp
);
744 ServerAlias
= cupsArrayNew(NULL
, NULL
);
746 cupsdAddAlias(ServerAlias
, temp
);
747 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
749 if (HostNameLookups
|| RemotePort
)
751 struct hostent
*host
; /* Host entry to get FQDN */
753 if ((host
= gethostbyname(temp
)) != NULL
)
755 if (strcasecmp(temp
, host
->h_name
))
757 cupsdSetString(&ServerName
, host
->h_name
);
758 cupsdAddAlias(ServerAlias
, host
->h_name
);
759 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
765 for (i
= 0; host
->h_aliases
[i
]; i
++)
766 if (strcasecmp(temp
, host
->h_aliases
[i
]))
768 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
769 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
777 * Make sure we have the base hostname added as an alias, too!
780 if ((slash
= strchr(temp
, '.')) != NULL
)
783 cupsdAddAlias(ServerAlias
, temp
);
784 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
788 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
790 ServerNameIsIP
= !*slash
;
793 * Make sure ServerAdmin is initialized...
797 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
800 * Use the default system group if none was supplied in cupsd.conf...
803 if (NumSystemGroups
== 0)
805 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
808 * Find the group associated with GID 0...
815 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
817 cupsdSetString(&SystemGroups
[0], "unknown");
819 SystemGroupIDs
[0] = 0;
825 * Get the access control list for browsing...
828 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
831 * Open the system log for cupsd if necessary...
835 if (!strcmp(AccessLog
, "syslog") ||
836 !strcmp(ErrorLog
, "syslog") ||
837 !strcmp(PageLog
, "syslog"))
838 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
839 #endif /* HAVE_VSYSLOG */
842 * Log the configuration file that was used...
845 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
849 * Validate the Group and SystemGroup settings - they cannot be the same,
850 * otherwise the CGI programs will be able to authenticate as root without
856 for (i
= 0; i
< NumSystemGroups
; i
++)
857 if (Group
== SystemGroupIDs
[i
])
860 if (i
< NumSystemGroups
)
863 * Log the error and reset the group to a safe value...
866 cupsdLogMessage(CUPSD_LOG_NOTICE
,
867 "Group and SystemGroup cannot use the same groups!");
868 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
870 group
= getgrnam("nobody");
874 Group
= group
->gr_gid
;
878 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
879 * complement number...)
888 * Check that we have at least one listen/port line; if not, report this
889 * as an error and exit!
892 if (cupsArrayCount(Listeners
) == 0)
898 cupsdLogMessage(CUPSD_LOG_EMERG
,
899 "No valid Listen or Port lines were found in the "
900 "configuration file!");
906 cupsdEndProcess(getpid(), 0);
910 * Set the default locale using the language and charset...
913 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
916 * Update all relative filenames to include the full path from ServerRoot...
919 if (DocumentRoot
[0] != '/')
920 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
922 if (RequestRoot
[0] != '/')
923 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
925 if (ServerBin
[0] != '/')
926 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
928 if (StateDir
[0] != '/')
929 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
931 if (CacheDir
[0] != '/')
932 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
935 if (ServerCertificate
[0] != '/')
936 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
938 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
939 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
941 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
944 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
945 if (ServerKey
[0] != '/')
946 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
948 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
949 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
950 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
952 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
953 #endif /* HAVE_SSL */
956 * Make sure that directories and config files are owned and
957 * writable by the user and group in the cupsd.conf file...
960 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
962 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
964 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
966 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
968 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
970 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
971 SystemGroupIDs
[0], 1, 1) < 0 ||
972 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
974 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
976 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
978 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
980 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
982 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
984 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
986 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
990 * Update TempDir to the default if it hasn't been set already...
995 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
998 * TMPDIR is defined, see if it is OK for us to use...
1001 if (stat(tmpdir
, &tmpinfo
))
1002 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
1003 tmpdir
, strerror(errno
));
1004 else if (!S_ISDIR(tmpinfo
.st_mode
))
1005 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
1007 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1008 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1009 !(tmpinfo
.st_mode
& S_IWOTH
))
1010 cupsdLogMessage(CUPSD_LOG_ERROR
,
1011 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
1013 cupsdSetString(&TempDir
, tmpdir
);
1018 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1020 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1025 * Make sure the temporary directory has the right permissions...
1028 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1032 * Update ownership and permissions if the CUPS temp directory
1033 * is under the spool directory or does not exist...
1036 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1037 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1042 * Setup environment variables...
1048 * Update default paper size setting as needed...
1051 if (!DefaultPaperSize
)
1053 #ifdef HAVE_LIBPAPER
1054 char *paper_result
; /* Paper size name from libpaper */
1056 if ((paper_result
= systempapername()) != NULL
)
1057 cupsdSetString(&DefaultPaperSize
, paper_result
);
1059 #endif /* HAVE_LIBPAPER */
1060 if (!DefaultLanguage
||
1061 !strcasecmp(DefaultLanguage
, "C") ||
1062 !strcasecmp(DefaultLanguage
, "POSIX") ||
1063 !strcasecmp(DefaultLanguage
, "en") ||
1064 !strncasecmp(DefaultLanguage
, "en.", 3) ||
1065 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
1066 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1067 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
1070 * These are the only locales that will default to "letter" size...
1073 cupsdSetString(&DefaultPaperSize
, "Letter");
1076 cupsdSetString(&DefaultPaperSize
, "A4");
1080 * Update classification setting as needed...
1083 if (Classification
&& !strcasecmp(Classification
, "none"))
1084 cupsdClearString(&Classification
);
1087 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1090 * Check the MaxClients setting, and then allocate memory for it...
1093 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1096 cupsdLogMessage(CUPSD_LOG_INFO
,
1097 "MaxClients limited to 1/3 (%d) of the file descriptor "
1099 MaxFDs
/ 3, MaxFDs
);
1101 MaxClients
= MaxFDs
/ 3;
1104 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1108 * Check the MaxActiveJobs setting; limit to 1/3 the available
1109 * file descriptors, since we need a pipe for each job...
1112 if (MaxActiveJobs
> (MaxFDs
/ 3))
1113 MaxActiveJobs
= MaxFDs
/ 3;
1116 * Update the MaxClientsPerHost value, as needed...
1119 if (MaxClientsPerHost
<= 0)
1120 MaxClientsPerHost
= MaxClients
;
1122 if (MaxClientsPerHost
> MaxClients
)
1123 MaxClientsPerHost
= MaxClients
;
1125 cupsdLogMessage(CUPSD_LOG_INFO
,
1126 "Allowing up to %d client connections per host.",
1130 * Make sure that BrowseTimeout is at least twice the interval...
1133 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1135 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1139 BrowseTimeout
= BrowseInterval
* 2;
1141 BrowseTimeout
= DEFAULT_TIMEOUT
;
1143 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1148 * Update the default policy, as needed...
1152 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1154 DefaultPolicyPtr
= NULL
;
1156 if (!DefaultPolicyPtr
)
1158 cupsd_location_t
*po
; /* New policy operation */
1162 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1165 cupsdSetString(&DefaultPolicy
, "default");
1167 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1168 cupsdLogMessage(CUPSD_LOG_INFO
,
1169 "Using policy \"default\" as the default!");
1172 cupsdLogMessage(CUPSD_LOG_INFO
,
1173 "Creating CUPS default administrative policy:");
1175 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1177 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1178 cupsdLogMessage(CUPSD_LOG_INFO
,
1179 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1180 "Release-Job Restart-Job Purge-Jobs "
1181 "Set-Job-Attributes Create-Job-Subscription "
1182 "Renew-Subscription Cancel-Subscription "
1183 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1184 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1185 "CUPS-Authenticate-Job CUPS-Get-Document>");
1186 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1188 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1189 po
->order_type
= CUPSD_AUTH_ALLOW
;
1190 po
->level
= CUPSD_AUTH_USER
;
1192 cupsdAddName(po
, "@OWNER");
1193 cupsdAddName(po
, "@SYSTEM");
1194 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1196 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1197 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1198 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1199 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1200 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1201 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1202 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1203 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1204 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1205 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1206 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1207 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1208 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1209 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1210 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1211 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1212 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1213 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1215 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1217 cupsdLogMessage(CUPSD_LOG_INFO
,
1218 "<Limit Pause-Printer Resume-Printer "
1219 "Set-Printer-Attributes Enable-Printer "
1220 "Disable-Printer Pause-Printer-After-Current-Job "
1221 "Hold-New-Jobs Release-Held-New-Jobs "
1222 "Deactivate-Printer Activate-Printer Restart-Printer "
1223 "Shutdown-Printer Startup-Printer Promote-Job "
1224 "Schedule-Job-After CUPS-Add-Printer "
1225 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1226 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1227 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1228 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1230 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1231 po
->order_type
= CUPSD_AUTH_ALLOW
;
1232 po
->type
= CUPSD_AUTH_DEFAULT
;
1233 po
->level
= CUPSD_AUTH_USER
;
1235 cupsdAddName(po
, "@SYSTEM");
1236 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1238 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1239 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1240 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1241 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1242 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1243 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1244 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1245 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1246 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1247 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1248 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1249 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1250 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1251 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1252 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1253 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1254 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1255 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1256 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1257 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1258 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1260 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1262 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1263 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1265 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1266 po
->order_type
= CUPSD_AUTH_ALLOW
;
1268 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1269 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1273 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1274 cupsArrayCount(Policies
));
1275 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1277 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1278 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1279 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1282 * If we are doing a full reload or the server root has changed, flush
1283 * the jobs, printers, etc. and start from scratch...
1286 if (NeedReload
== RELOAD_ALL
||
1287 old_remote_port
!= RemotePort
||
1288 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1289 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1291 mime_type_t
*type
; /* Current type */
1292 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1293 /* MIME type name */
1296 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1299 * Free all memory...
1302 cupsdDeleteAllSubscriptions();
1304 cupsdDeleteAllPrinters();
1306 DefaultPrinter
= NULL
;
1308 if (MimeDatabase
!= NULL
)
1309 mimeDelete(MimeDatabase
);
1313 for (i
= 0; i
< NumMimeTypes
; i
++)
1314 _cupsStrFree(MimeTypes
[i
]);
1320 * Read the MIME type and conversion database...
1323 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1324 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1326 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1327 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1328 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1329 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1333 cupsdLogMessage(CUPSD_LOG_EMERG
,
1334 "Unable to load MIME database from \"%s\" or \"%s\"!",
1335 mimedir
, ServerRoot
);
1336 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1340 cupsdLogMessage(CUPSD_LOG_INFO
,
1341 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1342 "%d filters...", mimedir
, ServerRoot
,
1343 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1346 * Create a list of MIME types for the document-format-supported
1350 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1351 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1354 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1356 cupsdLogMessage(CUPSD_LOG_ERROR
,
1357 "Unable to allocate memory for %d MIME types!",
1363 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1365 i
++, type
= mimeNextType(MimeDatabase
))
1367 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1369 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1372 if (i
< NumMimeTypes
)
1373 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1376 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1378 mime_filter_t
*filter
; /* Current filter */
1381 for (type
= mimeFirstType(MimeDatabase
);
1383 type
= mimeNextType(MimeDatabase
))
1384 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1385 type
->super
, type
->type
);
1387 for (filter
= mimeFirstFilter(MimeDatabase
);
1389 filter
= mimeNextFilter(MimeDatabase
))
1390 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1391 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1392 filter
->src
->super
, filter
->src
->type
,
1393 filter
->dst
->super
, filter
->dst
->type
,
1394 filter
->cost
, filter
->filter
);
1401 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1402 cupsdLoadBanners(temp
);
1405 * Load printers and classes...
1408 cupsdLoadAllPrinters();
1409 cupsdLoadAllClasses();
1410 cupsdLoadRemoteCache();
1412 cupsdCreateCommonData();
1415 * Update the printcap file as needed...
1418 if (Printcap
&& *Printcap
&& access(Printcap
, 0))
1419 cupsdWritePrintcap();
1422 * Load queued jobs...
1428 * Load subscriptions...
1431 cupsdLoadAllSubscriptions();
1433 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1438 * Not a full reload, so recreate the common printer attributes...
1441 cupsdCreateCommonData();
1444 * Update all printers as needed...
1447 cupsdUpdatePrinters();
1448 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1450 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1454 * Reset the reload state...
1457 NeedReload
= RELOAD_NONE
;
1459 cupsdClearString(&old_serverroot
);
1460 cupsdClearString(&old_requestroot
);
1467 * 'get_address()' - Get an address + port number from a line.
1470 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1471 get_address(const char *value
, /* I - Value string */
1472 int defport
) /* I - Default port */
1474 char buffer
[1024], /* Hostname + port number buffer */
1475 defpname
[255], /* Default port name */
1476 *hostname
, /* Hostname or IP */
1477 *portname
; /* Port number or name */
1478 http_addrlist_t
*addrlist
; /* Address list */
1482 * Check for an empty value...
1487 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1492 * Grab a hostname and port number; if there is no colon and the port name
1493 * is only digits, then we have a port number by itself...
1496 strlcpy(buffer
, value
, sizeof(buffer
));
1498 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1505 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1510 * Use the default port...
1513 sprintf(defpname
, "%d", defport
);
1514 portname
= defpname
;
1520 * The buffer contains just a port number...
1528 if (hostname
&& !strcmp(hostname
, "*"))
1532 * Now lookup the address using httpAddrGetList()...
1535 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1536 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1537 hostname
? hostname
: "(nil)");
1544 * 'get_addr_and_mask()' - Get an IP address and netmask.
1547 static int /* O - 1 on success, 0 on failure */
1548 get_addr_and_mask(const char *value
, /* I - String from config file */
1549 unsigned *ip
, /* O - Address value */
1550 unsigned *mask
) /* O - Mask value */
1552 int i
, j
, /* Looping vars */
1553 family
, /* Address family */
1554 ipcount
; /* Count of fields in address */
1555 unsigned ipval
; /* Value */
1556 const char *maskval
, /* Pointer to start of mask value */
1557 *ptr
, /* Pointer into value */
1562 * Get the address...
1565 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1566 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1568 if ((maskval
= strchr(value
, '/')) != NULL
)
1571 maskval
= value
+ strlen(value
);
1575 * Check for an IPv6 address...
1581 * Parse hexadecimal IPv6 address...
1586 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1590 else if (!strncmp(ptr
, "::", 2))
1592 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1594 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1599 else if (isxdigit(*ptr
& 255))
1601 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1609 ip
[i
/ 2] |= ipval
<< 16;
1623 if (*ptr
&& *ptr
!= '/')
1627 #endif /* AF_INET6 */
1630 * Parse dotted-decimal IPv4 address...
1633 unsigned val
[4]; /* IPv4 address values */
1637 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1640 * Range check the IP numbers...
1643 for (i
= 0; i
< ipcount
; i
++)
1648 * Make sure the trailing values are zeroed, as some C libraries like
1649 * glibc apparently like to fill the unused arguments with garbage...
1652 for (i
= ipcount
; i
< 4; i
++)
1656 * Merge everything into a 32-bit IPv4 address in ip[3]...
1659 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1662 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1668 * Get the netmask value(s)...
1671 memset(mask
, 0, sizeof(unsigned) * 4);
1673 if (strchr(maskval
, '.'))
1676 * Get dotted-decimal mask...
1679 if (family
!= AF_INET
)
1682 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1685 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1686 mask
[0] = mask
[1] = mask
[2] = 0;
1691 * Get address/bits format...
1697 if (family
== AF_INET6
)
1705 mask
[0] = 0xffffffff;
1707 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1710 mask
[1] = 0xffffffff;
1714 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1717 mask
[2] = 0xffffffff;
1721 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1724 mask
[3] = 0xffffffff;
1728 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1731 #endif /* AF_INET6 */
1736 mask
[0] = 0xffffffff;
1737 mask
[1] = 0xffffffff;
1738 mask
[2] = 0xffffffff;
1741 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1743 mask
[3] = 0xffffffff;
1748 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1749 "get_addr_and_mask(value=\"%s\", "
1750 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1751 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1755 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1758 if ((ip
[0] & ~mask
[0]) != 0 ||
1759 (ip
[1] & ~mask
[1]) != 0 ||
1760 (ip
[2] & ~mask
[2]) != 0 ||
1761 (ip
[3] & ~mask
[3]) != 0)
1769 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1772 static int /* O - 1 on success, 0 on failure */
1773 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1774 char *line
, /* I - Line from file */
1775 char *value
, /* I - Start of value data */
1776 int linenum
) /* I - Current line number */
1778 char *valptr
; /* Pointer into value */
1779 unsigned ip
[4], /* IP address components */
1780 mask
[4]; /* IP netmask components */
1783 if (!strcasecmp(line
, "Encryption"))
1786 * "Encryption xxx" - set required encryption level...
1789 if (!strcasecmp(value
, "never"))
1790 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1791 else if (!strcasecmp(value
, "always"))
1793 cupsdLogMessage(CUPSD_LOG_ERROR
,
1794 "Encryption value \"%s\" on line %d is invalid in this "
1795 "context. Using \"required\" instead.", value
, linenum
);
1797 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1799 else if (!strcasecmp(value
, "required"))
1800 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1801 else if (!strcasecmp(value
, "ifrequested"))
1802 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1805 cupsdLogMessage(CUPSD_LOG_ERROR
,
1806 "Unknown Encryption value %s on line %d.", value
, linenum
);
1810 else if (!strcasecmp(line
, "Order"))
1813 * "Order Deny,Allow" or "Order Allow,Deny"...
1816 if (!strncasecmp(value
, "deny", 4))
1817 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1818 else if (!strncasecmp(value
, "allow", 5))
1819 loc
->order_type
= CUPSD_AUTH_DENY
;
1822 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1827 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1830 * Allow [From] host/ip...
1831 * Deny [From] host/ip...
1836 if (!strncasecmp(value
, "from", 4))
1839 * Strip leading "from"...
1844 while (isspace(*value
& 255))
1852 * Find the end of the value...
1855 for (valptr
= value
; *valptr
&& !isspace(*valptr
& 255); valptr
++);
1857 while (isspace(*valptr
& 255))
1861 * Figure out what form the allow/deny address takes:
1872 * nnn.nnn.nnn.nnn/mm
1873 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1876 if (!strcasecmp(value
, "all"))
1882 if (!strcasecmp(line
, "Allow"))
1883 cupsdAllowIP(loc
, zeros
, zeros
);
1885 cupsdDenyIP(loc
, zeros
, zeros
);
1887 else if (!strcasecmp(value
, "none"))
1893 if (!strcasecmp(line
, "Allow"))
1894 cupsdAllowIP(loc
, ones
, zeros
);
1896 cupsdDenyIP(loc
, ones
, zeros
);
1899 else if (value
[0] == '*' || value
[0] == '.' ||
1900 (!isdigit(value
[0] & 255) && value
[0] != '['))
1902 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1903 #endif /* AF_INET6 */
1906 * Host or domain name...
1909 if (value
[0] == '*')
1912 if (!strcasecmp(line
, "Allow"))
1913 cupsdAllowHost(loc
, value
);
1915 cupsdDenyHost(loc
, value
);
1920 * One of many IP address forms...
1923 if (!get_addr_and_mask(value
, ip
, mask
))
1925 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1930 if (!strcasecmp(line
, "Allow"))
1931 cupsdAllowIP(loc
, ip
, mask
);
1933 cupsdDenyIP(loc
, ip
, mask
);
1937 * Advance to next value...
1943 else if (!strcasecmp(line
, "AuthType"))
1946 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1949 if (!strcasecmp(value
, "none"))
1951 loc
->type
= CUPSD_AUTH_NONE
;
1952 loc
->level
= CUPSD_AUTH_ANON
;
1954 else if (!strcasecmp(value
, "basic"))
1956 loc
->type
= CUPSD_AUTH_BASIC
;
1958 if (loc
->level
== CUPSD_AUTH_ANON
)
1959 loc
->level
= CUPSD_AUTH_USER
;
1961 else if (!strcasecmp(value
, "digest"))
1963 loc
->type
= CUPSD_AUTH_DIGEST
;
1965 if (loc
->level
== CUPSD_AUTH_ANON
)
1966 loc
->level
= CUPSD_AUTH_USER
;
1968 else if (!strcasecmp(value
, "basicdigest"))
1970 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1972 if (loc
->level
== CUPSD_AUTH_ANON
)
1973 loc
->level
= CUPSD_AUTH_USER
;
1975 else if (!strcasecmp(value
, "default"))
1977 loc
->type
= CUPSD_AUTH_DEFAULT
;
1979 if (loc
->level
== CUPSD_AUTH_ANON
)
1980 loc
->level
= CUPSD_AUTH_USER
;
1983 else if (!strcasecmp(value
, "negotiate"))
1985 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1987 if (loc
->level
== CUPSD_AUTH_ANON
)
1988 loc
->level
= CUPSD_AUTH_USER
;
1990 #endif /* HAVE_GSSAPI */
1993 cupsdLogMessage(CUPSD_LOG_WARN
,
1994 "Unknown authorization type %s on line %d.",
1999 else if (!strcasecmp(line
, "AuthClass"))
2002 * AuthClass anonymous, user, system, group
2005 if (!strcasecmp(value
, "anonymous"))
2007 loc
->type
= CUPSD_AUTH_NONE
;
2008 loc
->level
= CUPSD_AUTH_ANON
;
2010 cupsdLogMessage(CUPSD_LOG_WARN
,
2011 "\"AuthClass %s\" is deprecated; consider removing "
2015 else if (!strcasecmp(value
, "user"))
2017 loc
->level
= CUPSD_AUTH_USER
;
2019 cupsdLogMessage(CUPSD_LOG_WARN
,
2020 "\"AuthClass %s\" is deprecated; consider using "
2021 "\"Require valid-user\" on line %d.",
2024 else if (!strcasecmp(value
, "group"))
2026 loc
->level
= CUPSD_AUTH_GROUP
;
2028 cupsdLogMessage(CUPSD_LOG_WARN
,
2029 "\"AuthClass %s\" is deprecated; consider using "
2030 "\"Require user @groupname\" on line %d.",
2033 else if (!strcasecmp(value
, "system"))
2035 loc
->level
= CUPSD_AUTH_GROUP
;
2037 cupsdAddName(loc
, "@SYSTEM");
2039 cupsdLogMessage(CUPSD_LOG_WARN
,
2040 "\"AuthClass %s\" is deprecated; consider using "
2041 "\"Require user @SYSTEM\" on line %d.",
2046 cupsdLogMessage(CUPSD_LOG_WARN
,
2047 "Unknown authorization class %s on line %d.",
2052 else if (!strcasecmp(line
, "AuthGroupName"))
2054 cupsdAddName(loc
, value
);
2056 cupsdLogMessage(CUPSD_LOG_WARN
,
2057 "\"AuthGroupName %s\" directive is deprecated; consider "
2058 "using \"Require user @%s\" on line %d.",
2059 value
, value
, linenum
);
2061 else if (!strcasecmp(line
, "Require"))
2064 * Apache synonym for AuthClass and AuthGroupName...
2068 * Require valid-user
2069 * Require group names
2070 * Require user names
2073 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2078 if (!strcasecmp(value
, "valid-user") ||
2079 !strcasecmp(value
, "user"))
2080 loc
->level
= CUPSD_AUTH_USER
;
2081 else if (!strcasecmp(value
, "group"))
2082 loc
->level
= CUPSD_AUTH_GROUP
;
2085 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2091 * Get the list of names from the line...
2094 for (value
= valptr
; *value
;)
2096 while (isspace(*value
& 255))
2099 #ifdef HAVE_AUTHORIZATION_H
2100 if (!strncmp(value
, "@AUTHKEY(", 9))
2103 * Grab "@AUTHKEY(name)" value...
2106 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2112 #endif /* HAVE_AUTHORIZATION_H */
2113 if (*value
== '\"' || *value
== '\'')
2116 * Grab quoted name...
2119 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2126 * Grab literal name.
2129 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2135 cupsdAddName(loc
, value
);
2137 for (value
= valptr
; isspace(*value
& 255); value
++);
2140 else if (!strcasecmp(line
, "Satisfy"))
2142 if (!strcasecmp(value
, "all"))
2143 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2144 else if (!strcasecmp(value
, "any"))
2145 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2148 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2161 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2164 static int /* O - FatalErrors bits */
2165 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2167 int fatal
; /* FatalErrors bits */
2168 char value
[1024], /* Value string */
2169 *valstart
, /* Pointer into value */
2170 *valend
; /* End of value */
2174 * Empty FatalErrors line yields NULL pointer...
2178 return (CUPSD_FATAL_NONE
);
2181 * Loop through the value string,...
2184 strlcpy(value
, s
, sizeof(value
));
2186 fatal
= CUPSD_FATAL_NONE
;
2188 for (valstart
= value
; *valstart
;)
2191 * Get the current space/comma-delimited kind name...
2194 for (valend
= valstart
; *valend
; valend
++)
2195 if (isspace(*valend
& 255) || *valend
== ',')
2202 * Add the error to the bitmask...
2205 if (!strcasecmp(valstart
, "all"))
2206 fatal
= CUPSD_FATAL_ALL
;
2207 else if (!strcasecmp(valstart
, "browse"))
2208 fatal
|= CUPSD_FATAL_BROWSE
;
2209 else if (!strcasecmp(valstart
, "-browse"))
2210 fatal
&= ~CUPSD_FATAL_BROWSE
;
2211 else if (!strcasecmp(valstart
, "config"))
2212 fatal
|= CUPSD_FATAL_CONFIG
;
2213 else if (!strcasecmp(valstart
, "-config"))
2214 fatal
&= ~CUPSD_FATAL_CONFIG
;
2215 else if (!strcasecmp(valstart
, "listen"))
2216 fatal
|= CUPSD_FATAL_LISTEN
;
2217 else if (!strcasecmp(valstart
, "-listen"))
2218 fatal
&= ~CUPSD_FATAL_LISTEN
;
2219 else if (!strcasecmp(valstart
, "log"))
2220 fatal
|= CUPSD_FATAL_LOG
;
2221 else if (!strcasecmp(valstart
, "-log"))
2222 fatal
&= ~CUPSD_FATAL_LOG
;
2223 else if (!strcasecmp(valstart
, "permissions"))
2224 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2225 else if (!strcasecmp(valstart
, "-permissions"))
2226 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2227 else if (strcasecmp(valstart
, "none"))
2228 cupsdLogMessage(CUPSD_LOG_ERROR
,
2229 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2231 for (valstart
= valend
; *valstart
; valstart
++)
2232 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2241 * 'parse_groups()' - Parse system group names in a string.
2244 static int /* O - 1 on success, 0 on failure */
2245 parse_groups(const char *s
) /* I - Space-delimited groups */
2247 int status
; /* Return status */
2248 char value
[1024], /* Value string */
2249 *valstart
, /* Pointer into value */
2250 *valend
, /* End of value */
2251 quote
; /* Quote character */
2252 struct group
*group
; /* Group */
2256 * Make a copy of the string and parse out the groups...
2259 strlcpy(value
, s
, sizeof(value
));
2264 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2266 if (*valstart
== '\'' || *valstart
== '\"')
2269 * Scan quoted name...
2272 quote
= *valstart
++;
2274 for (valend
= valstart
; *valend
; valend
++)
2275 if (*valend
== quote
)
2281 * Scan space or comma-delimited name...
2284 for (valend
= valstart
; *valend
; valend
++)
2285 if (isspace(*valend
) || *valend
== ',')
2292 group
= getgrnam(valstart
);
2295 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2296 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2307 while (*valstart
== ',' || isspace(*valstart
))
2316 * 'parse_protocols()' - Parse browse protocols in a string.
2319 static int /* O - Browse protocol bits */
2320 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2322 int protocols
; /* Browse protocol bits */
2323 char value
[1024], /* Value string */
2324 *valstart
, /* Pointer into value */
2325 *valend
; /* End of value */
2329 * Empty protocol line yields NULL pointer...
2336 * Loop through the value string,...
2339 strlcpy(value
, s
, sizeof(value
));
2343 for (valstart
= value
; *valstart
;)
2346 * Get the current space/comma-delimited protocol name...
2349 for (valend
= valstart
; *valend
; valend
++)
2350 if (isspace(*valend
& 255) || *valend
== ',')
2357 * Add the protocol to the bitmask...
2360 if (!strcasecmp(valstart
, "cups"))
2361 protocols
|= BROWSE_CUPS
;
2362 else if (!strcasecmp(valstart
, "slp"))
2363 protocols
|= BROWSE_SLP
;
2364 else if (!strcasecmp(valstart
, "ldap"))
2365 protocols
|= BROWSE_LDAP
;
2366 else if (!strcasecmp(valstart
, "dnssd") ||
2367 !strcasecmp(valstart
, "dns-sd") ||
2368 !strcasecmp(valstart
, "bonjour"))
2369 protocols
|= BROWSE_DNSSD
;
2370 else if (!strcasecmp(valstart
, "lpd"))
2371 protocols
|= BROWSE_LPD
;
2372 else if (!strcasecmp(valstart
, "smb"))
2373 protocols
|= BROWSE_SMB
;
2374 else if (!strcasecmp(valstart
, "all"))
2375 protocols
|= BROWSE_ALL
;
2376 else if (strcasecmp(valstart
, "none"))
2377 cupsdLogMessage(CUPSD_LOG_ERROR
,
2378 "Unknown browse protocol \"%s\" ignored!", valstart
);
2380 for (valstart
= valend
; *valstart
; valstart
++)
2381 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2390 * 'read_configuration()' - Read a configuration file.
2393 static int /* O - 1 on success, 0 on failure */
2394 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2396 int i
; /* Looping var */
2397 int linenum
; /* Current line number */
2398 char line
[HTTP_MAX_BUFFER
],
2399 /* Line from file */
2400 temp
[HTTP_MAX_BUFFER
],
2401 /* Temporary buffer for value */
2402 temp2
[HTTP_MAX_BUFFER
],
2403 /* Temporary buffer 2 for value */
2404 *ptr
, /* Pointer into line/temp */
2405 *value
, /* Pointer to value */
2406 *valueptr
; /* Pointer into value */
2407 int valuelen
; /* Length of value */
2408 cupsd_var_t
const *var
; /* Current variable */
2409 http_addrlist_t
*addrlist
, /* Address list */
2410 *addr
; /* Current address */
2411 unsigned ip
[4], /* Address value */
2412 mask
[4]; /* Netmask value */
2413 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2414 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2415 cupsd_location_t
*location
; /* Browse location */
2416 cups_file_t
*incfile
; /* Include file */
2417 char incname
[1024]; /* Include filename */
2418 struct group
*group
; /* Group */
2422 * Loop through each line in the file...
2427 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2430 * Decode the directive...
2433 if (!strcasecmp(line
, "Include") && value
)
2439 if (value
[0] == '/')
2440 strlcpy(incname
, value
, sizeof(incname
));
2442 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2444 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2445 cupsdLogMessage(CUPSD_LOG_ERROR
,
2446 "Unable to include config file \"%s\" - %s",
2447 incname
, strerror(errno
));
2450 read_configuration(incfile
);
2451 cupsFileClose(incfile
);
2454 else if (!strcasecmp(line
, "<Location") && value
)
2460 linenum
= read_location(fp
, value
, linenum
);
2464 else if (!strcasecmp(line
, "<Policy") && value
)
2470 linenum
= read_policy(fp
, value
, linenum
);
2474 else if (!strcasecmp(line
, "FatalErrors"))
2475 FatalErrors
= parse_fatal_errors(value
);
2476 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2478 JobRetryInterval
= atoi(value
);
2479 cupsdLogMessage(CUPSD_LOG_WARN
,
2480 "FaxRetryInterval is deprecated; use "
2481 "JobRetryInterval on line %d.", linenum
);
2483 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2485 JobRetryLimit
= atoi(value
);
2486 cupsdLogMessage(CUPSD_LOG_WARN
,
2487 "FaxRetryLimit is deprecated; use "
2488 "JobRetryLimit on line %d.", linenum
);
2490 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2492 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2493 #endif /* HAVE_SSL */
2497 * Add listening address(es) to the list...
2500 cupsd_listener_t
*lis
; /* New listeners array */
2504 * Get the address list...
2507 addrlist
= get_address(value
, IPP_PORT
);
2511 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2517 * Add each address...
2520 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2523 * See if this address is already present...
2526 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2528 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2529 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2530 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2535 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2536 cupsdLogMessage(CUPSD_LOG_WARN
,
2537 "Duplicate listen address \"%s\" ignored!", temp
);
2542 * Allocate another listener...
2546 Listeners
= cupsArrayNew(NULL
, NULL
);
2550 cupsdLogMessage(CUPSD_LOG_ERROR
,
2551 "Unable to allocate %s at line %d - %s.",
2552 line
, linenum
, strerror(errno
));
2556 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2558 cupsdLogMessage(CUPSD_LOG_ERROR
,
2559 "Unable to allocate %s at line %d - %s.",
2560 line
, linenum
, strerror(errno
));
2564 cupsArrayAdd(Listeners
, lis
);
2567 * Copy the current address and log it...
2570 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2574 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2575 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2576 #endif /* HAVE_SSL */
2578 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2581 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2582 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2583 ntohs(lis
->address
.ipv6
.sin6_port
));
2585 #endif /* AF_INET6 */
2587 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2588 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2590 #endif /* AF_LOCAL */
2591 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2592 ntohs(lis
->address
.ipv4
.sin_port
));
2594 if (!httpAddrLocalhost(&(lis
->address
)))
2597 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2598 RemotePort
= ntohs(lis
->address
.ipv6
.sin6_port
);
2600 #endif /* AF_INET6 */
2601 RemotePort
= ntohs(lis
->address
.ipv4
.sin_port
);
2609 httpAddrFreeList(addrlist
);
2611 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2614 * Add a browse address to the list...
2617 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2620 if (NumBrowsers
== 0)
2621 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2623 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2627 cupsdLogMessage(CUPSD_LOG_ERROR
,
2628 "Unable to allocate BrowseAddress at line %d - %s.",
2629 linenum
, strerror(errno
));
2634 dira
+= NumBrowsers
;
2636 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2638 if (!strcasecmp(value
, "@LOCAL"))
2641 * Send browse data to all local interfaces...
2644 strcpy(dira
->iface
, "*");
2647 else if (!strncasecmp(value
, "@IF(", 4))
2650 * Send browse data to the named interface...
2653 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2655 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2661 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2664 * Only IPv4 addresses are supported...
2667 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2668 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2673 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2674 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2676 cupsdLogMessage(CUPSD_LOG_INFO
,
2677 "Sending browsing info to %s:%d (IPv4)",
2678 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2683 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2686 httpAddrFreeList(addrlist
);
2689 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2692 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2695 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2698 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2699 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2701 if (location
== NULL
)
2702 cupsdLogMessage(CUPSD_LOG_ERROR
,
2703 "Unable to initialize browse access control list!");
2704 else if (!strncasecmp(value
, "deny", 4))
2705 location
->order_type
= CUPSD_AUTH_ALLOW
;
2706 else if (!strncasecmp(value
, "allow", 5))
2707 location
->order_type
= CUPSD_AUTH_DENY
;
2709 cupsdLogMessage(CUPSD_LOG_ERROR
,
2710 "Unknown BrowseOrder value %s on line %d.",
2713 else if (!strcasecmp(line
, "BrowseProtocols") ||
2714 !strcasecmp(line
, "BrowseLocalProtocols") ||
2715 !strcasecmp(line
, "BrowseRemoteProtocols"))
2718 * "BrowseProtocols name [... name]"
2719 * "BrowseLocalProtocols name [... name]"
2720 * "BrowseRemoteProtocols name [... name]"
2723 int protocols
= parse_protocols(value
);
2727 cupsdLogMessage(CUPSD_LOG_ERROR
,
2728 "Unknown browse protocol \"%s\" on line %d.",
2733 if (strcasecmp(line
, "BrowseLocalProtocols"))
2734 BrowseRemoteProtocols
= protocols
;
2735 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2736 BrowseLocalProtocols
= protocols
;
2738 else if ((!strcasecmp(line
, "BrowseAllow") ||
2739 !strcasecmp(line
, "BrowseDeny")) && value
)
2742 * BrowseAllow [From] host/ip...
2743 * BrowseDeny [From] host/ip...
2746 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2747 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2749 if (location
== NULL
)
2750 cupsdLogMessage(CUPSD_LOG_ERROR
,
2751 "Unable to initialize browse access control list!");
2756 if (!strncasecmp(value
, "from", 4))
2759 * Strip leading "from"...
2764 while (isspace(*value
& 255))
2772 * Find the end of the value...
2775 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2777 while (isspace(*valueptr
& 255))
2781 * Figure out what form the allow/deny address takes:
2792 * nnn.nnn.nnn.nnn/mm
2793 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2796 if (!strcasecmp(value
, "all"))
2802 if (!strcasecmp(line
, "BrowseAllow"))
2803 cupsdAllowIP(location
, zeros
, zeros
);
2805 cupsdDenyIP(location
, zeros
, zeros
);
2807 else if (!strcasecmp(value
, "none"))
2813 if (!strcasecmp(line
, "BrowseAllow"))
2814 cupsdAllowIP(location
, ones
, zeros
);
2816 cupsdDenyIP(location
, ones
, zeros
);
2819 else if (value
[0] == '*' || value
[0] == '.' ||
2820 (!isdigit(value
[0] & 255) && value
[0] != '['))
2822 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2823 #endif /* AF_INET6 */
2826 * Host or domain name...
2829 if (value
[0] == '*')
2832 if (!strcasecmp(line
, "BrowseAllow"))
2833 cupsdAllowHost(location
, value
);
2835 cupsdDenyHost(location
, value
);
2840 * One of many IP address forms...
2843 if (!get_addr_and_mask(value
, ip
, mask
))
2845 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2850 if (!strcasecmp(line
, "BrowseAllow"))
2851 cupsdAllowIP(location
, ip
, mask
);
2853 cupsdDenyIP(location
, ip
, mask
);
2857 * Advance to next value...
2864 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2867 * BrowseRelay [from] source [to] destination
2871 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2873 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2877 cupsdLogMessage(CUPSD_LOG_ERROR
,
2878 "Unable to allocate BrowseRelay at line %d - %s.",
2879 linenum
, strerror(errno
));
2886 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2888 if (!strncasecmp(value
, "from ", 5))
2891 * Strip leading "from"...
2896 while (isspace(*value
))
2901 * Figure out what form the from address takes:
2910 * nnn.nnn.nnn.nnn/mm
2911 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2915 if (value
[0] == '*' || value
[0] == '.' ||
2916 (!isdigit(value
[0] & 255) && value
[0] != '['))
2918 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2919 #endif /* AF_INET6 */
2922 * Host or domain name...
2925 if (value
[0] == '*')
2928 strlcpy(temp
, value
, sizeof(temp
));
2929 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2932 relay
->from
.type
= CUPSD_AUTH_NAME
;
2934 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2936 cupsdLogMessage(CUPSD_LOG_ERROR
,
2937 "Unable to allocate BrowseRelay name at line %d - %s.",
2938 linenum
, strerror(errno
));
2942 relay
->from
.mask
.name
.length
= strlen(temp
);
2947 * One of many IP address forms...
2950 if (!get_addr_and_mask(value
, ip
, mask
))
2952 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2957 relay
->from
.type
= CUPSD_AUTH_IP
;
2958 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2959 sizeof(relay
->from
.mask
.ip
.address
));
2960 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2961 sizeof(relay
->from
.mask
.ip
.netmask
));
2965 * Skip value and trailing whitespace...
2968 for (; *value
; value
++)
2969 if (isspace(*value
))
2972 while (isspace(*value
))
2975 if (!strncasecmp(value
, "to ", 3))
2978 * Strip leading "to"...
2983 while (isspace(*value
))
2988 * Get "to" address and port...
2991 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2994 * Only IPv4 addresses are supported...
2997 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2998 if (addr
->addr
.addr
.sa_family
== AF_INET
)
3003 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
3005 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
3007 if (relay
->from
.type
== CUPSD_AUTH_IP
)
3008 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
3009 relay
->from
.mask
.ip
.address
[0] >> 24,
3010 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
3011 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
3012 relay
->from
.mask
.ip
.address
[0] & 255,
3013 relay
->from
.mask
.ip
.netmask
[0] >> 24,
3014 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
3015 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
3016 relay
->from
.mask
.ip
.netmask
[0] & 255);
3018 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
3020 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
3021 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
3026 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3029 httpAddrFreeList(addrlist
);
3033 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
3034 free(relay
->from
.mask
.name
.name
);
3036 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3040 else if (!strcasecmp(line
, "BrowsePoll") && value
)
3043 * BrowsePoll address[:port]
3046 char *portname
; /* Port name */
3047 int portnum
; /* Port number */
3048 struct servent
*service
; /* Service */
3052 * Extract the port name from the address...
3055 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
3059 if (isdigit(*portname
& 255))
3060 portnum
= atoi(portname
);
3061 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
3062 portnum
= ntohs(service
->s_port
);
3065 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
3071 portnum
= ippPort();
3074 * Add the poll entry...
3078 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
3080 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
3084 cupsdLogMessage(CUPSD_LOG_ERROR
,
3085 "Unable to allocate BrowsePoll at line %d - %s.",
3086 linenum
, strerror(errno
));
3094 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
3096 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
3097 pollp
->port
= portnum
;
3099 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
3102 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
3105 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3108 if (!strcasecmp(value
, "none"))
3109 DefaultAuthType
= CUPSD_AUTH_NONE
;
3110 else if (!strcasecmp(value
, "basic"))
3111 DefaultAuthType
= CUPSD_AUTH_BASIC
;
3112 else if (!strcasecmp(value
, "digest"))
3113 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
3114 else if (!strcasecmp(value
, "basicdigest"))
3115 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
3117 else if (!strcasecmp(value
, "negotiate"))
3118 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
3119 #endif /* HAVE_GSSAPI */
3122 cupsdLogMessage(CUPSD_LOG_WARN
,
3123 "Unknown default authorization type %s on line %d.",
3125 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3130 else if (!strcasecmp(line
, "DefaultEncryption"))
3133 * DefaultEncryption {Never,IfRequested,Required}
3136 if (!value
|| !strcasecmp(value
, "never"))
3137 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3138 else if (!strcasecmp(value
, "required"))
3139 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3140 else if (!strcasecmp(value
, "ifrequested"))
3141 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3144 cupsdLogMessage(CUPSD_LOG_WARN
,
3145 "Unknown default encryption %s on line %d.",
3147 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3151 #endif /* HAVE_SSL */
3152 else if (!strcasecmp(line
, "User") && value
)
3155 * User ID to run as...
3158 if (isdigit(value
[0] & 255))
3160 int uid
= atoi(value
);
3163 cupsdLogMessage(CUPSD_LOG_ERROR
,
3164 "Will not use User 0 as specified on line %d "
3165 "for security reasons. You must use a non-"
3166 "privileged account instead.",
3173 struct passwd
*p
; /* Password information */
3176 p
= getpwnam(value
);
3181 cupsdLogMessage(CUPSD_LOG_ERROR
,
3182 "Will not use User %s (UID=0) as specified on line "
3183 "%d for security reasons. You must use a non-"
3184 "privileged account instead.",
3190 cupsdLogMessage(CUPSD_LOG_ERROR
,
3191 "Unknown User \"%s\" on line %d, ignoring!",
3195 else if (!strcasecmp(line
, "Group") && value
)
3198 * Group ID to run as...
3201 if (isdigit(value
[0]))
3202 Group
= atoi(value
);
3206 group
= getgrnam(value
);
3209 Group
= group
->gr_gid
;
3211 cupsdLogMessage(CUPSD_LOG_ERROR
,
3212 "Unknown Group \"%s\" on line %d, ignoring!",
3216 else if (!strcasecmp(line
, "SystemGroup") && value
)
3219 * SystemGroup (admin) group(s)...
3222 if (!parse_groups(value
))
3223 cupsdLogMessage(CUPSD_LOG_ERROR
,
3224 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3227 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3230 * Do hostname lookups?
3233 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3234 !strcasecmp(value
, "false"))
3235 HostNameLookups
= 0;
3236 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3237 !strcasecmp(value
, "true"))
3238 HostNameLookups
= 1;
3239 else if (!strcasecmp(value
, "double"))
3240 HostNameLookups
= 2;
3242 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3245 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3248 * Amount of logging to do to access log...
3251 if (!strcasecmp(value
, "all"))
3252 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3253 else if (!strcasecmp(value
, "actions"))
3254 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3255 else if (!strcasecmp(value
, "config"))
3256 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3258 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3261 else if (!strcasecmp(line
, "LogLevel") && value
)
3264 * Amount of logging to do to error log...
3267 if (!strcasecmp(value
, "debug2"))
3268 LogLevel
= CUPSD_LOG_DEBUG2
;
3269 else if (!strcasecmp(value
, "debug"))
3270 LogLevel
= CUPSD_LOG_DEBUG
;
3271 else if (!strcasecmp(value
, "info"))
3272 LogLevel
= CUPSD_LOG_INFO
;
3273 else if (!strcasecmp(value
, "notice"))
3274 LogLevel
= CUPSD_LOG_NOTICE
;
3275 else if (!strcasecmp(value
, "warn"))
3276 LogLevel
= CUPSD_LOG_WARN
;
3277 else if (!strcasecmp(value
, "error"))
3278 LogLevel
= CUPSD_LOG_ERROR
;
3279 else if (!strcasecmp(value
, "crit"))
3280 LogLevel
= CUPSD_LOG_CRIT
;
3281 else if (!strcasecmp(value
, "alert"))
3282 LogLevel
= CUPSD_LOG_ALERT
;
3283 else if (!strcasecmp(value
, "emerg"))
3284 LogLevel
= CUPSD_LOG_EMERG
;
3285 else if (!strcasecmp(value
, "none"))
3286 LogLevel
= CUPSD_LOG_NONE
;
3288 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3291 else if (!strcasecmp(line
, "LogTimeFormat") && value
)
3294 * Amount of logging to do to error log...
3297 if (!strcasecmp(value
, "standard"))
3298 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3299 else if (!strcasecmp(value
, "usecs"))
3300 LogTimeFormat
= CUPSD_TIME_USECS
;
3302 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3305 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3308 * Format of printcap file?
3311 if (!strcasecmp(value
, "bsd"))
3312 PrintcapFormat
= PRINTCAP_BSD
;
3313 else if (!strcasecmp(value
, "plist"))
3314 PrintcapFormat
= PRINTCAP_PLIST
;
3315 else if (!strcasecmp(value
, "solaris"))
3316 PrintcapFormat
= PRINTCAP_SOLARIS
;
3318 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3321 else if (!strcasecmp(line
, "ServerTokens") && value
)
3324 * Set the string used for the Server header...
3327 struct utsname plat
; /* Platform info */
3332 if (!strcasecmp(value
, "ProductOnly"))
3333 cupsdSetString(&ServerHeader
, "CUPS");
3334 else if (!strcasecmp(value
, "Major"))
3335 cupsdSetString(&ServerHeader
, "CUPS/1");
3336 else if (!strcasecmp(value
, "Minor"))
3337 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3338 else if (!strcasecmp(value
, "Minimal"))
3339 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3340 else if (!strcasecmp(value
, "OS"))
3341 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3342 else if (!strcasecmp(value
, "Full"))
3343 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3345 else if (!strcasecmp(value
, "None"))
3346 cupsdClearString(&ServerHeader
);
3348 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3351 else if (!strcasecmp(line
, "PassEnv") && value
)
3354 * PassEnv variable [... variable]
3359 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3360 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3363 if (value
[valuelen
])
3365 value
[valuelen
] = '\0';
3369 cupsdSetEnv(value
, NULL
);
3371 for (value
+= valuelen
; *value
; value
++)
3372 if (!isspace(*value
) || *value
!= ',')
3376 else if (!strcasecmp(line
, "ServerAlias") && value
)
3379 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3381 cupsdAddAlias(ServerAlias
, value
);
3383 else if (!strcasecmp(line
, "SetEnv") && value
)
3386 * SetEnv variable value
3389 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3397 while (isspace(*valueptr
& 255))
3400 cupsdSetEnv(value
, valueptr
);
3403 cupsdLogMessage(CUPSD_LOG_ERROR
,
3404 "Missing value for SetEnv directive on line %d.",
3408 else if (!strcasecmp(line
, "SSLOptions"))
3411 * SSLOptions options
3414 if (!value
|| !strcasecmp(value
, "none"))
3415 SSLOptions
= CUPSD_SSL_NONE
;
3416 else if (!strcasecmp(value
, "noemptyfragments"))
3417 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3419 cupsdLogMessage(CUPSD_LOG_ERROR
,
3420 "Unknown value \"%s\" for SSLOptions directive on "
3421 "line %d.", value
, linenum
);
3423 #endif /* HAVE_SSL */
3427 * Find a simple variable in the list...
3430 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3431 if (!strcasecmp(line
, var
->name
))
3437 * Unknown directive! Output an error message and continue...
3441 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3444 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3451 case CUPSD_VARTYPE_INTEGER
:
3453 cupsdLogMessage(CUPSD_LOG_ERROR
,
3454 "Missing integer value for %s on line %d!",
3459 char *units
; /* Units */
3462 n
= strtol(value
, &units
, 0);
3464 if (units
&& *units
)
3466 if (tolower(units
[0] & 255) == 'g')
3467 n
*= 1024 * 1024 * 1024;
3468 else if (tolower(units
[0] & 255) == 'm')
3470 else if (tolower(units
[0] & 255) == 'k')
3472 else if (tolower(units
[0] & 255) == 't')
3477 cupsdLogMessage(CUPSD_LOG_ERROR
,
3478 "Bad negative integer value for %s on line %d!",
3481 *((int *)var
->ptr
) = n
;
3485 case CUPSD_VARTYPE_BOOLEAN
:
3487 cupsdLogMessage(CUPSD_LOG_ERROR
,
3488 "Missing boolean value for %s on line %d!",
3490 else if (!strcasecmp(value
, "true") ||
3491 !strcasecmp(value
, "on") ||
3492 !strcasecmp(value
, "enabled") ||
3493 !strcasecmp(value
, "yes") ||
3495 *((int *)var
->ptr
) = TRUE
;
3496 else if (!strcasecmp(value
, "false") ||
3497 !strcasecmp(value
, "off") ||
3498 !strcasecmp(value
, "disabled") ||
3499 !strcasecmp(value
, "no") ||
3500 !strcasecmp(value
, "0"))
3501 *((int *)var
->ptr
) = FALSE
;
3503 cupsdLogMessage(CUPSD_LOG_ERROR
,
3504 "Unknown boolean value %s on line %d.",
3508 case CUPSD_VARTYPE_PATHNAME
:
3511 cupsdLogMessage(CUPSD_LOG_ERROR
,
3512 "Missing pathname value for %s on line %d!",
3517 if (value
[0] == '/')
3518 strlcpy(temp
, value
, sizeof(temp
));
3520 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3522 if (access(temp
, 0))
3524 cupsdLogMessage(CUPSD_LOG_ERROR
,
3525 "File or directory for \"%s %s\" on line %d "
3526 "does not exist!", line
, value
, linenum
);
3530 case CUPSD_VARTYPE_STRING
:
3531 cupsdSetString((char **)var
->ptr
, value
);
3542 * 'read_location()' - Read a <Location path> definition.
3545 static int /* O - New line number or 0 on error */
3546 read_location(cups_file_t
*fp
, /* I - Configuration file */
3547 char *location
, /* I - Location name/path */
3548 int linenum
) /* I - Current line number */
3550 cupsd_location_t
*loc
, /* New location */
3551 *parent
; /* Parent location */
3552 char line
[HTTP_MAX_BUFFER
],
3554 *value
, /* Value for directive */
3555 *valptr
; /* Pointer into value */
3558 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3561 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3564 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3567 * Decode the directive...
3570 if (!strcasecmp(line
, "</Location>"))
3572 else if (!strcasecmp(line
, "<Limit") ||
3573 !strcasecmp(line
, "<LimitExcept"))
3577 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3578 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3584 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3590 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3595 if (!strcmp(value
, "ALL"))
3596 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3597 else if (!strcmp(value
, "GET"))
3598 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3599 else if (!strcmp(value
, "HEAD"))
3600 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3601 else if (!strcmp(value
, "OPTIONS"))
3602 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3603 else if (!strcmp(value
, "POST"))
3604 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3605 else if (!strcmp(value
, "PUT"))
3606 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3607 else if (!strcmp(value
, "TRACE"))
3608 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3610 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3613 for (value
= valptr
; isspace(*value
& 255); value
++);
3616 if (!strcasecmp(line
, "<LimitExcept"))
3617 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3619 parent
->limit
&= ~loc
->limit
;
3621 else if (!strcasecmp(line
, "</Limit>") ||
3622 !strcasecmp(line
, "</LimitExcept>"))
3624 else if (!parse_aaa(loc
, line
, value
, linenum
))
3626 cupsdLogMessage(CUPSD_LOG_ERROR
,
3627 "Unknown Location directive %s on line %d.",
3629 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3634 cupsdLogMessage(CUPSD_LOG_ERROR
,
3635 "Unexpected end-of-file at line %d while reading location!",
3638 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3643 * 'read_policy()' - Read a <Policy name> definition.
3646 static int /* O - New line number or 0 on error */
3647 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3648 char *policy
, /* I - Location name/path */
3649 int linenum
) /* I - Current line number */
3651 int i
; /* Looping var */
3652 cupsd_policy_t
*pol
; /* Policy */
3653 cupsd_location_t
*op
; /* Policy operation */
3654 int num_ops
; /* Number of IPP operations */
3655 ipp_op_t ops
[100]; /* Operations */
3656 char line
[HTTP_MAX_BUFFER
],
3658 *value
, /* Value for directive */
3659 *valptr
; /* Pointer into value */
3663 * Create the policy...
3666 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3670 * Read from the file...
3676 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3679 * Decode the directive...
3682 if (!strcasecmp(line
, "</Policy>"))
3685 cupsdLogMessage(CUPSD_LOG_WARN
,
3686 "Missing </Limit> before </Policy> on line %d!",
3690 * Verify that we have an explicit policy for CUPS-Get-Document
3691 * (ensures that upgrades do not introduce new security issues...)
3694 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3695 op
->op
== IPP_ANY_OPERATION
)
3697 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3698 op
->op
!= IPP_ANY_OPERATION
)
3701 * Add a new limit for CUPS-Get-Document using the Send-Document
3702 * limit as a template...
3705 cupsdLogMessage(CUPSD_LOG_WARN
,
3706 "No limit for CUPS-Get-Document defined in policy %s "
3707 "- using Send-Document's policy", pol
->name
);
3709 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3715 else if (!strcasecmp(line
, "<Limit") && !op
)
3719 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3720 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3727 * Scan for IPP operation names...
3734 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3739 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3741 if (!strcasecmp(value
, "All"))
3742 ops
[num_ops
] = IPP_ANY_OPERATION
;
3743 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3744 cupsdLogMessage(CUPSD_LOG_ERROR
,
3745 "Bad IPP operation name \"%s\" on line %d!",
3751 cupsdLogMessage(CUPSD_LOG_ERROR
,
3752 "Too many operations listed on line %d!",
3755 for (value
= valptr
; isspace(*value
& 255); value
++);
3759 * If none are specified, apply the policy to all operations...
3764 ops
[0] = IPP_ANY_OPERATION
;
3769 * Add a new policy for the first operation...
3772 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3774 else if (!strcasecmp(line
, "</Limit>") && op
)
3777 * Finish the current operation limit...
3783 * Copy the policy to the other operations...
3786 for (i
= 1; i
< num_ops
; i
++)
3787 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3794 cupsdLogMessage(CUPSD_LOG_ERROR
,
3795 "Missing <Limit ops> directive before %s on line %d.",
3797 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3800 else if (!parse_aaa(op
, line
, value
, linenum
))
3803 cupsdLogMessage(CUPSD_LOG_ERROR
,
3804 "Unknown Policy Limit directive %s on line %d.",
3807 cupsdLogMessage(CUPSD_LOG_ERROR
,
3808 "Unknown Policy directive %s on line %d.",
3811 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3816 cupsdLogMessage(CUPSD_LOG_ERROR
,
3817 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3820 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3825 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".