2 * "$Id: conf.c 5167 2006-02-25 02:11:44Z 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 { "RunAsUser", &RunAsUser
, CUPSD_VARTYPE_BOOLEAN
},
156 { "RootCertDuration", &RootCertDuration
, CUPSD_VARTYPE_INTEGER
},
157 { "ServerAdmin", &ServerAdmin
, CUPSD_VARTYPE_STRING
},
158 { "ServerBin", &ServerBin
, CUPSD_VARTYPE_STRING
},
160 { "ServerCertificate", &ServerCertificate
, CUPSD_VARTYPE_STRING
},
161 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
162 { "ServerKey", &ServerKey
, CUPSD_VARTYPE_STRING
},
163 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
164 #endif /* HAVE_SSL */
166 { "LaunchdTimeout", &LaunchdTimeout
, CUPSD_VARTYPE_INTEGER
},
167 { "LaunchdConf", &LaunchdConf
, CUPSD_VARTYPE_STRING
},
168 #endif /* HAVE_LAUNCHD */
169 { "ServerName", &ServerName
, CUPSD_VARTYPE_STRING
},
170 { "ServerRoot", &ServerRoot
, CUPSD_VARTYPE_STRING
},
171 { "StateDir", &StateDir
, CUPSD_VARTYPE_STRING
},
172 { "TempDir", &TempDir
, CUPSD_VARTYPE_STRING
},
173 { "Timeout", &Timeout
, CUPSD_VARTYPE_INTEGER
},
174 { "UseNetworkDefault", &UseNetworkDefault
, CUPSD_VARTYPE_BOOLEAN
}
176 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
179 static unsigned ones
[4] =
181 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
183 static unsigned zeros
[4] =
185 0x00000000, 0x00000000, 0x00000000, 0x00000000
192 static int check_permissions(const char *filename
,
193 const char *suffix
, int mode
,
194 int user
, int group
, int is_dir
,
196 static http_addrlist_t
*get_address(const char *value
, int defport
);
197 static int get_addr_and_mask(const char *value
, unsigned *ip
,
199 static int parse_aaa(cupsd_location_t
*loc
, char *line
,
200 char *value
, int linenum
);
201 static int parse_groups(const char *s
);
202 static int parse_protocols(const char *s
);
203 static int read_configuration(cups_file_t
*fp
);
204 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
205 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
209 * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
212 int /* O - 1 on success, 0 otherwise */
213 cupsdReadConfiguration(void)
215 int i
; /* Looping var */
216 cups_file_t
*fp
; /* Configuration file */
217 int status
; /* Return status */
218 char temp
[1024], /* Temporary buffer */
219 *slash
; /* Directory separator */
220 cups_lang_t
*language
; /* Language */
221 struct passwd
*user
; /* Default user */
222 struct group
*group
; /* Default group */
223 char *old_serverroot
, /* Old ServerRoot */
224 *old_requestroot
; /* Old RequestRoot */
225 const char *tmpdir
; /* TMPDIR environment variable */
226 struct stat tmpinfo
; /* Temporary directory info */
230 * Save the old root paths...
233 old_serverroot
= NULL
;
234 cupsdSetString(&old_serverroot
, ServerRoot
);
235 old_requestroot
= NULL
;
236 cupsdSetString(&old_requestroot
, RequestRoot
);
239 * Reset the server configuration data...
242 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(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
, "/etc/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 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
293 if ((slash
= strrchr(temp
, '/')) != NULL
)
296 cupsdSetString(&ServerRoot
, temp
);
298 cupsdClearString(&Classification
);
299 ClassifyOverride
= 0;
303 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
305 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
306 cupsdSetString(&ServerKey
, "ssl/server.key");
307 # endif /* HAVE_CDSASSL */
308 #endif /* HAVE_SSL */
310 language
= cupsLangDefault();
312 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
313 cupsdSetString(&DefaultLanguage
, "en");
315 cupsdSetString(&DefaultLanguage
, language
->language
);
317 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
319 cupsdSetString(&RIPCache
, "8m");
321 cupsdSetString(&TempDir
, NULL
);
324 * Find the default user...
327 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
332 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
333 * complement number...)
342 * Find the default group (nobody)...
345 group
= getgrnam("nobody");
349 Group
= group
->gr_gid
;
353 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
354 * complement number...)
364 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
365 DefaultAuthType
= AUTH_BASIC
;
367 JobRetryInterval
= 300;
372 HostNameLookups
= FALSE
;
373 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
374 ImplicitAnyClasses
= FALSE
;
375 HideImplicitMembers
= TRUE
;
377 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
378 ListenBackLog
= SOMAXCONN
;
379 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
380 LogLevel
= CUPSD_LOG_ERROR
;
382 MaxClientsPerHost
= 0;
383 MaxLogSize
= 1024 * 1024;
384 MaxPrinterHistory
= 10;
387 RootCertDuration
= 300;
389 Timeout
= DEFAULT_TIMEOUT
;
392 BrowseInterval
= DEFAULT_INTERVAL
;
393 BrowsePort
= ippPort();
394 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
395 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
396 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
397 BrowseTimeout
= DEFAULT_TIMEOUT
;
398 Browsing
= CUPS_DEFAULT_BROWSING
;
399 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
401 cupsdClearString(&BrowseLocalOptions
);
402 cupsdClearString(&BrowseRemoteOptions
);
405 cupsdClearString(&BrowseLDAPBindDN
);
406 cupsdClearString(&BrowseLDAPDN
);
407 cupsdClearString(&BrowseLDAPPassword
);
408 cupsdClearString(&BrowseLDAPServer
);
409 #endif /* HAVE_LDAP */
411 JobHistory
= DEFAULT_HISTORY
;
412 JobFiles
= DEFAULT_FILES
;
417 MaxJobsPerPrinter
= 0;
420 cupsdDeleteAllPolicies();
421 cupsdClearString(&DefaultPolicy
);
423 MaxSubscriptions
= 100;
424 MaxSubscriptionsPerJob
= 0;
425 MaxSubscriptionsPerPrinter
= 0;
426 MaxSubscriptionsPerUser
= 0;
427 DefaultLeaseDuration
= 86400;
428 MaxLeaseDuration
= 0;
431 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
432 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
433 #endif /* HAVE_LAUNCHD */
436 * Read the configuration file...
439 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
442 status
= read_configuration(fp
);
455 * Use the default system group if none was supplied in cupsd.conf...
458 if (NumSystemGroups
== 0)
460 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
463 * Find the group associated with GID 0...
470 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
472 cupsdSetString(&SystemGroups
[0], "unknown");
474 SystemGroupIDs
[0] = 0;
480 * Get the access control list for browsing...
483 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
486 * Open the system log for cupsd if necessary...
490 if (!strcmp(AccessLog
, "syslog") ||
491 !strcmp(ErrorLog
, "syslog") ||
492 !strcmp(PageLog
, "syslog"))
493 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
494 #endif /* HAVE_VSYSLOG */
497 * Log the configuration file that was used...
500 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
504 * Validate the Group and SystemGroup settings - they cannot be the same,
505 * otherwise the CGI programs will be able to authenticate as root without
511 for (i
= 0; i
< NumSystemGroups
; i
++)
512 if (Group
== SystemGroupIDs
[i
])
515 if (i
< NumSystemGroups
)
518 * Log the error and reset the group to a safe value...
521 cupsdLogMessage(CUPSD_LOG_NOTICE
,
522 "Group and SystemGroup cannot use the same groups!");
523 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
525 group
= getgrnam("nobody");
529 Group
= group
->gr_gid
;
533 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
534 * complement number...)
543 * Check that we have at least one listen/port line; if not, report this
544 * as an error and exit!
547 if (cupsArrayCount(Listeners
) == 0)
553 cupsdLogMessage(CUPSD_LOG_EMERG
,
554 "No valid Listen or Port lines were found in the configuration file!");
560 cupsdEndProcess(getpid(), 0);
564 * Set the default locale using the language and charset...
567 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
570 * Update all relative filenames to include the full path from ServerRoot...
573 if (DocumentRoot
[0] != '/')
574 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
576 if (RequestRoot
[0] != '/')
577 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
579 if (ServerBin
[0] != '/')
580 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
582 if (StateDir
[0] != '/')
583 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
585 if (CacheDir
[0] != '/')
586 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
589 if (ServerCertificate
[0] != '/')
590 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
592 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
594 chown(ServerCertificate
, RunUser
, Group
);
595 chmod(ServerCertificate
, 0600);
598 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
599 if (ServerKey
[0] != '/')
600 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
602 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
604 chown(ServerKey
, RunUser
, Group
);
605 chmod(ServerKey
, 0600);
607 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
608 #endif /* HAVE_SSL */
611 * Make sure that directories and config files are owned and
612 * writable by the user and group in the cupsd.conf file...
615 check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1);
616 /* check_permissions(CacheDir, "ppd", 0755, RunUser, Group, 1, 1);*/
618 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1);
619 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
620 SystemGroupIDs
[0], 1, 1);
622 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0);
623 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1);
624 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0);
625 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
, Group
,
627 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
, 0, 0);
628 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
, 0, 0);
629 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0);
632 * Update TempDir to the default if it hasn't been set already...
637 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
640 * TMPDIR is defined, see if it is OK for us to use...
643 if (stat(tmpdir
, &tmpinfo
))
644 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
645 tmpdir
, strerror(errno
));
646 else if (!S_ISDIR(tmpinfo
.st_mode
))
647 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
649 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
650 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
651 !(tmpinfo
.st_mode
& S_IWOTH
))
652 cupsdLogMessage(CUPSD_LOG_ERROR
,
653 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
655 cupsdSetString(&TempDir
, tmpdir
);
658 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
663 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
667 * Make sure the request and temporary directories have the right
671 check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1);
673 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
677 * Update ownership and permissions if the CUPS temp directory
678 * is under the spool directory or does not exist...
681 check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1);
684 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
687 * Clean out the temporary directory...
690 cups_dir_t
*dir
; /* Temporary directory */
691 cups_dentry_t
*dent
; /* Directory entry */
692 char tempfile
[1024]; /* Temporary filename */
695 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
697 cupsdLogMessage(CUPSD_LOG_INFO
,
698 "Cleaning out old temporary files in \"%s\"...", TempDir
);
700 while ((dent
= cupsDirRead(dir
)) != NULL
)
702 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
704 if (unlink(tempfile
))
705 cupsdLogMessage(CUPSD_LOG_ERROR
,
706 "Unable to remove temporary file \"%s\" - %s",
707 tempfile
, strerror(errno
));
709 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
716 cupsdLogMessage(CUPSD_LOG_ERROR
,
717 "Unable to open temporary directory \"%s\" - %s",
718 TempDir
, strerror(errno
));
722 * Setup environment variables...
728 * Check the MaxClients setting, and then allocate memory for it...
731 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
734 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
737 MaxClients
= MaxFDs
/ 3;
740 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
744 * Check the MaxActiveJobs setting; limit to 1/3 the available
745 * file descriptors, since we need a pipe for each job...
748 if (MaxActiveJobs
> (MaxFDs
/ 3))
749 MaxActiveJobs
= MaxFDs
/ 3;
751 if (Classification
&& strcasecmp(Classification
, "none") == 0)
752 cupsdClearString(&Classification
);
755 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
758 * Update the MaxClientsPerHost value, as needed...
761 if (MaxClientsPerHost
<= 0)
762 MaxClientsPerHost
= MaxClients
;
764 if (MaxClientsPerHost
> MaxClients
)
765 MaxClientsPerHost
= MaxClients
;
767 cupsdLogMessage(CUPSD_LOG_INFO
,
768 "Allowing up to %d client connections per host.",
772 * Update the default policy, as needed...
776 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
778 DefaultPolicyPtr
= NULL
;
780 if (!DefaultPolicyPtr
)
782 cupsd_policy_t
*p
; /* New policy */
783 cupsd_location_t
*po
; /* New policy operation */
787 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
790 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
791 cupsdLogMessage(CUPSD_LOG_INFO
,
792 "Using policy \"default\" as the default!");
795 cupsdLogMessage(CUPSD_LOG_INFO
,
796 "Creating CUPS default administrative policy:");
798 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
800 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
801 cupsdLogMessage(CUPSD_LOG_INFO
,
802 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
803 "Release-Job Restart-Job Purge-Jobs "
804 "Set-Job-Attributes Create-Job-Subscription "
805 "Renew-Subscription Cancel-Subscription "
806 "Get-Notifications Reprocess-Job Cancel-Current-Job "
807 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
808 "CUPS-Authenticate-Job>");
809 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
811 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
812 po
->order_type
= AUTH_ALLOW
;
813 po
->level
= AUTH_USER
;
815 cupsdAddName(po
, "@OWNER");
816 cupsdAddName(po
, "@SYSTEM");
817 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
819 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
820 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
821 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
822 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
823 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
824 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
825 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
826 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
827 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
828 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
829 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
830 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
831 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
832 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
833 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
834 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
835 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
837 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
839 cupsdLogMessage(CUPSD_LOG_INFO
,
840 "<Limit Pause-Printer Resume-Printer "
841 "Set-Printer-Attributes Enable-Printer "
842 "Disable-Printer Pause-Printer-After-Current-Job "
843 "Hold-New-Jobs Release-Held-New-Jobs "
844 "Deactivate-Printer Activate-Printer Restart-Printer "
845 "Shutdown-Printer Startup-Printer Promote-Job "
846 "Schedule-Job-After CUPS-Add-Printer "
847 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
848 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
849 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
850 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
852 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
853 po
->order_type
= AUTH_ALLOW
;
854 po
->type
= AUTH_BASIC
;
855 po
->level
= AUTH_USER
;
857 cupsdAddName(po
, "@SYSTEM");
858 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
860 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
861 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
862 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
863 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
864 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
865 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
866 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
867 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
868 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
869 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
870 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
871 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
872 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
873 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
874 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
875 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
876 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
877 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
878 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
879 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
880 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
882 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
884 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
885 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
887 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
888 po
->order_type
= AUTH_ALLOW
;
890 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
891 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
895 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
897 for (i
= 0; i
< NumPolicies
; i
++)
898 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
899 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
903 * If we are doing a full reload or the server root has changed, flush
904 * the jobs, printers, etc. and start from scratch...
907 if (NeedReload
== RELOAD_ALL
||
908 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
909 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
911 mime_type_t
*type
; /* Current type */
912 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
916 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
922 cupsdDeleteAllSubscriptions();
924 cupsdDeleteAllClasses();
925 cupsdDeleteAllPrinters();
927 DefaultPrinter
= NULL
;
929 if (MimeDatabase
!= NULL
)
930 mimeDelete(MimeDatabase
);
934 for (i
= 0; i
< NumMimeTypes
; i
++)
935 _cups_sp_free(MimeTypes
[i
]);
941 * Read the MIME type and conversion database...
944 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
946 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
950 cupsdLogMessage(CUPSD_LOG_EMERG
,
951 "Unable to load MIME database from \'%s\'!", ServerRoot
);
955 cupsdLogMessage(CUPSD_LOG_INFO
,
956 "Loaded MIME database from \'%s\': %d types, %d filters...",
957 ServerRoot
, mimeNumTypes(MimeDatabase
),
958 mimeNumFilters(MimeDatabase
));
961 * Create a list of MIME types for the document-format-supported
965 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
966 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
969 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
971 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
973 i
++, type
= mimeNextType(MimeDatabase
))
975 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
977 MimeTypes
[i
] = _cups_sp_alloc(mimetype
);
980 if (i
< NumMimeTypes
)
981 MimeTypes
[i
] = _cups_sp_alloc("application/octet-stream");
983 if (LogLevel
== CUPSD_LOG_DEBUG2
)
985 mime_filter_t
*filter
; /* Current filter */
988 for (type
= mimeFirstType(MimeDatabase
);
990 type
= mimeNextType(MimeDatabase
))
991 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
992 type
->super
, type
->type
);
994 for (filter
= mimeFirstFilter(MimeDatabase
);
996 filter
= mimeNextFilter(MimeDatabase
))
997 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
998 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
999 filter
->src
->super
, filter
->src
->type
,
1000 filter
->dst
->super
, filter
->dst
->type
,
1001 filter
->cost
, filter
->filter
);
1008 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1009 cupsdLoadBanners(temp
);
1012 * Load printers and classes...
1015 cupsdLoadAllPrinters();
1016 cupsdLoadAllClasses();
1017 cupsdLoadRemoteCache();
1018 cupsdWritePrintcap();
1020 cupsdCreateCommonData();
1023 * Load queued jobs...
1029 * Load subscriptions...
1032 cupsdLoadAllSubscriptions();
1034 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1039 * Not a full reload, so recreate the common printer attributes...
1042 cupsdCreateCommonData();
1045 * Update all printers as needed...
1048 cupsdUpdatePrinters();
1049 cupsdWritePrintcap();
1051 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1055 * Reset the reload state...
1058 NeedReload
= RELOAD_NONE
;
1060 cupsdClearString(&old_serverroot
);
1061 cupsdClearString(&old_requestroot
);
1068 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1071 static int /* O - 0 on success, -1 on error */
1072 check_permissions(const char *filename
, /* I - File/directory name */
1073 const char *suffix
, /* I - Additional file/directory name */
1074 int mode
, /* I - Permissions */
1075 int user
, /* I - Owner */
1076 int group
, /* I - Group */
1077 int is_dir
, /* I - 1 = directory, 0 = file */
1078 int create_dir
)/* I - 1 = create directory, 0 = not */
1080 int dir_created
= 0; /* Did we create a directory? */
1081 char pathname
[1024]; /* File name with prefix */
1082 struct stat fileinfo
; /* Stat buffer */
1086 * Prepend the given root to the filename before testing it...
1091 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1092 filename
= pathname
;
1096 * See if we can stat the file/directory...
1099 if (stat(filename
, &fileinfo
))
1101 if (errno
== ENOENT
&& create_dir
)
1103 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1106 if (mkdir(filename
, mode
))
1108 cupsdLogMessage(CUPSD_LOG_ERROR
,
1109 "Unable to create directory \"%s\" - %s", filename
,
1121 * Make sure it's a regular file...
1124 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1126 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1130 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1132 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1137 * Fix owner, group, and mode as needed...
1140 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1142 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1144 if (chown(filename
, user
, group
))
1146 cupsdLogMessage(CUPSD_LOG_ERROR
,
1147 "Unable to change ownership of \"%s\" - %s", filename
,
1153 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
1155 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1157 if (chmod(filename
, mode
))
1159 cupsdLogMessage(CUPSD_LOG_ERROR
,
1160 "Unable to change permissions of \"%s\" - %s", filename
,
1167 * Everything is OK...
1175 * 'get_address()' - Get an address + port number from a line.
1178 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1179 get_address(const char *value
, /* I - Value string */
1180 int defport
) /* I - Default port */
1182 char buffer
[1024], /* Hostname + port number buffer */
1183 defpname
[255], /* Default port name */
1184 *hostname
, /* Hostname or IP */
1185 *portname
; /* Port number or name */
1186 http_addrlist_t
*addrlist
; /* Address list */
1190 * Check for an empty value...
1195 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1200 * Grab a hostname and port number; if there is no colon and the port name
1201 * is only digits, then we have a port number by itself...
1204 strlcpy(buffer
, value
, sizeof(buffer
));
1206 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1213 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1218 * Use the default port...
1221 sprintf(defpname
, "%d", defport
);
1222 portname
= defpname
;
1228 * The buffer contains just a port number...
1236 if (hostname
&& !strcmp(hostname
, "*"))
1240 * Now lookup the address using httpAddrGetList()...
1243 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1244 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1245 hostname
? hostname
: "(nil)");
1252 * 'get_addr_and_mask()' - Get an IP address and netmask.
1255 static int /* O - 1 on success, 0 on failure */
1256 get_addr_and_mask(const char *value
, /* I - String from config file */
1257 unsigned *ip
, /* O - Address value */
1258 unsigned *mask
) /* O - Mask value */
1260 int i
, j
, /* Looping vars */
1261 family
, /* Address family */
1262 ipcount
; /* Count of fields in address */
1263 unsigned ipval
; /* Value */
1264 const char *maskval
, /* Pointer to start of mask value */
1265 *ptr
, /* Pointer into value */
1267 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1269 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1270 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1271 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1272 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1275 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1277 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1278 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1279 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1280 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1281 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1282 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1283 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1284 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1286 #endif /* AF_INET6 */
1290 * Get the address...
1293 memset(ip
, 0, sizeof(unsigned) * 4);
1295 if ((maskval
= strchr(value
, '/')) != NULL
)
1298 maskval
= value
+ strlen(value
);
1302 * Check for an IPv6 address...
1308 * Parse hexadecimal IPv6 address...
1313 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1317 else if (!strncmp(ptr
, "::", 2))
1319 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1321 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1325 else if (isxdigit(*ptr
& 255))
1327 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1335 ip
[i
] |= ipval
<< 16;
1346 if (*ptr
&& *ptr
!= '/')
1350 #endif /* AF_INET6 */
1353 * Parse dotted-decimal IPv4 address...
1357 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1359 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1360 ip
[0] = ip
[1] = ip
[2] = 0;
1366 * Get the netmask value(s)...
1369 memset(mask
, 0, sizeof(unsigned) * 4);
1372 if (*maskval
== '[')
1375 * Get hexadecimal mask value...
1378 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1382 else if (!strncmp(ptr
, "::", 2))
1384 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1386 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1390 else if (isxdigit(*ptr
& 255))
1392 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1400 mask
[i
] |= ipval
<< 16;
1413 #endif /* AF_INET6 */
1414 if (strchr(maskval
, '.'))
1417 * Get dotted-decimal mask...
1420 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1423 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1424 mask
[0] = mask
[1] = mask
[2] = 0;
1429 * Get address/bits format...
1435 if (family
== AF_INET6
)
1440 mask
[0] = 0xffffffff;
1442 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1445 mask
[1] = 0xffffffff;
1449 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1452 mask
[2] = 0xffffffff;
1456 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1459 mask
[3] = 0xffffffff;
1463 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1466 #endif /* AF_INET6 */
1470 mask
[0] = 0xffffffff;
1471 mask
[1] = 0xffffffff;
1472 mask
[2] = 0xffffffff;
1475 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1477 mask
[3] = 0xffffffff;
1482 else if (family
== AF_INET6
)
1483 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1484 #endif /* AF_INET6 */
1486 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1488 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1489 "get_addr_and_mask(value=\"%s\", "
1490 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1491 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1495 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1498 if ((ip
[0] & ~mask
[0]) != 0 ||
1499 (ip
[1] & ~mask
[1]) != 0 ||
1500 (ip
[2] & ~mask
[2]) != 0 ||
1501 (ip
[3] & ~mask
[3]) != 0)
1509 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1512 static int /* O - 1 on success, 0 on failure */
1513 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1514 char *line
, /* I - Line from file */
1515 char *value
, /* I - Start of value data */
1516 int linenum
) /* I - Current line number */
1518 char *valptr
; /* Pointer into value */
1519 unsigned ip
[4], /* IP address components */
1520 mask
[4]; /* IP netmask components */
1523 if (!strcasecmp(line
, "Encryption"))
1526 * "Encryption xxx" - set required encryption level...
1529 if (!strcasecmp(value
, "never"))
1530 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1531 else if (!strcasecmp(value
, "always"))
1533 cupsdLogMessage(CUPSD_LOG_ERROR
,
1534 "Encryption value \"%s\" on line %d is invalid in this "
1535 "context. Using \"required\" instead.", value
, linenum
);
1537 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1539 else if (!strcasecmp(value
, "required"))
1540 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1541 else if (!strcasecmp(value
, "ifrequested"))
1542 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1545 cupsdLogMessage(CUPSD_LOG_ERROR
,
1546 "Unknown Encryption value %s on line %d.", value
, linenum
);
1550 else if (!strcasecmp(line
, "Order"))
1553 * "Order Deny,Allow" or "Order Allow,Deny"...
1556 if (!strncasecmp(value
, "deny", 4))
1557 loc
->order_type
= AUTH_ALLOW
;
1558 else if (!strncasecmp(value
, "allow", 5))
1559 loc
->order_type
= AUTH_DENY
;
1562 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1567 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1570 * Allow [From] host/ip...
1571 * Deny [From] host/ip...
1574 if (!strncasecmp(value
, "from", 4))
1577 * Strip leading "from"...
1582 while (isspace(*value
& 255))
1587 * Figure out what form the allow/deny address takes:
1598 * nnn.nnn.nnn.nnn/mm
1599 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1602 if (!strcasecmp(value
, "all"))
1608 if (!strcasecmp(line
, "Allow"))
1609 cupsdAllowIP(loc
, zeros
, zeros
);
1611 cupsdDenyIP(loc
, zeros
, zeros
);
1613 else if (!strcasecmp(value
, "none"))
1619 if (!strcasecmp(line
, "Allow"))
1620 cupsdAllowIP(loc
, ones
, zeros
);
1622 cupsdDenyIP(loc
, ones
, zeros
);
1624 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1627 * Host or domain name...
1630 if (value
[0] == '*')
1633 if (!strcasecmp(line
, "Allow"))
1634 cupsdAllowHost(loc
, value
);
1636 cupsdDenyHost(loc
, value
);
1641 * One of many IP address forms...
1644 if (!get_addr_and_mask(value
, ip
, mask
))
1646 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1651 if (!strcasecmp(line
, "Allow"))
1652 cupsdAllowIP(loc
, ip
, mask
);
1654 cupsdDenyIP(loc
, ip
, mask
);
1657 else if (!strcasecmp(line
, "AuthType"))
1660 * AuthType {none,basic,digest,basicdigest}
1663 if (!strcasecmp(value
, "none"))
1665 loc
->type
= AUTH_NONE
;
1666 loc
->level
= AUTH_ANON
;
1668 else if (!strcasecmp(value
, "basic"))
1670 loc
->type
= AUTH_BASIC
;
1672 if (loc
->level
== AUTH_ANON
)
1673 loc
->level
= AUTH_USER
;
1675 else if (!strcasecmp(value
, "digest"))
1677 loc
->type
= AUTH_DIGEST
;
1679 if (loc
->level
== AUTH_ANON
)
1680 loc
->level
= AUTH_USER
;
1682 else if (!strcasecmp(value
, "basicdigest"))
1684 loc
->type
= AUTH_BASICDIGEST
;
1686 if (loc
->level
== AUTH_ANON
)
1687 loc
->level
= AUTH_USER
;
1691 cupsdLogMessage(CUPSD_LOG_WARN
,
1692 "Unknown authorization type %s on line %d.",
1697 else if (!strcasecmp(line
, "AuthClass"))
1700 * AuthClass anonymous, user, system, group
1703 if (!strcasecmp(value
, "anonymous"))
1705 loc
->type
= AUTH_NONE
;
1706 loc
->level
= AUTH_ANON
;
1708 cupsdLogMessage(CUPSD_LOG_WARN
,
1709 "\"AuthClass %s\" is deprecated; consider removing "
1713 else if (!strcasecmp(value
, "user"))
1715 loc
->level
= AUTH_USER
;
1717 cupsdLogMessage(CUPSD_LOG_WARN
,
1718 "\"AuthClass %s\" is deprecated; consider using "
1719 "\"Require valid-user\" on line %d.",
1722 else if (!strcasecmp(value
, "group"))
1724 loc
->level
= AUTH_GROUP
;
1726 cupsdLogMessage(CUPSD_LOG_WARN
,
1727 "\"AuthClass %s\" is deprecated; consider using "
1728 "\"Require @groupname\" on line %d.",
1731 else if (!strcasecmp(value
, "system"))
1733 loc
->level
= AUTH_GROUP
;
1735 cupsdAddName(loc
, "@SYSTEM");
1737 cupsdLogMessage(CUPSD_LOG_WARN
,
1738 "\"AuthClass %s\" is deprecated; consider using "
1739 "\"Require @SYSTEM\" on line %d.",
1744 cupsdLogMessage(CUPSD_LOG_WARN
,
1745 "Unknown authorization class %s on line %d.",
1750 else if (!strcasecmp(line
, "AuthGroupName"))
1752 cupsdAddName(loc
, value
);
1754 cupsdLogMessage(CUPSD_LOG_WARN
,
1755 "\"AuthGroupName %s\" directive is deprecated; consider "
1756 "using \"Require @%s\" on line %d.",
1757 value
, value
, linenum
);
1759 else if (!strcasecmp(line
, "Require"))
1762 * Apache synonym for AuthClass and AuthGroupName...
1766 * Require valid-user
1767 * Require group names
1768 * Require user names
1771 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1776 if (!strcasecmp(value
, "valid-user") ||
1777 !strcasecmp(value
, "user"))
1778 loc
->level
= AUTH_USER
;
1779 else if (!strcasecmp(value
, "group"))
1780 loc
->level
= AUTH_GROUP
;
1783 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1789 * Get the list of names from the line...
1792 for (value
= valptr
; *value
;)
1794 while (isspace(*value
& 255))
1797 if (*value
== '\"' || *value
== '\'')
1800 * Grab quoted name...
1803 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1810 * Grab literal name.
1813 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1819 cupsdAddName(loc
, value
);
1821 for (value
= valptr
; isspace(*value
& 255); value
++);
1824 else if (!strcasecmp(line
, "Satisfy"))
1826 if (!strcasecmp(value
, "all"))
1827 loc
->satisfy
= AUTH_SATISFY_ALL
;
1828 else if (!strcasecmp(value
, "any"))
1829 loc
->satisfy
= AUTH_SATISFY_ANY
;
1832 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1845 * 'parse_groups()' - Parse system group names in a string.
1848 static int /* O - 1 on success, 0 on failure */
1849 parse_groups(const char *s
) /* I - Space-delimited groups */
1851 int status
; /* Return status */
1852 char value
[1024], /* Value string */
1853 *valstart
, /* Pointer into value */
1854 *valend
, /* End of value */
1855 quote
; /* Quote character */
1856 struct group
*group
; /* Group */
1860 * Make a copy of the string and parse out the groups...
1863 strlcpy(value
, s
, sizeof(value
));
1868 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1870 if (*valstart
== '\'' || *valstart
== '\"')
1873 * Scan quoted name...
1876 quote
= *valstart
++;
1878 for (valend
= valstart
; *valend
; valend
++)
1879 if (*valend
== quote
)
1885 * Scan space or comma-delimited name...
1888 for (valend
= valstart
; *valend
; valend
++)
1889 if (isspace(*valend
) || *valend
== ',')
1896 group
= getgrnam(valstart
);
1899 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1900 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1911 while (*valstart
== ',' || isspace(*valstart
))
1920 * 'parse_protocols()' - Parse browse protocols in a string.
1923 static int /* O - Browse protocol bits */
1924 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1926 int protocols
; /* Browse protocol bits */
1927 char value
[1024], /* Value string */
1928 *valstart
, /* Pointer into value */
1929 *valend
; /* End of value */
1933 * Loop through the value string,...
1936 strlcpy(value
, s
, sizeof(value
));
1940 for (valstart
= value
; *valstart
;)
1943 * Get the current space/comma-delimited protocol name...
1946 for (valend
= valstart
; *valend
; valend
++)
1947 if (isspace(*valend
& 255) || *valend
== ',')
1954 * Add the protocol to the bitmask...
1957 if (!strcasecmp(valstart
, "cups"))
1958 protocols
|= BROWSE_CUPS
;
1959 else if (!strcasecmp(valstart
, "slp"))
1960 protocols
|= BROWSE_SLP
;
1961 else if (!strcasecmp(valstart
, "ldap"))
1962 protocols
|= BROWSE_LDAP
;
1963 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
1964 protocols
|= BROWSE_DNSSD
;
1965 else if (!strcasecmp(valstart
, "all"))
1966 protocols
|= BROWSE_ALL
;
1970 for (valstart
= valend
; *valstart
; valstart
++)
1971 if (!isspace(*valstart
& 255) || *valstart
!= ',')
1980 * 'read_configuration()' - Read a configuration file.
1983 static int /* O - 1 on success, 0 on failure */
1984 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1986 int i
; /* Looping var */
1987 int linenum
; /* Current line number */
1988 char line
[HTTP_MAX_BUFFER
],
1989 /* Line from file */
1990 temp
[HTTP_MAX_BUFFER
],
1991 /* Temporary buffer for value */
1992 temp2
[HTTP_MAX_BUFFER
],
1993 /* Temporary buffer 2 for value */
1994 *ptr
, /* Pointer into line/temp */
1995 *value
, /* Pointer to value */
1996 *valueptr
; /* Pointer into value */
1997 int valuelen
; /* Length of value */
1998 cupsd_var_t
*var
; /* Current variable */
1999 http_addrlist_t
*addrlist
, /* Address list */
2000 *addr
; /* Current address */
2001 unsigned ip
[4], /* Address value */
2002 mask
[4]; /* Netmask value */
2003 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2004 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2005 cupsd_location_t
*location
; /* Browse location */
2006 cups_file_t
*incfile
; /* Include file */
2007 char incname
[1024]; /* Include filename */
2008 struct group
*group
; /* Group */
2012 * Loop through each line in the file...
2017 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2020 * Decode the directive...
2023 if (!strcasecmp(line
, "Include"))
2029 if (value
[0] == '/')
2030 strlcpy(incname
, value
, sizeof(incname
));
2032 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2034 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2035 cupsdLogMessage(CUPSD_LOG_ERROR
,
2036 "Unable to include config file \"%s\" - %s",
2037 incname
, strerror(errno
));
2040 read_configuration(incfile
);
2041 cupsFileClose(incfile
);
2044 else if (!strcasecmp(line
, "<Location"))
2052 linenum
= read_location(fp
, value
, linenum
);
2058 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2063 else if (!strcasecmp(line
, "<Policy"))
2071 linenum
= read_policy(fp
, value
, linenum
);
2077 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2081 else if (!strcasecmp(line
, "FaxRetryInterval"))
2085 JobRetryInterval
= atoi(value
);
2086 cupsdLogMessage(CUPSD_LOG_WARN
,
2087 "FaxRetryInterval is deprecated; use "
2088 "JobRetryInterval on line %d.", linenum
);
2092 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2096 else if (!strcasecmp(line
, "FaxRetryLimit"))
2100 JobRetryLimit
= atoi(value
);
2101 cupsdLogMessage(CUPSD_LOG_WARN
,
2102 "FaxRetryLimit is deprecated; use "
2103 "JobRetryLimit on line %d.", linenum
);
2107 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2111 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2113 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2114 #endif /* HAVE_SSL */
2118 * Add listening address(es) to the list...
2121 cupsd_listener_t
*lis
; /* New listeners array */
2125 * Get the address list...
2128 addrlist
= get_address(value
, IPP_PORT
);
2132 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2138 * Add each address...
2141 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2144 * Allocate another listener...
2148 Listeners
= cupsArrayNew(NULL
, NULL
);
2152 cupsdLogMessage(CUPSD_LOG_ERROR
,
2153 "Unable to allocate %s at line %d - %s.",
2154 line
, linenum
, strerror(errno
));
2158 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2160 cupsdLogMessage(CUPSD_LOG_ERROR
,
2161 "Unable to allocate %s at line %d - %s.",
2162 line
, linenum
, strerror(errno
));
2166 cupsArrayAdd(Listeners
, lis
);
2169 * Copy the current address and log it...
2172 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2176 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2177 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2178 #endif /* HAVE_SSL */
2180 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2183 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2184 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2185 ntohs(lis
->address
.ipv6
.sin6_port
));
2187 #endif /* AF_INET6 */
2189 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2190 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2192 #endif /* AF_LOCAL */
2193 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2194 ntohs(lis
->address
.ipv4
.sin_port
));
2201 httpAddrFreeList(addrlist
);
2203 else if (!strcasecmp(line
, "BrowseAddress"))
2206 * Add a browse address to the list...
2209 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2212 if (NumBrowsers
== 0)
2213 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2215 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2219 cupsdLogMessage(CUPSD_LOG_ERROR
,
2220 "Unable to allocate BrowseAddress at line %d - %s.",
2221 linenum
, strerror(errno
));
2226 dira
+= NumBrowsers
;
2228 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2230 if (!strcasecmp(value
, "@LOCAL"))
2233 * Send browse data to all local interfaces...
2236 strcpy(dira
->iface
, "*");
2239 else if (!strncasecmp(value
, "@IF(", 4))
2242 * Send browse data to the named interface...
2245 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2247 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2253 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2256 * Only IPv4 addresses are supported...
2259 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2260 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2265 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2266 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2268 cupsdLogMessage(CUPSD_LOG_INFO
,
2269 "Sending browsing info to %s:%d (IPv4)",
2270 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2275 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2278 httpAddrFreeList(addrlist
);
2281 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2284 else if (!strcasecmp(line
, "BrowseOrder"))
2287 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2290 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2291 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2293 if (location
== NULL
)
2294 cupsdLogMessage(CUPSD_LOG_ERROR
,
2295 "Unable to initialize browse access control list!");
2296 else if (!strncasecmp(value
, "deny", 4))
2297 location
->order_type
= AUTH_ALLOW
;
2298 else if (!strncasecmp(value
, "allow", 5))
2299 location
->order_type
= AUTH_DENY
;
2301 cupsdLogMessage(CUPSD_LOG_ERROR
,
2302 "Unknown BrowseOrder value %s on line %d.",
2305 else if (!strcasecmp(line
, "BrowseProtocols") ||
2306 !strcasecmp(line
, "BrowseLocalProtocols") ||
2307 !strcasecmp(line
, "BrowseRemoteProtocols"))
2310 * "BrowseProtocols name [... name]"
2311 * "BrowseLocalProtocols name [... name]"
2312 * "BrowseRemoteProtocols name [... name]"
2315 int protocols
= parse_protocols(value
);
2319 cupsdLogMessage(CUPSD_LOG_ERROR
,
2320 "Unknown browse protocol \"%s\" on line %d.",
2325 if (strcasecmp(line
, "BrowseLocalProtocols"))
2326 BrowseRemoteProtocols
= protocols
;
2327 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2328 BrowseLocalProtocols
= protocols
;
2330 else if (!strcasecmp(line
, "BrowseAllow") ||
2331 !strcasecmp(line
, "BrowseDeny"))
2334 * BrowseAllow [From] host/ip...
2335 * BrowseDeny [From] host/ip...
2338 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2339 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2341 if (location
== NULL
)
2342 cupsdLogMessage(CUPSD_LOG_ERROR
,
2343 "Unable to initialize browse access control list!");
2346 if (!strncasecmp(value
, "from ", 5))
2349 * Strip leading "from"...
2354 while (isspace(*value
))
2359 * Figure out what form the allow/deny address takes:
2370 * nnn.nnn.nnn.nnn/mm
2371 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2374 if (!strcasecmp(value
, "all"))
2380 if (!strcasecmp(line
, "BrowseAllow"))
2381 cupsdAllowIP(location
, zeros
, zeros
);
2383 cupsdDenyIP(location
, zeros
, zeros
);
2385 else if (!strcasecmp(value
, "none"))
2391 if (!strcasecmp(line
, "BrowseAllow"))
2392 cupsdAllowIP(location
, ones
, zeros
);
2394 cupsdDenyIP(location
, ones
, zeros
);
2396 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2399 * Host or domain name...
2402 if (value
[0] == '*')
2405 if (!strcasecmp(line
, "BrowseAllow"))
2406 cupsdAllowHost(location
, value
);
2408 cupsdDenyHost(location
, value
);
2413 * One of many IP address forms...
2416 if (!get_addr_and_mask(value
, ip
, mask
))
2418 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2423 if (!strcasecmp(line
, "BrowseAllow"))
2424 cupsdAllowIP(location
, ip
, mask
);
2426 cupsdDenyIP(location
, ip
, mask
);
2430 else if (!strcasecmp(line
, "BrowseRelay"))
2433 * BrowseRelay [from] source [to] destination
2437 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2439 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2443 cupsdLogMessage(CUPSD_LOG_ERROR
,
2444 "Unable to allocate BrowseRelay at line %d - %s.",
2445 linenum
, strerror(errno
));
2452 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2454 if (!strncasecmp(value
, "from ", 5))
2457 * Strip leading "from"...
2462 while (isspace(*value
))
2467 * Figure out what form the from address takes:
2476 * nnn.nnn.nnn.nnn/mm
2477 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2480 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2483 * Host or domain name...
2486 if (value
[0] == '*')
2489 strlcpy(temp
, value
, sizeof(temp
));
2490 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2493 relay
->from
.type
= AUTH_NAME
;
2494 relay
->from
.mask
.name
.name
= strdup(temp
);
2495 relay
->from
.mask
.name
.length
= strlen(temp
);
2500 * One of many IP address forms...
2503 if (!get_addr_and_mask(value
, ip
, mask
))
2505 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2510 relay
->from
.type
= AUTH_IP
;
2511 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2512 sizeof(relay
->from
.mask
.ip
.address
));
2513 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2514 sizeof(relay
->from
.mask
.ip
.netmask
));
2518 * Skip value and trailing whitespace...
2521 for (; *value
; value
++)
2522 if (isspace(*value
))
2525 while (isspace(*value
))
2528 if (!strncasecmp(value
, "to ", 3))
2531 * Strip leading "to"...
2536 while (isspace(*value
))
2541 * Get "to" address and port...
2544 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2547 * Only IPv4 addresses are supported...
2550 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2551 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2556 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2558 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2560 if (relay
->from
.type
== AUTH_IP
)
2561 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2562 relay
->from
.mask
.ip
.address
[0],
2563 relay
->from
.mask
.ip
.address
[1],
2564 relay
->from
.mask
.ip
.address
[2],
2565 relay
->from
.mask
.ip
.address
[3],
2566 relay
->from
.mask
.ip
.netmask
[0],
2567 relay
->from
.mask
.ip
.netmask
[1],
2568 relay
->from
.mask
.ip
.netmask
[2],
2569 relay
->from
.mask
.ip
.netmask
[3]);
2571 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2573 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2574 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2579 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2582 httpAddrFreeList(addrlist
);
2586 if (relay
->from
.type
== AUTH_NAME
)
2587 free(relay
->from
.mask
.name
.name
);
2589 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2593 else if (!strcasecmp(line
, "BrowsePoll"))
2596 * BrowsePoll address[:port]
2599 char *portname
; /* Port name */
2600 int portnum
; /* Port number */
2601 struct servent
*service
; /* Service */
2605 * Extract the port name from the address...
2608 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2612 if (isdigit(*portname
& 255))
2613 portnum
= atoi(portname
);
2614 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2615 portnum
= ntohs(service
->s_port
);
2618 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2624 portnum
= ippPort();
2627 * Add the poll entry...
2631 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2633 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2637 cupsdLogMessage(CUPSD_LOG_ERROR
,
2638 "Unable to allocate BrowsePoll at line %d - %s.",
2639 linenum
, strerror(errno
));
2647 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2649 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2650 pollp
->port
= portnum
;
2652 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2655 else if (!strcasecmp(line
, "DefaultAuthType"))
2658 * DefaultAuthType {basic,digest,basicdigest}
2661 if (!strcasecmp(value
, "basic"))
2662 DefaultAuthType
= AUTH_BASIC
;
2663 else if (!strcasecmp(value
, "digest"))
2664 DefaultAuthType
= AUTH_DIGEST
;
2665 else if (!strcasecmp(value
, "basicdigest"))
2666 DefaultAuthType
= AUTH_BASICDIGEST
;
2669 cupsdLogMessage(CUPSD_LOG_WARN
,
2670 "Unknown default authorization type %s on line %d.",
2675 else if (!strcasecmp(line
, "User"))
2678 * User ID to run as...
2681 if (value
&& isdigit(value
[0] & 255))
2683 int uid
= atoi(value
);
2686 cupsdLogMessage(CUPSD_LOG_ERROR
,
2687 "Will not use User 0 as specified on line %d "
2688 "for security reasons. You must use a non-"
2689 "privileged account instead.",
2696 struct passwd
*p
; /* Password information */
2699 p
= getpwnam(value
);
2704 cupsdLogMessage(CUPSD_LOG_ERROR
,
2705 "Will not use User %s (UID=0) as specified on line "
2706 "%d for security reasons. You must use a non-"
2707 "privileged account instead.",
2713 cupsdLogMessage(CUPSD_LOG_ERROR
,
2714 "Unknown User \"%s\" on line %d, ignoring!",
2718 cupsdLogMessage(CUPSD_LOG_ERROR
,
2719 "User directive on line %d missing the username!",
2722 else if (!strcasecmp(line
, "Group"))
2725 * Group ID to run as...
2728 if (isdigit(value
[0]))
2729 Group
= atoi(value
);
2733 group
= getgrnam(value
);
2736 Group
= group
->gr_gid
;
2738 cupsdLogMessage(CUPSD_LOG_ERROR
,
2739 "Unknown Group \"%s\" on line %d, ignoring!",
2743 else if (!strcasecmp(line
, "SystemGroup"))
2746 * SystemGroup (admin) group(s)...
2749 if (!parse_groups(value
))
2750 cupsdLogMessage(CUPSD_LOG_ERROR
,
2751 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2754 else if (!strcasecmp(line
, "HostNameLookups"))
2757 * Do hostname lookups?
2760 if (!strcasecmp(value
, "off"))
2761 HostNameLookups
= 0;
2762 else if (!strcasecmp(value
, "on"))
2763 HostNameLookups
= 1;
2764 else if (!strcasecmp(value
, "double"))
2765 HostNameLookups
= 2;
2767 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2770 else if (!strcasecmp(line
, "LogLevel"))
2773 * Amount of logging to do...
2776 if (!strcasecmp(value
, "debug2"))
2777 LogLevel
= CUPSD_LOG_DEBUG2
;
2778 else if (!strcasecmp(value
, "debug"))
2779 LogLevel
= CUPSD_LOG_DEBUG
;
2780 else if (!strcasecmp(value
, "info"))
2781 LogLevel
= CUPSD_LOG_INFO
;
2782 else if (!strcasecmp(value
, "notice"))
2783 LogLevel
= CUPSD_LOG_NOTICE
;
2784 else if (!strcasecmp(value
, "warn"))
2785 LogLevel
= CUPSD_LOG_WARN
;
2786 else if (!strcasecmp(value
, "error"))
2787 LogLevel
= CUPSD_LOG_ERROR
;
2788 else if (!strcasecmp(value
, "crit"))
2789 LogLevel
= CUPSD_LOG_CRIT
;
2790 else if (!strcasecmp(value
, "alert"))
2791 LogLevel
= CUPSD_LOG_ALERT
;
2792 else if (!strcasecmp(value
, "emerg"))
2793 LogLevel
= CUPSD_LOG_EMERG
;
2794 else if (!strcasecmp(value
, "none"))
2795 LogLevel
= CUPSD_LOG_NONE
;
2797 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2800 else if (!strcasecmp(line
, "PrintcapFormat"))
2803 * Format of printcap file?
2806 if (!strcasecmp(value
, "bsd"))
2807 PrintcapFormat
= PRINTCAP_BSD
;
2808 else if (!strcasecmp(value
, "solaris"))
2809 PrintcapFormat
= PRINTCAP_SOLARIS
;
2811 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2814 else if (!strcasecmp(line
, "ServerTokens"))
2817 * Set the string used for the Server header...
2820 struct utsname plat
; /* Platform info */
2825 if (!strcasecmp(value
, "ProductOnly"))
2826 cupsdSetString(&ServerHeader
, "CUPS");
2827 else if (!strcasecmp(value
, "Major"))
2828 cupsdSetString(&ServerHeader
, "CUPS/1");
2829 else if (!strcasecmp(value
, "Minor"))
2830 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2831 else if (!strcasecmp(value
, "Minimal"))
2832 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2833 else if (!strcasecmp(value
, "OS"))
2834 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2835 else if (!strcasecmp(value
, "Full"))
2836 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2838 else if (!strcasecmp(value
, "None"))
2839 cupsdClearString(&ServerHeader
);
2841 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2844 else if (!strcasecmp(line
, "PassEnv"))
2847 * PassEnv variable [... variable]
2852 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2853 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2856 if (value
[valuelen
])
2858 value
[valuelen
] = '\0';
2862 cupsdSetEnv(value
, NULL
);
2864 for (value
+= valuelen
; *value
; value
++)
2865 if (!isspace(*value
) || *value
!= ',')
2869 else if (!strcasecmp(line
, "SetEnv"))
2872 * SetEnv variable value
2875 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2883 while (isspace(*valueptr
& 255))
2886 cupsdSetEnv(value
, valueptr
);
2889 cupsdLogMessage(CUPSD_LOG_ERROR
,
2890 "Missing value for SetEnv directive on line %d.",
2896 * Find a simple variable in the list...
2899 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2900 if (!strcasecmp(line
, var
->name
))
2906 * Unknown directive! Output an error message and continue...
2909 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2916 case CUPSD_VARTYPE_INTEGER
:
2919 char *units
; /* Units */
2922 n
= strtol(value
, &units
, 0);
2924 if (units
&& *units
)
2926 if (tolower(units
[0] & 255) == 'g')
2927 n
*= 1024 * 1024 * 1024;
2928 else if (tolower(units
[0] & 255) == 'm')
2930 else if (tolower(units
[0] & 255) == 'k')
2932 else if (tolower(units
[0] & 255) == 't')
2936 *((int *)var
->ptr
) = n
;
2940 case CUPSD_VARTYPE_BOOLEAN
:
2941 if (!strcasecmp(value
, "true") ||
2942 !strcasecmp(value
, "on") ||
2943 !strcasecmp(value
, "enabled") ||
2944 !strcasecmp(value
, "yes") ||
2946 *((int *)var
->ptr
) = TRUE
;
2947 else if (!strcasecmp(value
, "false") ||
2948 !strcasecmp(value
, "off") ||
2949 !strcasecmp(value
, "disabled") ||
2950 !strcasecmp(value
, "no") ||
2951 !strcasecmp(value
, "0"))
2952 *((int *)var
->ptr
) = FALSE
;
2954 cupsdLogMessage(CUPSD_LOG_ERROR
,
2955 "Unknown boolean value %s on line %d.",
2959 case CUPSD_VARTYPE_STRING
:
2960 cupsdSetString((char **)var
->ptr
, value
);
2971 * 'read_location()' - Read a <Location path> definition.
2974 static int /* O - New line number or 0 on error */
2975 read_location(cups_file_t
*fp
, /* I - Configuration file */
2976 char *location
, /* I - Location name/path */
2977 int linenum
) /* I - Current line number */
2979 cupsd_location_t
*loc
, /* New location */
2980 *parent
; /* Parent location */
2981 char line
[HTTP_MAX_BUFFER
],
2983 *value
, /* Value for directive */
2984 *valptr
; /* Pointer into value */
2987 if ((parent
= cupsdAddLocation(location
)) == NULL
)
2990 parent
->limit
= AUTH_LIMIT_ALL
;
2993 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2996 * Decode the directive...
2999 if (!strcasecmp(line
, "</Location>"))
3001 else if (!strcasecmp(line
, "<Limit") ||
3002 !strcasecmp(line
, "<LimitExcept"))
3006 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3010 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3016 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3021 if (!strcmp(value
, "ALL"))
3022 loc
->limit
= AUTH_LIMIT_ALL
;
3023 else if (!strcmp(value
, "GET"))
3024 loc
->limit
|= AUTH_LIMIT_GET
;
3025 else if (!strcmp(value
, "HEAD"))
3026 loc
->limit
|= AUTH_LIMIT_HEAD
;
3027 else if (!strcmp(value
, "OPTIONS"))
3028 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3029 else if (!strcmp(value
, "POST"))
3030 loc
->limit
|= AUTH_LIMIT_POST
;
3031 else if (!strcmp(value
, "PUT"))
3032 loc
->limit
|= AUTH_LIMIT_PUT
;
3033 else if (!strcmp(value
, "TRACE"))
3034 loc
->limit
|= AUTH_LIMIT_TRACE
;
3036 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3039 for (value
= valptr
; isspace(*value
& 255); value
++);
3042 if (!strcasecmp(line
, "<LimitExcept"))
3043 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3045 parent
->limit
&= ~loc
->limit
;
3047 else if (!strcasecmp(line
, "</Limit>"))
3049 else if (!parse_aaa(loc
, line
, value
, linenum
))
3051 cupsdLogMessage(CUPSD_LOG_ERROR
,
3052 "Unknown Location directive %s on line %d.",
3058 cupsdLogMessage(CUPSD_LOG_ERROR
,
3059 "Unexpected end-of-file at line %d while reading location!",
3067 * 'read_policy()' - Read a <Policy name> definition.
3070 static int /* O - New line number or 0 on error */
3071 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3072 char *policy
, /* I - Location name/path */
3073 int linenum
) /* I - Current line number */
3075 int i
; /* Looping var */
3076 cupsd_policy_t
*pol
; /* Policy */
3077 cupsd_location_t
*op
; /* Policy operation */
3078 int num_ops
; /* Number of IPP operations */
3079 ipp_op_t ops
[100]; /* Operations */
3080 char line
[HTTP_MAX_BUFFER
],
3082 *value
, /* Value for directive */
3083 *valptr
; /* Pointer into value */
3087 * Create the policy...
3090 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3094 * Read from the file...
3100 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3103 * Decode the directive...
3106 if (!strcasecmp(line
, "</Policy>"))
3109 cupsdLogMessage(CUPSD_LOG_WARN
,
3110 "Missing </Limit> before </Policy> on line %d!",
3115 else if (!strcasecmp(line
, "<Limit") && !op
)
3119 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3124 * Scan for IPP operation names...
3131 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3136 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3138 if (!strcasecmp(value
, "All"))
3139 ops
[num_ops
] = IPP_ANY_OPERATION
;
3140 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3141 cupsdLogMessage(CUPSD_LOG_ERROR
,
3142 "Bad IPP operation name \"%s\" on line %d!",
3148 cupsdLogMessage(CUPSD_LOG_ERROR
,
3149 "Too many operations listed on line %d!",
3152 for (value
= valptr
; isspace(*value
& 255); value
++);
3156 * If none are specified, apply the policy to all operations...
3161 ops
[0] = IPP_ANY_OPERATION
;
3166 * Add a new policy for the first operation...
3169 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3171 else if (!strcasecmp(line
, "</Limit>") && op
)
3174 * Finish the current operation limit...
3180 * Copy the policy to the other operations...
3183 for (i
= 1; i
< num_ops
; i
++)
3184 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3191 cupsdLogMessage(CUPSD_LOG_ERROR
,
3192 "Missing <Limit ops> directive before %s on line %d.",
3196 else if (!parse_aaa(op
, line
, value
, linenum
))
3199 cupsdLogMessage(CUPSD_LOG_ERROR
,
3200 "Unknown Policy Limit directive %s on line %d.",
3203 cupsdLogMessage(CUPSD_LOG_ERROR
,
3204 "Unknown Policy directive %s on line %d.",
3211 cupsdLogMessage(CUPSD_LOG_ERROR
,
3212 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3220 * End of "$Id: conf.c 5167 2006-02-25 02:11:44Z mike $".