2 * "$Id: conf.c 6205 2007-01-22 22:04:43Z 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
},
120 { "HideImplicitMembers", &HideImplicitMembers
, CUPSD_VARTYPE_BOOLEAN
},
121 { "ImplicitClasses", &ImplicitClasses
, CUPSD_VARTYPE_BOOLEAN
},
122 { "ImplicitAnyClasses", &ImplicitAnyClasses
, CUPSD_VARTYPE_BOOLEAN
},
123 { "JobRetryLimit", &JobRetryLimit
, CUPSD_VARTYPE_INTEGER
},
124 { "JobRetryInterval", &JobRetryInterval
, CUPSD_VARTYPE_INTEGER
},
125 { "KeepAliveTimeout", &KeepAliveTimeout
, CUPSD_VARTYPE_INTEGER
},
126 { "KeepAlive", &KeepAlive
, CUPSD_VARTYPE_BOOLEAN
},
127 { "LimitRequestBody", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
128 { "ListenBackLog", &ListenBackLog
, CUPSD_VARTYPE_INTEGER
},
129 { "LogFilePerm", &LogFilePerm
, CUPSD_VARTYPE_INTEGER
},
130 { "MaxActiveJobs", &MaxActiveJobs
, CUPSD_VARTYPE_INTEGER
},
131 { "MaxClients", &MaxClients
, CUPSD_VARTYPE_INTEGER
},
132 { "MaxClientsPerHost", &MaxClientsPerHost
, CUPSD_VARTYPE_INTEGER
},
133 { "MaxCopies", &MaxCopies
, CUPSD_VARTYPE_INTEGER
},
134 { "MaxEvents", &MaxEvents
, CUPSD_VARTYPE_INTEGER
},
135 { "MaxJobs", &MaxJobs
, CUPSD_VARTYPE_INTEGER
},
136 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
137 { "MaxJobsPerUser", &MaxJobsPerUser
, CUPSD_VARTYPE_INTEGER
},
138 { "MaxLeaseDuration", &MaxLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
139 { "MaxLogSize", &MaxLogSize
, CUPSD_VARTYPE_INTEGER
},
140 { "MaxPrinterHistory", &MaxPrinterHistory
, CUPSD_VARTYPE_INTEGER
},
141 { "MaxRequestSize", &MaxRequestSize
, CUPSD_VARTYPE_INTEGER
},
142 { "MaxSubscriptions", &MaxSubscriptions
, CUPSD_VARTYPE_INTEGER
},
143 { "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob
, CUPSD_VARTYPE_INTEGER
},
144 { "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter
, CUPSD_VARTYPE_INTEGER
},
145 { "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser
, CUPSD_VARTYPE_INTEGER
},
146 { "PageLog", &PageLog
, CUPSD_VARTYPE_STRING
},
147 { "PreserveJobFiles", &JobFiles
, CUPSD_VARTYPE_BOOLEAN
},
148 { "PreserveJobHistory", &JobHistory
, CUPSD_VARTYPE_BOOLEAN
},
149 { "Printcap", &Printcap
, CUPSD_VARTYPE_STRING
},
150 { "PrintcapGUI", &PrintcapGUI
, CUPSD_VARTYPE_STRING
},
151 { "ReloadTimeout", &ReloadTimeout
, CUPSD_VARTYPE_INTEGER
},
152 { "RemoteRoot", &RemoteRoot
, CUPSD_VARTYPE_STRING
},
153 { "RequestRoot", &RequestRoot
, CUPSD_VARTYPE_STRING
},
154 { "RIPCache", &RIPCache
, CUPSD_VARTYPE_STRING
},
155 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
156 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
157 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
159 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
160 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
161 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
162 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
163 #endif /* HAVE_SSL */
165 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
166 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
167 #endif /* HAVE_LAUNCHD */
168 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
169 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
170 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
171 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
172 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
173 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
175 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
178 static unsigned ones
[4] =
180 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
182 static unsigned zeros
[4] =
184 0x00000000, 0x00000000, 0x00000000, 0x00000000
191 static int check_permissions(const char *filename
,
192 const char *suffix
, int mode
,
193 int user
, int group
, int is_dir
,
195 static http_addrlist_t
*get_address(const char *value
, int defport
);
196 static int get_addr_and_mask(const char *value
, unsigned *ip
,
198 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
199 char *value
, int linenum
);
200 static int parse_groups(const char *s
);
201 static int parse_protocols(const char *s
);
202 static int read_configuration(cups_file_t
*fp
);
203 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
204 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
208 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
211 int /* O - 1 on success, 0 otherwise */
212 cupsdReadConfiguration(void)
214 int i
; /* Looping var */
215 cups_file_t
*fp
; /* Configuration file */
216 int status
; /* Return status */
217 char temp
[1024], /* Temporary buffer */
218 *slash
; /* Directory separator */
219 cups_lang_t
*language
; /* Language */
220 struct passwd
*user
; /* Default user */
221 struct group
*group
; /* Default group */
222 char *old_serverroot
, /* Old ServerRoot */
223 *old_requestroot
; /* Old RequestRoot */
224 const char *tmpdir
; /* TMPDIR environment variable */
225 struct stat tmpinfo
; /* Temporary directory info */
229 * Save the old root paths...
232 old_serverroot
= NULL
;
233 cupsdSetString(&old_serverroot
, ServerRoot
);
234 old_requestroot
= NULL
;
235 cupsdSetString(&old_requestroot
, RequestRoot
);
238 * Reset the server configuration data...
241 cupsdDeleteAllLocations();
260 for (i
= 0; i
< NumRelays
; i
++)
261 if (Relays
[i
].from
.type
== AUTH_NAME
)
262 free(Relays
[i
].from
.mask
.name
.name
);
269 cupsdDeleteAllListeners();
275 cupsdSetString(&ServerName
, httpGetHostname(NULL
, temp
, sizeof(temp
)));
276 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
277 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
278 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
279 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
280 cupsdSetString(&DataDir
, CUPS_DATADIR
);
281 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
282 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
283 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
284 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
285 cupsdSetString(&Printcap
, CUPS_DEFAULT_PRINTCAP
);
286 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
287 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
288 cupsdSetString(&RemoteRoot
, "remroot");
289 cupsdSetString(&ServerHeader
, "CUPS/1.2");
290 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
292 if (!strcmp(CUPS_DEFAULT_PRINTCAP
, "/etc/printers.conf"))
293 PrintcapFormat
= PRINTCAP_SOLARIS
;
295 PrintcapFormat
= PRINTCAP_BSD
;
297 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
298 if ((slash
= strrchr(temp
, '/')) != NULL
)
301 cupsdSetString(&ServerRoot
, temp
);
303 cupsdClearString(&Classification
);
304 ClassifyOverride
= 0;
308 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
310 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
311 cupsdSetString(&ServerKey
, "ssl/server.key");
312 # endif /* HAVE_CDSASSL */
313 #endif /* HAVE_SSL */
315 language
= cupsLangDefault();
317 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
318 cupsdSetString(&DefaultLanguage
, "en");
320 cupsdSetString(&DefaultLanguage
, language
->language
);
322 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
324 cupsdSetString(&RIPCache
, "8m");
326 cupsdSetString(&TempDir
, NULL
);
329 * Find the default user...
332 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
337 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
338 * complement number...)
347 * Find the default group...
350 group
= getgrnam(CUPS_DEFAULT_GROUP
);
354 Group
= group
->gr_gid
;
358 * Fallback to group "nobody"...
361 group
= getgrnam("nobody");
365 Group
= group
->gr_gid
;
369 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
370 * complement number...)
381 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
382 DefaultAuthType
= AUTH_BASIC
;
384 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
385 #endif /* HAVE_SSL */
387 JobRetryInterval
= 300;
392 HostNameLookups
= FALSE
;
393 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
394 ImplicitAnyClasses
= FALSE
;
395 HideImplicitMembers
= TRUE
;
397 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
398 ListenBackLog
= SOMAXCONN
;
399 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
400 LogLevel
= CUPSD_LOG_ERROR
;
402 MaxClientsPerHost
= 0;
403 MaxLogSize
= 1024 * 1024;
404 MaxPrinterHistory
= 10;
407 RootCertDuration
= 300;
408 Timeout
= DEFAULT_TIMEOUT
;
411 BrowseInterval
= DEFAULT_INTERVAL
;
412 BrowsePort
= ippPort();
413 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
414 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
415 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
416 BrowseTimeout
= DEFAULT_TIMEOUT
;
417 Browsing
= CUPS_DEFAULT_BROWSING
;
418 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
420 cupsdClearString(&BrowseLocalOptions
);
421 cupsdClearString(&BrowseRemoteOptions
);
424 cupsdClearString(&BrowseLDAPBindDN
);
425 cupsdClearString(&BrowseLDAPDN
);
426 cupsdClearString(&BrowseLDAPPassword
);
427 cupsdClearString(&BrowseLDAPServer
);
428 #endif /* HAVE_LDAP */
430 JobHistory
= DEFAULT_HISTORY
;
431 JobFiles
= DEFAULT_FILES
;
436 MaxJobsPerPrinter
= 0;
439 cupsdDeleteAllPolicies();
440 cupsdClearString(&DefaultPolicy
);
442 MaxSubscriptions
= 100;
443 MaxSubscriptionsPerJob
= 0;
444 MaxSubscriptionsPerPrinter
= 0;
445 MaxSubscriptionsPerUser
= 0;
446 DefaultLeaseDuration
= 86400;
447 MaxLeaseDuration
= 0;
450 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
451 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
452 #endif /* HAVE_LAUNCHD */
455 * Read the configuration file...
458 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
461 status
= read_configuration(fp
);
471 * See if the ServerName is an IP address...
474 for (slash
= ServerName
; isdigit(*slash
& 255) || *slash
== '.'; slash
++);
476 ServerNameIsIP
= !*slash
;
479 * Use the default system group if none was supplied in cupsd.conf...
482 if (NumSystemGroups
== 0)
484 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
487 * Find the group associated with GID 0...
494 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
496 cupsdSetString(&SystemGroups
[0], "unknown");
498 SystemGroupIDs
[0] = 0;
504 * Get the access control list for browsing...
507 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
510 * Open the system log for cupsd if necessary...
514 if (!strcmp(AccessLog
, "syslog") ||
515 !strcmp(ErrorLog
, "syslog") ||
516 !strcmp(PageLog
, "syslog"))
517 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
518 #endif /* HAVE_VSYSLOG */
521 * Log the configuration file that was used...
524 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
528 * Validate the Group and SystemGroup settings - they cannot be the same,
529 * otherwise the CGI programs will be able to authenticate as root without
535 for (i
= 0; i
< NumSystemGroups
; i
++)
536 if (Group
== SystemGroupIDs
[i
])
539 if (i
< NumSystemGroups
)
542 * Log the error and reset the group to a safe value...
545 cupsdLogMessage(CUPSD_LOG_NOTICE
,
546 "Group and SystemGroup cannot use the same groups!");
547 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
549 group
= getgrnam("nobody");
553 Group
= group
->gr_gid
;
557 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
558 * complement number...)
567 * Check that we have at least one listen/port line; if not, report this
568 * as an error and exit!
571 if (cupsArrayCount(Listeners
) == 0)
577 cupsdLogMessage(CUPSD_LOG_EMERG
,
578 "No valid Listen or Port lines were found in the configuration file!");
584 cupsdEndProcess(getpid(), 0);
588 * Set the default locale using the language and charset...
591 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
594 * Update all relative filenames to include the full path from ServerRoot...
597 if (DocumentRoot
[0] != '/')
598 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
600 if (RequestRoot
[0] != '/')
601 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
603 if (ServerBin
[0] != '/')
604 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
606 if (StateDir
[0] != '/')
607 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
609 if (CacheDir
[0] != '/')
610 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
613 if (ServerCertificate
[0] != '/')
614 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
616 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
618 chown(ServerCertificate
, RunUser
, Group
);
619 chmod(ServerCertificate
, 0600);
622 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
623 if (ServerKey
[0] != '/')
624 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
626 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
628 chown(ServerKey
, RunUser
, Group
);
629 chmod(ServerKey
, 0600);
631 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
632 #endif /* HAVE_SSL */
635 * Make sure that directories and config files are owned and
636 * writable by the user and group in the cupsd.conf file...
639 if (check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1) < 0 ||
640 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1) < 0 ||
641 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
642 SystemGroupIDs
[0], 1, 1) < 0 ||
643 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0) < 0 ||
644 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1) < 0 ||
645 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0) < 0 ||
646 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
,
648 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
,
650 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
,
652 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0) < 0)
656 * Update TempDir to the default if it hasn't been set already...
661 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
664 * TMPDIR is defined, see if it is OK for us to use...
667 if (stat(tmpdir
, &tmpinfo
))
668 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
669 tmpdir
, strerror(errno
));
670 else if (!S_ISDIR(tmpinfo
.st_mode
))
671 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
673 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
674 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
675 !(tmpinfo
.st_mode
& S_IWOTH
))
676 cupsdLogMessage(CUPSD_LOG_ERROR
,
677 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
679 cupsdSetString(&TempDir
, tmpdir
);
684 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
686 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
691 * Make sure the request and temporary directories have the right
695 if (check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1) < 0)
698 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
702 * Update ownership and permissions if the CUPS temp directory
703 * is under the spool directory or does not exist...
706 if (check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1) < 0)
710 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
713 * Clean out the temporary directory...
716 cups_dir_t
*dir
; /* Temporary directory */
717 cups_dentry_t
*dent
; /* Directory entry */
718 char tempfile
[1024]; /* Temporary filename */
721 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
723 cupsdLogMessage(CUPSD_LOG_INFO
,
724 "Cleaning out old temporary files in \"%s\"...", TempDir
);
726 while ((dent
= cupsDirRead(dir
)) != NULL
)
728 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
730 if (unlink(tempfile
))
731 cupsdLogMessage(CUPSD_LOG_ERROR
,
732 "Unable to remove temporary file \"%s\" - %s",
733 tempfile
, strerror(errno
));
735 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
742 cupsdLogMessage(CUPSD_LOG_ERROR
,
743 "Unable to open temporary directory \"%s\" - %s",
744 TempDir
, strerror(errno
));
748 * Setup environment variables...
754 * Check the MaxClients setting, and then allocate memory for it...
757 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
760 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
763 MaxClients
= MaxFDs
/ 3;
766 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
770 * Check the MaxActiveJobs setting; limit to 1/3 the available
771 * file descriptors, since we need a pipe for each job...
774 if (MaxActiveJobs
> (MaxFDs
/ 3))
775 MaxActiveJobs
= MaxFDs
/ 3;
777 if (Classification
&& !strcasecmp(Classification
, "none"))
778 cupsdClearString(&Classification
);
781 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
784 * Update the MaxClientsPerHost value, as needed...
787 if (MaxClientsPerHost
<= 0)
788 MaxClientsPerHost
= MaxClients
;
790 if (MaxClientsPerHost
> MaxClients
)
791 MaxClientsPerHost
= MaxClients
;
793 cupsdLogMessage(CUPSD_LOG_INFO
,
794 "Allowing up to %d client connections per host.",
798 * Make sure that BrowseTimeout is at least twice the interval...
801 if (BrowseTimeout
< (2 * BrowseInterval
) || BrowseTimeout
<= 0)
803 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid BrowseTimeout value %d!",
807 BrowseTimeout
= BrowseInterval
* 2;
809 BrowseTimeout
= DEFAULT_TIMEOUT
;
811 cupsdLogMessage(CUPSD_LOG_ALERT
, "Reset BrowseTimeout to %d!",
816 * Update the default policy, as needed...
820 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
822 DefaultPolicyPtr
= NULL
;
824 if (!DefaultPolicyPtr
)
826 cupsd_policy_t
*p
; /* New policy */
827 cupsd_location_t
*po
; /* New policy operation */
831 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
834 cupsdSetString(&DefaultPolicy
, "default");
836 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
837 cupsdLogMessage(CUPSD_LOG_INFO
,
838 "Using policy \"default\" as the default!");
841 cupsdLogMessage(CUPSD_LOG_INFO
,
842 "Creating CUPS default administrative policy:");
844 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
846 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
847 cupsdLogMessage(CUPSD_LOG_INFO
,
848 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
849 "Release-Job Restart-Job Purge-Jobs "
850 "Set-Job-Attributes Create-Job-Subscription "
851 "Renew-Subscription Cancel-Subscription "
852 "Get-Notifications Reprocess-Job Cancel-Current-Job "
853 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
854 "CUPS-Authenticate-Job>");
855 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
857 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
858 po
->order_type
= AUTH_ALLOW
;
859 po
->level
= AUTH_USER
;
861 cupsdAddName(po
, "@OWNER");
862 cupsdAddName(po
, "@SYSTEM");
863 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
865 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
866 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
867 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
868 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
869 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
870 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
871 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
872 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
873 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
874 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
875 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
876 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
877 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
878 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
879 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
880 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
881 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
883 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
885 cupsdLogMessage(CUPSD_LOG_INFO
,
886 "<Limit Pause-Printer Resume-Printer "
887 "Set-Printer-Attributes Enable-Printer "
888 "Disable-Printer Pause-Printer-After-Current-Job "
889 "Hold-New-Jobs Release-Held-New-Jobs "
890 "Deactivate-Printer Activate-Printer Restart-Printer "
891 "Shutdown-Printer Startup-Printer Promote-Job "
892 "Schedule-Job-After CUPS-Add-Printer "
893 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
894 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
895 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
896 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
898 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
899 po
->order_type
= AUTH_ALLOW
;
900 po
->type
= AUTH_BASIC
;
901 po
->level
= AUTH_USER
;
903 cupsdAddName(po
, "@SYSTEM");
904 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
906 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
907 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
908 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
909 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
910 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
911 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
912 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
913 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
914 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
915 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
916 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
917 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
918 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
919 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
920 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
921 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
922 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
923 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
924 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
925 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
926 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
928 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
930 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
931 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
933 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
934 po
->order_type
= AUTH_ALLOW
;
936 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
937 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
941 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
943 for (i
= 0; i
< NumPolicies
; i
++)
944 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
945 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
949 * If we are doing a full reload or the server root has changed, flush
950 * the jobs, printers, etc. and start from scratch...
953 if (NeedReload
== RELOAD_ALL
||
954 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
955 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
957 mime_type_t
*type
; /* Current type */
958 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
962 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
968 cupsdDeleteAllSubscriptions();
970 cupsdDeleteAllClasses();
971 cupsdDeleteAllPrinters();
973 DefaultPrinter
= NULL
;
975 if (MimeDatabase
!= NULL
)
976 mimeDelete(MimeDatabase
);
980 for (i
= 0; i
< NumMimeTypes
; i
++)
981 _cupsStrFree(MimeTypes
[i
]);
987 * Read the MIME type and conversion database...
990 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
992 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
996 cupsdLogMessage(CUPSD_LOG_EMERG
,
997 "Unable to load MIME database from \'%s\'!", ServerRoot
);
1001 cupsdLogMessage(CUPSD_LOG_INFO
,
1002 "Loaded MIME database from \'%s\': %d types, %d filters...",
1003 ServerRoot
, mimeNumTypes(MimeDatabase
),
1004 mimeNumFilters(MimeDatabase
));
1007 * Create a list of MIME types for the document-format-supported
1011 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
1012 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
1015 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
1017 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
1019 i
++, type
= mimeNextType(MimeDatabase
))
1021 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
1023 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
1026 if (i
< NumMimeTypes
)
1027 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1029 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1031 mime_filter_t
*filter
; /* Current filter */
1034 for (type
= mimeFirstType(MimeDatabase
);
1036 type
= mimeNextType(MimeDatabase
))
1037 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1038 type
->super
, type
->type
);
1040 for (filter
= mimeFirstFilter(MimeDatabase
);
1042 filter
= mimeNextFilter(MimeDatabase
))
1043 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1044 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1045 filter
->src
->super
, filter
->src
->type
,
1046 filter
->dst
->super
, filter
->dst
->type
,
1047 filter
->cost
, filter
->filter
);
1054 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1055 cupsdLoadBanners(temp
);
1058 * Load printers and classes...
1061 cupsdLoadAllPrinters();
1062 cupsdLoadAllClasses();
1063 cupsdLoadRemoteCache();
1064 cupsdWritePrintcap();
1066 cupsdCreateCommonData();
1069 * Load queued jobs...
1075 * Load subscriptions...
1078 cupsdLoadAllSubscriptions();
1080 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1085 * Not a full reload, so recreate the common printer attributes...
1088 cupsdCreateCommonData();
1091 * Update all printers as needed...
1094 cupsdUpdatePrinters();
1095 cupsdWritePrintcap();
1097 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1101 * Reset the reload state...
1104 NeedReload
= RELOAD_NONE
;
1106 cupsdClearString(&old_serverroot
);
1107 cupsdClearString(&old_requestroot
);
1114 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1117 static int /* O - 0 on success, -1 on error, 1 on warning */
1118 check_permissions(const char *filename
, /* I - File/directory name */
1119 const char *suffix
, /* I - Additional file/directory name */
1120 int mode
, /* I - Permissions */
1121 int user
, /* I - Owner */
1122 int group
, /* I - Group */
1123 int is_dir
, /* I - 1 = directory, 0 = file */
1124 int create_dir
)/* I - 1 = create directory, 0 = not */
1126 int dir_created
= 0; /* Did we create a directory? */
1127 char pathname
[1024]; /* File name with prefix */
1128 struct stat fileinfo
; /* Stat buffer */
1132 * Prepend the given root to the filename before testing it...
1137 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1138 filename
= pathname
;
1142 * See if we can stat the file/directory...
1145 if (stat(filename
, &fileinfo
))
1147 if (errno
== ENOENT
&& create_dir
)
1149 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1152 if (mkdir(filename
, mode
))
1154 cupsdLogMessage(CUPSD_LOG_ERROR
,
1155 "Unable to create directory \"%s\" - %s", filename
,
1163 return (create_dir
? -1 : 1);
1167 * Make sure it's a regular file...
1170 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1172 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1176 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1178 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1183 * Fix owner, group, and mode as needed...
1186 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1188 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1190 if (chown(filename
, user
, group
))
1192 cupsdLogMessage(CUPSD_LOG_ERROR
,
1193 "Unable to change ownership of \"%s\" - %s", filename
,
1199 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
1201 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1203 if (chmod(filename
, mode
))
1205 cupsdLogMessage(CUPSD_LOG_ERROR
,
1206 "Unable to change permissions of \"%s\" - %s", filename
,
1213 * Everything is OK...
1221 * 'get_address()' - Get an address + port number from a line.
1224 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1225 get_address(const char *value
, /* I - Value string */
1226 int defport
) /* I - Default port */
1228 char buffer
[1024], /* Hostname + port number buffer */
1229 defpname
[255], /* Default port name */
1230 *hostname
, /* Hostname or IP */
1231 *portname
; /* Port number or name */
1232 http_addrlist_t
*addrlist
; /* Address list */
1236 * Check for an empty value...
1241 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1246 * Grab a hostname and port number; if there is no colon and the port name
1247 * is only digits, then we have a port number by itself...
1250 strlcpy(buffer
, value
, sizeof(buffer
));
1252 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1259 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1264 * Use the default port...
1267 sprintf(defpname
, "%d", defport
);
1268 portname
= defpname
;
1274 * The buffer contains just a port number...
1282 if (hostname
&& !strcmp(hostname
, "*"))
1286 * Now lookup the address using httpAddrGetList()...
1289 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1290 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1291 hostname
? hostname
: "(nil)");
1298 * 'get_addr_and_mask()' - Get an IP address and netmask.
1301 static int /* O - 1 on success, 0 on failure */
1302 get_addr_and_mask(const char *value
, /* I - String from config file */
1303 unsigned *ip
, /* O - Address value */
1304 unsigned *mask
) /* O - Mask value */
1306 int i
, j
, /* Looping vars */
1307 family
, /* Address family */
1308 ipcount
; /* Count of fields in address */
1309 unsigned ipval
; /* Value */
1310 const char *maskval
, /* Pointer to start of mask value */
1311 *ptr
, /* Pointer into value */
1316 * Get the address...
1319 ip
[0] = ip
[1] = ip
[2] = ip
[3] = 0x00000000;
1320 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1322 if ((maskval
= strchr(value
, '/')) != NULL
)
1325 maskval
= value
+ strlen(value
);
1329 * Check for an IPv6 address...
1335 * Parse hexadecimal IPv6 address...
1340 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1344 else if (!strncmp(ptr
, "::", 2))
1346 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1348 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1353 else if (isxdigit(*ptr
& 255))
1355 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1363 ip
[i
/ 2] |= ipval
<< 16;
1377 if (*ptr
&& *ptr
!= '/')
1381 #endif /* AF_INET6 */
1384 * Parse dotted-decimal IPv4 address...
1387 unsigned val
[4]; /* IPv4 address values */
1391 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1394 * Range check the IP numbers...
1397 for (i
= 0; i
< ipcount
; i
++)
1402 * Make sure the trailing values are zeroed, as some C libraries like
1403 * glibc apparently like to fill the unused arguments with garbage...
1406 for (i
= ipcount
; i
< 4; i
++)
1410 * Merge everything into a 32-bit IPv4 address in ip[3]...
1413 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1416 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1422 * Get the netmask value(s)...
1425 memset(mask
, 0, sizeof(unsigned) * 4);
1427 if (strchr(maskval
, '.'))
1430 * Get dotted-decimal mask...
1433 if (family
!= AF_INET
)
1436 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1439 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1440 mask
[0] = mask
[1] = mask
[2] = 0;
1445 * Get address/bits format...
1451 if (family
== AF_INET6
)
1459 mask
[0] = 0xffffffff;
1461 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1464 mask
[1] = 0xffffffff;
1468 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1471 mask
[2] = 0xffffffff;
1475 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1478 mask
[3] = 0xffffffff;
1482 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1485 #endif /* AF_INET6 */
1490 mask
[0] = 0xffffffff;
1491 mask
[1] = 0xffffffff;
1492 mask
[2] = 0xffffffff;
1495 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1497 mask
[3] = 0xffffffff;
1502 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1503 "get_addr_and_mask(value=\"%s\", "
1504 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
1505 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1509 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1512 if ((ip
[0] & ~mask
[0]) != 0 ||
1513 (ip
[1] & ~mask
[1]) != 0 ||
1514 (ip
[2] & ~mask
[2]) != 0 ||
1515 (ip
[3] & ~mask
[3]) != 0)
1523 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1526 static int /* O - 1 on success, 0 on failure */
1527 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1528 char *line
, /* I - Line from file */
1529 char *value
, /* I - Start of value data */
1530 int linenum
) /* I - Current line number */
1532 char *valptr
; /* Pointer into value */
1533 unsigned ip
[4], /* IP address components */
1534 mask
[4]; /* IP netmask components */
1537 if (!strcasecmp(line
, "Encryption"))
1540 * "Encryption xxx" - set required encryption level...
1543 if (!strcasecmp(value
, "never"))
1544 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1545 else if (!strcasecmp(value
, "always"))
1547 cupsdLogMessage(CUPSD_LOG_ERROR
,
1548 "Encryption value \"%s\" on line %d is invalid in this "
1549 "context. Using \"required\" instead.", value
, linenum
);
1551 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1553 else if (!strcasecmp(value
, "required"))
1554 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1555 else if (!strcasecmp(value
, "ifrequested"))
1556 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1559 cupsdLogMessage(CUPSD_LOG_ERROR
,
1560 "Unknown Encryption value %s on line %d.", value
, linenum
);
1564 else if (!strcasecmp(line
, "Order"))
1567 * "Order Deny,Allow" or "Order Allow,Deny"...
1570 if (!strncasecmp(value
, "deny", 4))
1571 loc
->order_type
= AUTH_ALLOW
;
1572 else if (!strncasecmp(value
, "allow", 5))
1573 loc
->order_type
= AUTH_DENY
;
1576 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1581 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1584 * Allow [From] host/ip...
1585 * Deny [From] host/ip...
1588 if (!strncasecmp(value
, "from", 4))
1591 * Strip leading "from"...
1596 while (isspace(*value
& 255))
1601 * Figure out what form the allow/deny address takes:
1612 * nnn.nnn.nnn.nnn/mm
1613 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1616 if (!strcasecmp(value
, "all"))
1622 if (!strcasecmp(line
, "Allow"))
1623 cupsdAllowIP(loc
, zeros
, zeros
);
1625 cupsdDenyIP(loc
, zeros
, zeros
);
1627 else if (!strcasecmp(value
, "none"))
1633 if (!strcasecmp(line
, "Allow"))
1634 cupsdAllowIP(loc
, ones
, zeros
);
1636 cupsdDenyIP(loc
, ones
, zeros
);
1639 else if (value
[0] == '*' || value
[0] == '.' ||
1640 (!isdigit(value
[0] & 255) && value
[0] != '['))
1642 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1643 #endif /* AF_INET6 */
1646 * Host or domain name...
1649 if (value
[0] == '*')
1652 if (!strcasecmp(line
, "Allow"))
1653 cupsdAllowHost(loc
, value
);
1655 cupsdDenyHost(loc
, value
);
1660 * One of many IP address forms...
1663 if (!get_addr_and_mask(value
, ip
, mask
))
1665 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1670 if (!strcasecmp(line
, "Allow"))
1671 cupsdAllowIP(loc
, ip
, mask
);
1673 cupsdDenyIP(loc
, ip
, mask
);
1676 else if (!strcasecmp(line
, "AuthType"))
1679 * AuthType {none,basic,digest,basicdigest}
1682 if (!strcasecmp(value
, "none"))
1684 loc
->type
= AUTH_NONE
;
1685 loc
->level
= AUTH_ANON
;
1687 else if (!strcasecmp(value
, "basic"))
1689 loc
->type
= AUTH_BASIC
;
1691 if (loc
->level
== AUTH_ANON
)
1692 loc
->level
= AUTH_USER
;
1694 else if (!strcasecmp(value
, "digest"))
1696 loc
->type
= AUTH_DIGEST
;
1698 if (loc
->level
== AUTH_ANON
)
1699 loc
->level
= AUTH_USER
;
1701 else if (!strcasecmp(value
, "basicdigest"))
1703 loc
->type
= AUTH_BASICDIGEST
;
1705 if (loc
->level
== AUTH_ANON
)
1706 loc
->level
= AUTH_USER
;
1710 cupsdLogMessage(CUPSD_LOG_WARN
,
1711 "Unknown authorization type %s on line %d.",
1716 else if (!strcasecmp(line
, "AuthClass"))
1719 * AuthClass anonymous, user, system, group
1722 if (!strcasecmp(value
, "anonymous"))
1724 loc
->type
= AUTH_NONE
;
1725 loc
->level
= AUTH_ANON
;
1727 cupsdLogMessage(CUPSD_LOG_WARN
,
1728 "\"AuthClass %s\" is deprecated; consider removing "
1732 else if (!strcasecmp(value
, "user"))
1734 loc
->level
= AUTH_USER
;
1736 cupsdLogMessage(CUPSD_LOG_WARN
,
1737 "\"AuthClass %s\" is deprecated; consider using "
1738 "\"Require valid-user\" on line %d.",
1741 else if (!strcasecmp(value
, "group"))
1743 loc
->level
= AUTH_GROUP
;
1745 cupsdLogMessage(CUPSD_LOG_WARN
,
1746 "\"AuthClass %s\" is deprecated; consider using "
1747 "\"Require @groupname\" on line %d.",
1750 else if (!strcasecmp(value
, "system"))
1752 loc
->level
= AUTH_GROUP
;
1754 cupsdAddName(loc
, "@SYSTEM");
1756 cupsdLogMessage(CUPSD_LOG_WARN
,
1757 "\"AuthClass %s\" is deprecated; consider using "
1758 "\"Require @SYSTEM\" on line %d.",
1763 cupsdLogMessage(CUPSD_LOG_WARN
,
1764 "Unknown authorization class %s on line %d.",
1769 else if (!strcasecmp(line
, "AuthGroupName"))
1771 cupsdAddName(loc
, value
);
1773 cupsdLogMessage(CUPSD_LOG_WARN
,
1774 "\"AuthGroupName %s\" directive is deprecated; consider "
1775 "using \"Require @%s\" on line %d.",
1776 value
, value
, linenum
);
1778 else if (!strcasecmp(line
, "Require"))
1781 * Apache synonym for AuthClass and AuthGroupName...
1785 * Require valid-user
1786 * Require group names
1787 * Require user names
1790 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1795 if (!strcasecmp(value
, "valid-user") ||
1796 !strcasecmp(value
, "user"))
1797 loc
->level
= AUTH_USER
;
1798 else if (!strcasecmp(value
, "group"))
1799 loc
->level
= AUTH_GROUP
;
1802 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1808 * Get the list of names from the line...
1811 for (value
= valptr
; *value
;)
1813 while (isspace(*value
& 255))
1816 if (*value
== '\"' || *value
== '\'')
1819 * Grab quoted name...
1822 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1829 * Grab literal name.
1832 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1838 cupsdAddName(loc
, value
);
1840 for (value
= valptr
; isspace(*value
& 255); value
++);
1843 else if (!strcasecmp(line
, "Satisfy"))
1845 if (!strcasecmp(value
, "all"))
1846 loc
->satisfy
= AUTH_SATISFY_ALL
;
1847 else if (!strcasecmp(value
, "any"))
1848 loc
->satisfy
= AUTH_SATISFY_ANY
;
1851 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1864 * 'parse_groups()' - Parse system group names in a string.
1867 static int /* O - 1 on success, 0 on failure */
1868 parse_groups(const char *s
) /* I - Space-delimited groups */
1870 int status
; /* Return status */
1871 char value
[1024], /* Value string */
1872 *valstart
, /* Pointer into value */
1873 *valend
, /* End of value */
1874 quote
; /* Quote character */
1875 struct group
*group
; /* Group */
1879 * Make a copy of the string and parse out the groups...
1882 strlcpy(value
, s
, sizeof(value
));
1887 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1889 if (*valstart
== '\'' || *valstart
== '\"')
1892 * Scan quoted name...
1895 quote
= *valstart
++;
1897 for (valend
= valstart
; *valend
; valend
++)
1898 if (*valend
== quote
)
1904 * Scan space or comma-delimited name...
1907 for (valend
= valstart
; *valend
; valend
++)
1908 if (isspace(*valend
) || *valend
== ',')
1915 group
= getgrnam(valstart
);
1918 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1919 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1930 while (*valstart
== ',' || isspace(*valstart
))
1939 * 'parse_protocols()' - Parse browse protocols in a string.
1942 static int /* O - Browse protocol bits */
1943 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1945 int protocols
; /* Browse protocol bits */
1946 char value
[1024], /* Value string */
1947 *valstart
, /* Pointer into value */
1948 *valend
; /* End of value */
1952 * Empty protocol line yields NULL pointer...
1959 * Loop through the value string,...
1962 strlcpy(value
, s
, sizeof(value
));
1966 for (valstart
= value
; *valstart
;)
1969 * Get the current space/comma-delimited protocol name...
1972 for (valend
= valstart
; *valend
; valend
++)
1973 if (isspace(*valend
& 255) || *valend
== ',')
1980 * Add the protocol to the bitmask...
1983 if (!strcasecmp(valstart
, "cups"))
1984 protocols
|= BROWSE_CUPS
;
1985 else if (!strcasecmp(valstart
, "slp"))
1986 protocols
|= BROWSE_SLP
;
1987 else if (!strcasecmp(valstart
, "ldap"))
1988 protocols
|= BROWSE_LDAP
;
1989 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
1990 protocols
|= BROWSE_DNSSD
;
1991 else if (!strcasecmp(valstart
, "all"))
1992 protocols
|= BROWSE_ALL
;
1993 else if (strcasecmp(valstart
, "none"))
1996 for (valstart
= valend
; *valstart
; valstart
++)
1997 if (!isspace(*valstart
& 255) || *valstart
!= ',')
2006 * 'read_configuration()' - Read a configuration file.
2009 static int /* O - 1 on success, 0 on failure */
2010 read_configuration(cups_file_t
*fp
) /* I - File to read from */
2012 int i
; /* Looping var */
2013 int linenum
; /* Current line number */
2014 char line
[HTTP_MAX_BUFFER
],
2015 /* Line from file */
2016 temp
[HTTP_MAX_BUFFER
],
2017 /* Temporary buffer for value */
2018 temp2
[HTTP_MAX_BUFFER
],
2019 /* Temporary buffer 2 for value */
2020 *ptr
, /* Pointer into line/temp */
2021 *value
, /* Pointer to value */
2022 *valueptr
; /* Pointer into value */
2023 int valuelen
; /* Length of value */
2024 cupsd_var_t
*var
; /* Current variable */
2025 http_addrlist_t
*addrlist
, /* Address list */
2026 *addr
; /* Current address */
2027 unsigned ip
[4], /* Address value */
2028 mask
[4]; /* Netmask value */
2029 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2030 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2031 cupsd_location_t
*location
; /* Browse location */
2032 cups_file_t
*incfile
; /* Include file */
2033 char incname
[1024]; /* Include filename */
2034 struct group
*group
; /* Group */
2038 * Loop through each line in the file...
2043 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2046 * Decode the directive...
2049 if (!strcasecmp(line
, "Include"))
2055 if (value
[0] == '/')
2056 strlcpy(incname
, value
, sizeof(incname
));
2058 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2060 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2061 cupsdLogMessage(CUPSD_LOG_ERROR
,
2062 "Unable to include config file \"%s\" - %s",
2063 incname
, strerror(errno
));
2066 read_configuration(incfile
);
2067 cupsFileClose(incfile
);
2070 else if (!strcasecmp(line
, "<Location"))
2078 linenum
= read_location(fp
, value
, linenum
);
2084 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2089 else if (!strcasecmp(line
, "<Policy"))
2097 linenum
= read_policy(fp
, value
, linenum
);
2103 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2107 else if (!strcasecmp(line
, "FaxRetryInterval"))
2111 JobRetryInterval
= atoi(value
);
2112 cupsdLogMessage(CUPSD_LOG_WARN
,
2113 "FaxRetryInterval is deprecated; use "
2114 "JobRetryInterval on line %d.", linenum
);
2118 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2122 else if (!strcasecmp(line
, "FaxRetryLimit"))
2126 JobRetryLimit
= atoi(value
);
2127 cupsdLogMessage(CUPSD_LOG_WARN
,
2128 "FaxRetryLimit is deprecated; use "
2129 "JobRetryLimit on line %d.", linenum
);
2133 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2137 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2139 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2140 #endif /* HAVE_SSL */
2144 * Add listening address(es) to the list...
2147 cupsd_listener_t
*lis
; /* New listeners array */
2151 * Get the address list...
2154 addrlist
= get_address(value
, IPP_PORT
);
2158 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2164 * Add each address...
2167 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2170 * Allocate another listener...
2174 Listeners
= cupsArrayNew(NULL
, NULL
);
2178 cupsdLogMessage(CUPSD_LOG_ERROR
,
2179 "Unable to allocate %s at line %d - %s.",
2180 line
, linenum
, strerror(errno
));
2184 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2186 cupsdLogMessage(CUPSD_LOG_ERROR
,
2187 "Unable to allocate %s at line %d - %s.",
2188 line
, linenum
, strerror(errno
));
2192 cupsArrayAdd(Listeners
, lis
);
2195 * Copy the current address and log it...
2198 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2202 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2203 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2204 #endif /* HAVE_SSL */
2206 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2209 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2210 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2211 ntohs(lis
->address
.ipv6
.sin6_port
));
2213 #endif /* AF_INET6 */
2215 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2216 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2218 #endif /* AF_LOCAL */
2219 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2220 ntohs(lis
->address
.ipv4
.sin_port
));
2227 httpAddrFreeList(addrlist
);
2229 else if (!strcasecmp(line
, "BrowseAddress"))
2232 * Add a browse address to the list...
2235 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2238 if (NumBrowsers
== 0)
2239 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2241 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2245 cupsdLogMessage(CUPSD_LOG_ERROR
,
2246 "Unable to allocate BrowseAddress at line %d - %s.",
2247 linenum
, strerror(errno
));
2252 dira
+= NumBrowsers
;
2254 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2256 if (!strcasecmp(value
, "@LOCAL"))
2259 * Send browse data to all local interfaces...
2262 strcpy(dira
->iface
, "*");
2265 else if (!strncasecmp(value
, "@IF(", 4))
2268 * Send browse data to the named interface...
2271 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2273 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2279 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2282 * Only IPv4 addresses are supported...
2285 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2286 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2291 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2292 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2294 cupsdLogMessage(CUPSD_LOG_INFO
,
2295 "Sending browsing info to %s:%d (IPv4)",
2296 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2301 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2304 httpAddrFreeList(addrlist
);
2307 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2310 else if (!strcasecmp(line
, "BrowseOrder"))
2313 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2316 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2317 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2319 if (location
== NULL
)
2320 cupsdLogMessage(CUPSD_LOG_ERROR
,
2321 "Unable to initialize browse access control list!");
2322 else if (!strncasecmp(value
, "deny", 4))
2323 location
->order_type
= AUTH_ALLOW
;
2324 else if (!strncasecmp(value
, "allow", 5))
2325 location
->order_type
= AUTH_DENY
;
2327 cupsdLogMessage(CUPSD_LOG_ERROR
,
2328 "Unknown BrowseOrder value %s on line %d.",
2331 else if (!strcasecmp(line
, "BrowseProtocols") ||
2332 !strcasecmp(line
, "BrowseLocalProtocols") ||
2333 !strcasecmp(line
, "BrowseRemoteProtocols"))
2336 * "BrowseProtocols name [... name]"
2337 * "BrowseLocalProtocols name [... name]"
2338 * "BrowseRemoteProtocols name [... name]"
2341 int protocols
= parse_protocols(value
);
2345 cupsdLogMessage(CUPSD_LOG_ERROR
,
2346 "Unknown browse protocol \"%s\" on line %d.",
2351 if (strcasecmp(line
, "BrowseLocalProtocols"))
2352 BrowseRemoteProtocols
= protocols
;
2353 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2354 BrowseLocalProtocols
= protocols
;
2356 else if (!strcasecmp(line
, "BrowseAllow") ||
2357 !strcasecmp(line
, "BrowseDeny"))
2360 * BrowseAllow [From] host/ip...
2361 * BrowseDeny [From] host/ip...
2364 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2365 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2367 if (location
== NULL
)
2368 cupsdLogMessage(CUPSD_LOG_ERROR
,
2369 "Unable to initialize browse access control list!");
2372 if (!strncasecmp(value
, "from ", 5))
2375 * Strip leading "from"...
2380 while (isspace(*value
))
2385 * Figure out what form the allow/deny address takes:
2396 * nnn.nnn.nnn.nnn/mm
2397 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2400 if (!strcasecmp(value
, "all"))
2406 if (!strcasecmp(line
, "BrowseAllow"))
2407 cupsdAllowIP(location
, zeros
, zeros
);
2409 cupsdDenyIP(location
, zeros
, zeros
);
2411 else if (!strcasecmp(value
, "none"))
2417 if (!strcasecmp(line
, "BrowseAllow"))
2418 cupsdAllowIP(location
, ones
, zeros
);
2420 cupsdDenyIP(location
, ones
, zeros
);
2423 else if (value
[0] == '*' || value
[0] == '.' ||
2424 (!isdigit(value
[0] & 255) && value
[0] != '['))
2426 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2427 #endif /* AF_INET6 */
2430 * Host or domain name...
2433 if (value
[0] == '*')
2436 if (!strcasecmp(line
, "BrowseAllow"))
2437 cupsdAllowHost(location
, value
);
2439 cupsdDenyHost(location
, value
);
2444 * One of many IP address forms...
2447 if (!get_addr_and_mask(value
, ip
, mask
))
2449 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2454 if (!strcasecmp(line
, "BrowseAllow"))
2455 cupsdAllowIP(location
, ip
, mask
);
2457 cupsdDenyIP(location
, ip
, mask
);
2461 else if (!strcasecmp(line
, "BrowseRelay"))
2464 * BrowseRelay [from] source [to] destination
2468 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2470 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2474 cupsdLogMessage(CUPSD_LOG_ERROR
,
2475 "Unable to allocate BrowseRelay at line %d - %s.",
2476 linenum
, strerror(errno
));
2483 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2485 if (!strncasecmp(value
, "from ", 5))
2488 * Strip leading "from"...
2493 while (isspace(*value
))
2498 * Figure out what form the from address takes:
2507 * nnn.nnn.nnn.nnn/mm
2508 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2512 if (value
[0] == '*' || value
[0] == '.' ||
2513 (!isdigit(value
[0] & 255) && value
[0] != '['))
2515 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2516 #endif /* AF_INET6 */
2519 * Host or domain name...
2522 if (value
[0] == '*')
2525 strlcpy(temp
, value
, sizeof(temp
));
2526 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2529 relay
->from
.type
= AUTH_NAME
;
2530 relay
->from
.mask
.name
.name
= strdup(temp
);
2531 relay
->from
.mask
.name
.length
= strlen(temp
);
2536 * One of many IP address forms...
2539 if (!get_addr_and_mask(value
, ip
, mask
))
2541 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2546 relay
->from
.type
= AUTH_IP
;
2547 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2548 sizeof(relay
->from
.mask
.ip
.address
));
2549 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2550 sizeof(relay
->from
.mask
.ip
.netmask
));
2554 * Skip value and trailing whitespace...
2557 for (; *value
; value
++)
2558 if (isspace(*value
))
2561 while (isspace(*value
))
2564 if (!strncasecmp(value
, "to ", 3))
2567 * Strip leading "to"...
2572 while (isspace(*value
))
2577 * Get "to" address and port...
2580 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2583 * Only IPv4 addresses are supported...
2586 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2587 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2592 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2594 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2596 if (relay
->from
.type
== AUTH_IP
)
2597 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2598 relay
->from
.mask
.ip
.address
[0],
2599 relay
->from
.mask
.ip
.address
[1],
2600 relay
->from
.mask
.ip
.address
[2],
2601 relay
->from
.mask
.ip
.address
[3],
2602 relay
->from
.mask
.ip
.netmask
[0],
2603 relay
->from
.mask
.ip
.netmask
[1],
2604 relay
->from
.mask
.ip
.netmask
[2],
2605 relay
->from
.mask
.ip
.netmask
[3]);
2607 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2609 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2610 temp2
, temp
, ntohs(relay
->to
.ipv4
.sin_port
));
2615 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2618 httpAddrFreeList(addrlist
);
2622 if (relay
->from
.type
== AUTH_NAME
)
2623 free(relay
->from
.mask
.name
.name
);
2625 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2629 else if (!strcasecmp(line
, "BrowsePoll"))
2632 * BrowsePoll address[:port]
2635 char *portname
; /* Port name */
2636 int portnum
; /* Port number */
2637 struct servent
*service
; /* Service */
2641 * Extract the port name from the address...
2644 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2648 if (isdigit(*portname
& 255))
2649 portnum
= atoi(portname
);
2650 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2651 portnum
= ntohs(service
->s_port
);
2654 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2660 portnum
= ippPort();
2663 * Add the poll entry...
2667 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2669 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2673 cupsdLogMessage(CUPSD_LOG_ERROR
,
2674 "Unable to allocate BrowsePoll at line %d - %s.",
2675 linenum
, strerror(errno
));
2683 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2685 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2686 pollp
->port
= portnum
;
2688 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2691 else if (!strcasecmp(line
, "DefaultAuthType"))
2694 * DefaultAuthType {basic,digest,basicdigest}
2697 if (!strcasecmp(value
, "basic"))
2698 DefaultAuthType
= AUTH_BASIC
;
2699 else if (!strcasecmp(value
, "digest"))
2700 DefaultAuthType
= AUTH_DIGEST
;
2701 else if (!strcasecmp(value
, "basicdigest"))
2702 DefaultAuthType
= AUTH_BASICDIGEST
;
2705 cupsdLogMessage(CUPSD_LOG_WARN
,
2706 "Unknown default authorization type %s on line %d.",
2712 else if (!strcasecmp(line
, "DefaultEncryption"))
2715 * DefaultEncryption {Never,IfRequested,Required}
2718 if (!value
|| !strcasecmp(value
, "never"))
2719 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2720 else if (!strcasecmp(value
, "required"))
2721 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2722 else if (!strcasecmp(value
, "ifrequested"))
2723 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2726 cupsdLogMessage(CUPSD_LOG_WARN
,
2727 "Unknown default encryption %s on line %d.",
2732 #endif /* HAVE_SSL */
2733 else if (!strcasecmp(line
, "User"))
2736 * User ID to run as...
2739 if (value
&& isdigit(value
[0] & 255))
2741 int uid
= atoi(value
);
2744 cupsdLogMessage(CUPSD_LOG_ERROR
,
2745 "Will not use User 0 as specified on line %d "
2746 "for security reasons. You must use a non-"
2747 "privileged account instead.",
2754 struct passwd
*p
; /* Password information */
2757 p
= getpwnam(value
);
2762 cupsdLogMessage(CUPSD_LOG_ERROR
,
2763 "Will not use User %s (UID=0) as specified on line "
2764 "%d for security reasons. You must use a non-"
2765 "privileged account instead.",
2771 cupsdLogMessage(CUPSD_LOG_ERROR
,
2772 "Unknown User \"%s\" on line %d, ignoring!",
2776 cupsdLogMessage(CUPSD_LOG_ERROR
,
2777 "User directive on line %d missing the username!",
2780 else if (!strcasecmp(line
, "Group"))
2783 * Group ID to run as...
2786 if (isdigit(value
[0]))
2787 Group
= atoi(value
);
2791 group
= getgrnam(value
);
2794 Group
= group
->gr_gid
;
2796 cupsdLogMessage(CUPSD_LOG_ERROR
,
2797 "Unknown Group \"%s\" on line %d, ignoring!",
2801 else if (!strcasecmp(line
, "SystemGroup"))
2804 * SystemGroup (admin) group(s)...
2807 if (!parse_groups(value
))
2808 cupsdLogMessage(CUPSD_LOG_ERROR
,
2809 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2812 else if (!strcasecmp(line
, "HostNameLookups"))
2815 * Do hostname lookups?
2818 if (!strcasecmp(value
, "off"))
2819 HostNameLookups
= 0;
2820 else if (!strcasecmp(value
, "on"))
2821 HostNameLookups
= 1;
2822 else if (!strcasecmp(value
, "double"))
2823 HostNameLookups
= 2;
2825 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2828 else if (!strcasecmp(line
, "LogLevel"))
2831 * Amount of logging to do...
2834 if (!strcasecmp(value
, "debug2"))
2835 LogLevel
= CUPSD_LOG_DEBUG2
;
2836 else if (!strcasecmp(value
, "debug"))
2837 LogLevel
= CUPSD_LOG_DEBUG
;
2838 else if (!strcasecmp(value
, "info"))
2839 LogLevel
= CUPSD_LOG_INFO
;
2840 else if (!strcasecmp(value
, "notice"))
2841 LogLevel
= CUPSD_LOG_NOTICE
;
2842 else if (!strcasecmp(value
, "warn"))
2843 LogLevel
= CUPSD_LOG_WARN
;
2844 else if (!strcasecmp(value
, "error"))
2845 LogLevel
= CUPSD_LOG_ERROR
;
2846 else if (!strcasecmp(value
, "crit"))
2847 LogLevel
= CUPSD_LOG_CRIT
;
2848 else if (!strcasecmp(value
, "alert"))
2849 LogLevel
= CUPSD_LOG_ALERT
;
2850 else if (!strcasecmp(value
, "emerg"))
2851 LogLevel
= CUPSD_LOG_EMERG
;
2852 else if (!strcasecmp(value
, "none"))
2853 LogLevel
= CUPSD_LOG_NONE
;
2855 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2858 else if (!strcasecmp(line
, "PrintcapFormat"))
2861 * Format of printcap file?
2864 if (!strcasecmp(value
, "bsd"))
2865 PrintcapFormat
= PRINTCAP_BSD
;
2866 else if (!strcasecmp(value
, "solaris"))
2867 PrintcapFormat
= PRINTCAP_SOLARIS
;
2869 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2872 else if (!strcasecmp(line
, "ServerTokens"))
2875 * Set the string used for the Server header...
2878 struct utsname plat
; /* Platform info */
2883 if (!strcasecmp(value
, "ProductOnly"))
2884 cupsdSetString(&ServerHeader
, "CUPS");
2885 else if (!strcasecmp(value
, "Major"))
2886 cupsdSetString(&ServerHeader
, "CUPS/1");
2887 else if (!strcasecmp(value
, "Minor"))
2888 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2889 else if (!strcasecmp(value
, "Minimal"))
2890 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2891 else if (!strcasecmp(value
, "OS"))
2892 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2893 else if (!strcasecmp(value
, "Full"))
2894 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2896 else if (!strcasecmp(value
, "None"))
2897 cupsdClearString(&ServerHeader
);
2899 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2902 else if (!strcasecmp(line
, "PassEnv"))
2905 * PassEnv variable [... variable]
2910 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2911 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2914 if (value
[valuelen
])
2916 value
[valuelen
] = '\0';
2920 cupsdSetEnv(value
, NULL
);
2922 for (value
+= valuelen
; *value
; value
++)
2923 if (!isspace(*value
) || *value
!= ',')
2927 else if (!strcasecmp(line
, "SetEnv"))
2930 * SetEnv variable value
2933 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2941 while (isspace(*valueptr
& 255))
2944 cupsdSetEnv(value
, valueptr
);
2947 cupsdLogMessage(CUPSD_LOG_ERROR
,
2948 "Missing value for SetEnv directive on line %d.",
2954 * Find a simple variable in the list...
2957 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2958 if (!strcasecmp(line
, var
->name
))
2964 * Unknown directive! Output an error message and continue...
2967 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2974 case CUPSD_VARTYPE_INTEGER
:
2976 cupsdLogMessage(CUPSD_LOG_ERROR
,
2977 "Missing integer value for %s on line %d!",
2982 char *units
; /* Units */
2985 n
= strtol(value
, &units
, 0);
2987 if (units
&& *units
)
2989 if (tolower(units
[0] & 255) == 'g')
2990 n
*= 1024 * 1024 * 1024;
2991 else if (tolower(units
[0] & 255) == 'm')
2993 else if (tolower(units
[0] & 255) == 'k')
2995 else if (tolower(units
[0] & 255) == 't')
3000 cupsdLogMessage(CUPSD_LOG_ERROR
,
3001 "Bad negative integer value for %s on line %d!",
3004 *((int *)var
->ptr
) = n
;
3008 case CUPSD_VARTYPE_BOOLEAN
:
3010 cupsdLogMessage(CUPSD_LOG_ERROR
,
3011 "Missing boolean value for %s on line %d!",
3013 else if (!strcasecmp(value
, "true") ||
3014 !strcasecmp(value
, "on") ||
3015 !strcasecmp(value
, "enabled") ||
3016 !strcasecmp(value
, "yes") ||
3018 *((int *)var
->ptr
) = TRUE
;
3019 else if (!strcasecmp(value
, "false") ||
3020 !strcasecmp(value
, "off") ||
3021 !strcasecmp(value
, "disabled") ||
3022 !strcasecmp(value
, "no") ||
3023 !strcasecmp(value
, "0"))
3024 *((int *)var
->ptr
) = FALSE
;
3026 cupsdLogMessage(CUPSD_LOG_ERROR
,
3027 "Unknown boolean value %s on line %d.",
3031 case CUPSD_VARTYPE_STRING
:
3032 cupsdSetString((char **)var
->ptr
, value
);
3043 * 'read_location()' - Read a <Location path> definition.
3046 static int /* O - New line number or 0 on error */
3047 read_location(cups_file_t
*fp
, /* I - Configuration file */
3048 char *location
, /* I - Location name/path */
3049 int linenum
) /* I - Current line number */
3051 cupsd_location_t
*loc
, /* New location */
3052 *parent
; /* Parent location */
3053 char line
[HTTP_MAX_BUFFER
],
3055 *value
, /* Value for directive */
3056 *valptr
; /* Pointer into value */
3059 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3062 parent
->limit
= AUTH_LIMIT_ALL
;
3065 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3068 * Decode the directive...
3071 if (!strcasecmp(line
, "</Location>"))
3073 else if (!strcasecmp(line
, "<Limit") ||
3074 !strcasecmp(line
, "<LimitExcept"))
3078 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3082 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3088 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3093 if (!strcmp(value
, "ALL"))
3094 loc
->limit
= AUTH_LIMIT_ALL
;
3095 else if (!strcmp(value
, "GET"))
3096 loc
->limit
|= AUTH_LIMIT_GET
;
3097 else if (!strcmp(value
, "HEAD"))
3098 loc
->limit
|= AUTH_LIMIT_HEAD
;
3099 else if (!strcmp(value
, "OPTIONS"))
3100 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3101 else if (!strcmp(value
, "POST"))
3102 loc
->limit
|= AUTH_LIMIT_POST
;
3103 else if (!strcmp(value
, "PUT"))
3104 loc
->limit
|= AUTH_LIMIT_PUT
;
3105 else if (!strcmp(value
, "TRACE"))
3106 loc
->limit
|= AUTH_LIMIT_TRACE
;
3108 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3111 for (value
= valptr
; isspace(*value
& 255); value
++);
3114 if (!strcasecmp(line
, "<LimitExcept"))
3115 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3117 parent
->limit
&= ~loc
->limit
;
3119 else if (!strcasecmp(line
, "</Limit>"))
3121 else if (!parse_aaa(loc
, line
, value
, linenum
))
3123 cupsdLogMessage(CUPSD_LOG_ERROR
,
3124 "Unknown Location directive %s on line %d.",
3130 cupsdLogMessage(CUPSD_LOG_ERROR
,
3131 "Unexpected end-of-file at line %d while reading location!",
3139 * 'read_policy()' - Read a <Policy name> definition.
3142 static int /* O - New line number or 0 on error */
3143 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3144 char *policy
, /* I - Location name/path */
3145 int linenum
) /* I - Current line number */
3147 int i
; /* Looping var */
3148 cupsd_policy_t
*pol
; /* Policy */
3149 cupsd_location_t
*op
; /* Policy operation */
3150 int num_ops
; /* Number of IPP operations */
3151 ipp_op_t ops
[100]; /* Operations */
3152 char line
[HTTP_MAX_BUFFER
],
3154 *value
, /* Value for directive */
3155 *valptr
; /* Pointer into value */
3159 * Create the policy...
3162 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3166 * Read from the file...
3172 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3175 * Decode the directive...
3178 if (!strcasecmp(line
, "</Policy>"))
3181 cupsdLogMessage(CUPSD_LOG_WARN
,
3182 "Missing </Limit> before </Policy> on line %d!",
3187 else if (!strcasecmp(line
, "<Limit") && !op
)
3191 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3196 * Scan for IPP operation names...
3203 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3208 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3210 if (!strcasecmp(value
, "All"))
3211 ops
[num_ops
] = IPP_ANY_OPERATION
;
3212 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3213 cupsdLogMessage(CUPSD_LOG_ERROR
,
3214 "Bad IPP operation name \"%s\" on line %d!",
3220 cupsdLogMessage(CUPSD_LOG_ERROR
,
3221 "Too many operations listed on line %d!",
3224 for (value
= valptr
; isspace(*value
& 255); value
++);
3228 * If none are specified, apply the policy to all operations...
3233 ops
[0] = IPP_ANY_OPERATION
;
3238 * Add a new policy for the first operation...
3241 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3243 else if (!strcasecmp(line
, "</Limit>") && op
)
3246 * Finish the current operation limit...
3252 * Copy the policy to the other operations...
3255 for (i
= 1; i
< num_ops
; i
++)
3256 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3263 cupsdLogMessage(CUPSD_LOG_ERROR
,
3264 "Missing <Limit ops> directive before %s on line %d.",
3268 else if (!parse_aaa(op
, line
, value
, linenum
))
3271 cupsdLogMessage(CUPSD_LOG_ERROR
,
3272 "Unknown Policy Limit directive %s on line %d.",
3275 cupsdLogMessage(CUPSD_LOG_ERROR
,
3276 "Unknown Policy directive %s on line %d.",
3283 cupsdLogMessage(CUPSD_LOG_ERROR
,
3284 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3292 * End of "$Id: conf.c 6205 2007-01-22 22:04:43Z mike $".