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 * Possibly missing network definitions...
50 # define INADDR_NONE 0xffffffff
51 #endif /* !INADDR_NONE */
55 * Configuration variable structure...
60 CUPSD_VARTYPE_INTEGER
, /* Integer option */
61 CUPSD_VARTYPE_STRING
, /* String option */
62 CUPSD_VARTYPE_BOOLEAN
, /* Boolean option */
63 CUPSD_VARTYPE_PATHNAME
/* File/directory name option */
68 char *name
; /* Name of variable */
69 void *ptr
; /* Pointer to variable */
70 cupsd_vartype_t type
; /* Type (int, string, address) */
78 static const cupsd_var_t variables
[] =
80 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
82 { "AppleQuotas", &AppleQuotas
, CUPSD_VARTYPE_BOOLEAN
},
83 #endif /* __APPLE__ */
84 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
85 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
87 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
89 { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile
, CUPSD_VARTYPE_PATHNAME
},
90 # endif /* HAVE_LDAP_SSL */
91 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
92 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
93 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
94 #endif /* HAVE_LDAP */
95 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
96 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
97 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
98 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
99 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
100 { "BrowseWebIF", &BrowseWebIF
, CUPSD_VARTYPE_BOOLEAN
},
101 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
102 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
103 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
104 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
105 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
106 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
107 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
108 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
109 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
110 { "DefaultPaperSize", &DefaultPaperSize
, CUPSD_VARTYPE_STRING
},
111 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
112 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
113 { "DirtyCleanInterval", &DirtyCleanInterval
, CUPSD_VARTYPE_INTEGER
},
114 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
115 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
116 { "ErrorPolicy", &ErrorPolicy
, CUPSD_VARTYPE_STRING
},
117 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
118 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
119 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
120 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
121 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
122 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
123 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
124 { "JobKillDelay", &JobKillDelay
, CUPSD_VARTYPE_INTEGER
},
125 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
126 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
127 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
128 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
130 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
131 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
132 #endif /* HAVE_LAUNCHD */
133 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
134 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
135 { "LogDebugHistory", &LogDebugHistory
, CUPSD_VARTYPE_INTEGER
},
136 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
137 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
138 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
151 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
152 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
153 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
154 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
155 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
156 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
157 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
158 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
159 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
160 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
161 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
162 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
163 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
164 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
165 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
166 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
167 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
169 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
170 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
171 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
172 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
173 #endif /* HAVE_SSL */
174 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
175 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
176 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
177 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
178 #ifdef HAVE_AUTHORIZATION_H
179 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
180 #endif /* HAVE_AUTHORIZATION_H */
181 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
182 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
183 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
185 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
188 static const unsigned ones
[4] =
190 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
192 static const unsigned zeros
[4] =
194 0x00000000, 0x00000000, 0x00000000, 0x00000000
202 static http_addrlist_t
*get_address(const char *value
, int defport
);
203 static int get_addr_and_mask(const char *value
, unsigned *ip
,
205 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
206 char *value
, int linenum
);
207 static int parse_fatal_errors(const char *s
);
208 static int parse_groups(const char *s
);
209 static int parse_protocols(const char *s
);
210 static int read_configuration(cups_file_t
*fp
);
211 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
212 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
216 * 'cupsdAddAlias()' - Add a host alias.
220 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
221 const char *name
) /* I - Name to add */
223 cupsd_alias_t
*a
; /* New alias */
224 size_t namelen
; /* Length of name */
227 namelen
= strlen(name
);
229 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
232 a
->namelen
= namelen
;
233 strcpy(a
->name
, name
); /* OK since a->name is allocated */
235 cupsArrayAdd(aliases
, a
);
240 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
243 int /* O - 0 on success, -1 on error, 1 on warning */
244 cupsdCheckPermissions(
245 const char *filename
, /* I - File/directory name */
246 const char *suffix
, /* I - Additional file/directory name */
247 int mode
, /* I - Permissions */
248 int user
, /* I - Owner */
249 int group
, /* I - Group */
250 int is_dir
, /* I - 1 = directory, 0 = file */
251 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
253 int dir_created
= 0; /* Did we create a directory? */
254 char pathname
[1024]; /* File name with prefix */
255 struct stat fileinfo
; /* Stat buffer */
256 int is_symlink
; /* Is "filename" a symlink? */
260 * Prepend the given root to the filename before testing it...
265 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
270 * See if we can stat the file/directory...
273 if (lstat(filename
, &fileinfo
))
275 if (errno
== ENOENT
&& create_dir
)
278 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
281 if (mkdir(filename
, mode
))
284 cupsdLogMessage(CUPSD_LOG_ERROR
,
285 "Unable to create directory \"%s\" - %s", filename
,
288 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
295 fileinfo
.st_mode
= mode
| S_IFDIR
;
298 return (create_dir
? -1 : 1);
301 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
303 if (stat(filename
, &fileinfo
))
305 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
306 filename
, strerror(errno
));
312 * Make sure it's a regular file or a directory as needed...
315 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
317 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
321 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
324 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
326 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
332 * If the filename is a symlink, do not change permissions (STR #2937)...
339 * Fix owner, group, and mode as needed...
342 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
345 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
348 if (chown(filename
, user
, group
) && !getuid())
351 cupsdLogMessage(CUPSD_LOG_ERROR
,
352 "Unable to change ownership of \"%s\" - %s", filename
,
355 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
362 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
365 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
368 if (chmod(filename
, mode
))
371 cupsdLogMessage(CUPSD_LOG_ERROR
,
372 "Unable to change permissions of \"%s\" - %s", filename
,
375 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
383 * Everything is OK...
391 * 'cupsdFreeAliases()' - Free all of the alias entries.
395 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
397 cupsd_alias_t
*a
; /* Current alias */
400 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
402 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
405 cupsArrayDelete(aliases
);
410 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
413 int /* O - 1 on success, 0 otherwise */
414 cupsdReadConfiguration(void)
416 int i
; /* Looping var */
417 cups_file_t
*fp
; /* Configuration file */
418 int status
; /* Return status */
419 char temp
[1024], /* Temporary buffer */
420 mimedir
[1024], /* MIME directory */
421 *slash
; /* Directory separator */
422 cups_lang_t
*language
; /* Language */
423 struct passwd
*user
; /* Default user */
424 struct group
*group
; /* Default group */
425 char *old_serverroot
, /* Old ServerRoot */
426 *old_requestroot
; /* Old RequestRoot */
427 int old_remote_port
; /* Old RemotePort */
428 const char *tmpdir
; /* TMPDIR environment variable */
429 struct stat tmpinfo
; /* Temporary directory info */
430 cupsd_policy_t
*p
; /* Policy */
434 * Save the old root paths...
437 old_serverroot
= NULL
;
438 cupsdSetString(&old_serverroot
, ServerRoot
);
439 old_requestroot
= NULL
;
440 cupsdSetString(&old_requestroot
, RequestRoot
);
443 * Reset the server configuration data...
446 cupsdDeleteAllLocations();
465 for (i
= 0; i
< NumRelays
; i
++)
466 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
467 free(Relays
[i
].from
.mask
.name
.name
);
474 cupsdDeleteAllListeners();
476 old_remote_port
= RemotePort
;
483 cupsdFreeAliases(ServerAlias
);
486 cupsdClearString(&ServerName
);
487 cupsdClearString(&ServerAdmin
);
488 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
489 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
490 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
491 cupsdSetString(&DataDir
, CUPS_DATADIR
);
492 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
493 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
494 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
495 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
496 cupsdSetString(&PageLogFormat
,
497 "%p %j %u %T %P %C %{job-billing} "
498 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
499 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
500 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
501 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
502 cupsdSetString(&RemoteRoot
, "remroot");
503 cupsdSetString(&ServerHeader
, "CUPS/1.4");
504 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
506 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
507 PrintcapFormat
= PRINTCAP_SOLARIS
;
508 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
509 "/Library/Preferences/org.cups.printers.plist"))
510 PrintcapFormat
= PRINTCAP_PLIST
;
512 PrintcapFormat
= PRINTCAP_BSD
;
514 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
515 if ((slash
= strrchr(temp
, '/')) != NULL
)
518 cupsdSetString(&ServerRoot
, temp
);
520 cupsdClearString(&Classification
);
521 ClassifyOverride
= 0;
525 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
527 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
528 cupsdSetString(&ServerKey
, "ssl/server.key");
529 # endif /* HAVE_CDSASSL */
530 #endif /* HAVE_SSL */
532 language
= cupsLangDefault();
534 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
535 cupsdSetString(&DefaultLanguage
, "en");
537 cupsdSetString(&DefaultLanguage
, language
->language
);
539 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
541 cupsdClearString(&DefaultPaperSize
);
543 cupsdSetString(&RIPCache
, "8m");
545 cupsdSetString(&TempDir
, NULL
);
548 * Find the default user...
551 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
556 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
557 * complement number...)
566 * Find the default group...
569 group
= getgrnam(CUPS_DEFAULT_GROUP
);
573 Group
= group
->gr_gid
;
577 * Fallback to group "nobody"...
580 group
= getgrnam("nobody");
584 Group
= group
->gr_gid
;
588 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
589 * complement number...)
600 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
601 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
602 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
603 DefaultAuthType
= CUPSD_AUTH_BASIC
;
605 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
606 SSLOptions
= CUPSD_SSL_NONE
;
607 #endif /* HAVE_SSL */
608 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
609 JobKillDelay
= DEFAULT_TIMEOUT
;
611 JobRetryInterval
= 300;
616 HostNameLookups
= FALSE
;
617 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
618 ImplicitAnyClasses
= FALSE
;
619 HideImplicitMembers
= TRUE
;
621 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
622 ListenBackLog
= SOMAXCONN
;
623 LogDebugHistory
= 200;
624 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
625 LogLevel
= CUPSD_LOG_WARN
;
626 LogTimeFormat
= CUPSD_TIME_STANDARD
;
628 MaxClientsPerHost
= 0;
629 MaxLogSize
= 1024 * 1024;
630 MaxPrinterHistory
= 10;
632 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
633 ReloadTimeout
= DEFAULT_KEEPALIVE
;
634 RootCertDuration
= 300;
635 Timeout
= DEFAULT_TIMEOUT
;
638 BrowseInterval
= DEFAULT_INTERVAL
;
639 BrowsePort
= ippPort();
640 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
641 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
642 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
643 BrowseTimeout
= DEFAULT_TIMEOUT
;
645 Browsing
= CUPS_DEFAULT_BROWSING
;
646 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
648 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
649 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
651 cupsdClearString(&BrowseLocalOptions
);
652 cupsdClearString(&BrowseRemoteOptions
);
654 cupsdSetString(&ErrorPolicy
, "stop-printer");
657 cupsdClearString(&BrowseLDAPBindDN
);
658 cupsdClearString(&BrowseLDAPDN
);
659 cupsdClearString(&BrowseLDAPPassword
);
660 cupsdClearString(&BrowseLDAPServer
);
661 # ifdef HAVE_LDAP_SSL
662 cupsdClearString(&BrowseLDAPCACertFile
);
663 # endif /* HAVE_LDAP_SSL */
664 #endif /* HAVE_LDAP */
666 JobHistory
= DEFAULT_HISTORY
;
667 JobFiles
= DEFAULT_FILES
;
672 MaxJobsPerPrinter
= 0;
673 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
675 cupsdDeleteAllPolicies();
676 cupsdClearString(&DefaultPolicy
);
678 #ifdef HAVE_AUTHORIZATION_H
679 cupsdClearString(&SystemGroupAuthKey
);
680 #endif /* HAVE_AUTHORIZATION_H */
682 MaxSubscriptions
= 100;
683 MaxSubscriptionsPerJob
= 0;
684 MaxSubscriptionsPerPrinter
= 0;
685 MaxSubscriptionsPerUser
= 0;
686 DefaultLeaseDuration
= 86400;
687 MaxLeaseDuration
= 0;
690 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
691 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
692 #endif /* HAVE_LAUNCHD */
696 #endif /* __APPLE__ */
699 * Read the configuration file...
702 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
705 status
= read_configuration(fp
);
714 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
715 RemotePort
? "enabled" : "disabled");
718 * See if the ServerName is an IP address...
724 ServerAlias
= cupsArrayNew(NULL
, NULL
);
726 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
730 if (gethostname(temp
, sizeof(temp
)))
732 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
734 strlcpy(temp
, "localhost", sizeof(temp
));
737 cupsdSetString(&ServerName
, temp
);
740 ServerAlias
= cupsArrayNew(NULL
, NULL
);
742 cupsdAddAlias(ServerAlias
, temp
);
743 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
745 if (HostNameLookups
|| RemotePort
)
747 struct hostent
*host
; /* Host entry to get FQDN */
749 if ((host
= gethostbyname(temp
)) != NULL
)
751 if (strcasecmp(temp
, host
->h_name
))
753 cupsdSetString(&ServerName
, host
->h_name
);
754 cupsdAddAlias(ServerAlias
, host
->h_name
);
755 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
761 for (i
= 0; host
->h_aliases
[i
]; i
++)
762 if (strcasecmp(temp
, host
->h_aliases
[i
]))
764 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
765 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
773 * Make sure we have the base hostname added as an alias, too!
776 if ((slash
= strchr(temp
, '.')) != NULL
)
779 cupsdAddAlias(ServerAlias
, temp
);
780 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
784 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
786 ServerNameIsIP
= !*slash
;
789 * Make sure ServerAdmin is initialized...
793 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
796 * Use the default system group if none was supplied in cupsd.conf...
799 if (NumSystemGroups
== 0)
801 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
804 * Find the group associated with GID 0...
811 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
813 cupsdSetString(&SystemGroups
[0], "unknown");
815 SystemGroupIDs
[0] = 0;
821 * Get the access control list for browsing...
824 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
827 * Open the system log for cupsd if necessary...
831 if (!strcmp(AccessLog
, "syslog") ||
832 !strcmp(ErrorLog
, "syslog") ||
833 !strcmp(PageLog
, "syslog"))
834 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
835 #endif /* HAVE_VSYSLOG */
838 * Log the configuration file that was used...
841 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
845 * Validate the Group and SystemGroup settings - they cannot be the same,
846 * otherwise the CGI programs will be able to authenticate as root without
852 for (i
= 0; i
< NumSystemGroups
; i
++)
853 if (Group
== SystemGroupIDs
[i
])
856 if (i
< NumSystemGroups
)
859 * Log the error and reset the group to a safe value...
862 cupsdLogMessage(CUPSD_LOG_NOTICE
,
863 "Group and SystemGroup cannot use the same groups!");
864 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
866 group
= getgrnam("nobody");
870 Group
= group
->gr_gid
;
874 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
875 * complement number...)
884 * Check that we have at least one listen/port line; if not, report this
885 * as an error and exit!
888 if (cupsArrayCount(Listeners
) == 0)
894 cupsdLogMessage(CUPSD_LOG_EMERG
,
895 "No valid Listen or Port lines were found in the "
896 "configuration file!");
902 cupsdEndProcess(getpid(), 0);
906 * Set the default locale using the language and charset...
909 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
912 * Update all relative filenames to include the full path from ServerRoot...
915 if (DocumentRoot
[0] != '/')
916 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
918 if (RequestRoot
[0] != '/')
919 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
921 if (ServerBin
[0] != '/')
922 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
924 if (StateDir
[0] != '/')
925 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
927 if (CacheDir
[0] != '/')
928 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
931 if (ServerCertificate
[0] != '/')
932 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
934 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
935 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
937 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
940 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
941 if (ServerKey
[0] != '/')
942 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
944 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
945 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
946 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
948 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
949 #endif /* HAVE_SSL */
952 * Make sure that directories and config files are owned and
953 * writable by the user and group in the cupsd.conf file...
956 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
958 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
960 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
962 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
964 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
966 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
967 SystemGroupIDs
[0], 1, 1) < 0 ||
968 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
970 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
972 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
974 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
976 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
978 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
980 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
982 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
986 * Update TempDir to the default if it hasn't been set already...
991 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
994 * TMPDIR is defined, see if it is OK for us to use...
997 if (stat(tmpdir
, &tmpinfo
))
998 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
999 tmpdir
, strerror(errno
));
1000 else if (!S_ISDIR(tmpinfo
.st_mode
))
1001 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
1003 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1004 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1005 !(tmpinfo
.st_mode
& S_IWOTH
))
1006 cupsdLogMessage(CUPSD_LOG_ERROR
,
1007 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
1009 cupsdSetString(&TempDir
, tmpdir
);
1014 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1016 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1021 * Make sure the temporary directory has the right permissions...
1024 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1028 * Update ownership and permissions if the CUPS temp directory
1029 * is under the spool directory or does not exist...
1032 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1033 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1038 * Setup environment variables...
1044 * Update default paper size setting as needed...
1047 if (!DefaultPaperSize
)
1049 #ifdef HAVE_LIBPAPER
1050 char *paper_result
; /* Paper size name from libpaper */
1052 if ((paper_result
= systempapername()) != NULL
)
1053 cupsdSetString(&DefaultPaperSize
, paper_result
);
1055 #endif /* HAVE_LIBPAPER */
1056 if (!DefaultLanguage
||
1057 !strcasecmp(DefaultLanguage
, "C") ||
1058 !strcasecmp(DefaultLanguage
, "POSIX") ||
1059 !strcasecmp(DefaultLanguage
, "en") ||
1060 !strncasecmp(DefaultLanguage
, "en.", 3) ||
1061 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
1062 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1063 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
1066 * These are the only locales that will default to "letter" size...
1069 cupsdSetString(&DefaultPaperSize
, "Letter");
1072 cupsdSetString(&DefaultPaperSize
, "A4");
1076 * Update classification setting as needed...
1079 if (Classification
&& !strcasecmp(Classification
, "none"))
1080 cupsdClearString(&Classification
);
1083 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1086 * Check the MaxClients setting, and then allocate memory for it...
1089 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1092 cupsdLogMessage(CUPSD_LOG_INFO
,
1093 "MaxClients limited to 1/3 (%d) of the file descriptor "
1095 MaxFDs
/ 3, MaxFDs
);
1097 MaxClients
= MaxFDs
/ 3;
1100 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1104 * Check the MaxActiveJobs setting; limit to 1/3 the available
1105 * file descriptors, since we need a pipe for each job...
1108 if (MaxActiveJobs
> (MaxFDs
/ 3))
1109 MaxActiveJobs
= MaxFDs
/ 3;
1112 * Update the MaxClientsPerHost value, as needed...
1115 if (MaxClientsPerHost
<= 0)
1116 MaxClientsPerHost
= MaxClients
;
1118 if (MaxClientsPerHost
> MaxClients
)
1119 MaxClientsPerHost
= MaxClients
;
1121 cupsdLogMessage(CUPSD_LOG_INFO
,
1122 "Allowing up to %d client connections per host.",
1126 * Make sure that BrowseTimeout is at least twice the interval...
1129 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1131 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1135 BrowseTimeout
= BrowseInterval
* 2;
1137 BrowseTimeout
= DEFAULT_TIMEOUT
;
1139 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1144 * Update the default policy, as needed...
1148 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1150 DefaultPolicyPtr
= NULL
;
1152 if (!DefaultPolicyPtr
)
1154 cupsd_location_t
*po
; /* New policy operation */
1158 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1161 cupsdSetString(&DefaultPolicy
, "default");
1163 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1164 cupsdLogMessage(CUPSD_LOG_INFO
,
1165 "Using policy \"default\" as the default!");
1168 cupsdLogMessage(CUPSD_LOG_INFO
,
1169 "Creating CUPS default administrative policy:");
1171 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1173 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1174 cupsdLogMessage(CUPSD_LOG_INFO
,
1175 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1176 "Release-Job Restart-Job Purge-Jobs "
1177 "Set-Job-Attributes Create-Job-Subscription "
1178 "Renew-Subscription Cancel-Subscription "
1179 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1180 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1181 "CUPS-Authenticate-Job CUPS-Get-Document>");
1182 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1184 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1185 po
->order_type
= CUPSD_AUTH_ALLOW
;
1186 po
->level
= CUPSD_AUTH_USER
;
1188 cupsdAddName(po
, "@OWNER");
1189 cupsdAddName(po
, "@SYSTEM");
1190 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1192 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1193 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1194 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1195 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1196 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1197 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1198 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1199 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1200 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1201 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1202 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1203 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1204 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1205 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1206 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1207 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1208 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1209 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1211 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1213 cupsdLogMessage(CUPSD_LOG_INFO
,
1214 "<Limit Pause-Printer Resume-Printer "
1215 "Set-Printer-Attributes Enable-Printer "
1216 "Disable-Printer Pause-Printer-After-Current-Job "
1217 "Hold-New-Jobs Release-Held-New-Jobs "
1218 "Deactivate-Printer Activate-Printer Restart-Printer "
1219 "Shutdown-Printer Startup-Printer Promote-Job "
1220 "Schedule-Job-After CUPS-Add-Printer "
1221 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1222 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1223 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1224 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1226 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1227 po
->order_type
= CUPSD_AUTH_ALLOW
;
1228 po
->type
= CUPSD_AUTH_DEFAULT
;
1229 po
->level
= CUPSD_AUTH_USER
;
1231 cupsdAddName(po
, "@SYSTEM");
1232 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1234 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1235 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1236 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1237 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1238 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1239 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1240 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1241 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1242 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1243 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1244 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1245 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1246 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1247 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1248 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1249 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1250 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1251 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1252 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1253 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1254 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1256 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1258 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1259 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1261 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1262 po
->order_type
= CUPSD_AUTH_ALLOW
;
1264 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1265 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1269 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1270 cupsArrayCount(Policies
));
1271 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1273 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1274 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1275 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1278 * If we are doing a full reload or the server root has changed, flush
1279 * the jobs, printers, etc. and start from scratch...
1282 if (NeedReload
== RELOAD_ALL
||
1283 old_remote_port
!= RemotePort
||
1284 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1285 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1287 mime_type_t
*type
; /* Current type */
1288 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1289 /* MIME type name */
1292 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1295 * Free all memory...
1298 cupsdDeleteAllSubscriptions();
1300 cupsdDeleteAllPrinters();
1302 DefaultPrinter
= NULL
;
1304 if (MimeDatabase
!= NULL
)
1305 mimeDelete(MimeDatabase
);
1309 for (i
= 0; i
< NumMimeTypes
; i
++)
1310 _cupsStrFree(MimeTypes
[i
]);
1316 * Read the MIME type and conversion database...
1319 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1320 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1322 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1323 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1324 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1325 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1329 cupsdLogMessage(CUPSD_LOG_EMERG
,
1330 "Unable to load MIME database from \"%s\" or \"%s\"!",
1331 mimedir
, ServerRoot
);
1332 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1336 cupsdLogMessage(CUPSD_LOG_INFO
,
1337 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1338 "%d filters...", mimedir
, ServerRoot
,
1339 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1342 * Create a list of MIME types for the document-format-supported
1346 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1347 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1350 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1352 cupsdLogMessage(CUPSD_LOG_ERROR
,
1353 "Unable to allocate memory for %d MIME types!",
1359 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1361 i
++, type
= mimeNextType(MimeDatabase
))
1363 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1365 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1368 if (i
< NumMimeTypes
)
1369 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1372 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1374 mime_filter_t
*filter
; /* Current filter */
1377 for (type
= mimeFirstType(MimeDatabase
);
1379 type
= mimeNextType(MimeDatabase
))
1380 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1381 type
->super
, type
->type
);
1383 for (filter
= mimeFirstFilter(MimeDatabase
);
1385 filter
= mimeNextFilter(MimeDatabase
))
1386 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1387 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1388 filter
->src
->super
, filter
->src
->type
,
1389 filter
->dst
->super
, filter
->dst
->type
,
1390 filter
->cost
, filter
->filter
);
1397 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1398 cupsdLoadBanners(temp
);
1401 * Load printers and classes...
1404 cupsdLoadAllPrinters();
1405 cupsdLoadAllClasses();
1406 cupsdLoadRemoteCache();
1407 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1409 cupsdCreateCommonData();
1412 * Load queued jobs...
1418 * Load subscriptions...
1421 cupsdLoadAllSubscriptions();
1423 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1428 * Not a full reload, so recreate the common printer attributes...
1431 cupsdCreateCommonData();
1434 * Update all printers as needed...
1437 cupsdUpdatePrinters();
1438 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1440 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1444 * Reset the reload state...
1447 NeedReload
= RELOAD_NONE
;
1449 cupsdClearString(&old_serverroot
);
1450 cupsdClearString(&old_requestroot
);
1457 * 'get_address()' - Get an address + port number from a line.
1460 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1461 get_address(const char *value
, /* I - Value string */
1462 int defport
) /* I - Default port */
1464 char buffer
[1024], /* Hostname + port number buffer */
1465 defpname
[255], /* Default port name */
1466 *hostname
, /* Hostname or IP */
1467 *portname
; /* Port number or name */
1468 http_addrlist_t
*addrlist
; /* Address list */
1472 * Check for an empty value...
1477 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1482 * Grab a hostname and port number; if there is no colon and the port name
1483 * is only digits, then we have a port number by itself...
1486 strlcpy(buffer
, value
, sizeof(buffer
));
1488 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1495 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1500 * Use the default port...
1503 sprintf(defpname
, "%d", defport
);
1504 portname
= defpname
;
1510 * The buffer contains just a port number...
1518 if (hostname
&& !strcmp(hostname
, "*"))
1522 * Now lookup the address using httpAddrGetList()...
1525 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1526 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1527 hostname
? hostname
: "(nil)");
1534 * 'get_addr_and_mask()' - Get an IP address and netmask.
1537 static int /* O - 1 on success, 0 on failure */
1538 get_addr_and_mask(const char *value
, /* I - String from config file */
1539 unsigned *ip
, /* O - Address value */
1540 unsigned *mask
) /* O - Mask value */
1542 int i
, j
, /* Looping vars */
1543 family
, /* Address family */
1544 ipcount
; /* Count of fields in address */
1545 unsigned ipval
; /* Value */
1546 const char *maskval
, /* Pointer to start of mask value */
1547 *ptr
, /* Pointer into value */
1552 * Get the address...
1555 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1556 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1558 if ((maskval
= strchr(value
, '/')) != NULL
)
1561 maskval
= value
+ strlen(value
);
1565 * Check for an IPv6 address...
1571 * Parse hexadecimal IPv6 address...
1576 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1580 else if (!strncmp(ptr
, "::", 2))
1582 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1584 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1589 else if (isxdigit(*ptr
& 255))
1591 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1599 ip
[i
/ 2] |= ipval
<< 16;
1613 if (*ptr
&& *ptr
!= '/')
1617 #endif /* AF_INET6 */
1620 * Parse dotted-decimal IPv4 address...
1623 unsigned val
[4]; /* IPv4 address values */
1627 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1630 * Range check the IP numbers...
1633 for (i
= 0; i
< ipcount
; i
++)
1638 * Make sure the trailing values are zeroed, as some C libraries like
1639 * glibc apparently like to fill the unused arguments with garbage...
1642 for (i
= ipcount
; i
< 4; i
++)
1646 * Merge everything into a 32-bit IPv4 address in ip[3]...
1649 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1652 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1658 * Get the netmask value(s)...
1661 memset(mask
, 0, sizeof(unsigned) * 4);
1663 if (strchr(maskval
, '.'))
1666 * Get dotted-decimal mask...
1669 if (family
!= AF_INET
)
1672 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1675 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1676 mask
[0] = mask
[1] = mask
[2] = 0;
1681 * Get address/bits format...
1687 if (family
== AF_INET6
)
1695 mask
[0] = 0xffffffff;
1697 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1700 mask
[1] = 0xffffffff;
1704 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1707 mask
[2] = 0xffffffff;
1711 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1714 mask
[3] = 0xffffffff;
1718 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1721 #endif /* AF_INET6 */
1726 mask
[0] = 0xffffffff;
1727 mask
[1] = 0xffffffff;
1728 mask
[2] = 0xffffffff;
1731 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1733 mask
[3] = 0xffffffff;
1738 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1739 "get_addr_and_mask(value=\"%s\", "
1740 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1741 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1745 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1748 if ((ip
[0] & ~mask
[0]) != 0 ||
1749 (ip
[1] & ~mask
[1]) != 0 ||
1750 (ip
[2] & ~mask
[2]) != 0 ||
1751 (ip
[3] & ~mask
[3]) != 0)
1759 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1762 static int /* O - 1 on success, 0 on failure */
1763 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1764 char *line
, /* I - Line from file */
1765 char *value
, /* I - Start of value data */
1766 int linenum
) /* I - Current line number */
1768 char *valptr
; /* Pointer into value */
1769 unsigned ip
[4], /* IP address components */
1770 mask
[4]; /* IP netmask components */
1773 if (!strcasecmp(line
, "Encryption"))
1776 * "Encryption xxx" - set required encryption level...
1779 if (!strcasecmp(value
, "never"))
1780 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1781 else if (!strcasecmp(value
, "always"))
1783 cupsdLogMessage(CUPSD_LOG_ERROR
,
1784 "Encryption value \"%s\" on line %d is invalid in this "
1785 "context. Using \"required\" instead.", value
, linenum
);
1787 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1789 else if (!strcasecmp(value
, "required"))
1790 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1791 else if (!strcasecmp(value
, "ifrequested"))
1792 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1795 cupsdLogMessage(CUPSD_LOG_ERROR
,
1796 "Unknown Encryption value %s on line %d.", value
, linenum
);
1800 else if (!strcasecmp(line
, "Order"))
1803 * "Order Deny,Allow" or "Order Allow,Deny"...
1806 if (!strncasecmp(value
, "deny", 4))
1807 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1808 else if (!strncasecmp(value
, "allow", 5))
1809 loc
->order_type
= CUPSD_AUTH_DENY
;
1812 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1817 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1820 * Allow [From] host/ip...
1821 * Deny [From] host/ip...
1826 if (!strncasecmp(value
, "from", 4))
1829 * Strip leading "from"...
1834 while (isspace(*value
& 255))
1842 * Find the end of the value...
1845 for (valptr
= value
; *valptr
&& !isspace(*valptr
& 255); valptr
++);
1847 while (isspace(*valptr
& 255))
1851 * Figure out what form the allow/deny address takes:
1862 * nnn.nnn.nnn.nnn/mm
1863 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1866 if (!strcasecmp(value
, "all"))
1872 if (!strcasecmp(line
, "Allow"))
1873 cupsdAllowIP(loc
, zeros
, zeros
);
1875 cupsdDenyIP(loc
, zeros
, zeros
);
1877 else if (!strcasecmp(value
, "none"))
1883 if (!strcasecmp(line
, "Allow"))
1884 cupsdAllowIP(loc
, ones
, zeros
);
1886 cupsdDenyIP(loc
, ones
, zeros
);
1889 else if (value
[0] == '*' || value
[0] == '.' ||
1890 (!isdigit(value
[0] & 255) && value
[0] != '['))
1892 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1893 #endif /* AF_INET6 */
1896 * Host or domain name...
1899 if (value
[0] == '*')
1902 if (!strcasecmp(line
, "Allow"))
1903 cupsdAllowHost(loc
, value
);
1905 cupsdDenyHost(loc
, value
);
1910 * One of many IP address forms...
1913 if (!get_addr_and_mask(value
, ip
, mask
))
1915 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1920 if (!strcasecmp(line
, "Allow"))
1921 cupsdAllowIP(loc
, ip
, mask
);
1923 cupsdDenyIP(loc
, ip
, mask
);
1927 * Advance to next value...
1933 else if (!strcasecmp(line
, "AuthType"))
1936 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1939 if (!strcasecmp(value
, "none"))
1941 loc
->type
= CUPSD_AUTH_NONE
;
1942 loc
->level
= CUPSD_AUTH_ANON
;
1944 else if (!strcasecmp(value
, "basic"))
1946 loc
->type
= CUPSD_AUTH_BASIC
;
1948 if (loc
->level
== CUPSD_AUTH_ANON
)
1949 loc
->level
= CUPSD_AUTH_USER
;
1951 else if (!strcasecmp(value
, "digest"))
1953 loc
->type
= CUPSD_AUTH_DIGEST
;
1955 if (loc
->level
== CUPSD_AUTH_ANON
)
1956 loc
->level
= CUPSD_AUTH_USER
;
1958 else if (!strcasecmp(value
, "basicdigest"))
1960 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1962 if (loc
->level
== CUPSD_AUTH_ANON
)
1963 loc
->level
= CUPSD_AUTH_USER
;
1965 else if (!strcasecmp(value
, "default"))
1967 loc
->type
= CUPSD_AUTH_DEFAULT
;
1969 if (loc
->level
== CUPSD_AUTH_ANON
)
1970 loc
->level
= CUPSD_AUTH_USER
;
1973 else if (!strcasecmp(value
, "negotiate"))
1975 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1977 if (loc
->level
== CUPSD_AUTH_ANON
)
1978 loc
->level
= CUPSD_AUTH_USER
;
1980 #endif /* HAVE_GSSAPI */
1983 cupsdLogMessage(CUPSD_LOG_WARN
,
1984 "Unknown authorization type %s on line %d.",
1989 else if (!strcasecmp(line
, "AuthClass"))
1992 * AuthClass anonymous, user, system, group
1995 if (!strcasecmp(value
, "anonymous"))
1997 loc
->type
= CUPSD_AUTH_NONE
;
1998 loc
->level
= CUPSD_AUTH_ANON
;
2000 cupsdLogMessage(CUPSD_LOG_WARN
,
2001 "\"AuthClass %s\" is deprecated; consider removing "
2005 else if (!strcasecmp(value
, "user"))
2007 loc
->level
= CUPSD_AUTH_USER
;
2009 cupsdLogMessage(CUPSD_LOG_WARN
,
2010 "\"AuthClass %s\" is deprecated; consider using "
2011 "\"Require valid-user\" on line %d.",
2014 else if (!strcasecmp(value
, "group"))
2016 loc
->level
= CUPSD_AUTH_GROUP
;
2018 cupsdLogMessage(CUPSD_LOG_WARN
,
2019 "\"AuthClass %s\" is deprecated; consider using "
2020 "\"Require user @groupname\" on line %d.",
2023 else if (!strcasecmp(value
, "system"))
2025 loc
->level
= CUPSD_AUTH_GROUP
;
2027 cupsdAddName(loc
, "@SYSTEM");
2029 cupsdLogMessage(CUPSD_LOG_WARN
,
2030 "\"AuthClass %s\" is deprecated; consider using "
2031 "\"Require user @SYSTEM\" on line %d.",
2036 cupsdLogMessage(CUPSD_LOG_WARN
,
2037 "Unknown authorization class %s on line %d.",
2042 else if (!strcasecmp(line
, "AuthGroupName"))
2044 cupsdAddName(loc
, value
);
2046 cupsdLogMessage(CUPSD_LOG_WARN
,
2047 "\"AuthGroupName %s\" directive is deprecated; consider "
2048 "using \"Require user @%s\" on line %d.",
2049 value
, value
, linenum
);
2051 else if (!strcasecmp(line
, "Require"))
2054 * Apache synonym for AuthClass and AuthGroupName...
2058 * Require valid-user
2059 * Require group names
2060 * Require user names
2063 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2068 if (!strcasecmp(value
, "valid-user") ||
2069 !strcasecmp(value
, "user"))
2070 loc
->level
= CUPSD_AUTH_USER
;
2071 else if (!strcasecmp(value
, "group"))
2072 loc
->level
= CUPSD_AUTH_GROUP
;
2075 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2081 * Get the list of names from the line...
2084 for (value
= valptr
; *value
;)
2086 while (isspace(*value
& 255))
2089 #ifdef HAVE_AUTHORIZATION_H
2090 if (!strncmp(value
, "@AUTHKEY(", 9))
2093 * Grab "@AUTHKEY(name)" value...
2096 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2102 #endif /* HAVE_AUTHORIZATION_H */
2103 if (*value
== '\"' || *value
== '\'')
2106 * Grab quoted name...
2109 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2116 * Grab literal name.
2119 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2125 cupsdAddName(loc
, value
);
2127 for (value
= valptr
; isspace(*value
& 255); value
++);
2130 else if (!strcasecmp(line
, "Satisfy"))
2132 if (!strcasecmp(value
, "all"))
2133 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2134 else if (!strcasecmp(value
, "any"))
2135 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2138 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2151 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2154 static int /* O - FatalErrors bits */
2155 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2157 int fatal
; /* FatalErrors bits */
2158 char value
[1024], /* Value string */
2159 *valstart
, /* Pointer into value */
2160 *valend
; /* End of value */
2164 * Empty FatalErrors line yields NULL pointer...
2168 return (CUPSD_FATAL_NONE
);
2171 * Loop through the value string,...
2174 strlcpy(value
, s
, sizeof(value
));
2176 fatal
= CUPSD_FATAL_NONE
;
2178 for (valstart
= value
; *valstart
;)
2181 * Get the current space/comma-delimited kind name...
2184 for (valend
= valstart
; *valend
; valend
++)
2185 if (isspace(*valend
& 255) || *valend
== ',')
2192 * Add the error to the bitmask...
2195 if (!strcasecmp(valstart
, "all"))
2196 fatal
= CUPSD_FATAL_ALL
;
2197 else if (!strcasecmp(valstart
, "browse"))
2198 fatal
|= CUPSD_FATAL_BROWSE
;
2199 else if (!strcasecmp(valstart
, "-browse"))
2200 fatal
&= ~CUPSD_FATAL_BROWSE
;
2201 else if (!strcasecmp(valstart
, "config"))
2202 fatal
|= CUPSD_FATAL_CONFIG
;
2203 else if (!strcasecmp(valstart
, "-config"))
2204 fatal
&= ~CUPSD_FATAL_CONFIG
;
2205 else if (!strcasecmp(valstart
, "listen"))
2206 fatal
|= CUPSD_FATAL_LISTEN
;
2207 else if (!strcasecmp(valstart
, "-listen"))
2208 fatal
&= ~CUPSD_FATAL_LISTEN
;
2209 else if (!strcasecmp(valstart
, "log"))
2210 fatal
|= CUPSD_FATAL_LOG
;
2211 else if (!strcasecmp(valstart
, "-log"))
2212 fatal
&= ~CUPSD_FATAL_LOG
;
2213 else if (!strcasecmp(valstart
, "permissions"))
2214 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2215 else if (!strcasecmp(valstart
, "-permissions"))
2216 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2217 else if (strcasecmp(valstart
, "none"))
2218 cupsdLogMessage(CUPSD_LOG_ERROR
,
2219 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2221 for (valstart
= valend
; *valstart
; valstart
++)
2222 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2231 * 'parse_groups()' - Parse system group names in a string.
2234 static int /* O - 1 on success, 0 on failure */
2235 parse_groups(const char *s
) /* I - Space-delimited groups */
2237 int status
; /* Return status */
2238 char value
[1024], /* Value string */
2239 *valstart
, /* Pointer into value */
2240 *valend
, /* End of value */
2241 quote
; /* Quote character */
2242 struct group
*group
; /* Group */
2246 * Make a copy of the string and parse out the groups...
2249 strlcpy(value
, s
, sizeof(value
));
2254 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2256 if (*valstart
== '\'' || *valstart
== '\"')
2259 * Scan quoted name...
2262 quote
= *valstart
++;
2264 for (valend
= valstart
; *valend
; valend
++)
2265 if (*valend
== quote
)
2271 * Scan space or comma-delimited name...
2274 for (valend
= valstart
; *valend
; valend
++)
2275 if (isspace(*valend
) || *valend
== ',')
2282 group
= getgrnam(valstart
);
2285 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2286 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2297 while (*valstart
== ',' || isspace(*valstart
))
2306 * 'parse_protocols()' - Parse browse protocols in a string.
2309 static int /* O - Browse protocol bits */
2310 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2312 int protocols
; /* Browse protocol bits */
2313 char value
[1024], /* Value string */
2314 *valstart
, /* Pointer into value */
2315 *valend
; /* End of value */
2319 * Empty protocol line yields NULL pointer...
2326 * Loop through the value string,...
2329 strlcpy(value
, s
, sizeof(value
));
2333 for (valstart
= value
; *valstart
;)
2336 * Get the current space/comma-delimited protocol name...
2339 for (valend
= valstart
; *valend
; valend
++)
2340 if (isspace(*valend
& 255) || *valend
== ',')
2347 * Add the protocol to the bitmask...
2350 if (!strcasecmp(valstart
, "cups"))
2351 protocols
|= BROWSE_CUPS
;
2352 else if (!strcasecmp(valstart
, "slp"))
2353 protocols
|= BROWSE_SLP
;
2354 else if (!strcasecmp(valstart
, "ldap"))
2355 protocols
|= BROWSE_LDAP
;
2356 else if (!strcasecmp(valstart
, "dnssd") ||
2357 !strcasecmp(valstart
, "dns-sd") ||
2358 !strcasecmp(valstart
, "bonjour"))
2359 protocols
|= BROWSE_DNSSD
;
2360 else if (!strcasecmp(valstart
, "lpd"))
2361 protocols
|= BROWSE_LPD
;
2362 else if (!strcasecmp(valstart
, "smb"))
2363 protocols
|= BROWSE_SMB
;
2364 else if (!strcasecmp(valstart
, "all"))
2365 protocols
|= BROWSE_ALL
;
2366 else if (strcasecmp(valstart
, "none"))
2367 cupsdLogMessage(CUPSD_LOG_ERROR
,
2368 "Unknown browse protocol \"%s\" ignored!", valstart
);
2370 for (valstart
= valend
; *valstart
; valstart
++)
2371 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2380 * 'read_configuration()' - Read a configuration file.
2383 static int /* O - 1 on success, 0 on failure */
2384 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2386 int i
; /* Looping var */
2387 int linenum
; /* Current line number */
2388 char line
[HTTP_MAX_BUFFER
],
2389 /* Line from file */
2390 temp
[HTTP_MAX_BUFFER
],
2391 /* Temporary buffer for value */
2392 temp2
[HTTP_MAX_BUFFER
],
2393 /* Temporary buffer 2 for value */
2394 *ptr
, /* Pointer into line/temp */
2395 *value
, /* Pointer to value */
2396 *valueptr
; /* Pointer into value */
2397 int valuelen
; /* Length of value */
2398 cupsd_var_t
const *var
; /* Current variable */
2399 http_addrlist_t
*addrlist
, /* Address list */
2400 *addr
; /* Current address */
2401 unsigned ip
[4], /* Address value */
2402 mask
[4]; /* Netmask value */
2403 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2404 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2405 cupsd_location_t
*location
; /* Browse location */
2406 cups_file_t
*incfile
; /* Include file */
2407 char incname
[1024]; /* Include filename */
2408 struct group
*group
; /* Group */
2412 * Loop through each line in the file...
2417 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2420 * Decode the directive...
2423 if (!strcasecmp(line
, "Include") && value
)
2429 if (value
[0] == '/')
2430 strlcpy(incname
, value
, sizeof(incname
));
2432 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2434 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2435 cupsdLogMessage(CUPSD_LOG_ERROR
,
2436 "Unable to include config file \"%s\" - %s",
2437 incname
, strerror(errno
));
2440 read_configuration(incfile
);
2441 cupsFileClose(incfile
);
2444 else if (!strcasecmp(line
, "<Location") && value
)
2450 linenum
= read_location(fp
, value
, linenum
);
2454 else if (!strcasecmp(line
, "<Policy") && value
)
2460 linenum
= read_policy(fp
, value
, linenum
);
2464 else if (!strcasecmp(line
, "FatalErrors"))
2465 FatalErrors
= parse_fatal_errors(value
);
2466 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2468 JobRetryInterval
= atoi(value
);
2469 cupsdLogMessage(CUPSD_LOG_WARN
,
2470 "FaxRetryInterval is deprecated; use "
2471 "JobRetryInterval on line %d.", linenum
);
2473 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2475 JobRetryLimit
= atoi(value
);
2476 cupsdLogMessage(CUPSD_LOG_WARN
,
2477 "FaxRetryLimit is deprecated; use "
2478 "JobRetryLimit on line %d.", linenum
);
2480 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2482 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2483 #endif /* HAVE_SSL */
2487 * Add listening address(es) to the list...
2490 cupsd_listener_t
*lis
; /* New listeners array */
2494 * Get the address list...
2497 addrlist
= get_address(value
, IPP_PORT
);
2501 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2507 * Add each address...
2510 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2513 * See if this address is already present...
2516 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2518 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2519 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2520 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2525 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2526 cupsdLogMessage(CUPSD_LOG_WARN
,
2527 "Duplicate listen address \"%s\" ignored!", temp
);
2532 * Allocate another listener...
2536 Listeners
= cupsArrayNew(NULL
, NULL
);
2540 cupsdLogMessage(CUPSD_LOG_ERROR
,
2541 "Unable to allocate %s at line %d - %s.",
2542 line
, linenum
, strerror(errno
));
2546 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2548 cupsdLogMessage(CUPSD_LOG_ERROR
,
2549 "Unable to allocate %s at line %d - %s.",
2550 line
, linenum
, strerror(errno
));
2554 cupsArrayAdd(Listeners
, lis
);
2557 * Copy the current address and log it...
2560 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2564 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2565 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2566 #endif /* HAVE_SSL */
2568 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2571 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2572 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2573 ntohs(lis
->address
.ipv6
.sin6_port
));
2575 #endif /* AF_INET6 */
2577 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2578 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2580 #endif /* AF_LOCAL */
2581 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2582 ntohs(lis
->address
.ipv4
.sin_port
));
2584 if (!httpAddrLocalhost(&(lis
->address
)))
2587 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2588 RemotePort
= ntohs(lis
->address
.ipv6
.sin6_port
);
2590 #endif /* AF_INET6 */
2591 RemotePort
= ntohs(lis
->address
.ipv4
.sin_port
);
2599 httpAddrFreeList(addrlist
);
2601 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2604 * Add a browse address to the list...
2607 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2610 if (NumBrowsers
== 0)
2611 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2613 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2617 cupsdLogMessage(CUPSD_LOG_ERROR
,
2618 "Unable to allocate BrowseAddress at line %d - %s.",
2619 linenum
, strerror(errno
));
2624 dira
+= NumBrowsers
;
2626 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2628 if (!strcasecmp(value
, "@LOCAL"))
2631 * Send browse data to all local interfaces...
2634 strcpy(dira
->iface
, "*");
2637 else if (!strncasecmp(value
, "@IF(", 4))
2640 * Send browse data to the named interface...
2643 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2645 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2651 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2654 * Only IPv4 addresses are supported...
2657 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2658 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2663 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2664 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2666 cupsdLogMessage(CUPSD_LOG_INFO
,
2667 "Sending browsing info to %s:%d (IPv4)",
2668 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2673 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2676 httpAddrFreeList(addrlist
);
2679 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2682 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2685 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2688 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2689 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2691 if (location
== NULL
)
2692 cupsdLogMessage(CUPSD_LOG_ERROR
,
2693 "Unable to initialize browse access control list!");
2694 else if (!strncasecmp(value
, "deny", 4))
2695 location
->order_type
= CUPSD_AUTH_ALLOW
;
2696 else if (!strncasecmp(value
, "allow", 5))
2697 location
->order_type
= CUPSD_AUTH_DENY
;
2699 cupsdLogMessage(CUPSD_LOG_ERROR
,
2700 "Unknown BrowseOrder value %s on line %d.",
2703 else if (!strcasecmp(line
, "BrowseProtocols") ||
2704 !strcasecmp(line
, "BrowseLocalProtocols") ||
2705 !strcasecmp(line
, "BrowseRemoteProtocols"))
2708 * "BrowseProtocols name [... name]"
2709 * "BrowseLocalProtocols name [... name]"
2710 * "BrowseRemoteProtocols name [... name]"
2713 int protocols
= parse_protocols(value
);
2717 cupsdLogMessage(CUPSD_LOG_ERROR
,
2718 "Unknown browse protocol \"%s\" on line %d.",
2723 if (strcasecmp(line
, "BrowseLocalProtocols"))
2724 BrowseRemoteProtocols
= protocols
;
2725 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2726 BrowseLocalProtocols
= protocols
;
2728 else if ((!strcasecmp(line
, "BrowseAllow") ||
2729 !strcasecmp(line
, "BrowseDeny")) && value
)
2732 * BrowseAllow [From] host/ip...
2733 * BrowseDeny [From] host/ip...
2736 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2737 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2739 if (location
== NULL
)
2740 cupsdLogMessage(CUPSD_LOG_ERROR
,
2741 "Unable to initialize browse access control list!");
2746 if (!strncasecmp(value
, "from", 4))
2749 * Strip leading "from"...
2754 while (isspace(*value
& 255))
2762 * Find the end of the value...
2765 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2767 while (isspace(*valueptr
& 255))
2771 * Figure out what form the allow/deny address takes:
2782 * nnn.nnn.nnn.nnn/mm
2783 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2786 if (!strcasecmp(value
, "all"))
2792 if (!strcasecmp(line
, "BrowseAllow"))
2793 cupsdAllowIP(location
, zeros
, zeros
);
2795 cupsdDenyIP(location
, zeros
, zeros
);
2797 else if (!strcasecmp(value
, "none"))
2803 if (!strcasecmp(line
, "BrowseAllow"))
2804 cupsdAllowIP(location
, ones
, zeros
);
2806 cupsdDenyIP(location
, ones
, zeros
);
2809 else if (value
[0] == '*' || value
[0] == '.' ||
2810 (!isdigit(value
[0] & 255) && value
[0] != '['))
2812 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2813 #endif /* AF_INET6 */
2816 * Host or domain name...
2819 if (value
[0] == '*')
2822 if (!strcasecmp(line
, "BrowseAllow"))
2823 cupsdAllowHost(location
, value
);
2825 cupsdDenyHost(location
, value
);
2830 * One of many IP address forms...
2833 if (!get_addr_and_mask(value
, ip
, mask
))
2835 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2840 if (!strcasecmp(line
, "BrowseAllow"))
2841 cupsdAllowIP(location
, ip
, mask
);
2843 cupsdDenyIP(location
, ip
, mask
);
2847 * Advance to next value...
2854 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2857 * BrowseRelay [from] source [to] destination
2861 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2863 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2867 cupsdLogMessage(CUPSD_LOG_ERROR
,
2868 "Unable to allocate BrowseRelay at line %d - %s.",
2869 linenum
, strerror(errno
));
2876 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2878 if (!strncasecmp(value
, "from ", 5))
2881 * Strip leading "from"...
2886 while (isspace(*value
))
2891 * Figure out what form the from address takes:
2900 * nnn.nnn.nnn.nnn/mm
2901 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2905 if (value
[0] == '*' || value
[0] == '.' ||
2906 (!isdigit(value
[0] & 255) && value
[0] != '['))
2908 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2909 #endif /* AF_INET6 */
2912 * Host or domain name...
2915 if (value
[0] == '*')
2918 strlcpy(temp
, value
, sizeof(temp
));
2919 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2922 relay
->from
.type
= CUPSD_AUTH_NAME
;
2924 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2926 cupsdLogMessage(CUPSD_LOG_ERROR
,
2927 "Unable to allocate BrowseRelay name at line %d - %s.",
2928 linenum
, strerror(errno
));
2932 relay
->from
.mask
.name
.length
= strlen(temp
);
2937 * One of many IP address forms...
2940 if (!get_addr_and_mask(value
, ip
, mask
))
2942 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2947 relay
->from
.type
= CUPSD_AUTH_IP
;
2948 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2949 sizeof(relay
->from
.mask
.ip
.address
));
2950 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2951 sizeof(relay
->from
.mask
.ip
.netmask
));
2955 * Skip value and trailing whitespace...
2958 for (; *value
; value
++)
2959 if (isspace(*value
))
2962 while (isspace(*value
))
2965 if (!strncasecmp(value
, "to ", 3))
2968 * Strip leading "to"...
2973 while (isspace(*value
))
2978 * Get "to" address and port...
2981 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2984 * Only IPv4 addresses are supported...
2987 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2988 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2993 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2995 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2997 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2998 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2999 relay
->from
.mask
.ip
.address
[0] >> 24,
3000 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
3001 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
3002 relay
->from
.mask
.ip
.address
[0] & 255,
3003 relay
->from
.mask
.ip
.netmask
[0] >> 24,
3004 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
3005 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
3006 relay
->from
.mask
.ip
.netmask
[0] & 255);
3008 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
3010 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
3011 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
3016 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3019 httpAddrFreeList(addrlist
);
3023 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
3024 free(relay
->from
.mask
.name
.name
);
3026 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3030 else if (!strcasecmp(line
, "BrowsePoll") && value
)
3033 * BrowsePoll address[:port]
3036 char *portname
; /* Port name */
3037 int portnum
; /* Port number */
3038 struct servent
*service
; /* Service */
3042 * Extract the port name from the address...
3045 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
3049 if (isdigit(*portname
& 255))
3050 portnum
= atoi(portname
);
3051 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
3052 portnum
= ntohs(service
->s_port
);
3055 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
3061 portnum
= ippPort();
3064 * Add the poll entry...
3068 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
3070 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
3074 cupsdLogMessage(CUPSD_LOG_ERROR
,
3075 "Unable to allocate BrowsePoll at line %d - %s.",
3076 linenum
, strerror(errno
));
3084 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
3086 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
3087 pollp
->port
= portnum
;
3089 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
3092 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
3095 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3098 if (!strcasecmp(value
, "none"))
3099 DefaultAuthType
= CUPSD_AUTH_NONE
;
3100 else if (!strcasecmp(value
, "basic"))
3101 DefaultAuthType
= CUPSD_AUTH_BASIC
;
3102 else if (!strcasecmp(value
, "digest"))
3103 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
3104 else if (!strcasecmp(value
, "basicdigest"))
3105 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
3107 else if (!strcasecmp(value
, "negotiate"))
3108 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
3109 #endif /* HAVE_GSSAPI */
3112 cupsdLogMessage(CUPSD_LOG_WARN
,
3113 "Unknown default authorization type %s on line %d.",
3115 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3120 else if (!strcasecmp(line
, "DefaultEncryption"))
3123 * DefaultEncryption {Never,IfRequested,Required}
3126 if (!value
|| !strcasecmp(value
, "never"))
3127 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3128 else if (!strcasecmp(value
, "required"))
3129 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3130 else if (!strcasecmp(value
, "ifrequested"))
3131 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3134 cupsdLogMessage(CUPSD_LOG_WARN
,
3135 "Unknown default encryption %s on line %d.",
3137 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3141 #endif /* HAVE_SSL */
3142 else if (!strcasecmp(line
, "User") && value
)
3145 * User ID to run as...
3148 if (isdigit(value
[0] & 255))
3150 int uid
= atoi(value
);
3153 cupsdLogMessage(CUPSD_LOG_ERROR
,
3154 "Will not use User 0 as specified on line %d "
3155 "for security reasons. You must use a non-"
3156 "privileged account instead.",
3163 struct passwd
*p
; /* Password information */
3166 p
= getpwnam(value
);
3171 cupsdLogMessage(CUPSD_LOG_ERROR
,
3172 "Will not use User %s (UID=0) as specified on line "
3173 "%d for security reasons. You must use a non-"
3174 "privileged account instead.",
3180 cupsdLogMessage(CUPSD_LOG_ERROR
,
3181 "Unknown User \"%s\" on line %d, ignoring!",
3185 else if (!strcasecmp(line
, "Group") && value
)
3188 * Group ID to run as...
3191 if (isdigit(value
[0]))
3192 Group
= atoi(value
);
3196 group
= getgrnam(value
);
3199 Group
= group
->gr_gid
;
3201 cupsdLogMessage(CUPSD_LOG_ERROR
,
3202 "Unknown Group \"%s\" on line %d, ignoring!",
3206 else if (!strcasecmp(line
, "SystemGroup") && value
)
3209 * SystemGroup (admin) group(s)...
3212 if (!parse_groups(value
))
3213 cupsdLogMessage(CUPSD_LOG_ERROR
,
3214 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3217 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3220 * Do hostname lookups?
3223 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3224 !strcasecmp(value
, "false"))
3225 HostNameLookups
= 0;
3226 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3227 !strcasecmp(value
, "true"))
3228 HostNameLookups
= 1;
3229 else if (!strcasecmp(value
, "double"))
3230 HostNameLookups
= 2;
3232 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3235 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3238 * Amount of logging to do to access log...
3241 if (!strcasecmp(value
, "all"))
3242 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3243 else if (!strcasecmp(value
, "actions"))
3244 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3245 else if (!strcasecmp(value
, "config"))
3246 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3248 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3251 else if (!strcasecmp(line
, "LogLevel") && value
)
3254 * Amount of logging to do to error log...
3257 if (!strcasecmp(value
, "debug2"))
3258 LogLevel
= CUPSD_LOG_DEBUG2
;
3259 else if (!strcasecmp(value
, "debug"))
3260 LogLevel
= CUPSD_LOG_DEBUG
;
3261 else if (!strcasecmp(value
, "info"))
3262 LogLevel
= CUPSD_LOG_INFO
;
3263 else if (!strcasecmp(value
, "notice"))
3264 LogLevel
= CUPSD_LOG_NOTICE
;
3265 else if (!strcasecmp(value
, "warn"))
3266 LogLevel
= CUPSD_LOG_WARN
;
3267 else if (!strcasecmp(value
, "error"))
3268 LogLevel
= CUPSD_LOG_ERROR
;
3269 else if (!strcasecmp(value
, "crit"))
3270 LogLevel
= CUPSD_LOG_CRIT
;
3271 else if (!strcasecmp(value
, "alert"))
3272 LogLevel
= CUPSD_LOG_ALERT
;
3273 else if (!strcasecmp(value
, "emerg"))
3274 LogLevel
= CUPSD_LOG_EMERG
;
3275 else if (!strcasecmp(value
, "none"))
3276 LogLevel
= CUPSD_LOG_NONE
;
3278 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3281 else if (!strcasecmp(line
, "LogTimeFormat") && value
)
3284 * Amount of logging to do to error log...
3287 if (!strcasecmp(value
, "standard"))
3288 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3289 else if (!strcasecmp(value
, "usecs"))
3290 LogTimeFormat
= CUPSD_TIME_USECS
;
3292 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3295 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3298 * Format of printcap file?
3301 if (!strcasecmp(value
, "bsd"))
3302 PrintcapFormat
= PRINTCAP_BSD
;
3303 else if (!strcasecmp(value
, "plist"))
3304 PrintcapFormat
= PRINTCAP_PLIST
;
3305 else if (!strcasecmp(value
, "solaris"))
3306 PrintcapFormat
= PRINTCAP_SOLARIS
;
3308 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3311 else if (!strcasecmp(line
, "ServerTokens") && value
)
3314 * Set the string used for the Server header...
3317 struct utsname plat
; /* Platform info */
3322 if (!strcasecmp(value
, "ProductOnly"))
3323 cupsdSetString(&ServerHeader
, "CUPS");
3324 else if (!strcasecmp(value
, "Major"))
3325 cupsdSetString(&ServerHeader
, "CUPS/1");
3326 else if (!strcasecmp(value
, "Minor"))
3327 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3328 else if (!strcasecmp(value
, "Minimal"))
3329 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3330 else if (!strcasecmp(value
, "OS"))
3331 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3332 else if (!strcasecmp(value
, "Full"))
3333 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3335 else if (!strcasecmp(value
, "None"))
3336 cupsdClearString(&ServerHeader
);
3338 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3341 else if (!strcasecmp(line
, "PassEnv") && value
)
3344 * PassEnv variable [... variable]
3349 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3350 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3353 if (value
[valuelen
])
3355 value
[valuelen
] = '\0';
3359 cupsdSetEnv(value
, NULL
);
3361 for (value
+= valuelen
; *value
; value
++)
3362 if (!isspace(*value
) || *value
!= ',')
3366 else if (!strcasecmp(line
, "ServerAlias") && value
)
3369 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3371 cupsdAddAlias(ServerAlias
, value
);
3373 else if (!strcasecmp(line
, "SetEnv") && value
)
3376 * SetEnv variable value
3379 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3387 while (isspace(*valueptr
& 255))
3390 cupsdSetEnv(value
, valueptr
);
3393 cupsdLogMessage(CUPSD_LOG_ERROR
,
3394 "Missing value for SetEnv directive on line %d.",
3398 else if (!strcasecmp(line
, "SSLOptions"))
3401 * SSLOptions options
3404 if (!value
|| !strcasecmp(value
, "none"))
3405 SSLOptions
= CUPSD_SSL_NONE
;
3406 else if (!strcasecmp(value
, "noemptyfragments"))
3407 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3409 cupsdLogMessage(CUPSD_LOG_ERROR
,
3410 "Unknown value \"%s\" for SSLOptions directive on "
3411 "line %d.", value
, linenum
);
3413 #endif /* HAVE_SSL */
3417 * Find a simple variable in the list...
3420 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3421 if (!strcasecmp(line
, var
->name
))
3427 * Unknown directive! Output an error message and continue...
3431 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3434 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3441 case CUPSD_VARTYPE_INTEGER
:
3443 cupsdLogMessage(CUPSD_LOG_ERROR
,
3444 "Missing integer value for %s on line %d!",
3449 char *units
; /* Units */
3452 n
= strtol(value
, &units
, 0);
3454 if (units
&& *units
)
3456 if (tolower(units
[0] & 255) == 'g')
3457 n
*= 1024 * 1024 * 1024;
3458 else if (tolower(units
[0] & 255) == 'm')
3460 else if (tolower(units
[0] & 255) == 'k')
3462 else if (tolower(units
[0] & 255) == 't')
3467 cupsdLogMessage(CUPSD_LOG_ERROR
,
3468 "Bad negative integer value for %s on line %d!",
3471 *((int *)var
->ptr
) = n
;
3475 case CUPSD_VARTYPE_BOOLEAN
:
3477 cupsdLogMessage(CUPSD_LOG_ERROR
,
3478 "Missing boolean value for %s on line %d!",
3480 else if (!strcasecmp(value
, "true") ||
3481 !strcasecmp(value
, "on") ||
3482 !strcasecmp(value
, "enabled") ||
3483 !strcasecmp(value
, "yes") ||
3485 *((int *)var
->ptr
) = TRUE
;
3486 else if (!strcasecmp(value
, "false") ||
3487 !strcasecmp(value
, "off") ||
3488 !strcasecmp(value
, "disabled") ||
3489 !strcasecmp(value
, "no") ||
3490 !strcasecmp(value
, "0"))
3491 *((int *)var
->ptr
) = FALSE
;
3493 cupsdLogMessage(CUPSD_LOG_ERROR
,
3494 "Unknown boolean value %s on line %d.",
3498 case CUPSD_VARTYPE_PATHNAME
:
3501 cupsdLogMessage(CUPSD_LOG_ERROR
,
3502 "Missing pathname value for %s on line %d!",
3507 if (value
[0] == '/')
3508 strlcpy(temp
, value
, sizeof(temp
));
3510 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3512 if (access(temp
, 0))
3514 cupsdLogMessage(CUPSD_LOG_ERROR
,
3515 "File or directory for \"%s %s\" on line %d "
3516 "does not exist!", line
, value
, linenum
);
3520 case CUPSD_VARTYPE_STRING
:
3521 cupsdSetString((char **)var
->ptr
, value
);
3532 * 'read_location()' - Read a <Location path> definition.
3535 static int /* O - New line number or 0 on error */
3536 read_location(cups_file_t
*fp
, /* I - Configuration file */
3537 char *location
, /* I - Location name/path */
3538 int linenum
) /* I - Current line number */
3540 cupsd_location_t
*loc
, /* New location */
3541 *parent
; /* Parent location */
3542 char line
[HTTP_MAX_BUFFER
],
3544 *value
, /* Value for directive */
3545 *valptr
; /* Pointer into value */
3548 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3551 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3554 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3557 * Decode the directive...
3560 if (!strcasecmp(line
, "</Location>"))
3562 else if (!strcasecmp(line
, "<Limit") ||
3563 !strcasecmp(line
, "<LimitExcept"))
3567 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3568 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3574 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3580 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3585 if (!strcmp(value
, "ALL"))
3586 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3587 else if (!strcmp(value
, "GET"))
3588 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3589 else if (!strcmp(value
, "HEAD"))
3590 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3591 else if (!strcmp(value
, "OPTIONS"))
3592 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3593 else if (!strcmp(value
, "POST"))
3594 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3595 else if (!strcmp(value
, "PUT"))
3596 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3597 else if (!strcmp(value
, "TRACE"))
3598 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3600 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3603 for (value
= valptr
; isspace(*value
& 255); value
++);
3606 if (!strcasecmp(line
, "<LimitExcept"))
3607 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3609 parent
->limit
&= ~loc
->limit
;
3611 else if (!strcasecmp(line
, "</Limit>") ||
3612 !strcasecmp(line
, "</LimitExcept>"))
3614 else if (!parse_aaa(loc
, line
, value
, linenum
))
3616 cupsdLogMessage(CUPSD_LOG_ERROR
,
3617 "Unknown Location directive %s on line %d.",
3619 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3624 cupsdLogMessage(CUPSD_LOG_ERROR
,
3625 "Unexpected end-of-file at line %d while reading location!",
3628 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3633 * 'read_policy()' - Read a <Policy name> definition.
3636 static int /* O - New line number or 0 on error */
3637 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3638 char *policy
, /* I - Location name/path */
3639 int linenum
) /* I - Current line number */
3641 int i
; /* Looping var */
3642 cupsd_policy_t
*pol
; /* Policy */
3643 cupsd_location_t
*op
; /* Policy operation */
3644 int num_ops
; /* Number of IPP operations */
3645 ipp_op_t ops
[100]; /* Operations */
3646 char line
[HTTP_MAX_BUFFER
],
3648 *value
, /* Value for directive */
3649 *valptr
; /* Pointer into value */
3653 * Create the policy...
3656 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3660 * Read from the file...
3666 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3669 * Decode the directive...
3672 if (!strcasecmp(line
, "</Policy>"))
3675 cupsdLogMessage(CUPSD_LOG_WARN
,
3676 "Missing </Limit> before </Policy> on line %d!",
3680 * Verify that we have an explicit policy for CUPS-Get-Document
3681 * (ensures that upgrades do not introduce new security issues...)
3684 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3685 op
->op
== IPP_ANY_OPERATION
)
3687 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3688 op
->op
!= IPP_ANY_OPERATION
)
3691 * Add a new limit for CUPS-Get-Document using the Send-Document
3692 * limit as a template...
3695 cupsdLogMessage(CUPSD_LOG_WARN
,
3696 "No limit for CUPS-Get-Document defined in policy %s "
3697 "- using Send-Document's policy", pol
->name
);
3699 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3705 else if (!strcasecmp(line
, "<Limit") && !op
)
3709 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3710 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3717 * Scan for IPP operation names...
3724 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3729 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3731 if (!strcasecmp(value
, "All"))
3732 ops
[num_ops
] = IPP_ANY_OPERATION
;
3733 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3734 cupsdLogMessage(CUPSD_LOG_ERROR
,
3735 "Bad IPP operation name \"%s\" on line %d!",
3741 cupsdLogMessage(CUPSD_LOG_ERROR
,
3742 "Too many operations listed on line %d!",
3745 for (value
= valptr
; isspace(*value
& 255); value
++);
3749 * If none are specified, apply the policy to all operations...
3754 ops
[0] = IPP_ANY_OPERATION
;
3759 * Add a new policy for the first operation...
3762 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3764 else if (!strcasecmp(line
, "</Limit>") && op
)
3767 * Finish the current operation limit...
3773 * Copy the policy to the other operations...
3776 for (i
= 1; i
< num_ops
; i
++)
3777 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3784 cupsdLogMessage(CUPSD_LOG_ERROR
,
3785 "Missing <Limit ops> directive before %s on line %d.",
3787 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3790 else if (!parse_aaa(op
, line
, value
, linenum
))
3793 cupsdLogMessage(CUPSD_LOG_ERROR
,
3794 "Unknown Policy Limit directive %s on line %d.",
3797 cupsdLogMessage(CUPSD_LOG_ERROR
,
3798 "Unknown Policy directive %s on line %d.",
3801 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3806 cupsdLogMessage(CUPSD_LOG_ERROR
,
3807 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3810 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3815 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".