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 const char *tmpdir
; /* TMPDIR environment variable */
427 struct stat tmpinfo
; /* Temporary directory info */
428 cupsd_policy_t
*p
; /* Policy */
432 * Save the old root paths...
435 old_serverroot
= NULL
;
436 cupsdSetString(&old_serverroot
, ServerRoot
);
437 old_requestroot
= NULL
;
438 cupsdSetString(&old_requestroot
, RequestRoot
);
441 * Reset the server configuration data...
444 cupsdDeleteAllLocations();
463 for (i
= 0; i
< NumRelays
; i
++)
464 if (Relays
[i
].from
.type
== CUPSD_AUTH_NAME
)
465 free(Relays
[i
].from
.mask
.name
.name
);
472 cupsdDeleteAllListeners();
474 RemoteAccessEnabled
= 0;
480 cupsdFreeAliases(ServerAlias
);
483 cupsdClearString(&ServerName
);
484 cupsdClearString(&ServerAdmin
);
485 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
486 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
487 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
488 cupsdSetString(&DataDir
, CUPS_DATADIR
);
489 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
490 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
491 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
492 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
493 cupsdSetString(&PageLogFormat
,
494 "%p %j %u %T %P %C %{job-billing} "
495 "%{job-originating-host-name} %{job-name} %{media} %{sides}");
496 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
497 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
498 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
499 cupsdSetString(&RemoteRoot
, "remroot");
500 cupsdSetString(&ServerHeader
, "CUPS/1.4");
501 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
503 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
504 PrintcapFormat
= PRINTCAP_SOLARIS
;
505 else if (!strcmp(CUPS_DEFAULT_PRINTCAP
,
506 "/Library/Preferences/org.cups.printers.plist"))
507 PrintcapFormat
= PRINTCAP_PLIST
;
509 PrintcapFormat
= PRINTCAP_BSD
;
511 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
512 if ((slash
= strrchr(temp
, '/')) != NULL
)
515 cupsdSetString(&ServerRoot
, temp
);
517 cupsdClearString(&Classification
);
518 ClassifyOverride
= 0;
522 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
524 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
525 cupsdSetString(&ServerKey
, "ssl/server.key");
526 # endif /* HAVE_CDSASSL */
527 #endif /* HAVE_SSL */
529 language
= cupsLangDefault();
531 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
532 cupsdSetString(&DefaultLanguage
, "en");
534 cupsdSetString(&DefaultLanguage
, language
->language
);
536 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
538 cupsdClearString(&DefaultPaperSize
);
540 cupsdSetString(&RIPCache
, "8m");
542 cupsdSetString(&TempDir
, NULL
);
545 * Find the default user...
548 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
553 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
554 * complement number...)
563 * Find the default group...
566 group
= getgrnam(CUPS_DEFAULT_GROUP
);
570 Group
= group
->gr_gid
;
574 * Fallback to group "nobody"...
577 group
= getgrnam("nobody");
581 Group
= group
->gr_gid
;
585 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
586 * complement number...)
597 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
598 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
599 FatalErrors
= parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS
);
600 DefaultAuthType
= CUPSD_AUTH_BASIC
;
602 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
603 SSLOptions
= CUPSD_SSL_NONE
;
604 #endif /* HAVE_SSL */
605 DirtyCleanInterval
= DEFAULT_KEEPALIVE
;
606 JobKillDelay
= DEFAULT_TIMEOUT
;
608 JobRetryInterval
= 300;
613 HostNameLookups
= FALSE
;
614 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
615 ImplicitAnyClasses
= FALSE
;
616 HideImplicitMembers
= TRUE
;
618 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
619 ListenBackLog
= SOMAXCONN
;
620 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
621 LogLevel
= CUPSD_LOG_WARN
;
622 LogTimeFormat
= CUPSD_TIME_STANDARD
;
624 MaxClientsPerHost
= 0;
625 MaxLogSize
= 1024 * 1024;
626 MaxPrinterHistory
= 10;
628 MultipleOperationTimeout
= DEFAULT_TIMEOUT
;
629 ReloadTimeout
= DEFAULT_KEEPALIVE
;
630 RootCertDuration
= 300;
631 Timeout
= DEFAULT_TIMEOUT
;
634 BrowseInterval
= DEFAULT_INTERVAL
;
635 BrowsePort
= ippPort();
636 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
637 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
638 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
639 BrowseTimeout
= DEFAULT_TIMEOUT
;
641 Browsing
= CUPS_DEFAULT_BROWSING
;
642 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
644 cupsdSetString(&LPDConfigFile
, CUPS_DEFAULT_LPD_CONFIG_FILE
);
645 cupsdSetString(&SMBConfigFile
, CUPS_DEFAULT_SMB_CONFIG_FILE
);
647 cupsdClearString(&BrowseLocalOptions
);
648 cupsdClearString(&BrowseRemoteOptions
);
650 cupsdSetString(&ErrorPolicy
, "stop-printer");
653 cupsdClearString(&BrowseLDAPBindDN
);
654 cupsdClearString(&BrowseLDAPDN
);
655 cupsdClearString(&BrowseLDAPPassword
);
656 cupsdClearString(&BrowseLDAPServer
);
657 # ifdef HAVE_LDAP_SSL
658 cupsdClearString(&BrowseLDAPCACertFile
);
659 # endif /* HAVE_LDAP_SSL */
660 #endif /* HAVE_LDAP */
662 JobHistory
= DEFAULT_HISTORY
;
663 JobFiles
= DEFAULT_FILES
;
668 MaxJobsPerPrinter
= 0;
669 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
671 cupsdDeleteAllPolicies();
672 cupsdClearString(&DefaultPolicy
);
674 #ifdef HAVE_AUTHORIZATION_H
675 cupsdClearString(&SystemGroupAuthKey
);
676 #endif /* HAVE_AUTHORIZATION_H */
678 MaxSubscriptions
= 100;
679 MaxSubscriptionsPerJob
= 0;
680 MaxSubscriptionsPerPrinter
= 0;
681 MaxSubscriptionsPerUser
= 0;
682 DefaultLeaseDuration
= 86400;
683 MaxLeaseDuration
= 0;
686 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
687 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
688 #endif /* HAVE_LAUNCHD */
692 #endif /* __APPLE__ */
695 * Read the configuration file...
698 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
701 status
= read_configuration(fp
);
710 cupsdLogMessage(CUPSD_LOG_INFO
, "Remote access is %s.",
711 RemoteAccessEnabled
? "enabled" : "disabled");
714 * See if the ServerName is an IP address...
719 if (gethostname(temp
, sizeof(temp
)))
721 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get hostname: %s",
723 strlcpy(temp
, "localhost", sizeof(temp
));
726 cupsdSetString(&ServerName
, temp
);
729 ServerAlias
= cupsArrayNew(NULL
, NULL
);
731 cupsdAddAlias(ServerAlias
, temp
);
732 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
734 if (HostNameLookups
|| RemoteAccessEnabled
)
736 struct hostent
*host
; /* Host entry to get FQDN */
738 if ((host
= gethostbyname(temp
)) != NULL
)
740 if (strcasecmp(temp
, host
->h_name
))
742 cupsdSetString(&ServerName
, host
->h_name
);
743 cupsdAddAlias(ServerAlias
, host
->h_name
);
744 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
750 for (i
= 0; host
->h_aliases
[i
]; i
++)
751 if (strcasecmp(temp
, host
->h_aliases
[i
]))
753 cupsdAddAlias(ServerAlias
, host
->h_aliases
[i
]);
754 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s",
762 * Make sure we have the base hostname added as an alias, too!
765 if ((slash
= strchr(temp
, '.')) != NULL
)
768 cupsdAddAlias(ServerAlias
, temp
);
769 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added auto ServerAlias %s", temp
);
773 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
775 ServerNameIsIP
= !*slash
;
778 * Make sure ServerAdmin is initialized...
782 cupsdSetStringf(&ServerAdmin
, "root@%s", ServerName
);
785 * Use the default system group if none was supplied in cupsd.conf...
788 if (NumSystemGroups
== 0)
790 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
793 * Find the group associated with GID 0...
800 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
802 cupsdSetString(&SystemGroups
[0], "unknown");
804 SystemGroupIDs
[0] = 0;
810 * Get the access control list for browsing...
813 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
816 * Open the system log for cupsd if necessary...
820 if (!strcmp(AccessLog
, "syslog") ||
821 !strcmp(ErrorLog
, "syslog") ||
822 !strcmp(PageLog
, "syslog"))
823 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
824 #endif /* HAVE_VSYSLOG */
827 * Log the configuration file that was used...
830 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
834 * Validate the Group and SystemGroup settings - they cannot be the same,
835 * otherwise the CGI programs will be able to authenticate as root without
841 for (i
= 0; i
< NumSystemGroups
; i
++)
842 if (Group
== SystemGroupIDs
[i
])
845 if (i
< NumSystemGroups
)
848 * Log the error and reset the group to a safe value...
851 cupsdLogMessage(CUPSD_LOG_NOTICE
,
852 "Group and SystemGroup cannot use the same groups!");
853 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
855 group
= getgrnam("nobody");
859 Group
= group
->gr_gid
;
863 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
864 * complement number...)
873 * Check that we have at least one listen/port line; if not, report this
874 * as an error and exit!
877 if (cupsArrayCount(Listeners
) == 0)
883 cupsdLogMessage(CUPSD_LOG_EMERG
,
884 "No valid Listen or Port lines were found in the "
885 "configuration file!");
891 cupsdEndProcess(getpid(), 0);
895 * Set the default locale using the language and charset...
898 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
901 * Update all relative filenames to include the full path from ServerRoot...
904 if (DocumentRoot
[0] != '/')
905 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
907 if (RequestRoot
[0] != '/')
908 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
910 if (ServerBin
[0] != '/')
911 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
913 if (StateDir
[0] != '/')
914 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
916 if (CacheDir
[0] != '/')
917 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
920 if (ServerCertificate
[0] != '/')
921 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
923 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)) &&
924 cupsdCheckPermissions(ServerCertificate
, NULL
, 0600, RunUser
, Group
,
926 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
929 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
930 if (ServerKey
[0] != '/')
931 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
933 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)) &&
934 cupsdCheckPermissions(ServerKey
, NULL
, 0600, RunUser
, Group
, 0, 0) < 0 &&
935 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
937 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
938 #endif /* HAVE_SSL */
941 * Make sure that directories and config files are owned and
942 * writable by the user and group in the cupsd.conf file...
945 snprintf(temp
, sizeof(temp
), "%s/rss", CacheDir
);
947 if ((cupsdCheckPermissions(RequestRoot
, NULL
, 0710, RunUser
,
949 cupsdCheckPermissions(CacheDir
, NULL
, 0775, RunUser
,
951 cupsdCheckPermissions(temp
, NULL
, 0775, RunUser
,
953 cupsdCheckPermissions(StateDir
, NULL
, 0755, RunUser
,
955 cupsdCheckPermissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
956 SystemGroupIDs
[0], 1, 1) < 0 ||
957 cupsdCheckPermissions(ServerRoot
, NULL
, 0755, RunUser
,
959 cupsdCheckPermissions(ServerRoot
, "ppd", 0755, RunUser
,
961 cupsdCheckPermissions(ServerRoot
, "ssl", 0700, RunUser
,
963 cupsdCheckPermissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
965 cupsdCheckPermissions(ServerRoot
, "classes.conf", 0600, RunUser
,
967 cupsdCheckPermissions(ServerRoot
, "printers.conf", 0600, RunUser
,
969 cupsdCheckPermissions(ServerRoot
, "passwd.md5", 0600, User
,
971 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
975 * Update TempDir to the default if it hasn't been set already...
980 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
983 * TMPDIR is defined, see if it is OK for us to use...
986 if (stat(tmpdir
, &tmpinfo
))
987 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
988 tmpdir
, strerror(errno
));
989 else if (!S_ISDIR(tmpinfo
.st_mode
))
990 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
992 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
993 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
994 !(tmpinfo
.st_mode
& S_IWOTH
))
995 cupsdLogMessage(CUPSD_LOG_ERROR
,
996 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
998 cupsdSetString(&TempDir
, tmpdir
);
1003 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
1005 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
1010 * Make sure the temporary directory has the right permissions...
1013 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
1017 * Update ownership and permissions if the CUPS temp directory
1018 * is under the spool directory or does not exist...
1021 if (cupsdCheckPermissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0 &&
1022 (FatalErrors
& CUPSD_FATAL_PERMISSIONS
))
1027 * Setup environment variables...
1033 * Update default paper size setting as needed...
1036 if (!DefaultPaperSize
)
1038 #ifdef HAVE_LIBPAPER
1039 char *paper_result
; /* Paper size name from libpaper */
1041 if ((paper_result
= systempapername()) != NULL
)
1042 cupsdSetString(&DefaultPaperSize
, paper_result
);
1044 #endif /* HAVE_LIBPAPER */
1045 if (!DefaultLanguage
||
1046 !strcasecmp(DefaultLanguage
, "C") ||
1047 !strcasecmp(DefaultLanguage
, "POSIX") ||
1048 !strcasecmp(DefaultLanguage
, "en") ||
1049 !strncasecmp(DefaultLanguage
, "en.", 3) ||
1050 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
1051 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
1052 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
1055 * These are the only locales that will default to "letter" size...
1058 cupsdSetString(&DefaultPaperSize
, "Letter");
1061 cupsdSetString(&DefaultPaperSize
, "A4");
1065 * Update classification setting as needed...
1068 if (Classification
&& !strcasecmp(Classification
, "none"))
1069 cupsdClearString(&Classification
);
1072 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
1075 * Check the MaxClients setting, and then allocate memory for it...
1078 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
1081 cupsdLogMessage(CUPSD_LOG_INFO
,
1082 "MaxClients limited to 1/3 (%d) of the file descriptor "
1084 MaxFDs
/ 3, MaxFDs
);
1086 MaxClients
= MaxFDs
/ 3;
1089 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
1093 * Check the MaxActiveJobs setting; limit to 1/3 the available
1094 * file descriptors, since we need a pipe for each job...
1097 if (MaxActiveJobs
> (MaxFDs
/ 3))
1098 MaxActiveJobs
= MaxFDs
/ 3;
1101 * Update the MaxClientsPerHost value, as needed...
1104 if (MaxClientsPerHost
<= 0)
1105 MaxClientsPerHost
= MaxClients
;
1107 if (MaxClientsPerHost
> MaxClients
)
1108 MaxClientsPerHost
= MaxClients
;
1110 cupsdLogMessage(CUPSD_LOG_INFO
,
1111 "Allowing up to %d client connections per host.",
1115 * Make sure that BrowseTimeout is at least twice the interval...
1118 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
1120 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
1124 BrowseTimeout
= BrowseInterval
* 2;
1126 BrowseTimeout
= DEFAULT_TIMEOUT
;
1128 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
1133 * Update the default policy, as needed...
1137 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
1139 DefaultPolicyPtr
= NULL
;
1141 if (!DefaultPolicyPtr
)
1143 cupsd_location_t
*po
; /* New policy operation */
1147 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
1150 cupsdSetString(&DefaultPolicy
, "default");
1152 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
1153 cupsdLogMessage(CUPSD_LOG_INFO
,
1154 "Using policy \"default\" as the default!");
1157 cupsdLogMessage(CUPSD_LOG_INFO
,
1158 "Creating CUPS default administrative policy:");
1160 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
1162 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
1163 cupsdLogMessage(CUPSD_LOG_INFO
,
1164 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
1165 "Release-Job Restart-Job Purge-Jobs "
1166 "Set-Job-Attributes Create-Job-Subscription "
1167 "Renew-Subscription Cancel-Subscription "
1168 "Get-Notifications Reprocess-Job Cancel-Current-Job "
1169 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
1170 "CUPS-Authenticate-Job CUPS-Get-Document>");
1171 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1173 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
1174 po
->order_type
= CUPSD_AUTH_ALLOW
;
1175 po
->level
= CUPSD_AUTH_USER
;
1177 cupsdAddName(po
, "@OWNER");
1178 cupsdAddName(po
, "@SYSTEM");
1179 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
1181 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
1182 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
1183 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
1184 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
1185 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
1186 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
1187 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
1188 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
1189 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
1190 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
1191 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
1192 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
1193 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
1194 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
1195 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
1196 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
1197 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
1198 cupsdAddPolicyOp(p
, po
, CUPS_GET_DOCUMENT
);
1200 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1202 cupsdLogMessage(CUPSD_LOG_INFO
,
1203 "<Limit Pause-Printer Resume-Printer "
1204 "Set-Printer-Attributes Enable-Printer "
1205 "Disable-Printer Pause-Printer-After-Current-Job "
1206 "Hold-New-Jobs Release-Held-New-Jobs "
1207 "Deactivate-Printer Activate-Printer Restart-Printer "
1208 "Shutdown-Printer Startup-Printer Promote-Job "
1209 "Schedule-Job-After CUPS-Add-Printer "
1210 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
1211 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
1212 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1213 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Default");
1215 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
1216 po
->order_type
= CUPSD_AUTH_ALLOW
;
1217 po
->type
= CUPSD_AUTH_DEFAULT
;
1218 po
->level
= CUPSD_AUTH_USER
;
1220 cupsdAddName(po
, "@SYSTEM");
1221 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
1223 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
1224 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
1225 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
1226 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
1227 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
1228 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
1229 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
1230 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
1231 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
1232 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
1233 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
1234 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
1235 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
1236 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
1237 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
1238 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
1239 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
1240 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
1241 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
1242 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
1243 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
1245 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1247 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
1248 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
1250 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
1251 po
->order_type
= CUPSD_AUTH_ALLOW
;
1253 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
1254 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
1258 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
1259 cupsArrayCount(Policies
));
1260 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
1262 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
1263 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1264 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
, p
->name
);
1267 * If we are doing a full reload or the server root has changed, flush
1268 * the jobs, printers, etc. and start from scratch...
1271 if (NeedReload
== RELOAD_ALL
||
1272 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
1273 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
1275 mime_type_t
*type
; /* Current type */
1276 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
1277 /* MIME type name */
1280 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
1283 * Free all memory...
1286 cupsdDeleteAllSubscriptions();
1288 cupsdDeleteAllPrinters();
1290 DefaultPrinter
= NULL
;
1292 if (MimeDatabase
!= NULL
)
1293 mimeDelete(MimeDatabase
);
1297 for (i
= 0; i
< NumMimeTypes
; i
++)
1298 _cupsStrFree(MimeTypes
[i
]);
1304 * Read the MIME type and conversion database...
1307 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1308 snprintf(mimedir
, sizeof(mimedir
), "%s/mime", DataDir
);
1310 MimeDatabase
= mimeLoadTypes(NULL
, mimedir
);
1311 MimeDatabase
= mimeLoadTypes(MimeDatabase
, ServerRoot
);
1312 MimeDatabase
= mimeLoadFilters(MimeDatabase
, mimedir
, temp
);
1313 MimeDatabase
= mimeLoadFilters(MimeDatabase
, ServerRoot
, temp
);
1317 cupsdLogMessage(CUPSD_LOG_EMERG
,
1318 "Unable to load MIME database from \"%s\" or \"%s\"!",
1319 mimedir
, ServerRoot
);
1320 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
1324 cupsdLogMessage(CUPSD_LOG_INFO
,
1325 "Loaded MIME database from \"%s\" and \"%s\": %d types, "
1326 "%d filters...", mimedir
, ServerRoot
,
1327 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
1330 * Create a list of MIME types for the document-format-supported
1334 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1335 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1338 if ((MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *))) == NULL
)
1340 cupsdLogMessage(CUPSD_LOG_ERROR
,
1341 "Unable to allocate memory for %d MIME types!",
1347 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1349 i
++, type
= mimeNextType(MimeDatabase
))
1351 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1353 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1356 if (i
< NumMimeTypes
)
1357 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1360 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1362 mime_filter_t
*filter
; /* Current filter */
1365 for (type
= mimeFirstType(MimeDatabase
);
1367 type
= mimeNextType(MimeDatabase
))
1368 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1369 type
->super
, type
->type
);
1371 for (filter
= mimeFirstFilter(MimeDatabase
);
1373 filter
= mimeNextFilter(MimeDatabase
))
1374 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1375 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1376 filter
->src
->super
, filter
->src
->type
,
1377 filter
->dst
->super
, filter
->dst
->type
,
1378 filter
->cost
, filter
->filter
);
1385 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1386 cupsdLoadBanners(temp
);
1389 * Load printers and classes...
1392 cupsdLoadAllPrinters();
1393 cupsdLoadAllClasses();
1394 cupsdLoadRemoteCache();
1395 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1397 cupsdCreateCommonData();
1400 * Load queued jobs...
1406 * Load subscriptions...
1409 cupsdLoadAllSubscriptions();
1411 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1416 * Not a full reload, so recreate the common printer attributes...
1419 cupsdCreateCommonData();
1422 * Update all printers as needed...
1425 cupsdUpdatePrinters();
1426 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1428 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1432 * Reset the reload state...
1435 NeedReload
= RELOAD_NONE
;
1437 cupsdClearString(&old_serverroot
);
1438 cupsdClearString(&old_requestroot
);
1445 * 'get_address()' - Get an address + port number from a line.
1448 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1449 get_address(const char *value
, /* I - Value string */
1450 int defport
) /* I - Default port */
1452 char buffer
[1024], /* Hostname + port number buffer */
1453 defpname
[255], /* Default port name */
1454 *hostname
, /* Hostname or IP */
1455 *portname
; /* Port number or name */
1456 http_addrlist_t
*addrlist
; /* Address list */
1460 * Check for an empty value...
1465 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1470 * Grab a hostname and port number; if there is no colon and the port name
1471 * is only digits, then we have a port number by itself...
1474 strlcpy(buffer
, value
, sizeof(buffer
));
1476 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1483 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1488 * Use the default port...
1491 sprintf(defpname
, "%d", defport
);
1492 portname
= defpname
;
1498 * The buffer contains just a port number...
1506 if (hostname
&& !strcmp(hostname
, "*"))
1510 * Now lookup the address using httpAddrGetList()...
1513 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1514 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1515 hostname
? hostname
: "(nil)");
1522 * 'get_addr_and_mask()' - Get an IP address and netmask.
1525 static int /* O - 1 on success, 0 on failure */
1526 get_addr_and_mask(const char *value
, /* I - String from config file */
1527 unsigned *ip
, /* O - Address value */
1528 unsigned *mask
) /* O - Mask value */
1530 int i
, j
, /* Looping vars */
1531 family
, /* Address family */
1532 ipcount
; /* Count of fields in address */
1533 unsigned ipval
; /* Value */
1534 const char *maskval
, /* Pointer to start of mask value */
1535 *ptr
, /* Pointer into value */
1540 * Get the address...
1543 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1544 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1546 if ((maskval
= strchr(value
, '/')) != NULL
)
1549 maskval
= value
+ strlen(value
);
1553 * Check for an IPv6 address...
1559 * Parse hexadecimal IPv6 address...
1564 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1568 else if (!strncmp(ptr
, "::", 2))
1570 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1572 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1577 else if (isxdigit(*ptr
& 255))
1579 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1587 ip
[i
/ 2] |= ipval
<< 16;
1601 if (*ptr
&& *ptr
!= '/')
1605 #endif /* AF_INET6 */
1608 * Parse dotted-decimal IPv4 address...
1611 unsigned val
[4]; /* IPv4 address values */
1615 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1618 * Range check the IP numbers...
1621 for (i
= 0; i
< ipcount
; i
++)
1626 * Make sure the trailing values are zeroed, as some C libraries like
1627 * glibc apparently like to fill the unused arguments with garbage...
1630 for (i
= ipcount
; i
< 4; i
++)
1634 * Merge everything into a 32-bit IPv4 address in ip[3]...
1637 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1640 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1646 * Get the netmask value(s)...
1649 memset(mask
, 0, sizeof(unsigned) * 4);
1651 if (strchr(maskval
, '.'))
1654 * Get dotted-decimal mask...
1657 if (family
!= AF_INET
)
1660 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1663 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1664 mask
[0] = mask
[1] = mask
[2] = 0;
1669 * Get address/bits format...
1675 if (family
== AF_INET6
)
1683 mask
[0] = 0xffffffff;
1685 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1688 mask
[1] = 0xffffffff;
1692 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1695 mask
[2] = 0xffffffff;
1699 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1702 mask
[3] = 0xffffffff;
1706 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1709 #endif /* AF_INET6 */
1714 mask
[0] = 0xffffffff;
1715 mask
[1] = 0xffffffff;
1716 mask
[2] = 0xffffffff;
1719 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1721 mask
[3] = 0xffffffff;
1726 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1727 "get_addr_and_mask(value=\"%s\", "
1728 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1729 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1733 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1736 if ((ip
[0] & ~mask
[0]) != 0 ||
1737 (ip
[1] & ~mask
[1]) != 0 ||
1738 (ip
[2] & ~mask
[2]) != 0 ||
1739 (ip
[3] & ~mask
[3]) != 0)
1747 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1750 static int /* O - 1 on success, 0 on failure */
1751 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1752 char *line
, /* I - Line from file */
1753 char *value
, /* I - Start of value data */
1754 int linenum
) /* I - Current line number */
1756 char *valptr
; /* Pointer into value */
1757 unsigned ip
[4], /* IP address components */
1758 mask
[4]; /* IP netmask components */
1761 if (!strcasecmp(line
, "Encryption"))
1764 * "Encryption xxx" - set required encryption level...
1767 if (!strcasecmp(value
, "never"))
1768 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1769 else if (!strcasecmp(value
, "always"))
1771 cupsdLogMessage(CUPSD_LOG_ERROR
,
1772 "Encryption value \"%s\" on line %d is invalid in this "
1773 "context. Using \"required\" instead.", value
, linenum
);
1775 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1777 else if (!strcasecmp(value
, "required"))
1778 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1779 else if (!strcasecmp(value
, "ifrequested"))
1780 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1783 cupsdLogMessage(CUPSD_LOG_ERROR
,
1784 "Unknown Encryption value %s on line %d.", value
, linenum
);
1788 else if (!strcasecmp(line
, "Order"))
1791 * "Order Deny,Allow" or "Order Allow,Deny"...
1794 if (!strncasecmp(value
, "deny", 4))
1795 loc
->order_type
= CUPSD_AUTH_ALLOW
;
1796 else if (!strncasecmp(value
, "allow", 5))
1797 loc
->order_type
= CUPSD_AUTH_DENY
;
1800 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1805 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1808 * Allow [From] host/ip...
1809 * Deny [From] host/ip...
1814 if (!strncasecmp(value
, "from", 4))
1817 * Strip leading "from"...
1822 while (isspace(*value
& 255))
1830 * Find the end of the value...
1833 for (valptr
= value
; *valptr
&& !isspace(*valptr
& 255); valptr
++);
1835 while (isspace(*valptr
& 255))
1839 * Figure out what form the allow/deny address takes:
1850 * nnn.nnn.nnn.nnn/mm
1851 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1854 if (!strcasecmp(value
, "all"))
1860 if (!strcasecmp(line
, "Allow"))
1861 cupsdAllowIP(loc
, zeros
, zeros
);
1863 cupsdDenyIP(loc
, zeros
, zeros
);
1865 else if (!strcasecmp(value
, "none"))
1871 if (!strcasecmp(line
, "Allow"))
1872 cupsdAllowIP(loc
, ones
, zeros
);
1874 cupsdDenyIP(loc
, ones
, zeros
);
1877 else if (value
[0] == '*' || value
[0] == '.' ||
1878 (!isdigit(value
[0] & 255) && value
[0] != '['))
1880 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1881 #endif /* AF_INET6 */
1884 * Host or domain name...
1887 if (value
[0] == '*')
1890 if (!strcasecmp(line
, "Allow"))
1891 cupsdAllowHost(loc
, value
);
1893 cupsdDenyHost(loc
, value
);
1898 * One of many IP address forms...
1901 if (!get_addr_and_mask(value
, ip
, mask
))
1903 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1908 if (!strcasecmp(line
, "Allow"))
1909 cupsdAllowIP(loc
, ip
, mask
);
1911 cupsdDenyIP(loc
, ip
, mask
);
1915 * Advance to next value...
1921 else if (!strcasecmp(line
, "AuthType"))
1924 * AuthType {none,basic,digest,basicdigest,negotiate,default}
1927 if (!strcasecmp(value
, "none"))
1929 loc
->type
= CUPSD_AUTH_NONE
;
1930 loc
->level
= CUPSD_AUTH_ANON
;
1932 else if (!strcasecmp(value
, "basic"))
1934 loc
->type
= CUPSD_AUTH_BASIC
;
1936 if (loc
->level
== CUPSD_AUTH_ANON
)
1937 loc
->level
= CUPSD_AUTH_USER
;
1939 else if (!strcasecmp(value
, "digest"))
1941 loc
->type
= CUPSD_AUTH_DIGEST
;
1943 if (loc
->level
== CUPSD_AUTH_ANON
)
1944 loc
->level
= CUPSD_AUTH_USER
;
1946 else if (!strcasecmp(value
, "basicdigest"))
1948 loc
->type
= CUPSD_AUTH_BASICDIGEST
;
1950 if (loc
->level
== CUPSD_AUTH_ANON
)
1951 loc
->level
= CUPSD_AUTH_USER
;
1953 else if (!strcasecmp(value
, "default"))
1955 loc
->type
= CUPSD_AUTH_DEFAULT
;
1957 if (loc
->level
== CUPSD_AUTH_ANON
)
1958 loc
->level
= CUPSD_AUTH_USER
;
1961 else if (!strcasecmp(value
, "negotiate"))
1963 loc
->type
= CUPSD_AUTH_NEGOTIATE
;
1965 if (loc
->level
== CUPSD_AUTH_ANON
)
1966 loc
->level
= CUPSD_AUTH_USER
;
1968 #endif /* HAVE_GSSAPI */
1971 cupsdLogMessage(CUPSD_LOG_WARN
,
1972 "Unknown authorization type %s on line %d.",
1977 else if (!strcasecmp(line
, "AuthClass"))
1980 * AuthClass anonymous, user, system, group
1983 if (!strcasecmp(value
, "anonymous"))
1985 loc
->type
= CUPSD_AUTH_NONE
;
1986 loc
->level
= CUPSD_AUTH_ANON
;
1988 cupsdLogMessage(CUPSD_LOG_WARN
,
1989 "\"AuthClass %s\" is deprecated; consider removing "
1993 else if (!strcasecmp(value
, "user"))
1995 loc
->level
= CUPSD_AUTH_USER
;
1997 cupsdLogMessage(CUPSD_LOG_WARN
,
1998 "\"AuthClass %s\" is deprecated; consider using "
1999 "\"Require valid-user\" on line %d.",
2002 else if (!strcasecmp(value
, "group"))
2004 loc
->level
= CUPSD_AUTH_GROUP
;
2006 cupsdLogMessage(CUPSD_LOG_WARN
,
2007 "\"AuthClass %s\" is deprecated; consider using "
2008 "\"Require user @groupname\" on line %d.",
2011 else if (!strcasecmp(value
, "system"))
2013 loc
->level
= CUPSD_AUTH_GROUP
;
2015 cupsdAddName(loc
, "@SYSTEM");
2017 cupsdLogMessage(CUPSD_LOG_WARN
,
2018 "\"AuthClass %s\" is deprecated; consider using "
2019 "\"Require user @SYSTEM\" on line %d.",
2024 cupsdLogMessage(CUPSD_LOG_WARN
,
2025 "Unknown authorization class %s on line %d.",
2030 else if (!strcasecmp(line
, "AuthGroupName"))
2032 cupsdAddName(loc
, value
);
2034 cupsdLogMessage(CUPSD_LOG_WARN
,
2035 "\"AuthGroupName %s\" directive is deprecated; consider "
2036 "using \"Require user @%s\" on line %d.",
2037 value
, value
, linenum
);
2039 else if (!strcasecmp(line
, "Require"))
2042 * Apache synonym for AuthClass and AuthGroupName...
2046 * Require valid-user
2047 * Require group names
2048 * Require user names
2051 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2056 if (!strcasecmp(value
, "valid-user") ||
2057 !strcasecmp(value
, "user"))
2058 loc
->level
= CUPSD_AUTH_USER
;
2059 else if (!strcasecmp(value
, "group"))
2060 loc
->level
= CUPSD_AUTH_GROUP
;
2063 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
2069 * Get the list of names from the line...
2072 for (value
= valptr
; *value
;)
2074 while (isspace(*value
& 255))
2077 #ifdef HAVE_AUTHORIZATION_H
2078 if (!strncmp(value
, "@AUTHKEY(", 9))
2081 * Grab "@AUTHKEY(name)" value...
2084 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
2090 #endif /* HAVE_AUTHORIZATION_H */
2091 if (*value
== '\"' || *value
== '\'')
2094 * Grab quoted name...
2097 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2104 * Grab literal name.
2107 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2113 cupsdAddName(loc
, value
);
2115 for (value
= valptr
; isspace(*value
& 255); value
++);
2118 else if (!strcasecmp(line
, "Satisfy"))
2120 if (!strcasecmp(value
, "all"))
2121 loc
->satisfy
= CUPSD_AUTH_SATISFY_ALL
;
2122 else if (!strcasecmp(value
, "any"))
2123 loc
->satisfy
= CUPSD_AUTH_SATISFY_ANY
;
2126 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
2139 * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
2142 static int /* O - FatalErrors bits */
2143 parse_fatal_errors(const char *s
) /* I - FatalErrors string */
2145 int fatal
; /* FatalErrors bits */
2146 char value
[1024], /* Value string */
2147 *valstart
, /* Pointer into value */
2148 *valend
; /* End of value */
2152 * Empty FatalErrors line yields NULL pointer...
2156 return (CUPSD_FATAL_NONE
);
2159 * Loop through the value string,...
2162 strlcpy(value
, s
, sizeof(value
));
2164 fatal
= CUPSD_FATAL_NONE
;
2166 for (valstart
= value
; *valstart
;)
2169 * Get the current space/comma-delimited kind name...
2172 for (valend
= valstart
; *valend
; valend
++)
2173 if (isspace(*valend
& 255) || *valend
== ',')
2180 * Add the error to the bitmask...
2183 if (!strcasecmp(valstart
, "all"))
2184 fatal
= CUPSD_FATAL_ALL
;
2185 else if (!strcasecmp(valstart
, "browse"))
2186 fatal
|= CUPSD_FATAL_BROWSE
;
2187 else if (!strcasecmp(valstart
, "-browse"))
2188 fatal
&= ~CUPSD_FATAL_BROWSE
;
2189 else if (!strcasecmp(valstart
, "config"))
2190 fatal
|= CUPSD_FATAL_CONFIG
;
2191 else if (!strcasecmp(valstart
, "-config"))
2192 fatal
&= ~CUPSD_FATAL_CONFIG
;
2193 else if (!strcasecmp(valstart
, "listen"))
2194 fatal
|= CUPSD_FATAL_LISTEN
;
2195 else if (!strcasecmp(valstart
, "-listen"))
2196 fatal
&= ~CUPSD_FATAL_LISTEN
;
2197 else if (!strcasecmp(valstart
, "log"))
2198 fatal
|= CUPSD_FATAL_LOG
;
2199 else if (!strcasecmp(valstart
, "-log"))
2200 fatal
&= ~CUPSD_FATAL_LOG
;
2201 else if (!strcasecmp(valstart
, "permissions"))
2202 fatal
|= CUPSD_FATAL_PERMISSIONS
;
2203 else if (!strcasecmp(valstart
, "-permissions"))
2204 fatal
&= ~CUPSD_FATAL_PERMISSIONS
;
2205 else if (strcasecmp(valstart
, "none"))
2206 cupsdLogMessage(CUPSD_LOG_ERROR
,
2207 "Unknown FatalErrors kind \"%s\" ignored!", valstart
);
2209 for (valstart
= valend
; *valstart
; valstart
++)
2210 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2219 * 'parse_groups()' - Parse system group names in a string.
2222 static int /* O - 1 on success, 0 on failure */
2223 parse_groups(const char *s
) /* I - Space-delimited groups */
2225 int status
; /* Return status */
2226 char value
[1024], /* Value string */
2227 *valstart
, /* Pointer into value */
2228 *valend
, /* End of value */
2229 quote
; /* Quote character */
2230 struct group
*group
; /* Group */
2234 * Make a copy of the string and parse out the groups...
2237 strlcpy(value
, s
, sizeof(value
));
2242 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
2244 if (*valstart
== '\'' || *valstart
== '\"')
2247 * Scan quoted name...
2250 quote
= *valstart
++;
2252 for (valend
= valstart
; *valend
; valend
++)
2253 if (*valend
== quote
)
2259 * Scan space or comma-delimited name...
2262 for (valend
= valstart
; *valend
; valend
++)
2263 if (isspace(*valend
) || *valend
== ',')
2270 group
= getgrnam(valstart
);
2273 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
2274 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
2285 while (*valstart
== ',' || isspace(*valstart
))
2294 * 'parse_protocols()' - Parse browse protocols in a string.
2297 static int /* O - Browse protocol bits */
2298 parse_protocols(const char *s
) /* I - Space-delimited protocols */
2300 int protocols
; /* Browse protocol bits */
2301 char value
[1024], /* Value string */
2302 *valstart
, /* Pointer into value */
2303 *valend
; /* End of value */
2307 * Empty protocol line yields NULL pointer...
2314 * Loop through the value string,...
2317 strlcpy(value
, s
, sizeof(value
));
2321 for (valstart
= value
; *valstart
;)
2324 * Get the current space/comma-delimited protocol name...
2327 for (valend
= valstart
; *valend
; valend
++)
2328 if (isspace(*valend
& 255) || *valend
== ',')
2335 * Add the protocol to the bitmask...
2338 if (!strcasecmp(valstart
, "cups"))
2339 protocols
|= BROWSE_CUPS
;
2340 else if (!strcasecmp(valstart
, "slp"))
2341 protocols
|= BROWSE_SLP
;
2342 else if (!strcasecmp(valstart
, "ldap"))
2343 protocols
|= BROWSE_LDAP
;
2344 else if (!strcasecmp(valstart
, "dnssd") ||
2345 !strcasecmp(valstart
, "dns-sd") ||
2346 !strcasecmp(valstart
, "bonjour"))
2347 protocols
|= BROWSE_DNSSD
;
2348 else if (!strcasecmp(valstart
, "lpd"))
2349 protocols
|= BROWSE_LPD
;
2350 else if (!strcasecmp(valstart
, "smb"))
2351 protocols
|= BROWSE_SMB
;
2352 else if (!strcasecmp(valstart
, "all"))
2353 protocols
|= BROWSE_ALL
;
2354 else if (strcasecmp(valstart
, "none"))
2355 cupsdLogMessage(CUPSD_LOG_ERROR
,
2356 "Unknown browse protocol \"%s\" ignored!", valstart
);
2358 for (valstart
= valend
; *valstart
; valstart
++)
2359 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2368 * 'read_configuration()' - Read a configuration file.
2371 static int /* O - 1 on success, 0 on failure */
2372 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2374 int i
; /* Looping var */
2375 int linenum
; /* Current line number */
2376 char line
[HTTP_MAX_BUFFER
],
2377 /* Line from file */
2378 temp
[HTTP_MAX_BUFFER
],
2379 /* Temporary buffer for value */
2380 temp2
[HTTP_MAX_BUFFER
],
2381 /* Temporary buffer 2 for value */
2382 *ptr
, /* Pointer into line/temp */
2383 *value
, /* Pointer to value */
2384 *valueptr
; /* Pointer into value */
2385 int valuelen
; /* Length of value */
2386 cupsd_var_t
const *var
; /* Current variable */
2387 http_addrlist_t
*addrlist
, /* Address list */
2388 *addr
; /* Current address */
2389 unsigned ip
[4], /* Address value */
2390 mask
[4]; /* Netmask value */
2391 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2392 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2393 cupsd_location_t
*location
; /* Browse location */
2394 cups_file_t
*incfile
; /* Include file */
2395 char incname
[1024]; /* Include filename */
2396 struct group
*group
; /* Group */
2400 * Loop through each line in the file...
2405 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2408 * Decode the directive...
2411 if (!strcasecmp(line
, "Include") && value
)
2417 if (value
[0] == '/')
2418 strlcpy(incname
, value
, sizeof(incname
));
2420 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2422 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2423 cupsdLogMessage(CUPSD_LOG_ERROR
,
2424 "Unable to include config file \"%s\" - %s",
2425 incname
, strerror(errno
));
2428 read_configuration(incfile
);
2429 cupsFileClose(incfile
);
2432 else if (!strcasecmp(line
, "<Location") && value
)
2438 linenum
= read_location(fp
, value
, linenum
);
2442 else if (!strcasecmp(line
, "<Policy") && value
)
2448 linenum
= read_policy(fp
, value
, linenum
);
2452 else if (!strcasecmp(line
, "FatalErrors"))
2453 FatalErrors
= parse_fatal_errors(value
);
2454 else if (!strcasecmp(line
, "FaxRetryInterval") && value
)
2456 JobRetryInterval
= atoi(value
);
2457 cupsdLogMessage(CUPSD_LOG_WARN
,
2458 "FaxRetryInterval is deprecated; use "
2459 "JobRetryInterval on line %d.", linenum
);
2461 else if (!strcasecmp(line
, "FaxRetryLimit") && value
)
2463 JobRetryLimit
= atoi(value
);
2464 cupsdLogMessage(CUPSD_LOG_WARN
,
2465 "FaxRetryLimit is deprecated; use "
2466 "JobRetryLimit on line %d.", linenum
);
2468 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2470 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2471 #endif /* HAVE_SSL */
2475 * Add listening address(es) to the list...
2478 cupsd_listener_t
*lis
; /* New listeners array */
2482 * Get the address list...
2485 addrlist
= get_address(value
, IPP_PORT
);
2489 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2495 * Add each address...
2498 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2501 * See if this address is already present...
2504 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
2506 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
2507 if (httpAddrEqual(&(addr
->addr
), &(lis
->address
)) &&
2508 _httpAddrPort(&(addr
->addr
)) == _httpAddrPort(&(lis
->address
)))
2513 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2514 cupsdLogMessage(CUPSD_LOG_WARN
,
2515 "Duplicate listen address \"%s\" ignored!", temp
);
2520 * Allocate another listener...
2524 Listeners
= cupsArrayNew(NULL
, NULL
);
2528 cupsdLogMessage(CUPSD_LOG_ERROR
,
2529 "Unable to allocate %s at line %d - %s.",
2530 line
, linenum
, strerror(errno
));
2534 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2536 cupsdLogMessage(CUPSD_LOG_ERROR
,
2537 "Unable to allocate %s at line %d - %s.",
2538 line
, linenum
, strerror(errno
));
2542 cupsArrayAdd(Listeners
, lis
);
2545 * Copy the current address and log it...
2548 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2552 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2553 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2554 #endif /* HAVE_SSL */
2556 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2559 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2560 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2561 ntohs(lis
->address
.ipv6
.sin6_port
));
2563 #endif /* AF_INET6 */
2565 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2566 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2568 #endif /* AF_LOCAL */
2569 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2570 ntohs(lis
->address
.ipv4
.sin_port
));
2572 if (!httpAddrLocalhost(&(lis
->address
)))
2573 RemoteAccessEnabled
= 1;
2580 httpAddrFreeList(addrlist
);
2582 else if (!strcasecmp(line
, "BrowseAddress") && value
)
2585 * Add a browse address to the list...
2588 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2591 if (NumBrowsers
== 0)
2592 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2594 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2598 cupsdLogMessage(CUPSD_LOG_ERROR
,
2599 "Unable to allocate BrowseAddress at line %d - %s.",
2600 linenum
, strerror(errno
));
2605 dira
+= NumBrowsers
;
2607 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2609 if (!strcasecmp(value
, "@LOCAL"))
2612 * Send browse data to all local interfaces...
2615 strcpy(dira
->iface
, "*");
2618 else if (!strncasecmp(value
, "@IF(", 4))
2621 * Send browse data to the named interface...
2624 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2626 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2632 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2635 * Only IPv4 addresses are supported...
2638 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2639 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2644 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2645 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2647 cupsdLogMessage(CUPSD_LOG_INFO
,
2648 "Sending browsing info to %s:%d (IPv4)",
2649 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2654 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2657 httpAddrFreeList(addrlist
);
2660 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2663 else if (!strcasecmp(line
, "BrowseOrder") && value
)
2666 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2669 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2670 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2672 if (location
== NULL
)
2673 cupsdLogMessage(CUPSD_LOG_ERROR
,
2674 "Unable to initialize browse access control list!");
2675 else if (!strncasecmp(value
, "deny", 4))
2676 location
->order_type
= CUPSD_AUTH_ALLOW
;
2677 else if (!strncasecmp(value
, "allow", 5))
2678 location
->order_type
= CUPSD_AUTH_DENY
;
2680 cupsdLogMessage(CUPSD_LOG_ERROR
,
2681 "Unknown BrowseOrder value %s on line %d.",
2684 else if (!strcasecmp(line
, "BrowseProtocols") ||
2685 !strcasecmp(line
, "BrowseLocalProtocols") ||
2686 !strcasecmp(line
, "BrowseRemoteProtocols"))
2689 * "BrowseProtocols name [... name]"
2690 * "BrowseLocalProtocols name [... name]"
2691 * "BrowseRemoteProtocols name [... name]"
2694 int protocols
= parse_protocols(value
);
2698 cupsdLogMessage(CUPSD_LOG_ERROR
,
2699 "Unknown browse protocol \"%s\" on line %d.",
2704 if (strcasecmp(line
, "BrowseLocalProtocols"))
2705 BrowseRemoteProtocols
= protocols
;
2706 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2707 BrowseLocalProtocols
= protocols
;
2709 else if ((!strcasecmp(line
, "BrowseAllow") ||
2710 !strcasecmp(line
, "BrowseDeny")) && value
)
2713 * BrowseAllow [From] host/ip...
2714 * BrowseDeny [From] host/ip...
2717 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2718 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2720 if (location
== NULL
)
2721 cupsdLogMessage(CUPSD_LOG_ERROR
,
2722 "Unable to initialize browse access control list!");
2727 if (!strncasecmp(value
, "from", 4))
2730 * Strip leading "from"...
2735 while (isspace(*value
& 255))
2743 * Find the end of the value...
2746 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2748 while (isspace(*valueptr
& 255))
2752 * Figure out what form the allow/deny address takes:
2763 * nnn.nnn.nnn.nnn/mm
2764 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2767 if (!strcasecmp(value
, "all"))
2773 if (!strcasecmp(line
, "BrowseAllow"))
2774 cupsdAllowIP(location
, zeros
, zeros
);
2776 cupsdDenyIP(location
, zeros
, zeros
);
2778 else if (!strcasecmp(value
, "none"))
2784 if (!strcasecmp(line
, "BrowseAllow"))
2785 cupsdAllowIP(location
, ones
, zeros
);
2787 cupsdDenyIP(location
, ones
, zeros
);
2790 else if (value
[0] == '*' || value
[0] == '.' ||
2791 (!isdigit(value
[0] & 255) && value
[0] != '['))
2793 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2794 #endif /* AF_INET6 */
2797 * Host or domain name...
2800 if (value
[0] == '*')
2803 if (!strcasecmp(line
, "BrowseAllow"))
2804 cupsdAllowHost(location
, value
);
2806 cupsdDenyHost(location
, value
);
2811 * One of many IP address forms...
2814 if (!get_addr_and_mask(value
, ip
, mask
))
2816 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2821 if (!strcasecmp(line
, "BrowseAllow"))
2822 cupsdAllowIP(location
, ip
, mask
);
2824 cupsdDenyIP(location
, ip
, mask
);
2828 * Advance to next value...
2835 else if (!strcasecmp(line
, "BrowseRelay") && value
)
2838 * BrowseRelay [from] source [to] destination
2842 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2844 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2848 cupsdLogMessage(CUPSD_LOG_ERROR
,
2849 "Unable to allocate BrowseRelay at line %d - %s.",
2850 linenum
, strerror(errno
));
2857 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2859 if (!strncasecmp(value
, "from ", 5))
2862 * Strip leading "from"...
2867 while (isspace(*value
))
2872 * Figure out what form the from address takes:
2881 * nnn.nnn.nnn.nnn/mm
2882 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2886 if (value
[0] == '*' || value
[0] == '.' ||
2887 (!isdigit(value
[0] & 255) && value
[0] != '['))
2889 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2890 #endif /* AF_INET6 */
2893 * Host or domain name...
2896 if (value
[0] == '*')
2899 strlcpy(temp
, value
, sizeof(temp
));
2900 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2903 relay
->from
.type
= CUPSD_AUTH_NAME
;
2905 if ((relay
->from
.mask
.name
.name
= strdup(temp
)) == NULL
)
2907 cupsdLogMessage(CUPSD_LOG_ERROR
,
2908 "Unable to allocate BrowseRelay name at line %d - %s.",
2909 linenum
, strerror(errno
));
2913 relay
->from
.mask
.name
.length
= strlen(temp
);
2918 * One of many IP address forms...
2921 if (!get_addr_and_mask(value
, ip
, mask
))
2923 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2928 relay
->from
.type
= CUPSD_AUTH_IP
;
2929 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2930 sizeof(relay
->from
.mask
.ip
.address
));
2931 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2932 sizeof(relay
->from
.mask
.ip
.netmask
));
2936 * Skip value and trailing whitespace...
2939 for (; *value
; value
++)
2940 if (isspace(*value
))
2943 while (isspace(*value
))
2946 if (!strncasecmp(value
, "to ", 3))
2949 * Strip leading "to"...
2954 while (isspace(*value
))
2959 * Get "to" address and port...
2962 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2965 * Only IPv4 addresses are supported...
2968 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2969 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2974 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2976 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2978 if (relay
->from
.type
== CUPSD_AUTH_IP
)
2979 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2980 relay
->from
.mask
.ip
.address
[0] >> 24,
2981 (relay
->from
.mask
.ip
.address
[0] >> 16) & 255,
2982 (relay
->from
.mask
.ip
.address
[0] >> 8) & 255,
2983 relay
->from
.mask
.ip
.address
[0] & 255,
2984 relay
->from
.mask
.ip
.netmask
[0] >> 24,
2985 (relay
->from
.mask
.ip
.netmask
[0] >> 16) & 255,
2986 (relay
->from
.mask
.ip
.netmask
[0] >> 8) & 255,
2987 relay
->from
.mask
.ip
.netmask
[0] & 255);
2989 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2991 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2992 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2997 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3000 httpAddrFreeList(addrlist
);
3004 if (relay
->from
.type
== CUPSD_AUTH_NAME
)
3005 free(relay
->from
.mask
.name
.name
);
3007 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
3011 else if (!strcasecmp(line
, "BrowsePoll") && value
)
3014 * BrowsePoll address[:port]
3017 char *portname
; /* Port name */
3018 int portnum
; /* Port number */
3019 struct servent
*service
; /* Service */
3023 * Extract the port name from the address...
3026 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
3030 if (isdigit(*portname
& 255))
3031 portnum
= atoi(portname
);
3032 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
3033 portnum
= ntohs(service
->s_port
);
3036 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
3042 portnum
= ippPort();
3045 * Add the poll entry...
3049 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
3051 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
3055 cupsdLogMessage(CUPSD_LOG_ERROR
,
3056 "Unable to allocate BrowsePoll at line %d - %s.",
3057 linenum
, strerror(errno
));
3065 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
3067 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
3068 pollp
->port
= portnum
;
3070 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
3073 else if (!strcasecmp(line
, "DefaultAuthType") && value
)
3076 * DefaultAuthType {basic,digest,basicdigest,negotiate}
3079 if (!strcasecmp(value
, "none"))
3080 DefaultAuthType
= CUPSD_AUTH_NONE
;
3081 else if (!strcasecmp(value
, "basic"))
3082 DefaultAuthType
= CUPSD_AUTH_BASIC
;
3083 else if (!strcasecmp(value
, "digest"))
3084 DefaultAuthType
= CUPSD_AUTH_DIGEST
;
3085 else if (!strcasecmp(value
, "basicdigest"))
3086 DefaultAuthType
= CUPSD_AUTH_BASICDIGEST
;
3088 else if (!strcasecmp(value
, "negotiate"))
3089 DefaultAuthType
= CUPSD_AUTH_NEGOTIATE
;
3090 #endif /* HAVE_GSSAPI */
3093 cupsdLogMessage(CUPSD_LOG_WARN
,
3094 "Unknown default authorization type %s on line %d.",
3096 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3101 else if (!strcasecmp(line
, "DefaultEncryption"))
3104 * DefaultEncryption {Never,IfRequested,Required}
3107 if (!value
|| !strcasecmp(value
, "never"))
3108 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
3109 else if (!strcasecmp(value
, "required"))
3110 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
3111 else if (!strcasecmp(value
, "ifrequested"))
3112 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
3115 cupsdLogMessage(CUPSD_LOG_WARN
,
3116 "Unknown default encryption %s on line %d.",
3118 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3122 #endif /* HAVE_SSL */
3123 else if (!strcasecmp(line
, "User") && value
)
3126 * User ID to run as...
3129 if (isdigit(value
[0] & 255))
3131 int uid
= atoi(value
);
3134 cupsdLogMessage(CUPSD_LOG_ERROR
,
3135 "Will not use User 0 as specified on line %d "
3136 "for security reasons. You must use a non-"
3137 "privileged account instead.",
3144 struct passwd
*p
; /* Password information */
3147 p
= getpwnam(value
);
3152 cupsdLogMessage(CUPSD_LOG_ERROR
,
3153 "Will not use User %s (UID=0) as specified on line "
3154 "%d for security reasons. You must use a non-"
3155 "privileged account instead.",
3161 cupsdLogMessage(CUPSD_LOG_ERROR
,
3162 "Unknown User \"%s\" on line %d, ignoring!",
3166 else if (!strcasecmp(line
, "Group") && value
)
3169 * Group ID to run as...
3172 if (isdigit(value
[0]))
3173 Group
= atoi(value
);
3177 group
= getgrnam(value
);
3180 Group
= group
->gr_gid
;
3182 cupsdLogMessage(CUPSD_LOG_ERROR
,
3183 "Unknown Group \"%s\" on line %d, ignoring!",
3187 else if (!strcasecmp(line
, "SystemGroup") && value
)
3190 * SystemGroup (admin) group(s)...
3193 if (!parse_groups(value
))
3194 cupsdLogMessage(CUPSD_LOG_ERROR
,
3195 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
3198 else if (!strcasecmp(line
, "HostNameLookups") && value
)
3201 * Do hostname lookups?
3204 if (!strcasecmp(value
, "off") || !strcasecmp(value
, "no") ||
3205 !strcasecmp(value
, "false"))
3206 HostNameLookups
= 0;
3207 else if (!strcasecmp(value
, "on") || !strcasecmp(value
, "yes") ||
3208 !strcasecmp(value
, "true"))
3209 HostNameLookups
= 1;
3210 else if (!strcasecmp(value
, "double"))
3211 HostNameLookups
= 2;
3213 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
3216 else if (!strcasecmp(line
, "AccessLogLevel") && value
)
3219 * Amount of logging to do to access log...
3222 if (!strcasecmp(value
, "all"))
3223 AccessLogLevel
= CUPSD_ACCESSLOG_ALL
;
3224 else if (!strcasecmp(value
, "actions"))
3225 AccessLogLevel
= CUPSD_ACCESSLOG_ACTIONS
;
3226 else if (!strcasecmp(value
, "config"))
3227 AccessLogLevel
= CUPSD_ACCESSLOG_CONFIG
;
3229 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown AccessLogLevel %s on line %d.",
3232 else if (!strcasecmp(line
, "LogLevel") && value
)
3235 * Amount of logging to do to error log...
3238 if (!strcasecmp(value
, "debug2"))
3239 LogLevel
= CUPSD_LOG_DEBUG2
;
3240 else if (!strcasecmp(value
, "debug"))
3241 LogLevel
= CUPSD_LOG_DEBUG
;
3242 else if (!strcasecmp(value
, "info"))
3243 LogLevel
= CUPSD_LOG_INFO
;
3244 else if (!strcasecmp(value
, "notice"))
3245 LogLevel
= CUPSD_LOG_NOTICE
;
3246 else if (!strcasecmp(value
, "warn"))
3247 LogLevel
= CUPSD_LOG_WARN
;
3248 else if (!strcasecmp(value
, "error"))
3249 LogLevel
= CUPSD_LOG_ERROR
;
3250 else if (!strcasecmp(value
, "crit"))
3251 LogLevel
= CUPSD_LOG_CRIT
;
3252 else if (!strcasecmp(value
, "alert"))
3253 LogLevel
= CUPSD_LOG_ALERT
;
3254 else if (!strcasecmp(value
, "emerg"))
3255 LogLevel
= CUPSD_LOG_EMERG
;
3256 else if (!strcasecmp(value
, "none"))
3257 LogLevel
= CUPSD_LOG_NONE
;
3259 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
3262 else if (!strcasecmp(line
, "LogTimeFormat") && value
)
3265 * Amount of logging to do to error log...
3268 if (!strcasecmp(value
, "standard"))
3269 LogTimeFormat
= CUPSD_TIME_STANDARD
;
3270 else if (!strcasecmp(value
, "usecs"))
3271 LogTimeFormat
= CUPSD_TIME_USECS
;
3273 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogTimeFormat %s on line %d.",
3276 else if (!strcasecmp(line
, "PrintcapFormat") && value
)
3279 * Format of printcap file?
3282 if (!strcasecmp(value
, "bsd"))
3283 PrintcapFormat
= PRINTCAP_BSD
;
3284 else if (!strcasecmp(value
, "plist"))
3285 PrintcapFormat
= PRINTCAP_PLIST
;
3286 else if (!strcasecmp(value
, "solaris"))
3287 PrintcapFormat
= PRINTCAP_SOLARIS
;
3289 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
3292 else if (!strcasecmp(line
, "ServerTokens") && value
)
3295 * Set the string used for the Server header...
3298 struct utsname plat
; /* Platform info */
3303 if (!strcasecmp(value
, "ProductOnly"))
3304 cupsdSetString(&ServerHeader
, "CUPS");
3305 else if (!strcasecmp(value
, "Major"))
3306 cupsdSetString(&ServerHeader
, "CUPS/1");
3307 else if (!strcasecmp(value
, "Minor"))
3308 cupsdSetString(&ServerHeader
, "CUPS/1.4");
3309 else if (!strcasecmp(value
, "Minimal"))
3310 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
3311 else if (!strcasecmp(value
, "OS"))
3312 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
3313 else if (!strcasecmp(value
, "Full"))
3314 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
3316 else if (!strcasecmp(value
, "None"))
3317 cupsdClearString(&ServerHeader
);
3319 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
3322 else if (!strcasecmp(line
, "PassEnv") && value
)
3325 * PassEnv variable [... variable]
3330 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
3331 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
3334 if (value
[valuelen
])
3336 value
[valuelen
] = '\0';
3340 cupsdSetEnv(value
, NULL
);
3342 for (value
+= valuelen
; *value
; value
++)
3343 if (!isspace(*value
) || *value
!= ',')
3347 else if (!strcasecmp(line
, "ServerAlias") && value
)
3350 ServerAlias
= cupsArrayNew(NULL
, NULL
);
3352 cupsdAddAlias(ServerAlias
, value
);
3354 else if (!strcasecmp(line
, "SetEnv") && value
)
3357 * SetEnv variable value
3360 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
3368 while (isspace(*valueptr
& 255))
3371 cupsdSetEnv(value
, valueptr
);
3374 cupsdLogMessage(CUPSD_LOG_ERROR
,
3375 "Missing value for SetEnv directive on line %d.",
3379 else if (!strcasecmp(line
, "SSLOptions"))
3382 * SSLOptions options
3385 if (!value
|| !strcasecmp(value
, "none"))
3386 SSLOptions
= CUPSD_SSL_NONE
;
3387 else if (!strcasecmp(value
, "noemptyfragments"))
3388 SSLOptions
= CUPSD_SSL_NOEMPTY
;
3390 cupsdLogMessage(CUPSD_LOG_ERROR
,
3391 "Unknown value \"%s\" for SSLOptions directive on "
3392 "line %d.", value
, linenum
);
3394 #endif /* HAVE_SSL */
3398 * Find a simple variable in the list...
3401 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3402 if (!strcasecmp(line
, var
->name
))
3408 * Unknown directive! Output an error message and continue...
3412 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing value for %s on line %d.",
3415 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3422 case CUPSD_VARTYPE_INTEGER
:
3424 cupsdLogMessage(CUPSD_LOG_ERROR
,
3425 "Missing integer value for %s on line %d!",
3430 char *units
; /* Units */
3433 n
= strtol(value
, &units
, 0);
3435 if (units
&& *units
)
3437 if (tolower(units
[0] & 255) == 'g')
3438 n
*= 1024 * 1024 * 1024;
3439 else if (tolower(units
[0] & 255) == 'm')
3441 else if (tolower(units
[0] & 255) == 'k')
3443 else if (tolower(units
[0] & 255) == 't')
3448 cupsdLogMessage(CUPSD_LOG_ERROR
,
3449 "Bad negative integer value for %s on line %d!",
3452 *((int *)var
->ptr
) = n
;
3456 case CUPSD_VARTYPE_BOOLEAN
:
3458 cupsdLogMessage(CUPSD_LOG_ERROR
,
3459 "Missing boolean value for %s on line %d!",
3461 else if (!strcasecmp(value
, "true") ||
3462 !strcasecmp(value
, "on") ||
3463 !strcasecmp(value
, "enabled") ||
3464 !strcasecmp(value
, "yes") ||
3466 *((int *)var
->ptr
) = TRUE
;
3467 else if (!strcasecmp(value
, "false") ||
3468 !strcasecmp(value
, "off") ||
3469 !strcasecmp(value
, "disabled") ||
3470 !strcasecmp(value
, "no") ||
3471 !strcasecmp(value
, "0"))
3472 *((int *)var
->ptr
) = FALSE
;
3474 cupsdLogMessage(CUPSD_LOG_ERROR
,
3475 "Unknown boolean value %s on line %d.",
3479 case CUPSD_VARTYPE_PATHNAME
:
3482 cupsdLogMessage(CUPSD_LOG_ERROR
,
3483 "Missing pathname value for %s on line %d!",
3488 if (value
[0] == '/')
3489 strlcpy(temp
, value
, sizeof(temp
));
3491 snprintf(temp
, sizeof(temp
), "%s/%s", ServerRoot
, value
);
3493 if (access(temp
, 0))
3495 cupsdLogMessage(CUPSD_LOG_ERROR
,
3496 "File or directory for \"%s %s\" on line %d "
3497 "does not exist!", line
, value
, linenum
);
3501 case CUPSD_VARTYPE_STRING
:
3502 cupsdSetString((char **)var
->ptr
, value
);
3513 * 'read_location()' - Read a <Location path> definition.
3516 static int /* O - New line number or 0 on error */
3517 read_location(cups_file_t
*fp
, /* I - Configuration file */
3518 char *location
, /* I - Location name/path */
3519 int linenum
) /* I - Current line number */
3521 cupsd_location_t
*loc
, /* New location */
3522 *parent
; /* Parent location */
3523 char line
[HTTP_MAX_BUFFER
],
3525 *value
, /* Value for directive */
3526 *valptr
; /* Pointer into value */
3529 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3532 parent
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3535 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3538 * Decode the directive...
3541 if (!strcasecmp(line
, "</Location>"))
3543 else if (!strcasecmp(line
, "<Limit") ||
3544 !strcasecmp(line
, "<LimitExcept"))
3548 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3549 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3555 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3561 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3566 if (!strcmp(value
, "ALL"))
3567 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
;
3568 else if (!strcmp(value
, "GET"))
3569 loc
->limit
|= CUPSD_AUTH_LIMIT_GET
;
3570 else if (!strcmp(value
, "HEAD"))
3571 loc
->limit
|= CUPSD_AUTH_LIMIT_HEAD
;
3572 else if (!strcmp(value
, "OPTIONS"))
3573 loc
->limit
|= CUPSD_AUTH_LIMIT_OPTIONS
;
3574 else if (!strcmp(value
, "POST"))
3575 loc
->limit
|= CUPSD_AUTH_LIMIT_POST
;
3576 else if (!strcmp(value
, "PUT"))
3577 loc
->limit
|= CUPSD_AUTH_LIMIT_PUT
;
3578 else if (!strcmp(value
, "TRACE"))
3579 loc
->limit
|= CUPSD_AUTH_LIMIT_TRACE
;
3581 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3584 for (value
= valptr
; isspace(*value
& 255); value
++);
3587 if (!strcasecmp(line
, "<LimitExcept"))
3588 loc
->limit
= CUPSD_AUTH_LIMIT_ALL
^ loc
->limit
;
3590 parent
->limit
&= ~loc
->limit
;
3592 else if (!strcasecmp(line
, "</Limit>") ||
3593 !strcasecmp(line
, "</LimitExcept>"))
3595 else if (!parse_aaa(loc
, line
, value
, linenum
))
3597 cupsdLogMessage(CUPSD_LOG_ERROR
,
3598 "Unknown Location directive %s on line %d.",
3600 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3605 cupsdLogMessage(CUPSD_LOG_ERROR
,
3606 "Unexpected end-of-file at line %d while reading location!",
3609 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3614 * 'read_policy()' - Read a <Policy name> definition.
3617 static int /* O - New line number or 0 on error */
3618 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3619 char *policy
, /* I - Location name/path */
3620 int linenum
) /* I - Current line number */
3622 int i
; /* Looping var */
3623 cupsd_policy_t
*pol
; /* Policy */
3624 cupsd_location_t
*op
; /* Policy operation */
3625 int num_ops
; /* Number of IPP operations */
3626 ipp_op_t ops
[100]; /* Operations */
3627 char line
[HTTP_MAX_BUFFER
],
3629 *value
, /* Value for directive */
3630 *valptr
; /* Pointer into value */
3634 * Create the policy...
3637 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3641 * Read from the file...
3647 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3650 * Decode the directive...
3653 if (!strcasecmp(line
, "</Policy>"))
3656 cupsdLogMessage(CUPSD_LOG_WARN
,
3657 "Missing </Limit> before </Policy> on line %d!",
3661 * Verify that we have an explicit policy for CUPS-Get-Document
3662 * (ensures that upgrades do not introduce new security issues...)
3665 if ((op
= cupsdFindPolicyOp(pol
, CUPS_GET_DOCUMENT
)) == NULL
||
3666 op
->op
== IPP_ANY_OPERATION
)
3668 if ((op
= cupsdFindPolicyOp(pol
, IPP_SEND_DOCUMENT
)) != NULL
&&
3669 op
->op
!= IPP_ANY_OPERATION
)
3672 * Add a new limit for CUPS-Get-Document using the Send-Document
3673 * limit as a template...
3676 cupsdLogMessage(CUPSD_LOG_WARN
,
3677 "No limit for CUPS-Get-Document defined in policy %s "
3678 "- using Send-Document's policy", pol
->name
);
3680 cupsdAddPolicyOp(pol
, op
, CUPS_GET_DOCUMENT
);
3686 else if (!strcasecmp(line
, "<Limit") && !op
)
3690 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3691 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3698 * Scan for IPP operation names...
3705 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3710 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3712 if (!strcasecmp(value
, "All"))
3713 ops
[num_ops
] = IPP_ANY_OPERATION
;
3714 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3715 cupsdLogMessage(CUPSD_LOG_ERROR
,
3716 "Bad IPP operation name \"%s\" on line %d!",
3722 cupsdLogMessage(CUPSD_LOG_ERROR
,
3723 "Too many operations listed on line %d!",
3726 for (value
= valptr
; isspace(*value
& 255); value
++);
3730 * If none are specified, apply the policy to all operations...
3735 ops
[0] = IPP_ANY_OPERATION
;
3740 * Add a new policy for the first operation...
3743 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3745 else if (!strcasecmp(line
, "</Limit>") && op
)
3748 * Finish the current operation limit...
3754 * Copy the policy to the other operations...
3757 for (i
= 1; i
< num_ops
; i
++)
3758 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3765 cupsdLogMessage(CUPSD_LOG_ERROR
,
3766 "Missing <Limit ops> directive before %s on line %d.",
3768 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3771 else if (!parse_aaa(op
, line
, value
, linenum
))
3774 cupsdLogMessage(CUPSD_LOG_ERROR
,
3775 "Unknown Policy Limit directive %s on line %d.",
3778 cupsdLogMessage(CUPSD_LOG_ERROR
,
3779 "Unknown Policy directive %s on line %d.",
3782 if (FatalErrors
& CUPSD_FATAL_CONFIG
)
3787 cupsdLogMessage(CUPSD_LOG_ERROR
,
3788 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3791 return ((FatalErrors
& CUPSD_FATAL_CONFIG
) ? 0 : linenum
);
3796 * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".