2 * "$Id: conf.c 6253 2007-02-10 18:48:40Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdReadConfiguration() - Read the cupsd.conf file.
27 * check_permissions() - Fix the mode and ownership of a file or
29 * get_address() - Get an address + port number from a line.
30 * get_addr_and_mask() - Get an IP address and netmask.
31 * parse_aaa() - Parse authentication, authorization, and
32 * access control lines.
33 * parse_groups() - Parse system group names in a string.
34 * parse_protocols() - Parse browse protocols in a string.
35 * read_configuration() - Read a configuration file.
36 * read_location() - Read a <Location path> definition.
37 * read_policy() - Read a <Policy name> definition.
41 * Include necessary headers...
47 #include <sys/utsname.h>
52 #endif /* HAVE_VSYSLOG */
56 * Possibly missing network definitions...
60 # define INADDR_NONE 0xffffffff
61 #endif /* !INADDR_NONE */
65 * Configuration variable structure...
70 CUPSD_VARTYPE_INTEGER
, /* Integer option */
71 CUPSD_VARTYPE_STRING
, /* String option */
72 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
77 char *name
; /* Name of variable */
78 void *ptr
; /* Pointer to variable */
79 cupsd_vartype_t type
; /* Type (int, string, address) */
87 static cupsd_var_t variables
[] =
89 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
90 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
91 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
93 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
94 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
95 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
96 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
97 #endif /* HAVE_LDAP */
98 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
99 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
100 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
101 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
102 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
103 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
104 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
105 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
106 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
107 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
108 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
109 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
110 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
111 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
112 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
113 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
114 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
115 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
116 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
117 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
118 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
119 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
121 { "GSSServiceName", &GSSServiceName
, CUPSD_VARTYPE_STRING
},
122 #endif /* HAVE_GSSAPI */
123 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
124 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
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 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
146 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
147 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
148 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
149 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
150 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
151 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
152 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
153 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
154 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
155 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
156 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
157 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
158 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
159 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
160 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
161 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
162 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
163 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
165 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
166 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
167 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
168 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
169 #endif /* HAVE_SSL */
170 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
171 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
172 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
173 #ifdef HAVE_AUTHORIZATION_H
174 { "SystemGroupAuthKey", &SystemGroupAuthKey
, CUPSD_VARTYPE_STRING
},
175 #endif /* HAVE_AUTHORIZATION_H */
176 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
177 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
178 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
180 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
183 static unsigned ones
[4] =
185 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
187 static unsigned zeros
[4] =
189 0x00000000, 0x00000000, 0x00000000, 0x00000000
196 static int check_permissions(const char *filename
,
197 const char *suffix
, int mode
,
198 int user
, int group
, int is_dir
,
200 static http_addrlist_t
*get_address(const char *value
, int defport
);
201 static int get_addr_and_mask(const char *value
, unsigned *ip
,
203 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
204 char *value
, int linenum
);
205 static int parse_groups(const char *s
);
206 static int parse_protocols(const char *s
);
207 static int read_configuration(cups_file_t
*fp
);
208 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
209 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
213 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
216 int /* O - 1 on success, 0 otherwise */
217 cupsdReadConfiguration(void)
219 int i
; /* Looping var */
220 cups_file_t
*fp
; /* Configuration file */
221 int status
; /* Return status */
222 char temp
[1024], /* Temporary buffer */
223 *slash
; /* Directory separator */
224 cups_lang_t
*language
; /* Language */
225 struct passwd
*user
; /* Default user */
226 struct group
*group
; /* Default group */
227 char *old_serverroot
, /* Old ServerRoot */
228 *old_requestroot
; /* Old RequestRoot */
229 const char *tmpdir
; /* TMPDIR environment variable */
230 struct stat tmpinfo
; /* Temporary directory info */
234 * Save the old root paths...
237 old_serverroot
= NULL
;
238 cupsdSetString(&old_serverroot
, ServerRoot
);
239 old_requestroot
= NULL
;
240 cupsdSetString(&old_requestroot
, RequestRoot
);
243 * Reset the server configuration data...
246 cupsdDeleteAllLocations();
265 for (i
= 0; i
< NumRelays
; i
++)
266 if (Relays
[i
].from
.type
== AUTH_NAME
)
267 free(Relays
[i
].from
.mask
.name
.name
);
274 cupsdDeleteAllListeners();
280 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
281 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
282 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
283 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
284 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
285 cupsdSetString(&DataDir
, CUPS_DATADIR
);
286 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
287 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
288 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
289 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
290 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
291 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
292 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
293 cupsdSetString(&RemoteRoot
, "remroot");
294 cupsdSetString(&ServerHeader
, "CUPS/1.2");
295 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
297 cupsdSetString(&GSSServiceName
, CUPS_DEFAULT_GSSSERVICENAME
);
298 #endif /* HAVE_GSSAPI */
300 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
301 PrintcapFormat
= PRINTCAP_SOLARIS
;
303 PrintcapFormat
= PRINTCAP_BSD
;
305 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
306 if ((slash
= strrchr(temp
, '/')) != NULL
)
309 cupsdSetString(&ServerRoot
, temp
);
311 cupsdClearString(&Classification
);
312 ClassifyOverride
= 0;
316 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
318 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
319 cupsdSetString(&ServerKey
, "ssl/server.key");
320 # endif /* HAVE_CDSASSL */
321 #endif /* HAVE_SSL */
323 language
= cupsLangDefault();
325 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
326 cupsdSetString(&DefaultLanguage
, "en");
328 cupsdSetString(&DefaultLanguage
, language
->language
);
330 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
332 cupsdSetString(&RIPCache
, "8m");
334 cupsdSetString(&TempDir
, NULL
);
337 * Find the default user...
340 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
345 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
346 * complement number...)
355 * Find the default group...
358 group
= getgrnam(CUPS_DEFAULT_GROUP
);
362 Group
= group
->gr_gid
;
366 * Fallback to group "nobody"...
369 group
= getgrnam("nobody");
373 Group
= group
->gr_gid
;
377 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
378 * complement number...)
389 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
390 DefaultAuthType
= AUTH_BASIC
;
392 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
393 #endif /* HAVE_SSL */
395 JobRetryInterval
= 300;
400 HostNameLookups
= FALSE
;
401 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
402 ImplicitAnyClasses
= FALSE
;
403 HideImplicitMembers
= TRUE
;
405 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
406 ListenBackLog
= SOMAXCONN
;
407 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
408 LogLevel
= CUPSD_LOG_ERROR
;
410 MaxClientsPerHost
= 0;
411 MaxLogSize
= 1024 * 1024;
412 MaxPrinterHistory
= 10;
415 RootCertDuration
= 300;
416 Timeout
= DEFAULT_TIMEOUT
;
419 BrowseInterval
= DEFAULT_INTERVAL
;
420 BrowsePort
= ippPort();
421 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
422 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
423 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
424 BrowseTimeout
= DEFAULT_TIMEOUT
;
425 Browsing
= CUPS_DEFAULT_BROWSING
;
426 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
428 cupsdClearString(&BrowseLocalOptions
);
429 cupsdClearString(&BrowseRemoteOptions
);
432 cupsdClearString(&BrowseLDAPBindDN
);
433 cupsdClearString(&BrowseLDAPDN
);
434 cupsdClearString(&BrowseLDAPPassword
);
435 cupsdClearString(&BrowseLDAPServer
);
436 #endif /* HAVE_LDAP */
438 JobHistory
= DEFAULT_HISTORY
;
439 JobFiles
= DEFAULT_FILES
;
444 MaxJobsPerPrinter
= 0;
445 MaxCopies
= CUPS_DEFAULT_MAX_COPIES
;
447 cupsdDeleteAllPolicies();
448 cupsdClearString(&DefaultPolicy
);
450 #ifdef HAVE_AUTHORIZATION_H
451 cupsdClearString(&SystemGroupAuthKey
);
452 #endif /* HAVE_AUTHORIZATION_H */
454 MaxSubscriptions
= 100;
455 MaxSubscriptionsPerJob
= 0;
456 MaxSubscriptionsPerPrinter
= 0;
457 MaxSubscriptionsPerUser
= 0;
458 DefaultLeaseDuration
= 86400;
459 MaxLeaseDuration
= 0;
462 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
463 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
464 #endif /* HAVE_LAUNCHD */
467 * Read the configuration file...
470 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
473 status
= read_configuration(fp
);
483 * See if the ServerName is an IP address...
486 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
488 ServerNameIsIP
= !*slash
;
491 * Use the default system group if none was supplied in cupsd.conf...
494 if (NumSystemGroups
== 0)
496 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
499 * Find the group associated with GID 0...
506 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
508 cupsdSetString(&SystemGroups
[0], "unknown");
510 SystemGroupIDs
[0] = 0;
516 * Get the access control list for browsing...
519 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
522 * Open the system log for cupsd if necessary...
526 if (!strcmp(AccessLog
, "syslog") ||
527 !strcmp(ErrorLog
, "syslog") ||
528 !strcmp(PageLog
, "syslog"))
529 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
530 #endif /* HAVE_VSYSLOG */
533 * Log the configuration file that was used...
536 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
540 * Validate the Group and SystemGroup settings - they cannot be the same,
541 * otherwise the CGI programs will be able to authenticate as root without
547 for (i
= 0; i
< NumSystemGroups
; i
++)
548 if (Group
== SystemGroupIDs
[i
])
551 if (i
< NumSystemGroups
)
554 * Log the error and reset the group to a safe value...
557 cupsdLogMessage(CUPSD_LOG_NOTICE
,
558 "Group and SystemGroup cannot use the same groups!");
559 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
561 group
= getgrnam("nobody");
565 Group
= group
->gr_gid
;
569 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
570 * complement number...)
579 * Check that we have at least one listen/port line; if not, report this
580 * as an error and exit!
583 if (cupsArrayCount(Listeners
) == 0)
589 cupsdLogMessage(CUPSD_LOG_EMERG
,
590 "No valid Listen or Port lines were found in the configuration file!");
596 cupsdEndProcess(getpid(), 0);
600 * Set the default locale using the language and charset...
603 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
606 * Update all relative filenames to include the full path from ServerRoot...
609 if (DocumentRoot
[0] != '/')
610 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
612 if (RequestRoot
[0] != '/')
613 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
615 if (ServerBin
[0] != '/')
616 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
618 if (StateDir
[0] != '/')
619 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
621 if (CacheDir
[0] != '/')
622 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
625 if (ServerCertificate
[0] != '/')
626 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
628 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
630 chown(ServerCertificate
, RunUser
, Group
);
631 chmod(ServerCertificate
, 0600);
634 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
635 if (ServerKey
[0] != '/')
636 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
638 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
640 chown(ServerKey
, RunUser
, Group
);
641 chmod(ServerKey
, 0600);
643 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
644 #endif /* HAVE_SSL */
647 * Make sure that directories and config files are owned and
648 * writable by the user and group in the cupsd.conf file...
651 if (check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1) < 0 ||
652 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1) < 0 ||
653 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
654 SystemGroupIDs
[0], 1, 1) < 0 ||
655 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0) < 0 ||
656 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1) < 0 ||
657 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0) < 0 ||
658 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
660 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
,
662 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
,
664 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0) < 0)
668 * Update TempDir to the default if it hasn't been set already...
673 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
676 * TMPDIR is defined, see if it is OK for us to use...
679 if (stat(tmpdir
, &tmpinfo
))
680 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
681 tmpdir
, strerror(errno
));
682 else if (!S_ISDIR(tmpinfo
.st_mode
))
683 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
685 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
686 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
687 !(tmpinfo
.st_mode
& S_IWOTH
))
688 cupsdLogMessage(CUPSD_LOG_ERROR
,
689 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
691 cupsdSetString(&TempDir
, tmpdir
);
696 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
698 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
703 * Make sure the request and temporary directories have the right
707 if (check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1) < 0)
710 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
714 * Update ownership and permissions if the CUPS temp directory
715 * is under the spool directory or does not exist...
718 if (check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
722 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
725 * Clean out the temporary directory...
728 cups_dir_t
*dir
; /* Temporary directory */
729 cups_dentry_t
*dent
; /* Directory entry */
730 char tempfile
[1024]; /* Temporary filename */
733 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
735 cupsdLogMessage(CUPSD_LOG_INFO
,
736 "Cleaning out old temporary files in \"%s\"...", TempDir
);
738 while ((dent
= cupsDirRead(dir
)) != NULL
)
740 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
742 if (unlink(tempfile
))
743 cupsdLogMessage(CUPSD_LOG_ERROR
,
744 "Unable to remove temporary file \"%s\" - %s",
745 tempfile
, strerror(errno
));
747 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
754 cupsdLogMessage(CUPSD_LOG_ERROR
,
755 "Unable to open temporary directory \"%s\" - %s",
756 TempDir
, strerror(errno
));
760 * Setup environment variables...
766 * Check the MaxClients setting, and then allocate memory for it...
769 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
772 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
775 MaxClients
= MaxFDs
/ 3;
778 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
782 * Check the MaxActiveJobs setting; limit to 1/3 the available
783 * file descriptors, since we need a pipe for each job...
786 if (MaxActiveJobs
> (MaxFDs
/ 3))
787 MaxActiveJobs
= MaxFDs
/ 3;
789 if (Classification
&& !strcasecmp(Classification
, "none"))
790 cupsdClearString(&Classification
);
793 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
796 * Update the MaxClientsPerHost value, as needed...
799 if (MaxClientsPerHost
<= 0)
800 MaxClientsPerHost
= MaxClients
;
802 if (MaxClientsPerHost
> MaxClients
)
803 MaxClientsPerHost
= MaxClients
;
805 cupsdLogMessage(CUPSD_LOG_INFO
,
806 "Allowing up to %d client connections per host.",
810 * Make sure that BrowseTimeout is at least twice the interval...
813 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
815 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
819 BrowseTimeout
= BrowseInterval
* 2;
821 BrowseTimeout
= DEFAULT_TIMEOUT
;
823 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
828 * Update the default policy, as needed...
832 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
834 DefaultPolicyPtr
= NULL
;
836 if (!DefaultPolicyPtr
)
838 cupsd_policy_t
*p
; /* New policy */
839 cupsd_location_t
*po
; /* New policy operation */
843 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
846 cupsdSetString(&DefaultPolicy
, "default");
848 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
849 cupsdLogMessage(CUPSD_LOG_INFO
,
850 "Using policy \"default\" as the default!");
853 cupsdLogMessage(CUPSD_LOG_INFO
,
854 "Creating CUPS default administrative policy:");
856 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
858 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
859 cupsdLogMessage(CUPSD_LOG_INFO
,
860 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
861 "Release-Job Restart-Job Purge-Jobs "
862 "Set-Job-Attributes Create-Job-Subscription "
863 "Renew-Subscription Cancel-Subscription "
864 "Get-Notifications Reprocess-Job Cancel-Current-Job "
865 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
866 "CUPS-Authenticate-Job>");
867 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
869 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
870 po
->order_type
= AUTH_ALLOW
;
871 po
->level
= AUTH_USER
;
873 cupsdAddName(po
, "@OWNER");
874 cupsdAddName(po
, "@SYSTEM");
875 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
877 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
878 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
879 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
880 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
881 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
882 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
883 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
884 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
885 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
886 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
887 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
888 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
889 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
890 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
891 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
892 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
893 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
895 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
897 cupsdLogMessage(CUPSD_LOG_INFO
,
898 "<Limit Pause-Printer Resume-Printer "
899 "Set-Printer-Attributes Enable-Printer "
900 "Disable-Printer Pause-Printer-After-Current-Job "
901 "Hold-New-Jobs Release-Held-New-Jobs "
902 "Deactivate-Printer Activate-Printer Restart-Printer "
903 "Shutdown-Printer Startup-Printer Promote-Job "
904 "Schedule-Job-After CUPS-Add-Printer "
905 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
906 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
907 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
908 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
910 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
911 po
->order_type
= AUTH_ALLOW
;
912 po
->type
= AUTH_BASIC
;
913 po
->level
= AUTH_USER
;
915 cupsdAddName(po
, "@SYSTEM");
916 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
918 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
919 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
920 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
921 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
922 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
923 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
924 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
925 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
926 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
927 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
928 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
929 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
930 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
931 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
932 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
933 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
934 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
935 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
936 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
937 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
938 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
940 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
942 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
943 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
945 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
946 po
->order_type
= AUTH_ALLOW
;
948 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
949 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
953 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
955 for (i
= 0; i
< NumPolicies
; i
++)
956 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
957 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
961 * If we are doing a full reload or the server root has changed, flush
962 * the jobs, printers, etc. and start from scratch...
965 if (NeedReload
== RELOAD_ALL
||
966 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
967 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
969 mime_type_t
*type
; /* Current type */
970 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
974 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
980 cupsdDeleteAllSubscriptions();
982 cupsdDeleteAllClasses();
983 cupsdDeleteAllPrinters();
985 DefaultPrinter
= NULL
;
987 if (MimeDatabase
!= NULL
)
988 mimeDelete(MimeDatabase
);
992 for (i
= 0; i
< NumMimeTypes
; i
++)
993 _cupsStrFree(MimeTypes
[i
]);
999 * Read the MIME type and conversion database...
1002 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
1004 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
1008 cupsdLogMessage(CUPSD_LOG_EMERG
,
1009 "Unable to load MIME database from \'%s\'!", ServerRoot
);
1013 cupsdLogMessage(CUPSD_LOG_INFO
,
1014 "Loaded MIME database from \'%s\': %d types, %d filters...",
1015 ServerRoot
, mimeNumTypes(MimeDatabase
),
1016 mimeNumFilters(MimeDatabase
));
1019 * Create a list of MIME types for the document-format-supported
1023 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1024 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1027 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
1029 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1031 i
++, type
= mimeNextType(MimeDatabase
))
1033 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1035 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1038 if (i
< NumMimeTypes
)
1039 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1041 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1043 mime_filter_t
*filter
; /* Current filter */
1046 for (type
= mimeFirstType(MimeDatabase
);
1048 type
= mimeNextType(MimeDatabase
))
1049 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1050 type
->super
, type
->type
);
1052 for (filter
= mimeFirstFilter(MimeDatabase
);
1054 filter
= mimeNextFilter(MimeDatabase
))
1055 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1056 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1057 filter
->src
->super
, filter
->src
->type
,
1058 filter
->dst
->super
, filter
->dst
->type
,
1059 filter
->cost
, filter
->filter
);
1066 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1067 cupsdLoadBanners(temp
);
1070 * Load printers and classes...
1073 cupsdLoadAllPrinters();
1074 cupsdLoadAllClasses();
1075 cupsdLoadRemoteCache();
1076 cupsdWritePrintcap();
1078 cupsdCreateCommonData();
1081 * Load queued jobs...
1087 * Load subscriptions...
1090 cupsdLoadAllSubscriptions();
1092 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1097 * Not a full reload, so recreate the common printer attributes...
1100 cupsdCreateCommonData();
1103 * Update all printers as needed...
1106 cupsdUpdatePrinters();
1107 cupsdWritePrintcap();
1109 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1113 * Reset the reload state...
1116 NeedReload
= RELOAD_NONE
;
1118 cupsdClearString(&old_serverroot
);
1119 cupsdClearString(&old_requestroot
);
1126 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1129 static int /* O - 0 on success, -1 on error, 1 on warning */
1130 check_permissions(const char *filename
, /* I - File/directory name */
1131 const char *suffix
, /* I - Additional file/directory name */
1132 int mode
, /* I - Permissions */
1133 int user
, /* I - Owner */
1134 int group
, /* I - Group */
1135 int is_dir
, /* I - 1 = directory, 0 = file */
1136 int create_dir
)/* I - 1 = create directory, 0 = not */
1138 int dir_created
= 0; /* Did we create a directory? */
1139 char pathname
[1024]; /* File name with prefix */
1140 struct stat fileinfo
; /* Stat buffer */
1144 * Prepend the given root to the filename before testing it...
1149 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1150 filename
= pathname
;
1154 * See if we can stat the file/directory...
1157 if (stat(filename
, &fileinfo
))
1159 if (errno
== ENOENT
&& create_dir
)
1161 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1164 if (mkdir(filename
, mode
))
1166 cupsdLogMessage(CUPSD_LOG_ERROR
,
1167 "Unable to create directory \"%s\" - %s", filename
,
1175 return (create_dir
? -1 : 1);
1179 * Make sure it's a regular file...
1182 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1184 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1188 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1190 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1195 * Fix owner, group, and mode as needed...
1198 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1200 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1202 if (chown(filename
, user
, group
))
1204 cupsdLogMessage(CUPSD_LOG_ERROR
,
1205 "Unable to change ownership of \"%s\" - %s", filename
,
1211 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
1213 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1215 if (chmod(filename
, mode
))
1217 cupsdLogMessage(CUPSD_LOG_ERROR
,
1218 "Unable to change permissions of \"%s\" - %s", filename
,
1225 * Everything is OK...
1233 * 'get_address()' - Get an address + port number from a line.
1236 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1237 get_address(const char *value
, /* I - Value string */
1238 int defport
) /* I - Default port */
1240 char buffer
[1024], /* Hostname + port number buffer */
1241 defpname
[255], /* Default port name */
1242 *hostname
, /* Hostname or IP */
1243 *portname
; /* Port number or name */
1244 http_addrlist_t
*addrlist
; /* Address list */
1248 * Check for an empty value...
1253 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1258 * Grab a hostname and port number; if there is no colon and the port name
1259 * is only digits, then we have a port number by itself...
1262 strlcpy(buffer
, value
, sizeof(buffer
));
1264 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1271 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1276 * Use the default port...
1279 sprintf(defpname
, "%d", defport
);
1280 portname
= defpname
;
1286 * The buffer contains just a port number...
1294 if (hostname
&& !strcmp(hostname
, "*"))
1298 * Now lookup the address using httpAddrGetList()...
1301 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1302 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1303 hostname
? hostname
: "(nil)");
1310 * 'get_addr_and_mask()' - Get an IP address and netmask.
1313 static int /* O - 1 on success, 0 on failure */
1314 get_addr_and_mask(const char *value
, /* I - String from config file */
1315 unsigned *ip
, /* O - Address value */
1316 unsigned *mask
) /* O - Mask value */
1318 int i
, j
, /* Looping vars */
1319 family
, /* Address family */
1320 ipcount
; /* Count of fields in address */
1321 unsigned ipval
; /* Value */
1322 const char *maskval
, /* Pointer to start of mask value */
1323 *ptr
, /* Pointer into value */
1328 * Get the address...
1331 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1332 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1334 if ((maskval
= strchr(value
, '/')) != NULL
)
1337 maskval
= value
+ strlen(value
);
1341 * Check for an IPv6 address...
1347 * Parse hexadecimal IPv6 address...
1352 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1356 else if (!strncmp(ptr
, "::", 2))
1358 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1360 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1365 else if (isxdigit(*ptr
& 255))
1367 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1375 ip
[i
/ 2] |= ipval
<< 16;
1389 if (*ptr
&& *ptr
!= '/')
1393 #endif /* AF_INET6 */
1396 * Parse dotted-decimal IPv4 address...
1399 unsigned val
[4]; /* IPv4 address values */
1403 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1406 * Range check the IP numbers...
1409 for (i
= 0; i
< ipcount
; i
++)
1414 * Make sure the trailing values are zeroed, as some C libraries like
1415 * glibc apparently like to fill the unused arguments with garbage...
1418 for (i
= ipcount
; i
< 4; i
++)
1422 * Merge everything into a 32-bit IPv4 address in ip[3]...
1425 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1428 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1434 * Get the netmask value(s)...
1437 memset(mask
, 0, sizeof(unsigned) * 4);
1439 if (strchr(maskval
, '.'))
1442 * Get dotted-decimal mask...
1445 if (family
!= AF_INET
)
1448 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1451 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1452 mask
[0] = mask
[1] = mask
[2] = 0;
1457 * Get address/bits format...
1463 if (family
== AF_INET6
)
1471 mask
[0] = 0xffffffff;
1473 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1476 mask
[1] = 0xffffffff;
1480 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1483 mask
[2] = 0xffffffff;
1487 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1490 mask
[3] = 0xffffffff;
1494 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1497 #endif /* AF_INET6 */
1502 mask
[0] = 0xffffffff;
1503 mask
[1] = 0xffffffff;
1504 mask
[2] = 0xffffffff;
1507 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1509 mask
[3] = 0xffffffff;
1514 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1515 "get_addr_and_mask(value=\"%s\", "
1516 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1517 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1521 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1524 if ((ip
[0] & ~mask
[0]) != 0 ||
1525 (ip
[1] & ~mask
[1]) != 0 ||
1526 (ip
[2] & ~mask
[2]) != 0 ||
1527 (ip
[3] & ~mask
[3]) != 0)
1535 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1538 static int /* O - 1 on success, 0 on failure */
1539 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1540 char *line
, /* I - Line from file */
1541 char *value
, /* I - Start of value data */
1542 int linenum
) /* I - Current line number */
1544 char *valptr
; /* Pointer into value */
1545 unsigned ip
[4], /* IP address components */
1546 mask
[4]; /* IP netmask components */
1549 if (!strcasecmp(line
, "Encryption"))
1552 * "Encryption xxx" - set required encryption level...
1555 if (!strcasecmp(value
, "never"))
1556 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1557 else if (!strcasecmp(value
, "always"))
1559 cupsdLogMessage(CUPSD_LOG_ERROR
,
1560 "Encryption value \"%s\" on line %d is invalid in this "
1561 "context. Using \"required\" instead.", value
, linenum
);
1563 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1565 else if (!strcasecmp(value
, "required"))
1566 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1567 else if (!strcasecmp(value
, "ifrequested"))
1568 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1571 cupsdLogMessage(CUPSD_LOG_ERROR
,
1572 "Unknown Encryption value %s on line %d.", value
, linenum
);
1576 else if (!strcasecmp(line
, "Order"))
1579 * "Order Deny,Allow" or "Order Allow,Deny"...
1582 if (!strncasecmp(value
, "deny", 4))
1583 loc
->order_type
= AUTH_ALLOW
;
1584 else if (!strncasecmp(value
, "allow", 5))
1585 loc
->order_type
= AUTH_DENY
;
1588 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1593 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1596 * Allow [From] host/ip...
1597 * Deny [From] host/ip...
1600 if (!strncasecmp(value
, "from", 4))
1603 * Strip leading "from"...
1608 while (isspace(*value
& 255))
1613 * Figure out what form the allow/deny address takes:
1624 * nnn.nnn.nnn.nnn/mm
1625 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1628 if (!strcasecmp(value
, "all"))
1634 if (!strcasecmp(line
, "Allow"))
1635 cupsdAllowIP(loc
, zeros
, zeros
);
1637 cupsdDenyIP(loc
, zeros
, zeros
);
1639 else if (!strcasecmp(value
, "none"))
1645 if (!strcasecmp(line
, "Allow"))
1646 cupsdAllowIP(loc
, ones
, zeros
);
1648 cupsdDenyIP(loc
, ones
, zeros
);
1651 else if (value
[0] == '*' || value
[0] == '.' ||
1652 (!isdigit(value
[0] & 255) && value
[0] != '['))
1654 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1655 #endif /* AF_INET6 */
1658 * Host or domain name...
1661 if (value
[0] == '*')
1664 if (!strcasecmp(line
, "Allow"))
1665 cupsdAllowHost(loc
, value
);
1667 cupsdDenyHost(loc
, value
);
1672 * One of many IP address forms...
1675 if (!get_addr_and_mask(value
, ip
, mask
))
1677 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1682 if (!strcasecmp(line
, "Allow"))
1683 cupsdAllowIP(loc
, ip
, mask
);
1685 cupsdDenyIP(loc
, ip
, mask
);
1688 else if (!strcasecmp(line
, "AuthType"))
1691 * AuthType {none,basic,digest,basicdigest}
1694 if (!strcasecmp(value
, "none"))
1696 loc
->type
= AUTH_NONE
;
1697 loc
->level
= AUTH_ANON
;
1699 else if (!strcasecmp(value
, "basic"))
1701 loc
->type
= AUTH_BASIC
;
1703 if (loc
->level
== AUTH_ANON
)
1704 loc
->level
= AUTH_USER
;
1706 else if (!strcasecmp(value
, "digest"))
1708 loc
->type
= AUTH_DIGEST
;
1710 if (loc
->level
== AUTH_ANON
)
1711 loc
->level
= AUTH_USER
;
1713 else if (!strcasecmp(value
, "basicdigest"))
1715 loc
->type
= AUTH_BASICDIGEST
;
1717 if (loc
->level
== AUTH_ANON
)
1718 loc
->level
= AUTH_USER
;
1721 else if (!strcasecmp(value
, "kerberos") ||
1722 !strcasecmp(value
, "gssapi"))
1724 loc
->type
= AUTH_KERBEROS
;
1726 if (loc
->level
== AUTH_ANON
)
1727 loc
->level
= AUTH_USER
;
1729 #endif /* HAVE_GSSAPI */
1732 cupsdLogMessage(CUPSD_LOG_WARN
,
1733 "Unknown authorization type %s on line %d.",
1738 else if (!strcasecmp(line
, "AuthClass"))
1741 * AuthClass anonymous, user, system, group
1744 if (!strcasecmp(value
, "anonymous"))
1746 loc
->type
= AUTH_NONE
;
1747 loc
->level
= AUTH_ANON
;
1749 cupsdLogMessage(CUPSD_LOG_WARN
,
1750 "\"AuthClass %s\" is deprecated; consider removing "
1754 else if (!strcasecmp(value
, "user"))
1756 loc
->level
= AUTH_USER
;
1758 cupsdLogMessage(CUPSD_LOG_WARN
,
1759 "\"AuthClass %s\" is deprecated; consider using "
1760 "\"Require valid-user\" on line %d.",
1763 else if (!strcasecmp(value
, "group"))
1765 loc
->level
= AUTH_GROUP
;
1767 cupsdLogMessage(CUPSD_LOG_WARN
,
1768 "\"AuthClass %s\" is deprecated; consider using "
1769 "\"Require @groupname\" on line %d.",
1772 else if (!strcasecmp(value
, "system"))
1774 loc
->level
= AUTH_GROUP
;
1776 cupsdAddName(loc
, "@SYSTEM");
1778 cupsdLogMessage(CUPSD_LOG_WARN
,
1779 "\"AuthClass %s\" is deprecated; consider using "
1780 "\"Require @SYSTEM\" on line %d.",
1785 cupsdLogMessage(CUPSD_LOG_WARN
,
1786 "Unknown authorization class %s on line %d.",
1791 else if (!strcasecmp(line
, "AuthGroupName"))
1793 cupsdAddName(loc
, value
);
1795 cupsdLogMessage(CUPSD_LOG_WARN
,
1796 "\"AuthGroupName %s\" directive is deprecated; consider "
1797 "using \"Require @%s\" on line %d.",
1798 value
, value
, linenum
);
1800 else if (!strcasecmp(line
, "Require"))
1803 * Apache synonym for AuthClass and AuthGroupName...
1807 * Require valid-user
1808 * Require group names
1809 * Require user names
1812 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1817 if (!strcasecmp(value
, "valid-user") ||
1818 !strcasecmp(value
, "user"))
1819 loc
->level
= AUTH_USER
;
1820 else if (!strcasecmp(value
, "group"))
1821 loc
->level
= AUTH_GROUP
;
1824 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1830 * Get the list of names from the line...
1833 for (value
= valptr
; *value
;)
1835 while (isspace(*value
& 255))
1838 #ifdef HAVE_AUTHORIZATION_H
1839 if (!strncmp(value
, "@AUTHKEY(", 9))
1842 * Grab "@AUTHKEY(name)" value...
1845 for (valptr
= value
+ 9; *valptr
!= ')' && *valptr
; valptr
++);
1851 #endif /* HAVE_AUTHORIZATION_H */
1852 if (*value
== '\"' || *value
== '\'')
1855 * Grab quoted name...
1858 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1865 * Grab literal name.
1868 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1874 cupsdAddName(loc
, value
);
1876 for (value
= valptr
; isspace(*value
& 255); value
++);
1879 else if (!strcasecmp(line
, "Satisfy"))
1881 if (!strcasecmp(value
, "all"))
1882 loc
->satisfy
= AUTH_SATISFY_ALL
;
1883 else if (!strcasecmp(value
, "any"))
1884 loc
->satisfy
= AUTH_SATISFY_ANY
;
1887 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1900 * 'parse_groups()' - Parse system group names in a string.
1903 static int /* O - 1 on success, 0 on failure */
1904 parse_groups(const char *s
) /* I - Space-delimited groups */
1906 int status
; /* Return status */
1907 char value
[1024], /* Value string */
1908 *valstart
, /* Pointer into value */
1909 *valend
, /* End of value */
1910 quote
; /* Quote character */
1911 struct group
*group
; /* Group */
1915 * Make a copy of the string and parse out the groups...
1918 strlcpy(value
, s
, sizeof(value
));
1923 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1925 if (*valstart
== '\'' || *valstart
== '\"')
1928 * Scan quoted name...
1931 quote
= *valstart
++;
1933 for (valend
= valstart
; *valend
; valend
++)
1934 if (*valend
== quote
)
1940 * Scan space or comma-delimited name...
1943 for (valend
= valstart
; *valend
; valend
++)
1944 if (isspace(*valend
) || *valend
== ',')
1951 group
= getgrnam(valstart
);
1954 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1955 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1966 while (*valstart
== ',' || isspace(*valstart
))
1975 * 'parse_protocols()' - Parse browse protocols in a string.
1978 static int /* O - Browse protocol bits */
1979 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1981 int protocols
; /* Browse protocol bits */
1982 char value
[1024], /* Value string */
1983 *valstart
, /* Pointer into value */
1984 *valend
; /* End of value */
1988 * Empty protocol line yields NULL pointer...
1995 * Loop through the value string,...
1998 strlcpy(value
, s
, sizeof(value
));
2002 for (valstart
= value
; *valstart
;)
2005 * Get the current space/comma-delimited protocol name...
2008 for (valend
= valstart
; *valend
; valend
++)
2009 if (isspace(*valend
& 255) || *valend
== ',')
2016 * Add the protocol to the bitmask...
2019 if (!strcasecmp(valstart
, "cups"))
2020 protocols
|= BROWSE_CUPS
;
2021 else if (!strcasecmp(valstart
, "slp"))
2022 protocols
|= BROWSE_SLP
;
2023 else if (!strcasecmp(valstart
, "ldap"))
2024 protocols
|= BROWSE_LDAP
;
2025 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
2026 protocols
|= BROWSE_DNSSD
;
2027 else if (!strcasecmp(valstart
, "all"))
2028 protocols
|= BROWSE_ALL
;
2029 else if (strcasecmp(valstart
, "none"))
2032 for (valstart
= valend
; *valstart
; valstart
++)
2033 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2042 * 'read_configuration()' - Read a configuration file.
2045 static int /* O - 1 on success, 0 on failure */
2046 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2048 int i
; /* Looping var */
2049 int linenum
; /* Current line number */
2050 char line
[HTTP_MAX_BUFFER
],
2051 /* Line from file */
2052 temp
[HTTP_MAX_BUFFER
],
2053 /* Temporary buffer for value */
2054 temp2
[HTTP_MAX_BUFFER
],
2055 /* Temporary buffer 2 for value */
2056 *ptr
, /* Pointer into line/temp */
2057 *value
, /* Pointer to value */
2058 *valueptr
; /* Pointer into value */
2059 int valuelen
; /* Length of value */
2060 cupsd_var_t
*var
; /* Current variable */
2061 http_addrlist_t
*addrlist
, /* Address list */
2062 *addr
; /* Current address */
2063 unsigned ip
[4], /* Address value */
2064 mask
[4]; /* Netmask value */
2065 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2066 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2067 cupsd_location_t
*location
; /* Browse location */
2068 cups_file_t
*incfile
; /* Include file */
2069 char incname
[1024]; /* Include filename */
2070 struct group
*group
; /* Group */
2074 * Loop through each line in the file...
2079 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2082 * Decode the directive...
2085 if (!strcasecmp(line
, "Include"))
2091 if (value
[0] == '/')
2092 strlcpy(incname
, value
, sizeof(incname
));
2094 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2096 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2097 cupsdLogMessage(CUPSD_LOG_ERROR
,
2098 "Unable to include config file \"%s\" - %s",
2099 incname
, strerror(errno
));
2102 read_configuration(incfile
);
2103 cupsFileClose(incfile
);
2106 else if (!strcasecmp(line
, "<Location"))
2114 linenum
= read_location(fp
, value
, linenum
);
2120 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2125 else if (!strcasecmp(line
, "<Policy"))
2133 linenum
= read_policy(fp
, value
, linenum
);
2139 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2143 else if (!strcasecmp(line
, "FaxRetryInterval"))
2147 JobRetryInterval
= atoi(value
);
2148 cupsdLogMessage(CUPSD_LOG_WARN
,
2149 "FaxRetryInterval is deprecated; use "
2150 "JobRetryInterval on line %d.", linenum
);
2154 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2158 else if (!strcasecmp(line
, "FaxRetryLimit"))
2162 JobRetryLimit
= atoi(value
);
2163 cupsdLogMessage(CUPSD_LOG_WARN
,
2164 "FaxRetryLimit is deprecated; use "
2165 "JobRetryLimit on line %d.", linenum
);
2169 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2173 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2175 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2176 #endif /* HAVE_SSL */
2180 * Add listening address(es) to the list...
2183 cupsd_listener_t
*lis
; /* New listeners array */
2187 * Get the address list...
2190 addrlist
= get_address(value
, IPP_PORT
);
2194 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2200 * Add each address...
2203 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2206 * Allocate another listener...
2210 Listeners
= cupsArrayNew(NULL
, NULL
);
2214 cupsdLogMessage(CUPSD_LOG_ERROR
,
2215 "Unable to allocate %s at line %d - %s.",
2216 line
, linenum
, strerror(errno
));
2220 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2222 cupsdLogMessage(CUPSD_LOG_ERROR
,
2223 "Unable to allocate %s at line %d - %s.",
2224 line
, linenum
, strerror(errno
));
2228 cupsArrayAdd(Listeners
, lis
);
2231 * Copy the current address and log it...
2234 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2238 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2239 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2240 #endif /* HAVE_SSL */
2242 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2245 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2246 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2247 ntohs(lis
->address
.ipv6
.sin6_port
));
2249 #endif /* AF_INET6 */
2251 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2252 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2254 #endif /* AF_LOCAL */
2255 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2256 ntohs(lis
->address
.ipv4
.sin_port
));
2263 httpAddrFreeList(addrlist
);
2265 else if (!strcasecmp(line
, "BrowseAddress"))
2268 * Add a browse address to the list...
2271 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2274 if (NumBrowsers
== 0)
2275 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2277 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2281 cupsdLogMessage(CUPSD_LOG_ERROR
,
2282 "Unable to allocate BrowseAddress at line %d - %s.",
2283 linenum
, strerror(errno
));
2288 dira
+= NumBrowsers
;
2290 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2292 if (!strcasecmp(value
, "@LOCAL"))
2295 * Send browse data to all local interfaces...
2298 strcpy(dira
->iface
, "*");
2301 else if (!strncasecmp(value
, "@IF(", 4))
2304 * Send browse data to the named interface...
2307 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2309 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2315 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2318 * Only IPv4 addresses are supported...
2321 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2322 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2327 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2328 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2330 cupsdLogMessage(CUPSD_LOG_INFO
,
2331 "Sending browsing info to %s:%d (IPv4)",
2332 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2337 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2340 httpAddrFreeList(addrlist
);
2343 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2346 else if (!strcasecmp(line
, "BrowseOrder"))
2349 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2352 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2353 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2355 if (location
== NULL
)
2356 cupsdLogMessage(CUPSD_LOG_ERROR
,
2357 "Unable to initialize browse access control list!");
2358 else if (!strncasecmp(value
, "deny", 4))
2359 location
->order_type
= AUTH_ALLOW
;
2360 else if (!strncasecmp(value
, "allow", 5))
2361 location
->order_type
= AUTH_DENY
;
2363 cupsdLogMessage(CUPSD_LOG_ERROR
,
2364 "Unknown BrowseOrder value %s on line %d.",
2367 else if (!strcasecmp(line
, "BrowseProtocols") ||
2368 !strcasecmp(line
, "BrowseLocalProtocols") ||
2369 !strcasecmp(line
, "BrowseRemoteProtocols"))
2372 * "BrowseProtocols name [... name]"
2373 * "BrowseLocalProtocols name [... name]"
2374 * "BrowseRemoteProtocols name [... name]"
2377 int protocols
= parse_protocols(value
);
2381 cupsdLogMessage(CUPSD_LOG_ERROR
,
2382 "Unknown browse protocol \"%s\" on line %d.",
2387 if (strcasecmp(line
, "BrowseLocalProtocols"))
2388 BrowseRemoteProtocols
= protocols
;
2389 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2390 BrowseLocalProtocols
= protocols
;
2392 else if (!strcasecmp(line
, "BrowseAllow") ||
2393 !strcasecmp(line
, "BrowseDeny"))
2396 * BrowseAllow [From] host/ip...
2397 * BrowseDeny [From] host/ip...
2400 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2401 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2403 if (location
== NULL
)
2404 cupsdLogMessage(CUPSD_LOG_ERROR
,
2405 "Unable to initialize browse access control list!");
2408 if (!strncasecmp(value
, "from ", 5))
2411 * Strip leading "from"...
2416 while (isspace(*value
))
2421 * Figure out what form the allow/deny address takes:
2432 * nnn.nnn.nnn.nnn/mm
2433 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2436 if (!strcasecmp(value
, "all"))
2442 if (!strcasecmp(line
, "BrowseAllow"))
2443 cupsdAllowIP(location
, zeros
, zeros
);
2445 cupsdDenyIP(location
, zeros
, zeros
);
2447 else if (!strcasecmp(value
, "none"))
2453 if (!strcasecmp(line
, "BrowseAllow"))
2454 cupsdAllowIP(location
, ones
, zeros
);
2456 cupsdDenyIP(location
, ones
, zeros
);
2459 else if (value
[0] == '*' || value
[0] == '.' ||
2460 (!isdigit(value
[0] & 255) && value
[0] != '['))
2462 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2463 #endif /* AF_INET6 */
2466 * Host or domain name...
2469 if (value
[0] == '*')
2472 if (!strcasecmp(line
, "BrowseAllow"))
2473 cupsdAllowHost(location
, value
);
2475 cupsdDenyHost(location
, value
);
2480 * One of many IP address forms...
2483 if (!get_addr_and_mask(value
, ip
, mask
))
2485 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2490 if (!strcasecmp(line
, "BrowseAllow"))
2491 cupsdAllowIP(location
, ip
, mask
);
2493 cupsdDenyIP(location
, ip
, mask
);
2497 else if (!strcasecmp(line
, "BrowseRelay"))
2500 * BrowseRelay [from] source [to] destination
2504 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2506 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2510 cupsdLogMessage(CUPSD_LOG_ERROR
,
2511 "Unable to allocate BrowseRelay at line %d - %s.",
2512 linenum
, strerror(errno
));
2519 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2521 if (!strncasecmp(value
, "from ", 5))
2524 * Strip leading "from"...
2529 while (isspace(*value
))
2534 * Figure out what form the from address takes:
2543 * nnn.nnn.nnn.nnn/mm
2544 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2548 if (value
[0] == '*' || value
[0] == '.' ||
2549 (!isdigit(value
[0] & 255) && value
[0] != '['))
2551 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2552 #endif /* AF_INET6 */
2555 * Host or domain name...
2558 if (value
[0] == '*')
2561 strlcpy(temp
, value
, sizeof(temp
));
2562 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2565 relay
->from
.type
= AUTH_NAME
;
2566 relay
->from
.mask
.name
.name
= strdup(temp
);
2567 relay
->from
.mask
.name
.length
= strlen(temp
);
2572 * One of many IP address forms...
2575 if (!get_addr_and_mask(value
, ip
, mask
))
2577 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2582 relay
->from
.type
= AUTH_IP
;
2583 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2584 sizeof(relay
->from
.mask
.ip
.address
));
2585 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2586 sizeof(relay
->from
.mask
.ip
.netmask
));
2590 * Skip value and trailing whitespace...
2593 for (; *value
; value
++)
2594 if (isspace(*value
))
2597 while (isspace(*value
))
2600 if (!strncasecmp(value
, "to ", 3))
2603 * Strip leading "to"...
2608 while (isspace(*value
))
2613 * Get "to" address and port...
2616 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2619 * Only IPv4 addresses are supported...
2622 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2623 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2628 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2630 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2632 if (relay
->from
.type
== AUTH_IP
)
2633 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2634 relay
->from
.mask
.ip
.address
[0],
2635 relay
->from
.mask
.ip
.address
[1],
2636 relay
->from
.mask
.ip
.address
[2],
2637 relay
->from
.mask
.ip
.address
[3],
2638 relay
->from
.mask
.ip
.netmask
[0],
2639 relay
->from
.mask
.ip
.netmask
[1],
2640 relay
->from
.mask
.ip
.netmask
[2],
2641 relay
->from
.mask
.ip
.netmask
[3]);
2643 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2645 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2646 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2651 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2654 httpAddrFreeList(addrlist
);
2658 if (relay
->from
.type
== AUTH_NAME
)
2659 free(relay
->from
.mask
.name
.name
);
2661 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2665 else if (!strcasecmp(line
, "BrowsePoll"))
2668 * BrowsePoll address[:port]
2671 char *portname
; /* Port name */
2672 int portnum
; /* Port number */
2673 struct servent
*service
; /* Service */
2677 * Extract the port name from the address...
2680 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2684 if (isdigit(*portname
& 255))
2685 portnum
= atoi(portname
);
2686 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2687 portnum
= ntohs(service
->s_port
);
2690 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2696 portnum
= ippPort();
2699 * Add the poll entry...
2703 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2705 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2709 cupsdLogMessage(CUPSD_LOG_ERROR
,
2710 "Unable to allocate BrowsePoll at line %d - %s.",
2711 linenum
, strerror(errno
));
2719 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2721 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2722 pollp
->port
= portnum
;
2724 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2727 else if (!strcasecmp(line
, "DefaultAuthType"))
2730 * DefaultAuthType {basic,digest,basicdigest}
2733 if (!strcasecmp(value
, "basic"))
2734 DefaultAuthType
= AUTH_BASIC
;
2735 else if (!strcasecmp(value
, "digest"))
2736 DefaultAuthType
= AUTH_DIGEST
;
2737 else if (!strcasecmp(value
, "basicdigest"))
2738 DefaultAuthType
= AUTH_BASICDIGEST
;
2740 else if (!strcasecmp(value
, "kerberos"))
2741 DefaultAuthType
= AUTH_KERBEROS
;
2742 #endif /* HAVE_GSSAPI */
2745 cupsdLogMessage(CUPSD_LOG_WARN
,
2746 "Unknown default authorization type %s on line %d.",
2752 else if (!strcasecmp(line
, "DefaultEncryption"))
2755 * DefaultEncryption {Never,IfRequested,Required}
2758 if (!value
|| !strcasecmp(value
, "never"))
2759 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2760 else if (!strcasecmp(value
, "required"))
2761 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2762 else if (!strcasecmp(value
, "ifrequested"))
2763 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2766 cupsdLogMessage(CUPSD_LOG_WARN
,
2767 "Unknown default encryption %s on line %d.",
2772 #endif /* HAVE_SSL */
2774 else if (!strcasecmp(line
, "Krb5Keytab"))
2776 cupsdSetStringf(&Krb5Keytab
, "KRB5_KTNAME=%s", value
);
2779 # ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
2780 gsskrb5_register_acceptor_identity(value
);
2782 cupsdSetEnv("KRB5_KTNAME", value
);
2783 # endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
2785 #endif /* HAVE_GSSAPI */
2786 else if (!strcasecmp(line
, "User"))
2789 * User ID to run as...
2792 if (value
&& isdigit(value
[0] & 255))
2794 int uid
= atoi(value
);
2797 cupsdLogMessage(CUPSD_LOG_ERROR
,
2798 "Will not use User 0 as specified on line %d "
2799 "for security reasons. You must use a non-"
2800 "privileged account instead.",
2807 struct passwd
*p
; /* Password information */
2810 p
= getpwnam(value
);
2815 cupsdLogMessage(CUPSD_LOG_ERROR
,
2816 "Will not use User %s (UID=0) as specified on line "
2817 "%d for security reasons. You must use a non-"
2818 "privileged account instead.",
2824 cupsdLogMessage(CUPSD_LOG_ERROR
,
2825 "Unknown User \"%s\" on line %d, ignoring!",
2829 cupsdLogMessage(CUPSD_LOG_ERROR
,
2830 "User directive on line %d missing the username!",
2833 else if (!strcasecmp(line
, "Group"))
2836 * Group ID to run as...
2839 if (isdigit(value
[0]))
2840 Group
= atoi(value
);
2844 group
= getgrnam(value
);
2847 Group
= group
->gr_gid
;
2849 cupsdLogMessage(CUPSD_LOG_ERROR
,
2850 "Unknown Group \"%s\" on line %d, ignoring!",
2854 else if (!strcasecmp(line
, "SystemGroup"))
2857 * SystemGroup (admin) group(s)...
2860 if (!parse_groups(value
))
2861 cupsdLogMessage(CUPSD_LOG_ERROR
,
2862 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2865 else if (!strcasecmp(line
, "HostNameLookups"))
2868 * Do hostname lookups?
2871 if (!strcasecmp(value
, "off"))
2872 HostNameLookups
= 0;
2873 else if (!strcasecmp(value
, "on"))
2874 HostNameLookups
= 1;
2875 else if (!strcasecmp(value
, "double"))
2876 HostNameLookups
= 2;
2878 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2881 else if (!strcasecmp(line
, "LogLevel"))
2884 * Amount of logging to do...
2887 if (!strcasecmp(value
, "debug2"))
2888 LogLevel
= CUPSD_LOG_DEBUG2
;
2889 else if (!strcasecmp(value
, "debug"))
2890 LogLevel
= CUPSD_LOG_DEBUG
;
2891 else if (!strcasecmp(value
, "info"))
2892 LogLevel
= CUPSD_LOG_INFO
;
2893 else if (!strcasecmp(value
, "notice"))
2894 LogLevel
= CUPSD_LOG_NOTICE
;
2895 else if (!strcasecmp(value
, "warn"))
2896 LogLevel
= CUPSD_LOG_WARN
;
2897 else if (!strcasecmp(value
, "error"))
2898 LogLevel
= CUPSD_LOG_ERROR
;
2899 else if (!strcasecmp(value
, "crit"))
2900 LogLevel
= CUPSD_LOG_CRIT
;
2901 else if (!strcasecmp(value
, "alert"))
2902 LogLevel
= CUPSD_LOG_ALERT
;
2903 else if (!strcasecmp(value
, "emerg"))
2904 LogLevel
= CUPSD_LOG_EMERG
;
2905 else if (!strcasecmp(value
, "none"))
2906 LogLevel
= CUPSD_LOG_NONE
;
2908 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2911 else if (!strcasecmp(line
, "PrintcapFormat"))
2914 * Format of printcap file?
2917 if (!strcasecmp(value
, "bsd"))
2918 PrintcapFormat
= PRINTCAP_BSD
;
2919 else if (!strcasecmp(value
, "solaris"))
2920 PrintcapFormat
= PRINTCAP_SOLARIS
;
2922 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2925 else if (!strcasecmp(line
, "ServerTokens"))
2928 * Set the string used for the Server header...
2931 struct utsname plat
; /* Platform info */
2936 if (!strcasecmp(value
, "ProductOnly"))
2937 cupsdSetString(&ServerHeader
, "CUPS");
2938 else if (!strcasecmp(value
, "Major"))
2939 cupsdSetString(&ServerHeader
, "CUPS/1");
2940 else if (!strcasecmp(value
, "Minor"))
2941 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2942 else if (!strcasecmp(value
, "Minimal"))
2943 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2944 else if (!strcasecmp(value
, "OS"))
2945 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2946 else if (!strcasecmp(value
, "Full"))
2947 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2949 else if (!strcasecmp(value
, "None"))
2950 cupsdClearString(&ServerHeader
);
2952 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2955 else if (!strcasecmp(line
, "PassEnv"))
2958 * PassEnv variable [... variable]
2963 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2964 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2967 if (value
[valuelen
])
2969 value
[valuelen
] = '\0';
2973 cupsdSetEnv(value
, NULL
);
2975 for (value
+= valuelen
; *value
; value
++)
2976 if (!isspace(*value
) || *value
!= ',')
2980 else if (!strcasecmp(line
, "SetEnv"))
2983 * SetEnv variable value
2986 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2994 while (isspace(*valueptr
& 255))
2997 cupsdSetEnv(value
, valueptr
);
3000 cupsdLogMessage(CUPSD_LOG_ERROR
,
3001 "Missing value for SetEnv directive on line %d.",
3007 * Find a simple variable in the list...
3010 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
3011 if (!strcasecmp(line
, var
->name
))
3017 * Unknown directive! Output an error message and continue...
3020 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
3027 case CUPSD_VARTYPE_INTEGER
:
3029 cupsdLogMessage(CUPSD_LOG_ERROR
,
3030 "Missing integer value for %s on line %d!",
3035 char *units
; /* Units */
3038 n
= strtol(value
, &units
, 0);
3040 if (units
&& *units
)
3042 if (tolower(units
[0] & 255) == 'g')
3043 n
*= 1024 * 1024 * 1024;
3044 else if (tolower(units
[0] & 255) == 'm')
3046 else if (tolower(units
[0] & 255) == 'k')
3048 else if (tolower(units
[0] & 255) == 't')
3053 cupsdLogMessage(CUPSD_LOG_ERROR
,
3054 "Bad negative integer value for %s on line %d!",
3057 *((int *)var
->ptr
) = n
;
3061 case CUPSD_VARTYPE_BOOLEAN
:
3063 cupsdLogMessage(CUPSD_LOG_ERROR
,
3064 "Missing boolean value for %s on line %d!",
3066 else if (!strcasecmp(value
, "true") ||
3067 !strcasecmp(value
, "on") ||
3068 !strcasecmp(value
, "enabled") ||
3069 !strcasecmp(value
, "yes") ||
3071 *((int *)var
->ptr
) = TRUE
;
3072 else if (!strcasecmp(value
, "false") ||
3073 !strcasecmp(value
, "off") ||
3074 !strcasecmp(value
, "disabled") ||
3075 !strcasecmp(value
, "no") ||
3076 !strcasecmp(value
, "0"))
3077 *((int *)var
->ptr
) = FALSE
;
3079 cupsdLogMessage(CUPSD_LOG_ERROR
,
3080 "Unknown boolean value %s on line %d.",
3084 case CUPSD_VARTYPE_STRING
:
3085 cupsdSetString((char **)var
->ptr
, value
);
3096 * 'read_location()' - Read a <Location path> definition.
3099 static int /* O - New line number or 0 on error */
3100 read_location(cups_file_t
*fp
, /* I - Configuration file */
3101 char *location
, /* I - Location name/path */
3102 int linenum
) /* I - Current line number */
3104 cupsd_location_t
*loc
, /* New location */
3105 *parent
; /* Parent location */
3106 char line
[HTTP_MAX_BUFFER
],
3108 *value
, /* Value for directive */
3109 *valptr
; /* Pointer into value */
3112 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3115 parent
->limit
= AUTH_LIMIT_ALL
;
3118 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3121 * Decode the directive...
3124 if (!strcasecmp(line
, "</Location>"))
3126 else if (!strcasecmp(line
, "<Limit") ||
3127 !strcasecmp(line
, "<LimitExcept"))
3131 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3135 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3141 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3146 if (!strcmp(value
, "ALL"))
3147 loc
->limit
= AUTH_LIMIT_ALL
;
3148 else if (!strcmp(value
, "GET"))
3149 loc
->limit
|= AUTH_LIMIT_GET
;
3150 else if (!strcmp(value
, "HEAD"))
3151 loc
->limit
|= AUTH_LIMIT_HEAD
;
3152 else if (!strcmp(value
, "OPTIONS"))
3153 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3154 else if (!strcmp(value
, "POST"))
3155 loc
->limit
|= AUTH_LIMIT_POST
;
3156 else if (!strcmp(value
, "PUT"))
3157 loc
->limit
|= AUTH_LIMIT_PUT
;
3158 else if (!strcmp(value
, "TRACE"))
3159 loc
->limit
|= AUTH_LIMIT_TRACE
;
3161 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3164 for (value
= valptr
; isspace(*value
& 255); value
++);
3167 if (!strcasecmp(line
, "<LimitExcept"))
3168 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3170 parent
->limit
&= ~loc
->limit
;
3172 else if (!strcasecmp(line
, "</Limit>"))
3174 else if (!parse_aaa(loc
, line
, value
, linenum
))
3176 cupsdLogMessage(CUPSD_LOG_ERROR
,
3177 "Unknown Location directive %s on line %d.",
3183 cupsdLogMessage(CUPSD_LOG_ERROR
,
3184 "Unexpected end-of-file at line %d while reading location!",
3192 * 'read_policy()' - Read a <Policy name> definition.
3195 static int /* O - New line number or 0 on error */
3196 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3197 char *policy
, /* I - Location name/path */
3198 int linenum
) /* I - Current line number */
3200 int i
; /* Looping var */
3201 cupsd_policy_t
*pol
; /* Policy */
3202 cupsd_location_t
*op
; /* Policy operation */
3203 int num_ops
; /* Number of IPP operations */
3204 ipp_op_t ops
[100]; /* Operations */
3205 char line
[HTTP_MAX_BUFFER
],
3207 *value
, /* Value for directive */
3208 *valptr
; /* Pointer into value */
3212 * Create the policy...
3215 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3219 * Read from the file...
3225 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3228 * Decode the directive...
3231 if (!strcasecmp(line
, "</Policy>"))
3234 cupsdLogMessage(CUPSD_LOG_WARN
,
3235 "Missing </Limit> before </Policy> on line %d!",
3240 else if (!strcasecmp(line
, "<Limit") && !op
)
3244 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3249 * Scan for IPP operation names...
3256 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3261 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3263 if (!strcasecmp(value
, "All"))
3264 ops
[num_ops
] = IPP_ANY_OPERATION
;
3265 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3266 cupsdLogMessage(CUPSD_LOG_ERROR
,
3267 "Bad IPP operation name \"%s\" on line %d!",
3273 cupsdLogMessage(CUPSD_LOG_ERROR
,
3274 "Too many operations listed on line %d!",
3277 for (value
= valptr
; isspace(*value
& 255); value
++);
3281 * If none are specified, apply the policy to all operations...
3286 ops
[0] = IPP_ANY_OPERATION
;
3291 * Add a new policy for the first operation...
3294 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3296 else if (!strcasecmp(line
, "</Limit>") && op
)
3299 * Finish the current operation limit...
3305 * Copy the policy to the other operations...
3308 for (i
= 1; i
< num_ops
; i
++)
3309 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3316 cupsdLogMessage(CUPSD_LOG_ERROR
,
3317 "Missing <Limit ops> directive before %s on line %d.",
3321 else if (!parse_aaa(op
, line
, value
, linenum
))
3324 cupsdLogMessage(CUPSD_LOG_ERROR
,
3325 "Unknown Policy Limit directive %s on line %d.",
3328 cupsdLogMessage(CUPSD_LOG_ERROR
,
3329 "Unknown Policy directive %s on line %d.",
3336 cupsdLogMessage(CUPSD_LOG_ERROR
,
3337 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3345 * End of "$Id: conf.c 6253 2007-02-10 18:48:40Z mike $".