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 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
136 { "LPDConfigFile", &LPDConfigFile
, CUPSD_VARTYPE_STRING
},
137 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
151 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
152 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
153 { "MultipleOperationTimeout", &MultipleOperationTimeout
, CUPSD_VARTYPE_INTEGER
},
154 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
155 { "PageLogFormat", &PageLogFormat
, CUPSD_VARTYPE_STRING
},
156 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
157 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
158 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
159 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
160 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
161 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
162 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
163 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
164 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
165 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
166 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_PATHNAME
},
168 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_PATHNAME
},
169 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
170 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_PATHNAME
},
171 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
172 #endif /* HAVE_SSL */
173 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
174 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_PATHNAME
},
175 { "SMBConfigFile", &SMBConfigFile
, CUPSD_VARTYPE_STRING
},
176 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
177 #ifdef HAVE_AUTHORIZATION_H
178 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
179 #endif /* HAVE_AUTHORIZATION_H */
180 { "TempDir", &TempDir
, CUPSD_VARTYPE_PATHNAME
},
181 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
182 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
184 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
187 static const unsigned ones
[4] =
189 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
191 static const unsigned zeros
[4] =
193 0x00000000, 0x00000000, 0x00000000, 0x00000000
201 static http_addrlist_t
*get_address(const char *value
, int defport
);
202 static int get_addr_and_mask(const char *value
, unsigned *ip
,
204 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
205 char *value
, int linenum
);
206 static int parse_fatal_errors(const char *s
);
207 static int parse_groups(const char *s
);
208 static int parse_protocols(const char *s
);
209 static int read_configuration(cups_file_t
*fp
);
210 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
211 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
215 * 'cupsdAddAlias()' - Add a host alias.
219 cupsdAddAlias(cups_array_t
*aliases
, /* I - Array of aliases */
220 const char *name
) /* I - Name to add */
222 cupsd_alias_t
*a
; /* New alias */
223 size_t namelen
; /* Length of name */
226 namelen
= strlen(name
);
228 if ((a
= (cupsd_alias_t
*)malloc(sizeof(cupsd_alias_t
) + namelen
)) == NULL
)
231 a
->namelen
= namelen
;
232 strcpy(a
->name
, name
); /* OK since a->name is allocated */
234 cupsArrayAdd(aliases
, a
);
239 * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
242 int /* O - 0 on success, -1 on error, 1 on warning */
243 cupsdCheckPermissions(
244 const char *filename
, /* I - File/directory name */
245 const char *suffix
, /* I - Additional file/directory name */
246 int mode
, /* I - Permissions */
247 int user
, /* I - Owner */
248 int group
, /* I - Group */
249 int is_dir
, /* I - 1 = directory, 0 = file */
250 int create_dir
) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
252 int dir_created
= 0; /* Did we create a directory? */
253 char pathname
[1024]; /* File name with prefix */
254 struct stat fileinfo
; /* Stat buffer */
255 int is_symlink
; /* Is "filename" a symlink? */
259 * Prepend the given root to the filename before testing it...
264 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
269 * See if we can stat the file/directory...
272 if (lstat(filename
, &fileinfo
))
274 if (errno
== ENOENT
&& create_dir
)
277 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating missing directory \"%s\"",
280 if (mkdir(filename
, mode
))
283 cupsdLogMessage(CUPSD_LOG_ERROR
,
284 "Unable to create directory \"%s\" - %s", filename
,
287 syslog(LOG_ERR
, "Unable to create directory \"%s\" - %s", filename
,
294 fileinfo
.st_mode
= mode
| S_IFDIR
;
297 return (create_dir
? -1 : 1);
300 if ((is_symlink
= S_ISLNK(fileinfo
.st_mode
)) != 0)
302 if (stat(filename
, &fileinfo
))
304 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is a bad symlink - %s",
305 filename
, strerror(errno
));
311 * Make sure it's a regular file or a directory as needed...
314 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
316 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
320 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
323 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
325 syslog(LOG_ERR
, "\"%s\" is not a directory!", filename
);
331 * If the filename is a symlink, do not change permissions (STR #2937)...
338 * Fix owner, group, and mode as needed...
341 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
344 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing ownership of \"%s\"",
347 if (chown(filename
, user
, group
) && !getuid())
350 cupsdLogMessage(CUPSD_LOG_ERROR
,
351 "Unable to change ownership of \"%s\" - %s", filename
,
354 syslog(LOG_ERR
, "Unable to change ownership of \"%s\" - %s", filename
,
361 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
364 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Repairing access permissions of \"%s\"",
367 if (chmod(filename
, mode
))
370 cupsdLogMessage(CUPSD_LOG_ERROR
,
371 "Unable to change permissions of \"%s\" - %s", filename
,
374 syslog(LOG_ERR
, "Unable to change permissions of \"%s\" - %s", filename
,
382 * Everything is OK...
390 * 'cupsdFreeAliases()' - Free all of the alias entries.
394 cupsdFreeAliases(cups_array_t
*aliases
) /* I - Array of aliases */
396 cupsd_alias_t
*a
; /* Current alias */
399 for (a
= (cupsd_alias_t
*)cupsArrayFirst(aliases
);
401 a
= (cupsd_alias_t
*)cupsArrayNext(aliases
))
404 cupsArrayDelete(aliases
);
409 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
412 int /* O - 1 on success, 0 otherwise */
413 cupsdReadConfiguration(void)
415 int i
; /* Looping var */
416 cups_file_t
*fp
; /* Configuration file */
417 int status
; /* Return status */
418 char temp
[1024], /* Temporary buffer */
419 mimedir
[1024], /* MIME directory */
420 *slash
; /* Directory separator */
421 cups_lang_t
*language
; /* Language */
422 struct passwd
*user
; /* Default user */
423 struct group
*group
; /* Default group */
424 char *old_serverroot
, /* Old ServerRoot */
425 *old_requestroot
; /* Old RequestRoot */
426 int old_remote_port
; /* Old RemotePort */
427 const char *tmpdir
; /* TMPDIR environment variable */
428 struct stat tmpinfo
; /* Temporary directory info */
429 cupsd_policy_t
*p
; /* Policy */
433 * Save the old root paths...
436 old_serverroot
= NULL
;
437 cupsdSetString(&old_serverroot
, ServerRoot
);
438 old_requestroot
= NULL
;
439 cupsdSetString(&old_requestroot
, RequestRoot
);
442 * Reset the server configuration data...
445 cupsdDeleteAllLocations();
464 for (i
= 0; i
< NumRelays
; i
++)
465 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
466 free(Relays
[i
].from
.mask
.name
.name
);
473 cupsdDeleteAllListeners();
475 old_remote_port
= RemotePort
;
482 cupsdFreeAliases(ServerAlias
);
485 cupsdClearString(&ServerName
);
486 cupsdClearString(&ServerAdmin
);
487 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
488 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
489 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
490 cupsdSetString(&DataDir
, CUPS_DATADIR
);
491 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
492 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
493 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
494 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
495 cupsdSetString(&PageLogFormat
,
496 "%p %j %u %T %P %C %{job-billing} "
497 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
498 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
499 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
500 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
501 cupsdSetString(&RemoteRoot
, "remroot");
502 cupsdSetString(&ServerHeader
, "CUPS/1.4");
503 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
505 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
506 PrintcapFormat
= PRINTCAP_SOLARIS
;
507 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
508 "/Library/Preferences/org.cups.printers.plist"))
509 PrintcapFormat
= PRINTCAP_PLIST
;
511 PrintcapFormat
= PRINTCAP_BSD
;
513 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
514 if ((slash
= strrchr(temp
, '/')) != NULL
)
517 cupsdSetString(&ServerRoot
, temp
);
519 cupsdClearString(&Classification
);
520 ClassifyOverride
= 0;
524 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
526 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
527 cupsdSetString(&ServerKey
, "ssl/server.key");
528 # endif /* HAVE_CDSASSL */
529 #endif /* HAVE_SSL */
531 language
= cupsLangDefault();
533 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
534 cupsdSetString(&DefaultLanguage
, "en");
536 cupsdSetString(&DefaultLanguage
, language
->language
);
538 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
540 cupsdClearString(&DefaultPaperSize
);
542 cupsdSetString(&RIPCache
, "8m");
544 cupsdSetString(&TempDir
, NULL
);
547 * Find the default user...
550 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
555 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
556 * complement number...)
565 * Find the default group...
568 group
= getgrnam(CUPS_DEFAULT_GROUP
);
572 Group
= group
->gr_gid
;
576 * Fallback to group "nobody"...
579 group
= getgrnam("nobody");
583 Group
= group
->gr_gid
;
587 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
588 * complement number...)
599 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
600 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
601 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
602 DefaultAuthType
= CUPSD_AUTH_BASIC
;
604 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
605 SSLOptions
= CUPSD_SSL_NONE
;
606 #endif /* HAVE_SSL */
607 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
608 JobKillDelay
= DEFAULT_TIMEOUT
;
610 JobRetryInterval
= 300;
615 HostNameLookups
= FALSE
;
616 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
617 ImplicitAnyClasses
= FALSE
;
618 HideImplicitMembers
= TRUE
;
620 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
621 ListenBackLog
= SOMAXCONN
;
622 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
623 LogLevel
= CUPSD_LOG_WARN
;
624 LogTimeFormat
= CUPSD_TIME_STANDARD
;
626 MaxClientsPerHost
= 0;
627 MaxLogSize
= 1024 * 1024;
628 MaxPrinterHistory
= 10;
630 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
631 ReloadTimeout
= DEFAULT_KEEPALIVE
;
632 RootCertDuration
= 300;
633 Timeout
= DEFAULT_TIMEOUT
;
636 BrowseInterval
= DEFAULT_INTERVAL
;
637 BrowsePort
= ippPort();
638 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
639 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
640 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
641 BrowseTimeout
= DEFAULT_TIMEOUT
;
643 Browsing
= CUPS_DEFAULT_BROWSING
;
644 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
646 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
647 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
649 cupsdClearString(&BrowseLocalOptions
);
650 cupsdClearString(&BrowseRemoteOptions
);
652 cupsdSetString(&ErrorPolicy
, "stop-printer");
655 cupsdClearString(&BrowseLDAPBindDN
);
656 cupsdClearString(&BrowseLDAPDN
);
657 cupsdClearString(&BrowseLDAPPassword
);
658 cupsdClearString(&BrowseLDAPServer
);
659 # ifdef HAVE_LDAP_SSL
660 cupsdClearString(&BrowseLDAPCACertFile
);
661 # endif /* HAVE_LDAP_SSL */
662 #endif /* HAVE_LDAP */
664 JobHistory
= DEFAULT_HISTORY
;
665 JobFiles
= DEFAULT_FILES
;
670 MaxJobsPerPrinter
= 0;
671 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
673 cupsdDeleteAllPolicies();
674 cupsdClearString(&DefaultPolicy
);
676 #ifdef HAVE_AUTHORIZATION_H
677 cupsdClearString(&SystemGroupAuthKey
);
678 #endif /* HAVE_AUTHORIZATION_H */
680 MaxSubscriptions
= 100;
681 MaxSubscriptionsPerJob
= 0;
682 MaxSubscriptionsPerPrinter
= 0;
683 MaxSubscriptionsPerUser
= 0;
684 DefaultLeaseDuration
= 86400;
685 MaxLeaseDuration
= 0;
688 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
689 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
690 #endif /* HAVE_LAUNCHD */
694 #endif /* __APPLE__ */
697 * Read the configuration file...
700 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
703 status
= read_configuration(fp
);
712 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
713 RemotePort
? "enabled" : "disabled");
716 * See if the ServerName is an IP address...
722 ServerAlias
= cupsArrayNew(NULL
, NULL
);
724 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", ServerName
);
728 if (gethostname(temp
, sizeof(temp
)))
730 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
732 strlcpy(temp
, "localhost", sizeof(temp
));
735 cupsdSetString(&ServerName
, temp
);
738 ServerAlias
= cupsArrayNew(NULL
, NULL
);
740 cupsdAddAlias(ServerAlias
, temp
);
741 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
743 if (HostNameLookups
|| RemotePort
)
745 struct hostent
*host
; /* Host entry to get FQDN */
747 if ((host
= gethostbyname(temp
)) != NULL
)
749 if (strcasecmp(temp
, host
->h_name
))
751 cupsdSetString(&ServerName
, host
->h_name
);
752 cupsdAddAlias(ServerAlias
, host
->h_name
);
753 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
759 for (i
= 0; host
->h_aliases
[i
]; i
++)
760 if (strcasecmp(temp
, host
->h_aliases
[i
]))
762 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
763 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
771 * Make sure we have the base hostname added as an alias, too!
774 if ((slash
= strchr(temp
, '.')) != NULL
)
777 cupsdAddAlias(ServerAlias
, temp
);
778 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
782 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
784 ServerNameIsIP
= !*slash
;
787 * Make sure ServerAdmin is initialized...
791 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
794 * Use the default system group if none was supplied in cupsd.conf...
797 if (NumSystemGroups
== 0)
799 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
802 * Find the group associated with GID 0...
809 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
811 cupsdSetString(&SystemGroups
[0], "unknown");
813 SystemGroupIDs
[0] = 0;
819 * Get the access control list for browsing...
822 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
825 * Open the system log for cupsd if necessary...
829 if (!strcmp(AccessLog
, "syslog") ||
830 !strcmp(ErrorLog
, "syslog") ||
831 !strcmp(PageLog
, "syslog"))
832 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
833 #endif /* HAVE_VSYSLOG */
836 * Log the configuration file that was used...
839 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
843 * Validate the Group and SystemGroup settings - they cannot be the same,
844 * otherwise the CGI programs will be able to authenticate as root without
850 for (i
= 0; i
< NumSystemGroups
; i
++)
851 if (Group
== SystemGroupIDs
[i
])
854 if (i
< NumSystemGroups
)
857 * Log the error and reset the group to a safe value...
860 cupsdLogMessage(CUPSD_LOG_NOTICE
,
861 "Group and SystemGroup cannot use the same groups!");
862 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
864 group
= getgrnam("nobody");
868 Group
= group
->gr_gid
;
872 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
873 * complement number...)
882 * Check that we have at least one listen/port line; if not, report this
883 * as an error and exit!
886 if (cupsArrayCount(Listeners
) == 0)
892 cupsdLogMessage(CUPSD_LOG_EMERG
,
893 "No valid Listen or Port lines were found in the "
894 "configuration file!");
900 cupsdEndProcess(getpid(), 0);
904 * Set the default locale using the language and charset...
907 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
910 * Update all relative filenames to include the full path from ServerRoot...
913 if (DocumentRoot
[0] != '/')
914 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
916 if (RequestRoot
[0] != '/')
917 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
919 if (ServerBin
[0] != '/')
920 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
922 if (StateDir
[0] != '/')
923 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
925 if (CacheDir
[0] != '/')
926 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
929 if (ServerCertificate
[0] != '/')
930 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
932 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
933 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
935 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
938 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
939 if (ServerKey
[0] != '/')
940 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
942 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
943 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
944 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
946 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
947 #endif /* HAVE_SSL */
950 * Make sure that directories and config files are owned and
951 * writable by the user and group in the cupsd.conf file...
954 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
956 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
958 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
960 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
962 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
964 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
965 SystemGroupIDs
[0], 1, 1) < 0 ||
966 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
968 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
970 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
972 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
974 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
976 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
978 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
980 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
984 * Update TempDir to the default if it hasn't been set already...
989 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
992 * TMPDIR is defined, see if it is OK for us to use...
995 if (stat(tmpdir
, &tmpinfo
))
996 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
997 tmpdir
, strerror(errno
));
998 else if (!S_ISDIR(tmpinfo
.st_mode
))
999 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
1001 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
1002 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
1003 !(tmpinfo
.st_mode
& S_IWOTH
))
1004 cupsdLogMessage(CUPSD_LOG_ERROR
,
1005 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
1007 cupsdSetString(&TempDir
, tmpdir
);
1012 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1014 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1019 * Make sure the temporary directory has the right permissions...
1022 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1026 * Update ownership and permissions if the CUPS temp directory
1027 * is under the spool directory or does not exist...
1030 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1031 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1036 * Setup environment variables...
1042 * Update default paper size setting as needed...
1045 if (!DefaultPaperSize
)
1047 #ifdef HAVE_LIBPAPER
1048 char *paper_result
; /* Paper size name from libpaper */
1050 if ((paper_result
= systempapername()) != NULL
)
1051 cupsdSetString(&DefaultPaperSize
, paper_result
);
1053 #endif /* HAVE_LIBPAPER */
1054 if (!DefaultLanguage
||
1055 !strcasecmp(DefaultLanguage
, "C") ||
1056 !strcasecmp(DefaultLanguage
, "POSIX") ||
1057 !strcasecmp(DefaultLanguage
, "en") ||
1058 !strncasecmp(DefaultLanguage
, "en.", 3) ||
1059 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
1060 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1061 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
1064 * These are the only locales that will default to "letter" size...
1067 cupsdSetString(&DefaultPaperSize
, "Letter");
1070 cupsdSetString(&DefaultPaperSize
, "A4");
1074 * Update classification setting as needed...
1077 if (Classification
&& !strcasecmp(Classification
, "none"))
1078 cupsdClearString(&Classification
);
1081 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1084 * Check the MaxClients setting, and then allocate memory for it...
1087 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1090 cupsdLogMessage(CUPSD_LOG_INFO
,
1091 "MaxClients limited to 1/3 (%d) of the file descriptor "
1093 MaxFDs
/ 3, MaxFDs
);
1095 MaxClients
= MaxFDs
/ 3;
1098 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1102 * Check the MaxActiveJobs setting; limit to 1/3 the available
1103 * file descriptors, since we need a pipe for each job...
1106 if (MaxActiveJobs
> (MaxFDs
/ 3))
1107 MaxActiveJobs
= MaxFDs
/ 3;
1110 * Update the MaxClientsPerHost value, as needed...
1113 if (MaxClientsPerHost
<= 0)
1114 MaxClientsPerHost
= MaxClients
;
1116 if (MaxClientsPerHost
> MaxClients
)
1117 MaxClientsPerHost
= MaxClients
;
1119 cupsdLogMessage(CUPSD_LOG_INFO
,
1120 "Allowing up to %d client connections per host.",
1124 * Make sure that BrowseTimeout is at least twice the interval...
1127 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1129 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1133 BrowseTimeout
= BrowseInterval
* 2;
1135 BrowseTimeout
= DEFAULT_TIMEOUT
;
1137 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1142 * Update the default policy, as needed...
1146 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1148 DefaultPolicyPtr
= NULL
;
1150 if (!DefaultPolicyPtr
)
1152 cupsd_location_t
*po
; /* New policy operation */
1156 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1159 cupsdSetString(&DefaultPolicy
, "default");
1161 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1162 cupsdLogMessage(CUPSD_LOG_INFO
,
1163 "Using policy \"default\" as the default!");
1166 cupsdLogMessage(CUPSD_LOG_INFO
,
1167 "Creating CUPS default administrative policy:");
1169 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1171 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1172 cupsdLogMessage(CUPSD_LOG_INFO
,
1173 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1174 "Release-Job Restart-Job Purge-Jobs "
1175 "Set-Job-Attributes Create-Job-Subscription "
1176 "Renew-Subscription Cancel-Subscription "
1177 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1178 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1179 "CUPS-Authenticate-Job CUPS-Get-Document>");
1180 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1182 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1183 po
->order_type
= CUPSD_AUTH_ALLOW
;
1184 po
->level
= CUPSD_AUTH_USER
;
1186 cupsdAddName(po
, "@OWNER");
1187 cupsdAddName(po
, "@SYSTEM");
1188 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1190 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1191 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1192 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1193 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1194 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1195 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1196 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1197 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1198 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1199 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1200 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1201 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1202 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1203 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1204 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1205 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1206 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1207 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1209 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1211 cupsdLogMessage(CUPSD_LOG_INFO
,
1212 "<Limit Pause-Printer Resume-Printer "
1213 "Set-Printer-Attributes Enable-Printer "
1214 "Disable-Printer Pause-Printer-After-Current-Job "
1215 "Hold-New-Jobs Release-Held-New-Jobs "
1216 "Deactivate-Printer Activate-Printer Restart-Printer "
1217 "Shutdown-Printer Startup-Printer Promote-Job "
1218 "Schedule-Job-After CUPS-Add-Printer "
1219 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1220 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1221 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1222 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1224 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1225 po
->order_type
= CUPSD_AUTH_ALLOW
;
1226 po
->type
= CUPSD_AUTH_DEFAULT
;
1227 po
->level
= CUPSD_AUTH_USER
;
1229 cupsdAddName(po
, "@SYSTEM");
1230 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1232 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1233 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1234 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1235 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1236 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1237 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1238 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1239 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1240 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1241 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1242 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1243 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1244 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1245 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1246 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1247 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1248 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1249 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1250 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1251 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1252 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1254 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1256 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1257 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1259 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1260 po
->order_type
= CUPSD_AUTH_ALLOW
;
1262 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1263 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1267 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1268 cupsArrayCount(Policies
));
1269 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1271 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1272 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1273 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1276 * If we are doing a full reload or the server root has changed, flush
1277 * the jobs, printers, etc. and start from scratch...
1280 if (NeedReload
== RELOAD_ALL
||
1281 old_remote_port
!= RemotePort
||
1282 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1283 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1285 mime_type_t
*type
; /* Current type */
1286 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1287 /* MIME type name */
1290 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1293 * Free all memory...
1296 cupsdDeleteAllSubscriptions();
1298 cupsdDeleteAllPrinters();
1300 DefaultPrinter
= NULL
;
1302 if (MimeDatabase
!= NULL
)
1303 mimeDelete(MimeDatabase
);
1307 for (i
= 0; i
< NumMimeTypes
; i
++)
1308 _cupsStrFree(MimeTypes
[i
]);
1314 * Read the MIME type and conversion database...
1317 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1318 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1320 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1321 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1322 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1323 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1327 cupsdLogMessage(CUPSD_LOG_EMERG
,
1328 "Unable to load MIME database from \"%s\" or \"%s\"!",
1329 mimedir
, ServerRoot
);
1330 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1334 cupsdLogMessage(CUPSD_LOG_INFO
,
1335 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1336 "%d filters...", mimedir
, ServerRoot
,
1337 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1340 * Create a list of MIME types for the document-format-supported
1344 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1345 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1348 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1350 cupsdLogMessage(CUPSD_LOG_ERROR
,
1351 "Unable to allocate memory for %d MIME types!",
1357 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1359 i
++, type
= mimeNextType(MimeDatabase
))
1361 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1363 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1366 if (i
< NumMimeTypes
)
1367 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1370 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1372 mime_filter_t
*filter
; /* Current filter */
1375 for (type
= mimeFirstType(MimeDatabase
);
1377 type
= mimeNextType(MimeDatabase
))
1378 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1379 type
->super
, type
->type
);
1381 for (filter
= mimeFirstFilter(MimeDatabase
);
1383 filter
= mimeNextFilter(MimeDatabase
))
1384 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1385 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1386 filter
->src
->super
, filter
->src
->type
,
1387 filter
->dst
->super
, filter
->dst
->type
,
1388 filter
->cost
, filter
->filter
);
1395 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1396 cupsdLoadBanners(temp
);
1399 * Load printers and classes...
1402 cupsdLoadAllPrinters();
1403 cupsdLoadAllClasses();
1404 cupsdLoadRemoteCache();
1405 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1407 cupsdCreateCommonData();
1410 * Load queued jobs...
1416 * Load subscriptions...
1419 cupsdLoadAllSubscriptions();
1421 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1426 * Not a full reload, so recreate the common printer attributes...
1429 cupsdCreateCommonData();
1432 * Update all printers as needed...
1435 cupsdUpdatePrinters();
1436 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1438 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1442 * Reset the reload state...
1445 NeedReload
= RELOAD_NONE
;
1447 cupsdClearString(&old_serverroot
);
1448 cupsdClearString(&old_requestroot
);
1455 * 'get_address()' - Get an address + port number from a line.
1458 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1459 get_address(const char *value
, /* I - Value string */
1460 int defport
) /* I - Default port */
1462 char buffer
[1024], /* Hostname + port number buffer */
1463 defpname
[255], /* Default port name */
1464 *hostname
, /* Hostname or IP */
1465 *portname
; /* Port number or name */
1466 http_addrlist_t
*addrlist
; /* Address list */
1470 * Check for an empty value...
1475 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1480 * Grab a hostname and port number; if there is no colon and the port name
1481 * is only digits, then we have a port number by itself...
1484 strlcpy(buffer
, value
, sizeof(buffer
));
1486 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1493 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1498 * Use the default port...
1501 sprintf(defpname
, "%d", defport
);
1502 portname
= defpname
;
1508 * The buffer contains just a port number...
1516 if (hostname
&& !strcmp(hostname
, "*"))
1520 * Now lookup the address using httpAddrGetList()...
1523 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1524 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1525 hostname
? hostname
: "(nil)");
1532 * 'get_addr_and_mask()' - Get an IP address and netmask.
1535 static int /* O - 1 on success, 0 on failure */
1536 get_addr_and_mask(const char *value
, /* I - String from config file */
1537 unsigned *ip
, /* O - Address value */
1538 unsigned *mask
) /* O - Mask value */
1540 int i
, j
, /* Looping vars */
1541 family
, /* Address family */
1542 ipcount
; /* Count of fields in address */
1543 unsigned ipval
; /* Value */
1544 const char *maskval
, /* Pointer to start of mask value */
1545 *ptr
, /* Pointer into value */
1550 * Get the address...
1553 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1554 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1556 if ((maskval
= strchr(value
, '/')) != NULL
)
1559 maskval
= value
+ strlen(value
);
1563 * Check for an IPv6 address...
1569 * Parse hexadecimal IPv6 address...
1574 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1578 else if (!strncmp(ptr
, "::", 2))
1580 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1582 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1587 else if (isxdigit(*ptr
& 255))
1589 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1597 ip
[i
/ 2] |= ipval
<< 16;
1611 if (*ptr
&& *ptr
!= '/')
1615 #endif /* AF_INET6 */
1618 * Parse dotted-decimal IPv4 address...
1621 unsigned val
[4]; /* IPv4 address values */
1625 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1628 * Range check the IP numbers...
1631 for (i
= 0; i
< ipcount
; i
++)
1636 * Make sure the trailing values are zeroed, as some C libraries like
1637 * glibc apparently like to fill the unused arguments with garbage...
1640 for (i
= ipcount
; i
< 4; i
++)
1644 * Merge everything into a 32-bit IPv4 address in ip[3]...
1647 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1650 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1656 * Get the netmask value(s)...
1659 memset(mask
, 0, sizeof(unsigned) * 4);
1661 if (strchr(maskval
, '.'))
1664 * Get dotted-decimal mask...
1667 if (family
!= AF_INET
)
1670 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1673 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1674 mask
[0] = mask
[1] = mask
[2] = 0;
1679 * Get address/bits format...
1685 if (family
== AF_INET6
)
1693 mask
[0] = 0xffffffff;
1695 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1698 mask
[1] = 0xffffffff;
1702 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1705 mask
[2] = 0xffffffff;
1709 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1712 mask
[3] = 0xffffffff;
1716 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1719 #endif /* AF_INET6 */
1724 mask
[0] = 0xffffffff;
1725 mask
[1] = 0xffffffff;
1726 mask
[2] = 0xffffffff;
1729 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1731 mask
[3] = 0xffffffff;
1736 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1737 "get_addr_and_mask(value=\"%s\", "
1738 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1739 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1743 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1746 if ((ip
[0] & ~mask
[0]) != 0 ||
1747 (ip
[1] & ~mask
[1]) != 0 ||
1748 (ip
[2] & ~mask
[2]) != 0 ||
1749 (ip
[3] & ~mask
[3]) != 0)
1757 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1760 static int /* O - 1 on success, 0 on failure */
1761 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1762 char *line
, /* I - Line from file */
1763 char *value
, /* I - Start of value data */
1764 int linenum
) /* I - Current line number */
1766 char *valptr
; /* Pointer into value */
1767 unsigned ip
[4], /* IP address components */
1768 mask
[4]; /* IP netmask components */
1771 if (!strcasecmp(line
, "Encryption"))
1774 * "Encryption xxx" - set required encryption level...
1777 if (!strcasecmp(value
, "never"))
1778 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1779 else if (!strcasecmp(value
, "always"))
1781 cupsdLogMessage(CUPSD_LOG_ERROR
,
1782 "Encryption value \"%s\" on line %d is invalid in this "
1783 "context. Using \"required\" instead.", value
, linenum
);
1785 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1787 else if (!strcasecmp(value
, "required"))
1788 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1789 else if (!strcasecmp(value
, "ifrequested"))
1790 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1793 cupsdLogMessage(CUPSD_LOG_ERROR
,
1794 "Unknown Encryption value %s on line %d.", value
, linenum
);
1798 else if (!strcasecmp(line
, "Order"))
1801 * "Order Deny,Allow" or "Order Allow,Deny"...
1804 if (!strncasecmp(value
, "deny", 4))
1805 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1806 else if (!strncasecmp(value
, "allow", 5))
1807 loc
->order_type
= CUPSD_AUTH_DENY
;
1810 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1815 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1818 * Allow [From] host/ip...
1819 * Deny [From] host/ip...
1824 if (!strncasecmp(value
, "from", 4))
1827 * Strip leading "from"...
1832 while (isspace(*value
& 255))
1840 * Find the end of the value...
1843 for (valptr
= value
; *valptr
&& !isspace(*valptr
& 255); valptr
++);
1845 while (isspace(*valptr
& 255))
1849 * Figure out what form the allow/deny address takes:
1860 * nnn.nnn.nnn.nnn/mm
1861 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1864 if (!strcasecmp(value
, "all"))
1870 if (!strcasecmp(line
, "Allow"))
1871 cupsdAllowIP(loc
, zeros
, zeros
);
1873 cupsdDenyIP(loc
, zeros
, zeros
);
1875 else if (!strcasecmp(value
, "none"))
1881 if (!strcasecmp(line
, "Allow"))
1882 cupsdAllowIP(loc
, ones
, zeros
);
1884 cupsdDenyIP(loc
, ones
, zeros
);
1887 else if (value
[0] == '*' || value
[0] == '.' ||
1888 (!isdigit(value
[0] & 255) && value
[0] != '['))
1890 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1891 #endif /* AF_INET6 */
1894 * Host or domain name...
1897 if (value
[0] == '*')
1900 if (!strcasecmp(line
, "Allow"))
1901 cupsdAllowHost(loc
, value
);
1903 cupsdDenyHost(loc
, value
);
1908 * One of many IP address forms...
1911 if (!get_addr_and_mask(value
, ip
, mask
))
1913 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1918 if (!strcasecmp(line
, "Allow"))
1919 cupsdAllowIP(loc
, ip
, mask
);
1921 cupsdDenyIP(loc
, ip
, mask
);
1925 * Advance to next value...
1931 else if (!strcasecmp(line
, "AuthType"))
1934 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1937 if (!strcasecmp(value
, "none"))
1939 loc
->type
= CUPSD_AUTH_NONE
;
1940 loc
->level
= CUPSD_AUTH_ANON
;
1942 else if (!strcasecmp(value
, "basic"))
1944 loc
->type
= CUPSD_AUTH_BASIC
;
1946 if (loc
->level
== CUPSD_AUTH_ANON
)
1947 loc
->level
= CUPSD_AUTH_USER
;
1949 else if (!strcasecmp(value
, "digest"))
1951 loc
->type
= CUPSD_AUTH_DIGEST
;
1953 if (loc
->level
== CUPSD_AUTH_ANON
)
1954 loc
->level
= CUPSD_AUTH_USER
;
1956 else if (!strcasecmp(value
, "basicdigest"))
1958 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1960 if (loc
->level
== CUPSD_AUTH_ANON
)
1961 loc
->level
= CUPSD_AUTH_USER
;
1963 else if (!strcasecmp(value
, "default"))
1965 loc
->type
= CUPSD_AUTH_DEFAULT
;
1967 if (loc
->level
== CUPSD_AUTH_ANON
)
1968 loc
->level
= CUPSD_AUTH_USER
;
1971 else if (!strcasecmp(value
, "negotiate"))
1973 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1975 if (loc
->level
== CUPSD_AUTH_ANON
)
1976 loc
->level
= CUPSD_AUTH_USER
;
1978 #endif /* HAVE_GSSAPI */
1981 cupsdLogMessage(CUPSD_LOG_WARN
,
1982 "Unknown authorization type %s on line %d.",
1987 else if (!strcasecmp(line
, "AuthClass"))
1990 * AuthClass anonymous, user, system, group
1993 if (!strcasecmp(value
, "anonymous"))
1995 loc
->type
= CUPSD_AUTH_NONE
;
1996 loc
->level
= CUPSD_AUTH_ANON
;
1998 cupsdLogMessage(CUPSD_LOG_WARN
,
1999 "\"AuthClass %s\" is deprecated; consider removing "
2003 else if (!strcasecmp(value
, "user"))
2005 loc
->level
= CUPSD_AUTH_USER
;
2007 cupsdLogMessage(CUPSD_LOG_WARN
,
2008 "\"AuthClass %s\" is deprecated; consider using "
2009 "\"Require valid-user\" on line %d.",
2012 else if (!strcasecmp(value
, "group"))
2014 loc
->level
= CUPSD_AUTH_GROUP
;
2016 cupsdLogMessage(CUPSD_LOG_WARN
,
2017 "\"AuthClass %s\" is deprecated; consider using "
2018 "\"Require user @groupname\" on line %d.",
2021 else if (!strcasecmp(value
, "system"))
2023 loc
->level
= CUPSD_AUTH_GROUP
;
2025 cupsdAddName(loc
, "@SYSTEM");
2027 cupsdLogMessage(CUPSD_LOG_WARN
,
2028 "\"AuthClass %s\" is deprecated; consider using "
2029 "\"Require user @SYSTEM\" on line %d.",
2034 cupsdLogMessage(CUPSD_LOG_WARN
,
2035 "Unknown authorization class %s on line %d.",
2040 else if (!strcasecmp(line
, "AuthGroupName"))
2042 cupsdAddName(loc
, value
);
2044 cupsdLogMessage(CUPSD_LOG_WARN
,
2045 "\"AuthGroupName %s\" directive is deprecated; consider "
2046 "using \"Require user @%s\" on line %d.",
2047 value
, value
, linenum
);
2049 else if (!strcasecmp(line
, "Require"))
2052 * Apache synonym for AuthClass and AuthGroupName...
2056 * Require valid-user
2057 * Require group names
2058 * Require user names
2061 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2066 if (!strcasecmp(value
, "valid-user") ||
2067 !strcasecmp(value
, "user"))
2068 loc
->level
= CUPSD_AUTH_USER
;
2069 else if (!strcasecmp(value
, "group"))
2070 loc
->level
= CUPSD_AUTH_GROUP
;
2073 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2079 * Get the list of names from the line...
2082 for (value
= valptr
; *value
;)
2084 while (isspace(*value
& 255))
2087 #ifdef HAVE_AUTHORIZATION_H
2088 if (!strncmp(value
, "@AUTHKEY(", 9))
2091 * Grab "@AUTHKEY(name)" value...
2094 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2100 #endif /* HAVE_AUTHORIZATION_H */
2101 if (*value
== '\"' || *value
== '\'')
2104 * Grab quoted name...
2107 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2114 * Grab literal name.
2117 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2123 cupsdAddName(loc
, value
);
2125 for (value
= valptr
; isspace(*value
& 255); value
++);
2128 else if (!strcasecmp(line
, "Satisfy"))
2130 if (!strcasecmp(value
, "all"))
2131 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2132 else if (!strcasecmp(value
, "any"))
2133 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2136 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2149 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2152 static int /* O - FatalErrors bits */
2153 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2155 int fatal
; /* FatalErrors bits */
2156 char value
[1024], /* Value string */
2157 *valstart
, /* Pointer into value */
2158 *valend
; /* End of value */
2162 * Empty FatalErrors line yields NULL pointer...
2166 return (CUPSD_FATAL_NONE
);
2169 * Loop through the value string,...
2172 strlcpy(value
, s
, sizeof(value
));
2174 fatal
= CUPSD_FATAL_NONE
;
2176 for (valstart
= value
; *valstart
;)
2179 * Get the current space/comma-delimited kind name...
2182 for (valend
= valstart
; *valend
; valend
++)
2183 if (isspace(*valend
& 255) || *valend
== ',')
2190 * Add the error to the bitmask...
2193 if (!strcasecmp(valstart
, "all"))
2194 fatal
= CUPSD_FATAL_ALL
;
2195 else if (!strcasecmp(valstart
, "browse"))
2196 fatal
|= CUPSD_FATAL_BROWSE
;
2197 else if (!strcasecmp(valstart
, "-browse"))
2198 fatal
&= ~CUPSD_FATAL_BROWSE
;
2199 else if (!strcasecmp(valstart
, "config"))
2200 fatal
|= CUPSD_FATAL_CONFIG
;
2201 else if (!strcasecmp(valstart
, "-config"))
2202 fatal
&= ~CUPSD_FATAL_CONFIG
;
2203 else if (!strcasecmp(valstart
, "listen"))
2204 fatal
|= CUPSD_FATAL_LISTEN
;
2205 else if (!strcasecmp(valstart
, "-listen"))
2206 fatal
&= ~CUPSD_FATAL_LISTEN
;
2207 else if (!strcasecmp(valstart
, "log"))
2208 fatal
|= CUPSD_FATAL_LOG
;
2209 else if (!strcasecmp(valstart
, "-log"))
2210 fatal
&= ~CUPSD_FATAL_LOG
;
2211 else if (!strcasecmp(valstart
, "permissions"))
2212 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2213 else if (!strcasecmp(valstart
, "-permissions"))
2214 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2215 else if (strcasecmp(valstart
, "none"))
2216 cupsdLogMessage(CUPSD_LOG_ERROR
,
2217 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2219 for (valstart
= valend
; *valstart
; valstart
++)
2220 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2229 * 'parse_groups()' - Parse system group names in a string.
2232 static int /* O - 1 on success, 0 on failure */
2233 parse_groups(const char *s
) /* I - Space-delimited groups */
2235 int status
; /* Return status */
2236 char value
[1024], /* Value string */
2237 *valstart
, /* Pointer into value */
2238 *valend
, /* End of value */
2239 quote
; /* Quote character */
2240 struct group
*group
; /* Group */
2244 * Make a copy of the string and parse out the groups...
2247 strlcpy(value
, s
, sizeof(value
));
2252 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2254 if (*valstart
== '\'' || *valstart
== '\"')
2257 * Scan quoted name...
2260 quote
= *valstart
++;
2262 for (valend
= valstart
; *valend
; valend
++)
2263 if (*valend
== quote
)
2269 * Scan space or comma-delimited name...
2272 for (valend
= valstart
; *valend
; valend
++)
2273 if (isspace(*valend
) || *valend
== ',')
2280 group
= getgrnam(valstart
);
2283 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2284 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2295 while (*valstart
== ',' || isspace(*valstart
))
2304 * 'parse_protocols()' - Parse browse protocols in a string.
2307 static int /* O - Browse protocol bits */
2308 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2310 int protocols
; /* Browse protocol bits */
2311 char value
[1024], /* Value string */
2312 *valstart
, /* Pointer into value */
2313 *valend
; /* End of value */
2317 * Empty protocol line yields NULL pointer...
2324 * Loop through the value string,...
2327 strlcpy(value
, s
, sizeof(value
));
2331 for (valstart
= value
; *valstart
;)
2334 * Get the current space/comma-delimited protocol name...
2337 for (valend
= valstart
; *valend
; valend
++)
2338 if (isspace(*valend
& 255) || *valend
== ',')
2345 * Add the protocol to the bitmask...
2348 if (!strcasecmp(valstart
, "cups"))
2349 protocols
|= BROWSE_CUPS
;
2350 else if (!strcasecmp(valstart
, "slp"))
2351 protocols
|= BROWSE_SLP
;
2352 else if (!strcasecmp(valstart
, "ldap"))
2353 protocols
|= BROWSE_LDAP
;
2354 else if (!strcasecmp(valstart
, "dnssd") ||
2355 !strcasecmp(valstart
, "dns-sd") ||
2356 !strcasecmp(valstart
, "bonjour"))
2357 protocols
|= BROWSE_DNSSD
;
2358 else if (!strcasecmp(valstart
, "lpd"))
2359 protocols
|= BROWSE_LPD
;
2360 else if (!strcasecmp(valstart
, "smb"))
2361 protocols
|= BROWSE_SMB
;
2362 else if (!strcasecmp(valstart
, "all"))
2363 protocols
|= BROWSE_ALL
;
2364 else if (strcasecmp(valstart
, "none"))
2365 cupsdLogMessage(CUPSD_LOG_ERROR
,
2366 "Unknown browse protocol \"%s\" ignored!", valstart
);
2368 for (valstart
= valend
; *valstart
; valstart
++)
2369 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2378 * 'read_configuration()' - Read a configuration file.
2381 static int /* O - 1 on success, 0 on failure */
2382 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2384 int i
; /* Looping var */
2385 int linenum
; /* Current line number */
2386 char line
[HTTP_MAX_BUFFER
],
2387 /* Line from file */
2388 temp
[HTTP_MAX_BUFFER
],
2389 /* Temporary buffer for value */
2390 temp2
[HTTP_MAX_BUFFER
],
2391 /* Temporary buffer 2 for value */
2392 *ptr
, /* Pointer into line/temp */
2393 *value
, /* Pointer to value */
2394 *valueptr
; /* Pointer into value */
2395 int valuelen
; /* Length of value */
2396 cupsd_var_t
const *var
; /* Current variable */
2397 http_addrlist_t
*addrlist
, /* Address list */
2398 *addr
; /* Current address */
2399 unsigned ip
[4], /* Address value */
2400 mask
[4]; /* Netmask value */
2401 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2402 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2403 cupsd_location_t
*location
; /* Browse location */
2404 cups_file_t
*incfile
; /* Include file */
2405 char incname
[1024]; /* Include filename */
2406 struct group
*group
; /* Group */
2410 * Loop through each line in the file...
2415 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2418 * Decode the directive...
2421 if (!strcasecmp(line
, "Include") && value
)
2427 if (value
[0] == '/')
2428 strlcpy(incname
, value
, sizeof(incname
));
2430 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2432 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2433 cupsdLogMessage(CUPSD_LOG_ERROR
,
2434 "Unable to include config file \"%s\" - %s",
2435 incname
, strerror(errno
));
2438 read_configuration(incfile
);
2439 cupsFileClose(incfile
);
2442 else if (!strcasecmp(line
, "<Location") && value
)
2448 linenum
= read_location(fp
, value
, linenum
);
2452 else if (!strcasecmp(line
, "<Policy") && value
)
2458 linenum
= read_policy(fp
, value
, linenum
);
2462 else if (!strcasecmp(line
, "FatalErrors"))
2463 FatalErrors
= parse_fatal_errors(value
);
2464 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2466 JobRetryInterval
= atoi(value
);
2467 cupsdLogMessage(CUPSD_LOG_WARN
,
2468 "FaxRetryInterval is deprecated; use "
2469 "JobRetryInterval on line %d.", linenum
);
2471 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2473 JobRetryLimit
= atoi(value
);
2474 cupsdLogMessage(CUPSD_LOG_WARN
,
2475 "FaxRetryLimit is deprecated; use "
2476 "JobRetryLimit on line %d.", linenum
);
2478 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2480 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2481 #endif /* HAVE_SSL */
2485 * Add listening address(es) to the list...
2488 cupsd_listener_t
*lis
; /* New listeners array */
2492 * Get the address list...
2495 addrlist
= get_address(value
, IPP_PORT
);
2499 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2505 * Add each address...
2508 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2511 * See if this address is already present...
2514 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2516 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2517 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2518 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2523 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2524 cupsdLogMessage(CUPSD_LOG_WARN
,
2525 "Duplicate listen address \"%s\" ignored!", temp
);
2530 * Allocate another listener...
2534 Listeners
= cupsArrayNew(NULL
, NULL
);
2538 cupsdLogMessage(CUPSD_LOG_ERROR
,
2539 "Unable to allocate %s at line %d - %s.",
2540 line
, linenum
, strerror(errno
));
2544 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2546 cupsdLogMessage(CUPSD_LOG_ERROR
,
2547 "Unable to allocate %s at line %d - %s.",
2548 line
, linenum
, strerror(errno
));
2552 cupsArrayAdd(Listeners
, lis
);
2555 * Copy the current address and log it...
2558 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2562 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2563 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2564 #endif /* HAVE_SSL */
2566 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2569 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2570 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2571 ntohs(lis
->address
.ipv6
.sin6_port
));
2573 #endif /* AF_INET6 */
2575 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2576 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2578 #endif /* AF_LOCAL */
2579 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2580 ntohs(lis
->address
.ipv4
.sin_port
));
2582 if (!httpAddrLocalhost(&(lis
->address
)))
2585 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2586 RemotePort
= ntohs(lis
->address
.ipv6
.sin6_port
);
2588 #endif /* AF_INET6 */
2589 RemotePort
= ntohs(lis
->address
.ipv4
.sin_port
);
2597 httpAddrFreeList(addrlist
);
2599 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2602 * Add a browse address to the list...
2605 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2608 if (NumBrowsers
== 0)
2609 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2611 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2615 cupsdLogMessage(CUPSD_LOG_ERROR
,
2616 "Unable to allocate BrowseAddress at line %d - %s.",
2617 linenum
, strerror(errno
));
2622 dira
+= NumBrowsers
;
2624 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2626 if (!strcasecmp(value
, "@LOCAL"))
2629 * Send browse data to all local interfaces...
2632 strcpy(dira
->iface
, "*");
2635 else if (!strncasecmp(value
, "@IF(", 4))
2638 * Send browse data to the named interface...
2641 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2643 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2649 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2652 * Only IPv4 addresses are supported...
2655 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2656 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2661 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2662 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2664 cupsdLogMessage(CUPSD_LOG_INFO
,
2665 "Sending browsing info to %s:%d (IPv4)",
2666 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2671 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2674 httpAddrFreeList(addrlist
);
2677 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2680 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2683 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2686 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2687 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2689 if (location
== NULL
)
2690 cupsdLogMessage(CUPSD_LOG_ERROR
,
2691 "Unable to initialize browse access control list!");
2692 else if (!strncasecmp(value
, "deny", 4))
2693 location
->order_type
= CUPSD_AUTH_ALLOW
;
2694 else if (!strncasecmp(value
, "allow", 5))
2695 location
->order_type
= CUPSD_AUTH_DENY
;
2697 cupsdLogMessage(CUPSD_LOG_ERROR
,
2698 "Unknown BrowseOrder value %s on line %d.",
2701 else if (!strcasecmp(line
, "BrowseProtocols") ||
2702 !strcasecmp(line
, "BrowseLocalProtocols") ||
2703 !strcasecmp(line
, "BrowseRemoteProtocols"))
2706 * "BrowseProtocols name [... name]"
2707 * "BrowseLocalProtocols name [... name]"
2708 * "BrowseRemoteProtocols name [... name]"
2711 int protocols
= parse_protocols(value
);
2715 cupsdLogMessage(CUPSD_LOG_ERROR
,
2716 "Unknown browse protocol \"%s\" on line %d.",
2721 if (strcasecmp(line
, "BrowseLocalProtocols"))
2722 BrowseRemoteProtocols
= protocols
;
2723 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2724 BrowseLocalProtocols
= protocols
;
2726 else if ((!strcasecmp(line
, "BrowseAllow") ||
2727 !strcasecmp(line
, "BrowseDeny")) && value
)
2730 * BrowseAllow [From] host/ip...
2731 * BrowseDeny [From] host/ip...
2734 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2735 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2737 if (location
== NULL
)
2738 cupsdLogMessage(CUPSD_LOG_ERROR
,
2739 "Unable to initialize browse access control list!");
2744 if (!strncasecmp(value
, "from", 4))
2747 * Strip leading "from"...
2752 while (isspace(*value
& 255))
2760 * Find the end of the value...
2763 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2765 while (isspace(*valueptr
& 255))
2769 * Figure out what form the allow/deny address takes:
2780 * nnn.nnn.nnn.nnn/mm
2781 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2784 if (!strcasecmp(value
, "all"))
2790 if (!strcasecmp(line
, "BrowseAllow"))
2791 cupsdAllowIP(location
, zeros
, zeros
);
2793 cupsdDenyIP(location
, zeros
, zeros
);
2795 else if (!strcasecmp(value
, "none"))
2801 if (!strcasecmp(line
, "BrowseAllow"))
2802 cupsdAllowIP(location
, ones
, zeros
);
2804 cupsdDenyIP(location
, ones
, zeros
);
2807 else if (value
[0] == '*' || value
[0] == '.' ||
2808 (!isdigit(value
[0] & 255) && value
[0] != '['))
2810 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2811 #endif /* AF_INET6 */
2814 * Host or domain name...
2817 if (value
[0] == '*')
2820 if (!strcasecmp(line
, "BrowseAllow"))
2821 cupsdAllowHost(location
, value
);
2823 cupsdDenyHost(location
, value
);
2828 * One of many IP address forms...
2831 if (!get_addr_and_mask(value
, ip
, mask
))
2833 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2838 if (!strcasecmp(line
, "BrowseAllow"))
2839 cupsdAllowIP(location
, ip
, mask
);
2841 cupsdDenyIP(location
, ip
, mask
);
2845 * Advance to next value...
2852 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2855 * BrowseRelay [from] source [to] destination
2859 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2861 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2865 cupsdLogMessage(CUPSD_LOG_ERROR
,
2866 "Unable to allocate BrowseRelay at line %d - %s.",
2867 linenum
, strerror(errno
));
2874 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2876 if (!strncasecmp(value
, "from ", 5))
2879 * Strip leading "from"...
2884 while (isspace(*value
))
2889 * Figure out what form the from address takes:
2898 * nnn.nnn.nnn.nnn/mm
2899 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2903 if (value
[0] == '*' || value
[0] == '.' ||
2904 (!isdigit(value
[0] & 255) && value
[0] != '['))
2906 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2907 #endif /* AF_INET6 */
2910 * Host or domain name...
2913 if (value
[0] == '*')
2916 strlcpy(temp
, value
, sizeof(temp
));
2917 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2920 relay
->from
.type
= CUPSD_AUTH_NAME
;
2922 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2924 cupsdLogMessage(CUPSD_LOG_ERROR
,
2925 "Unable to allocate BrowseRelay name at line %d - %s.",
2926 linenum
, strerror(errno
));
2930 relay
->from
.mask
.name
.length
= strlen(temp
);
2935 * One of many IP address forms...
2938 if (!get_addr_and_mask(value
, ip
, mask
))
2940 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2945 relay
->from
.type
= CUPSD_AUTH_IP
;
2946 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2947 sizeof(relay
->from
.mask
.ip
.address
));
2948 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2949 sizeof(relay
->from
.mask
.ip
.netmask
));
2953 * Skip value and trailing whitespace...
2956 for (; *value
; value
++)
2957 if (isspace(*value
))
2960 while (isspace(*value
))
2963 if (!strncasecmp(value
, "to ", 3))
2966 * Strip leading "to"...
2971 while (isspace(*value
))
2976 * Get "to" address and port...
2979 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2982 * Only IPv4 addresses are supported...
2985 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2986 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2991 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2993 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2995 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2996 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2997 relay
->from
.mask
.ip
.address
[0] >> 24,
2998 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2999 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
3000 relay
->from
.mask
.ip
.address
[0] & 255,
3001 relay
->from
.mask
.ip
.netmask
[0] >> 24,
3002 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
3003 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
3004 relay
->from
.mask
.ip
.netmask
[0] & 255);
3006 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
3008 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
3009 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
3014 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3017 httpAddrFreeList(addrlist
);
3021 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
3022 free(relay
->from
.mask
.name
.name
);
3024 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3028 else if (!strcasecmp(line
, "BrowsePoll") && value
)
3031 * BrowsePoll address[:port]
3034 char *portname
; /* Port name */
3035 int portnum
; /* Port number */
3036 struct servent
*service
; /* Service */
3040 * Extract the port name from the address...
3043 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
3047 if (isdigit(*portname
& 255))
3048 portnum
= atoi(portname
);
3049 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
3050 portnum
= ntohs(service
->s_port
);
3053 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
3059 portnum
= ippPort();
3062 * Add the poll entry...
3066 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
3068 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
3072 cupsdLogMessage(CUPSD_LOG_ERROR
,
3073 "Unable to allocate BrowsePoll at line %d - %s.",
3074 linenum
, strerror(errno
));
3082 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
3084 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
3085 pollp
->port
= portnum
;
3087 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
3090 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
3093 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3096 if (!strcasecmp(value
, "none"))
3097 DefaultAuthType
= CUPSD_AUTH_NONE
;
3098 else if (!strcasecmp(value
, "basic"))
3099 DefaultAuthType
= CUPSD_AUTH_BASIC
;
3100 else if (!strcasecmp(value
, "digest"))
3101 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
3102 else if (!strcasecmp(value
, "basicdigest"))
3103 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
3105 else if (!strcasecmp(value
, "negotiate"))
3106 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
3107 #endif /* HAVE_GSSAPI */
3110 cupsdLogMessage(CUPSD_LOG_WARN
,
3111 "Unknown default authorization type %s on line %d.",
3113 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3118 else if (!strcasecmp(line
, "DefaultEncryption"))
3121 * DefaultEncryption {Never,IfRequested,Required}
3124 if (!value
|| !strcasecmp(value
, "never"))
3125 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3126 else if (!strcasecmp(value
, "required"))
3127 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3128 else if (!strcasecmp(value
, "ifrequested"))
3129 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3132 cupsdLogMessage(CUPSD_LOG_WARN
,
3133 "Unknown default encryption %s on line %d.",
3135 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3139 #endif /* HAVE_SSL */
3140 else if (!strcasecmp(line
, "User") && value
)
3143 * User ID to run as...
3146 if (isdigit(value
[0] & 255))
3148 int uid
= atoi(value
);
3151 cupsdLogMessage(CUPSD_LOG_ERROR
,
3152 "Will not use User 0 as specified on line %d "
3153 "for security reasons. You must use a non-"
3154 "privileged account instead.",
3161 struct passwd
*p
; /* Password information */
3164 p
= getpwnam(value
);
3169 cupsdLogMessage(CUPSD_LOG_ERROR
,
3170 "Will not use User %s (UID=0) as specified on line "
3171 "%d for security reasons. You must use a non-"
3172 "privileged account instead.",
3178 cupsdLogMessage(CUPSD_LOG_ERROR
,
3179 "Unknown User \"%s\" on line %d, ignoring!",
3183 else if (!strcasecmp(line
, "Group") && value
)
3186 * Group ID to run as...
3189 if (isdigit(value
[0]))
3190 Group
= atoi(value
);
3194 group
= getgrnam(value
);
3197 Group
= group
->gr_gid
;
3199 cupsdLogMessage(CUPSD_LOG_ERROR
,
3200 "Unknown Group \"%s\" on line %d, ignoring!",
3204 else if (!strcasecmp(line
, "SystemGroup") && value
)
3207 * SystemGroup (admin) group(s)...
3210 if (!parse_groups(value
))
3211 cupsdLogMessage(CUPSD_LOG_ERROR
,
3212 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3215 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3218 * Do hostname lookups?
3221 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3222 !strcasecmp(value
, "false"))
3223 HostNameLookups
= 0;
3224 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3225 !strcasecmp(value
, "true"))
3226 HostNameLookups
= 1;
3227 else if (!strcasecmp(value
, "double"))
3228 HostNameLookups
= 2;
3230 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3233 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3236 * Amount of logging to do to access log...
3239 if (!strcasecmp(value
, "all"))
3240 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3241 else if (!strcasecmp(value
, "actions"))
3242 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3243 else if (!strcasecmp(value
, "config"))
3244 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3246 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3249 else if (!strcasecmp(line
, "LogLevel") && value
)
3252 * Amount of logging to do to error log...
3255 if (!strcasecmp(value
, "debug2"))
3256 LogLevel
= CUPSD_LOG_DEBUG2
;
3257 else if (!strcasecmp(value
, "debug"))
3258 LogLevel
= CUPSD_LOG_DEBUG
;
3259 else if (!strcasecmp(value
, "info"))
3260 LogLevel
= CUPSD_LOG_INFO
;
3261 else if (!strcasecmp(value
, "notice"))
3262 LogLevel
= CUPSD_LOG_NOTICE
;
3263 else if (!strcasecmp(value
, "warn"))
3264 LogLevel
= CUPSD_LOG_WARN
;
3265 else if (!strcasecmp(value
, "error"))
3266 LogLevel
= CUPSD_LOG_ERROR
;
3267 else if (!strcasecmp(value
, "crit"))
3268 LogLevel
= CUPSD_LOG_CRIT
;
3269 else if (!strcasecmp(value
, "alert"))
3270 LogLevel
= CUPSD_LOG_ALERT
;
3271 else if (!strcasecmp(value
, "emerg"))
3272 LogLevel
= CUPSD_LOG_EMERG
;
3273 else if (!strcasecmp(value
, "none"))
3274 LogLevel
= CUPSD_LOG_NONE
;
3276 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3279 else if (!strcasecmp(line
, "LogTimeFormat") && value
)
3282 * Amount of logging to do to error log...
3285 if (!strcasecmp(value
, "standard"))
3286 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3287 else if (!strcasecmp(value
, "usecs"))
3288 LogTimeFormat
= CUPSD_TIME_USECS
;
3290 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3293 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3296 * Format of printcap file?
3299 if (!strcasecmp(value
, "bsd"))
3300 PrintcapFormat
= PRINTCAP_BSD
;
3301 else if (!strcasecmp(value
, "plist"))
3302 PrintcapFormat
= PRINTCAP_PLIST
;
3303 else if (!strcasecmp(value
, "solaris"))
3304 PrintcapFormat
= PRINTCAP_SOLARIS
;
3306 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3309 else if (!strcasecmp(line
, "ServerTokens") && value
)
3312 * Set the string used for the Server header...
3315 struct utsname plat
; /* Platform info */
3320 if (!strcasecmp(value
, "ProductOnly"))
3321 cupsdSetString(&ServerHeader
, "CUPS");
3322 else if (!strcasecmp(value
, "Major"))
3323 cupsdSetString(&ServerHeader
, "CUPS/1");
3324 else if (!strcasecmp(value
, "Minor"))
3325 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3326 else if (!strcasecmp(value
, "Minimal"))
3327 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3328 else if (!strcasecmp(value
, "OS"))
3329 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3330 else if (!strcasecmp(value
, "Full"))
3331 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3333 else if (!strcasecmp(value
, "None"))
3334 cupsdClearString(&ServerHeader
);
3336 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3339 else if (!strcasecmp(line
, "PassEnv") && value
)
3342 * PassEnv variable [... variable]
3347 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3348 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3351 if (value
[valuelen
])
3353 value
[valuelen
] = '\0';
3357 cupsdSetEnv(value
, NULL
);
3359 for (value
+= valuelen
; *value
; value
++)
3360 if (!isspace(*value
) || *value
!= ',')
3364 else if (!strcasecmp(line
, "ServerAlias") && value
)
3367 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3369 cupsdAddAlias(ServerAlias
, value
);
3371 else if (!strcasecmp(line
, "SetEnv") && value
)
3374 * SetEnv variable value
3377 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3385 while (isspace(*valueptr
& 255))
3388 cupsdSetEnv(value
, valueptr
);
3391 cupsdLogMessage(CUPSD_LOG_ERROR
,
3392 "Missing value for SetEnv directive on line %d.",
3396 else if (!strcasecmp(line
, "SSLOptions"))
3399 * SSLOptions options
3402 if (!value
|| !strcasecmp(value
, "none"))
3403 SSLOptions
= CUPSD_SSL_NONE
;
3404 else if (!strcasecmp(value
, "noemptyfragments"))
3405 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3407 cupsdLogMessage(CUPSD_LOG_ERROR
,
3408 "Unknown value \"%s\" for SSLOptions directive on "
3409 "line %d.", value
, linenum
);
3411 #endif /* HAVE_SSL */
3415 * Find a simple variable in the list...
3418 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3419 if (!strcasecmp(line
, var
->name
))
3425 * Unknown directive! Output an error message and continue...
3429 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3432 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3439 case CUPSD_VARTYPE_INTEGER
:
3441 cupsdLogMessage(CUPSD_LOG_ERROR
,
3442 "Missing integer value for %s on line %d!",
3447 char *units
; /* Units */
3450 n
= strtol(value
, &units
, 0);
3452 if (units
&& *units
)
3454 if (tolower(units
[0] & 255) == 'g')
3455 n
*= 1024 * 1024 * 1024;
3456 else if (tolower(units
[0] & 255) == 'm')
3458 else if (tolower(units
[0] & 255) == 'k')
3460 else if (tolower(units
[0] & 255) == 't')
3465 cupsdLogMessage(CUPSD_LOG_ERROR
,
3466 "Bad negative integer value for %s on line %d!",
3469 *((int *)var
->ptr
) = n
;
3473 case CUPSD_VARTYPE_BOOLEAN
:
3475 cupsdLogMessage(CUPSD_LOG_ERROR
,
3476 "Missing boolean value for %s on line %d!",
3478 else if (!strcasecmp(value
, "true") ||
3479 !strcasecmp(value
, "on") ||
3480 !strcasecmp(value
, "enabled") ||
3481 !strcasecmp(value
, "yes") ||
3483 *((int *)var
->ptr
) = TRUE
;
3484 else if (!strcasecmp(value
, "false") ||
3485 !strcasecmp(value
, "off") ||
3486 !strcasecmp(value
, "disabled") ||
3487 !strcasecmp(value
, "no") ||
3488 !strcasecmp(value
, "0"))
3489 *((int *)var
->ptr
) = FALSE
;
3491 cupsdLogMessage(CUPSD_LOG_ERROR
,
3492 "Unknown boolean value %s on line %d.",
3496 case CUPSD_VARTYPE_PATHNAME
:
3499 cupsdLogMessage(CUPSD_LOG_ERROR
,
3500 "Missing pathname value for %s on line %d!",
3505 if (value
[0] == '/')
3506 strlcpy(temp
, value
, sizeof(temp
));
3508 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3510 if (access(temp
, 0))
3512 cupsdLogMessage(CUPSD_LOG_ERROR
,
3513 "File or directory for \"%s %s\" on line %d "
3514 "does not exist!", line
, value
, linenum
);
3518 case CUPSD_VARTYPE_STRING
:
3519 cupsdSetString((char **)var
->ptr
, value
);
3530 * 'read_location()' - Read a <Location path> definition.
3533 static int /* O - New line number or 0 on error */
3534 read_location(cups_file_t
*fp
, /* I - Configuration file */
3535 char *location
, /* I - Location name/path */
3536 int linenum
) /* I - Current line number */
3538 cupsd_location_t
*loc
, /* New location */
3539 *parent
; /* Parent location */
3540 char line
[HTTP_MAX_BUFFER
],
3542 *value
, /* Value for directive */
3543 *valptr
; /* Pointer into value */
3546 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3549 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3552 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3555 * Decode the directive...
3558 if (!strcasecmp(line
, "</Location>"))
3560 else if (!strcasecmp(line
, "<Limit") ||
3561 !strcasecmp(line
, "<LimitExcept"))
3565 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3566 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3572 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3578 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3583 if (!strcmp(value
, "ALL"))
3584 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3585 else if (!strcmp(value
, "GET"))
3586 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3587 else if (!strcmp(value
, "HEAD"))
3588 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3589 else if (!strcmp(value
, "OPTIONS"))
3590 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3591 else if (!strcmp(value
, "POST"))
3592 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3593 else if (!strcmp(value
, "PUT"))
3594 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3595 else if (!strcmp(value
, "TRACE"))
3596 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3598 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3601 for (value
= valptr
; isspace(*value
& 255); value
++);
3604 if (!strcasecmp(line
, "<LimitExcept"))
3605 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3607 parent
->limit
&= ~loc
->limit
;
3609 else if (!strcasecmp(line
, "</Limit>") ||
3610 !strcasecmp(line
, "</LimitExcept>"))
3612 else if (!parse_aaa(loc
, line
, value
, linenum
))
3614 cupsdLogMessage(CUPSD_LOG_ERROR
,
3615 "Unknown Location directive %s on line %d.",
3617 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3622 cupsdLogMessage(CUPSD_LOG_ERROR
,
3623 "Unexpected end-of-file at line %d while reading location!",
3626 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3631 * 'read_policy()' - Read a <Policy name> definition.
3634 static int /* O - New line number or 0 on error */
3635 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3636 char *policy
, /* I - Location name/path */
3637 int linenum
) /* I - Current line number */
3639 int i
; /* Looping var */
3640 cupsd_policy_t
*pol
; /* Policy */
3641 cupsd_location_t
*op
; /* Policy operation */
3642 int num_ops
; /* Number of IPP operations */
3643 ipp_op_t ops
[100]; /* Operations */
3644 char line
[HTTP_MAX_BUFFER
],
3646 *value
, /* Value for directive */
3647 *valptr
; /* Pointer into value */
3651 * Create the policy...
3654 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3658 * Read from the file...
3664 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3667 * Decode the directive...
3670 if (!strcasecmp(line
, "</Policy>"))
3673 cupsdLogMessage(CUPSD_LOG_WARN
,
3674 "Missing </Limit> before </Policy> on line %d!",
3678 * Verify that we have an explicit policy for CUPS-Get-Document
3679 * (ensures that upgrades do not introduce new security issues...)
3682 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3683 op
->op
== IPP_ANY_OPERATION
)
3685 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3686 op
->op
!= IPP_ANY_OPERATION
)
3689 * Add a new limit for CUPS-Get-Document using the Send-Document
3690 * limit as a template...
3693 cupsdLogMessage(CUPSD_LOG_WARN
,
3694 "No limit for CUPS-Get-Document defined in policy %s "
3695 "- using Send-Document's policy", pol
->name
);
3697 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3703 else if (!strcasecmp(line
, "<Limit") && !op
)
3707 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3708 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3715 * Scan for IPP operation names...
3722 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3727 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3729 if (!strcasecmp(value
, "All"))
3730 ops
[num_ops
] = IPP_ANY_OPERATION
;
3731 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3732 cupsdLogMessage(CUPSD_LOG_ERROR
,
3733 "Bad IPP operation name \"%s\" on line %d!",
3739 cupsdLogMessage(CUPSD_LOG_ERROR
,
3740 "Too many operations listed on line %d!",
3743 for (value
= valptr
; isspace(*value
& 255); value
++);
3747 * If none are specified, apply the policy to all operations...
3752 ops
[0] = IPP_ANY_OPERATION
;
3757 * Add a new policy for the first operation...
3760 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3762 else if (!strcasecmp(line
, "</Limit>") && op
)
3765 * Finish the current operation limit...
3771 * Copy the policy to the other operations...
3774 for (i
= 1; i
< num_ops
; i
++)
3775 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3782 cupsdLogMessage(CUPSD_LOG_ERROR
,
3783 "Missing <Limit ops> directive before %s on line %d.",
3785 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3788 else if (!parse_aaa(op
, line
, value
, linenum
))
3791 cupsdLogMessage(CUPSD_LOG_ERROR
,
3792 "Unknown Policy Limit directive %s on line %d.",
3795 cupsdLogMessage(CUPSD_LOG_ERROR
,
3796 "Unknown Policy directive %s on line %d.",
3799 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3804 cupsdLogMessage(CUPSD_LOG_ERROR
,
3805 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3808 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3813 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".