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 * Use the default system group if none was supplied in cupsd.conf...
474 if (NumSystemGroups
== 0)
476 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
479 * Find the group associated with GID 0...
486 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
488 cupsdSetString(&SystemGroups
[0], "unknown");
490 SystemGroupIDs
[0] = 0;
496 * Get the access control list for browsing...
499 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
502 * Open the system log for cupsd if necessary...
506 if (!strcmp(AccessLog
, "syslog") ||
507 !strcmp(ErrorLog
, "syslog") ||
508 !strcmp(PageLog
, "syslog"))
509 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
510 #endif /* HAVE_VSYSLOG */
513 * Log the configuration file that was used...
516 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
520 * Validate the Group and SystemGroup settings - they cannot be the same,
521 * otherwise the CGI programs will be able to authenticate as root without
527 for (i
= 0; i
< NumSystemGroups
; i
++)
528 if (Group
== SystemGroupIDs
[i
])
531 if (i
< NumSystemGroups
)
534 * Log the error and reset the group to a safe value...
537 cupsdLogMessage(CUPSD_LOG_NOTICE
,
538 "Group and SystemGroup cannot use the same groups!");
539 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
541 group
= getgrnam("nobody");
545 Group
= group
->gr_gid
;
549 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
550 * complement number...)
559 * Check that we have at least one listen/port line; if not, report this
560 * as an error and exit!
563 if (cupsArrayCount(Listeners
) == 0)
569 cupsdLogMessage(CUPSD_LOG_EMERG
,
570 "No valid Listen or Port lines were found in the configuration file!");
576 cupsdEndProcess(getpid(), 0);
580 * Set the default locale using the language and charset...
583 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
586 * Update all relative filenames to include the full path from ServerRoot...
589 if (DocumentRoot
[0] != '/')
590 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
592 if (RequestRoot
[0] != '/')
593 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
595 if (ServerBin
[0] != '/')
596 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
598 if (StateDir
[0] != '/')
599 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
601 if (CacheDir
[0] != '/')
602 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
605 if (ServerCertificate
[0] != '/')
606 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
608 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
610 chown(ServerCertificate
, RunUser
, Group
);
611 chmod(ServerCertificate
, 0600);
614 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
615 if (ServerKey
[0] != '/')
616 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
618 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
620 chown(ServerKey
, RunUser
, Group
);
621 chmod(ServerKey
, 0600);
623 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
624 #endif /* HAVE_SSL */
627 * Make sure that directories and config files are owned and
628 * writable by the user and group in the cupsd.conf file...
631 check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1);
632 /* check_permissions(CacheDir, "ppd", 0755, RunUser, Group, 1, 1);*/
634 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1);
635 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
636 SystemGroupIDs
[0], 1, 1);
638 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0);
639 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1);
640 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0);
641 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
, Group
,
643 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
, 0, 0);
644 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
, 0, 0);
645 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0);
648 * Update TempDir to the default if it hasn't been set already...
653 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
656 * TMPDIR is defined, see if it is OK for us to use...
659 if (stat(tmpdir
, &tmpinfo
))
660 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
661 tmpdir
, strerror(errno
));
662 else if (!S_ISDIR(tmpinfo
.st_mode
))
663 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
665 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
666 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
667 !(tmpinfo
.st_mode
& S_IWOTH
))
668 cupsdLogMessage(CUPSD_LOG_ERROR
,
669 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
671 cupsdSetString(&TempDir
, tmpdir
);
674 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
679 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
683 * Make sure the request and temporary directories have the right
687 check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1);
689 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
693 * Update ownership and permissions if the CUPS temp directory
694 * is under the spool directory or does not exist...
697 check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1);
700 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
703 * Clean out the temporary directory...
706 cups_dir_t
*dir
; /* Temporary directory */
707 cups_dentry_t
*dent
; /* Directory entry */
708 char tempfile
[1024]; /* Temporary filename */
711 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
713 cupsdLogMessage(CUPSD_LOG_INFO
,
714 "Cleaning out old temporary files in \"%s\"...", TempDir
);
716 while ((dent
= cupsDirRead(dir
)) != NULL
)
718 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
720 if (unlink(tempfile
))
721 cupsdLogMessage(CUPSD_LOG_ERROR
,
722 "Unable to remove temporary file \"%s\" - %s",
723 tempfile
, strerror(errno
));
725 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
732 cupsdLogMessage(CUPSD_LOG_ERROR
,
733 "Unable to open temporary directory \"%s\" - %s",
734 TempDir
, strerror(errno
));
738 * Setup environment variables...
744 * Check the MaxClients setting, and then allocate memory for it...
747 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
750 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
753 MaxClients
= MaxFDs
/ 3;
756 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
760 * Check the MaxActiveJobs setting; limit to 1/3 the available
761 * file descriptors, since we need a pipe for each job...
764 if (MaxActiveJobs
> (MaxFDs
/ 3))
765 MaxActiveJobs
= MaxFDs
/ 3;
767 if (Classification
&& strcasecmp(Classification
, "none") == 0)
768 cupsdClearString(&Classification
);
771 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
774 * Update the MaxClientsPerHost value, as needed...
777 if (MaxClientsPerHost
<= 0)
778 MaxClientsPerHost
= MaxClients
;
780 if (MaxClientsPerHost
> MaxClients
)
781 MaxClientsPerHost
= MaxClients
;
783 cupsdLogMessage(CUPSD_LOG_INFO
,
784 "Allowing up to %d client connections per host.",
788 * Update the default policy, as needed...
792 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
794 DefaultPolicyPtr
= NULL
;
796 if (!DefaultPolicyPtr
)
798 cupsd_policy_t
*p
; /* New policy */
799 cupsd_location_t
*po
; /* New policy operation */
803 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
806 cupsdSetString(&DefaultPolicy
, "default");
808 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
809 cupsdLogMessage(CUPSD_LOG_INFO
,
810 "Using policy \"default\" as the default!");
813 cupsdLogMessage(CUPSD_LOG_INFO
,
814 "Creating CUPS default administrative policy:");
816 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
818 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
819 cupsdLogMessage(CUPSD_LOG_INFO
,
820 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
821 "Release-Job Restart-Job Purge-Jobs "
822 "Set-Job-Attributes Create-Job-Subscription "
823 "Renew-Subscription Cancel-Subscription "
824 "Get-Notifications Reprocess-Job Cancel-Current-Job "
825 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
826 "CUPS-Authenticate-Job>");
827 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
829 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
830 po
->order_type
= AUTH_ALLOW
;
831 po
->level
= AUTH_USER
;
833 cupsdAddName(po
, "@OWNER");
834 cupsdAddName(po
, "@SYSTEM");
835 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
837 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
838 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
839 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
840 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
841 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
842 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
843 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
844 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
845 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
846 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
847 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
848 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
849 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
850 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
851 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
852 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
853 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
855 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
857 cupsdLogMessage(CUPSD_LOG_INFO
,
858 "<Limit Pause-Printer Resume-Printer "
859 "Set-Printer-Attributes Enable-Printer "
860 "Disable-Printer Pause-Printer-After-Current-Job "
861 "Hold-New-Jobs Release-Held-New-Jobs "
862 "Deactivate-Printer Activate-Printer Restart-Printer "
863 "Shutdown-Printer Startup-Printer Promote-Job "
864 "Schedule-Job-After CUPS-Add-Printer "
865 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
866 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
867 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
868 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
870 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
871 po
->order_type
= AUTH_ALLOW
;
872 po
->type
= AUTH_BASIC
;
873 po
->level
= AUTH_USER
;
875 cupsdAddName(po
, "@SYSTEM");
876 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
878 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
879 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
880 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
881 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
882 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
883 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
884 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
885 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
886 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
887 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
888 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
889 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
890 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
891 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
892 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
893 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
894 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
895 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
896 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
897 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
898 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
900 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
902 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
903 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
905 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
906 po
->order_type
= AUTH_ALLOW
;
908 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
909 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
913 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
915 for (i
= 0; i
< NumPolicies
; i
++)
916 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
917 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
921 * If we are doing a full reload or the server root has changed, flush
922 * the jobs, printers, etc. and start from scratch...
925 if (NeedReload
== RELOAD_ALL
||
926 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
927 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
929 mime_type_t
*type
; /* Current type */
930 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
934 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
940 cupsdDeleteAllSubscriptions();
942 cupsdDeleteAllClasses();
943 cupsdDeleteAllPrinters();
945 DefaultPrinter
= NULL
;
947 if (MimeDatabase
!= NULL
)
948 mimeDelete(MimeDatabase
);
952 for (i
= 0; i
< NumMimeTypes
; i
++)
953 _cupsStrFree(MimeTypes
[i
]);
959 * Read the MIME type and conversion database...
962 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
964 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
968 cupsdLogMessage(CUPSD_LOG_EMERG
,
969 "Unable to load MIME database from \'%s\'!", ServerRoot
);
973 cupsdLogMessage(CUPSD_LOG_INFO
,
974 "Loaded MIME database from \'%s\': %d types, %d filters...",
975 ServerRoot
, mimeNumTypes(MimeDatabase
),
976 mimeNumFilters(MimeDatabase
));
979 * Create a list of MIME types for the document-format-supported
983 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
984 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
987 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
989 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
991 i
++, type
= mimeNextType(MimeDatabase
))
993 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
995 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
998 if (i
< NumMimeTypes
)
999 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
1001 if (LogLevel
== CUPSD_LOG_DEBUG2
)
1003 mime_filter_t
*filter
; /* Current filter */
1006 for (type
= mimeFirstType(MimeDatabase
);
1008 type
= mimeNextType(MimeDatabase
))
1009 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1010 type
->super
, type
->type
);
1012 for (filter
= mimeFirstFilter(MimeDatabase
);
1014 filter
= mimeNextFilter(MimeDatabase
))
1015 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1016 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1017 filter
->src
->super
, filter
->src
->type
,
1018 filter
->dst
->super
, filter
->dst
->type
,
1019 filter
->cost
, filter
->filter
);
1026 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1027 cupsdLoadBanners(temp
);
1030 * Load printers and classes...
1033 cupsdLoadAllPrinters();
1034 cupsdLoadAllClasses();
1035 cupsdLoadRemoteCache();
1036 cupsdWritePrintcap();
1038 cupsdCreateCommonData();
1041 * Load queued jobs...
1047 * Load subscriptions...
1050 cupsdLoadAllSubscriptions();
1052 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1057 * Not a full reload, so recreate the common printer attributes...
1060 cupsdCreateCommonData();
1063 * Update all printers as needed...
1066 cupsdUpdatePrinters();
1067 cupsdWritePrintcap();
1069 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1073 * Reset the reload state...
1076 NeedReload
= RELOAD_NONE
;
1078 cupsdClearString(&old_serverroot
);
1079 cupsdClearString(&old_requestroot
);
1086 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1089 static int /* O - 0 on success, -1 on error */
1090 check_permissions(const char *filename
, /* I - File/directory name */
1091 const char *suffix
, /* I - Additional file/directory name */
1092 int mode
, /* I - Permissions */
1093 int user
, /* I - Owner */
1094 int group
, /* I - Group */
1095 int is_dir
, /* I - 1 = directory, 0 = file */
1096 int create_dir
)/* I - 1 = create directory, 0 = not */
1098 int dir_created
= 0; /* Did we create a directory? */
1099 char pathname
[1024]; /* File name with prefix */
1100 struct stat fileinfo
; /* Stat buffer */
1104 * Prepend the given root to the filename before testing it...
1109 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1110 filename
= pathname
;
1114 * See if we can stat the file/directory...
1117 if (stat(filename
, &fileinfo
))
1119 if (errno
== ENOENT
&& create_dir
)
1121 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1124 if (mkdir(filename
, mode
))
1126 cupsdLogMessage(CUPSD_LOG_ERROR
,
1127 "Unable to create directory \"%s\" - %s", filename
,
1139 * Make sure it's a regular file...
1142 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1144 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1148 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1150 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1155 * Fix owner, group, and mode as needed...
1158 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1160 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1162 if (chown(filename
, user
, group
))
1164 cupsdLogMessage(CUPSD_LOG_ERROR
,
1165 "Unable to change ownership of \"%s\" - %s", filename
,
1171 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
1173 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1175 if (chmod(filename
, mode
))
1177 cupsdLogMessage(CUPSD_LOG_ERROR
,
1178 "Unable to change permissions of \"%s\" - %s", filename
,
1185 * Everything is OK...
1193 * 'get_address()' - Get an address + port number from a line.
1196 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1197 get_address(const char *value
, /* I - Value string */
1198 int defport
) /* I - Default port */
1200 char buffer
[1024], /* Hostname + port number buffer */
1201 defpname
[255], /* Default port name */
1202 *hostname
, /* Hostname or IP */
1203 *portname
; /* Port number or name */
1204 http_addrlist_t
*addrlist
; /* Address list */
1208 * Check for an empty value...
1213 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1218 * Grab a hostname and port number; if there is no colon and the port name
1219 * is only digits, then we have a port number by itself...
1222 strlcpy(buffer
, value
, sizeof(buffer
));
1224 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1231 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1236 * Use the default port...
1239 sprintf(defpname
, "%d", defport
);
1240 portname
= defpname
;
1246 * The buffer contains just a port number...
1254 if (hostname
&& !strcmp(hostname
, "*"))
1258 * Now lookup the address using httpAddrGetList()...
1261 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1262 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1263 hostname
? hostname
: "(nil)");
1270 * 'get_addr_and_mask()' - Get an IP address and netmask.
1273 static int /* O - 1 on success, 0 on failure */
1274 get_addr_and_mask(const char *value
, /* I - String from config file */
1275 unsigned *ip
, /* O - Address value */
1276 unsigned *mask
) /* O - Mask value */
1278 int i
, j
, /* Looping vars */
1279 family
, /* Address family */
1280 ipcount
; /* Count of fields in address */
1281 unsigned ipval
; /* Value */
1282 const char *maskval
, /* Pointer to start of mask value */
1283 *ptr
, /* Pointer into value */
1288 * Get the address...
1291 ip
[0] = ip
[1] = ip
[2] = ip
[2] = 0x00000000;
1292 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xffffffff;
1294 if ((maskval
= strchr(value
, '/')) != NULL
)
1297 maskval
= value
+ strlen(value
);
1301 * Check for an IPv6 address...
1307 * Parse hexadecimal IPv6 address...
1312 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1316 else if (!strncmp(ptr
, "::", 2))
1318 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1320 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1325 else if (isxdigit(*ptr
& 255))
1327 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1335 ip
[i
/ 2] |= ipval
<< 16;
1349 if (*ptr
&& *ptr
!= '/')
1353 #endif /* AF_INET6 */
1356 * Parse dotted-decimal IPv4 address...
1359 unsigned val
[4]; /* IPv4 address values */
1363 ipcount
= sscanf(value
, "%u.%u.%u.%u", val
+ 0, val
+ 1, val
+ 2, val
+ 3);
1366 * Range check the IP numbers...
1369 for (i
= 0; i
< ipcount
; i
++)
1374 * Make sure the trailing values are zeroed, as some C libraries like
1375 * glibc apparently like to fill the unused arguments with garbage...
1378 for (i
= ipcount
; i
< 4; i
++)
1382 * Merge everything into a 32-bit IPv4 address in ip[3]...
1385 ip
[3] = (((((val
[0] << 8) | val
[1]) << 8) | val
[2]) << 8) | val
[3];
1388 mask
[3] = (0xffffffff << (32 - 8 * ipcount
)) & 0xffffffff;
1394 * Get the netmask value(s)...
1397 memset(mask
, 0, sizeof(unsigned) * 4);
1399 if (strchr(maskval
, '.'))
1402 * Get dotted-decimal mask...
1405 if (family
!= AF_INET
)
1408 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1411 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1412 mask
[0] = mask
[1] = mask
[2] = 0;
1417 * Get address/bits format...
1423 if (family
== AF_INET6
)
1431 mask
[0] = 0xffffffff;
1433 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1436 mask
[1] = 0xffffffff;
1440 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1443 mask
[2] = 0xffffffff;
1447 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1450 mask
[3] = 0xffffffff;
1454 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1457 #endif /* AF_INET6 */
1462 mask
[0] = 0xffffffff;
1463 mask
[1] = 0xffffffff;
1464 mask
[2] = 0xffffffff;
1467 mask
[3] = (0xffffffff << (32 - i
)) & 0xffffffff;
1469 mask
[3] = 0xffffffff;
1474 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1475 "get_addr_and_mask(value=\"%s\", "
1476 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1477 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1481 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1484 if ((ip
[0] & ~mask
[0]) != 0 ||
1485 (ip
[1] & ~mask
[1]) != 0 ||
1486 (ip
[2] & ~mask
[2]) != 0 ||
1487 (ip
[3] & ~mask
[3]) != 0)
1495 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1498 static int /* O - 1 on success, 0 on failure */
1499 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1500 char *line
, /* I - Line from file */
1501 char *value
, /* I - Start of value data */
1502 int linenum
) /* I - Current line number */
1504 char *valptr
; /* Pointer into value */
1505 unsigned ip
[4], /* IP address components */
1506 mask
[4]; /* IP netmask components */
1509 if (!strcasecmp(line
, "Encryption"))
1512 * "Encryption xxx" - set required encryption level...
1515 if (!strcasecmp(value
, "never"))
1516 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1517 else if (!strcasecmp(value
, "always"))
1519 cupsdLogMessage(CUPSD_LOG_ERROR
,
1520 "Encryption value \"%s\" on line %d is invalid in this "
1521 "context. Using \"required\" instead.", value
, linenum
);
1523 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1525 else if (!strcasecmp(value
, "required"))
1526 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1527 else if (!strcasecmp(value
, "ifrequested"))
1528 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1531 cupsdLogMessage(CUPSD_LOG_ERROR
,
1532 "Unknown Encryption value %s on line %d.", value
, linenum
);
1536 else if (!strcasecmp(line
, "Order"))
1539 * "Order Deny,Allow" or "Order Allow,Deny"...
1542 if (!strncasecmp(value
, "deny", 4))
1543 loc
->order_type
= AUTH_ALLOW
;
1544 else if (!strncasecmp(value
, "allow", 5))
1545 loc
->order_type
= AUTH_DENY
;
1548 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1553 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1556 * Allow [From] host/ip...
1557 * Deny [From] host/ip...
1560 if (!strncasecmp(value
, "from", 4))
1563 * Strip leading "from"...
1568 while (isspace(*value
& 255))
1573 * Figure out what form the allow/deny address takes:
1584 * nnn.nnn.nnn.nnn/mm
1585 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1588 if (!strcasecmp(value
, "all"))
1594 if (!strcasecmp(line
, "Allow"))
1595 cupsdAllowIP(loc
, zeros
, zeros
);
1597 cupsdDenyIP(loc
, zeros
, zeros
);
1599 else if (!strcasecmp(value
, "none"))
1605 if (!strcasecmp(line
, "Allow"))
1606 cupsdAllowIP(loc
, ones
, zeros
);
1608 cupsdDenyIP(loc
, ones
, zeros
);
1611 else if (value
[0] == '*' || value
[0] == '.' ||
1612 (!isdigit(value
[0] & 255) && value
[0] != '['))
1614 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1615 #endif /* AF_INET6 */
1618 * Host or domain name...
1621 if (value
[0] == '*')
1624 if (!strcasecmp(line
, "Allow"))
1625 cupsdAllowHost(loc
, value
);
1627 cupsdDenyHost(loc
, value
);
1632 * One of many IP address forms...
1635 if (!get_addr_and_mask(value
, ip
, mask
))
1637 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1642 if (!strcasecmp(line
, "Allow"))
1643 cupsdAllowIP(loc
, ip
, mask
);
1645 cupsdDenyIP(loc
, ip
, mask
);
1648 else if (!strcasecmp(line
, "AuthType"))
1651 * AuthType {none,basic,digest,basicdigest}
1654 if (!strcasecmp(value
, "none"))
1656 loc
->type
= AUTH_NONE
;
1657 loc
->level
= AUTH_ANON
;
1659 else if (!strcasecmp(value
, "basic"))
1661 loc
->type
= AUTH_BASIC
;
1663 if (loc
->level
== AUTH_ANON
)
1664 loc
->level
= AUTH_USER
;
1666 else if (!strcasecmp(value
, "digest"))
1668 loc
->type
= AUTH_DIGEST
;
1670 if (loc
->level
== AUTH_ANON
)
1671 loc
->level
= AUTH_USER
;
1673 else if (!strcasecmp(value
, "basicdigest"))
1675 loc
->type
= AUTH_BASICDIGEST
;
1677 if (loc
->level
== AUTH_ANON
)
1678 loc
->level
= AUTH_USER
;
1682 cupsdLogMessage(CUPSD_LOG_WARN
,
1683 "Unknown authorization type %s on line %d.",
1688 else if (!strcasecmp(line
, "AuthClass"))
1691 * AuthClass anonymous, user, system, group
1694 if (!strcasecmp(value
, "anonymous"))
1696 loc
->type
= AUTH_NONE
;
1697 loc
->level
= AUTH_ANON
;
1699 cupsdLogMessage(CUPSD_LOG_WARN
,
1700 "\"AuthClass %s\" is deprecated; consider removing "
1704 else if (!strcasecmp(value
, "user"))
1706 loc
->level
= AUTH_USER
;
1708 cupsdLogMessage(CUPSD_LOG_WARN
,
1709 "\"AuthClass %s\" is deprecated; consider using "
1710 "\"Require valid-user\" on line %d.",
1713 else if (!strcasecmp(value
, "group"))
1715 loc
->level
= AUTH_GROUP
;
1717 cupsdLogMessage(CUPSD_LOG_WARN
,
1718 "\"AuthClass %s\" is deprecated; consider using "
1719 "\"Require @groupname\" on line %d.",
1722 else if (!strcasecmp(value
, "system"))
1724 loc
->level
= AUTH_GROUP
;
1726 cupsdAddName(loc
, "@SYSTEM");
1728 cupsdLogMessage(CUPSD_LOG_WARN
,
1729 "\"AuthClass %s\" is deprecated; consider using "
1730 "\"Require @SYSTEM\" on line %d.",
1735 cupsdLogMessage(CUPSD_LOG_WARN
,
1736 "Unknown authorization class %s on line %d.",
1741 else if (!strcasecmp(line
, "AuthGroupName"))
1743 cupsdAddName(loc
, value
);
1745 cupsdLogMessage(CUPSD_LOG_WARN
,
1746 "\"AuthGroupName %s\" directive is deprecated; consider "
1747 "using \"Require @%s\" on line %d.",
1748 value
, value
, linenum
);
1750 else if (!strcasecmp(line
, "Require"))
1753 * Apache synonym for AuthClass and AuthGroupName...
1757 * Require valid-user
1758 * Require group names
1759 * Require user names
1762 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1767 if (!strcasecmp(value
, "valid-user") ||
1768 !strcasecmp(value
, "user"))
1769 loc
->level
= AUTH_USER
;
1770 else if (!strcasecmp(value
, "group"))
1771 loc
->level
= AUTH_GROUP
;
1774 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1780 * Get the list of names from the line...
1783 for (value
= valptr
; *value
;)
1785 while (isspace(*value
& 255))
1788 if (*value
== '\"' || *value
== '\'')
1791 * Grab quoted name...
1794 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1801 * Grab literal name.
1804 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1810 cupsdAddName(loc
, value
);
1812 for (value
= valptr
; isspace(*value
& 255); value
++);
1815 else if (!strcasecmp(line
, "Satisfy"))
1817 if (!strcasecmp(value
, "all"))
1818 loc
->satisfy
= AUTH_SATISFY_ALL
;
1819 else if (!strcasecmp(value
, "any"))
1820 loc
->satisfy
= AUTH_SATISFY_ANY
;
1823 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1836 * 'parse_groups()' - Parse system group names in a string.
1839 static int /* O - 1 on success, 0 on failure */
1840 parse_groups(const char *s
) /* I - Space-delimited groups */
1842 int status
; /* Return status */
1843 char value
[1024], /* Value string */
1844 *valstart
, /* Pointer into value */
1845 *valend
, /* End of value */
1846 quote
; /* Quote character */
1847 struct group
*group
; /* Group */
1851 * Make a copy of the string and parse out the groups...
1854 strlcpy(value
, s
, sizeof(value
));
1859 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1861 if (*valstart
== '\'' || *valstart
== '\"')
1864 * Scan quoted name...
1867 quote
= *valstart
++;
1869 for (valend
= valstart
; *valend
; valend
++)
1870 if (*valend
== quote
)
1876 * Scan space or comma-delimited name...
1879 for (valend
= valstart
; *valend
; valend
++)
1880 if (isspace(*valend
) || *valend
== ',')
1887 group
= getgrnam(valstart
);
1890 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1891 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1902 while (*valstart
== ',' || isspace(*valstart
))
1911 * 'parse_protocols()' - Parse browse protocols in a string.
1914 static int /* O - Browse protocol bits */
1915 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1917 int protocols
; /* Browse protocol bits */
1918 char value
[1024], /* Value string */
1919 *valstart
, /* Pointer into value */
1920 *valend
; /* End of value */
1924 * Loop through the value string,...
1927 strlcpy(value
, s
, sizeof(value
));
1931 for (valstart
= value
; *valstart
;)
1934 * Get the current space/comma-delimited protocol name...
1937 for (valend
= valstart
; *valend
; valend
++)
1938 if (isspace(*valend
& 255) || *valend
== ',')
1945 * Add the protocol to the bitmask...
1948 if (!strcasecmp(valstart
, "cups"))
1949 protocols
|= BROWSE_CUPS
;
1950 else if (!strcasecmp(valstart
, "slp"))
1951 protocols
|= BROWSE_SLP
;
1952 else if (!strcasecmp(valstart
, "ldap"))
1953 protocols
|= BROWSE_LDAP
;
1954 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
1955 protocols
|= BROWSE_DNSSD
;
1956 else if (!strcasecmp(valstart
, "all"))
1957 protocols
|= BROWSE_ALL
;
1961 for (valstart
= valend
; *valstart
; valstart
++)
1962 if (!isspace(*valstart
& 255) || *valstart
!= ',')
1971 * 'read_configuration()' - Read a configuration file.
1974 static int /* O - 1 on success, 0 on failure */
1975 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1977 int i
; /* Looping var */
1978 int linenum
; /* Current line number */
1979 char line
[HTTP_MAX_BUFFER
],
1980 /* Line from file */
1981 temp
[HTTP_MAX_BUFFER
],
1982 /* Temporary buffer for value */
1983 temp2
[HTTP_MAX_BUFFER
],
1984 /* Temporary buffer 2 for value */
1985 *ptr
, /* Pointer into line/temp */
1986 *value
, /* Pointer to value */
1987 *valueptr
; /* Pointer into value */
1988 int valuelen
; /* Length of value */
1989 cupsd_var_t
*var
; /* Current variable */
1990 http_addrlist_t
*addrlist
, /* Address list */
1991 *addr
; /* Current address */
1992 unsigned ip
[4], /* Address value */
1993 mask
[4]; /* Netmask value */
1994 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
1995 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
1996 cupsd_location_t
*location
; /* Browse location */
1997 cups_file_t
*incfile
; /* Include file */
1998 char incname
[1024]; /* Include filename */
1999 struct group
*group
; /* Group */
2003 * Loop through each line in the file...
2008 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2011 * Decode the directive...
2014 if (!strcasecmp(line
, "Include"))
2020 if (value
[0] == '/')
2021 strlcpy(incname
, value
, sizeof(incname
));
2023 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2025 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2026 cupsdLogMessage(CUPSD_LOG_ERROR
,
2027 "Unable to include config file \"%s\" - %s",
2028 incname
, strerror(errno
));
2031 read_configuration(incfile
);
2032 cupsFileClose(incfile
);
2035 else if (!strcasecmp(line
, "<Location"))
2043 linenum
= read_location(fp
, value
, linenum
);
2049 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2054 else if (!strcasecmp(line
, "<Policy"))
2062 linenum
= read_policy(fp
, value
, linenum
);
2068 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2072 else if (!strcasecmp(line
, "FaxRetryInterval"))
2076 JobRetryInterval
= atoi(value
);
2077 cupsdLogMessage(CUPSD_LOG_WARN
,
2078 "FaxRetryInterval is deprecated; use "
2079 "JobRetryInterval on line %d.", linenum
);
2083 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2087 else if (!strcasecmp(line
, "FaxRetryLimit"))
2091 JobRetryLimit
= atoi(value
);
2092 cupsdLogMessage(CUPSD_LOG_WARN
,
2093 "FaxRetryLimit is deprecated; use "
2094 "JobRetryLimit on line %d.", linenum
);
2098 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2102 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2104 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2105 #endif /* HAVE_SSL */
2109 * Add listening address(es) to the list...
2112 cupsd_listener_t
*lis
; /* New listeners array */
2116 * Get the address list...
2119 addrlist
= get_address(value
, IPP_PORT
);
2123 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2129 * Add each address...
2132 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2135 * Allocate another listener...
2139 Listeners
= cupsArrayNew(NULL
, NULL
);
2143 cupsdLogMessage(CUPSD_LOG_ERROR
,
2144 "Unable to allocate %s at line %d - %s.",
2145 line
, linenum
, strerror(errno
));
2149 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2151 cupsdLogMessage(CUPSD_LOG_ERROR
,
2152 "Unable to allocate %s at line %d - %s.",
2153 line
, linenum
, strerror(errno
));
2157 cupsArrayAdd(Listeners
, lis
);
2160 * Copy the current address and log it...
2163 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2167 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2168 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2169 #endif /* HAVE_SSL */
2171 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2174 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2175 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2176 ntohs(lis
->address
.ipv6
.sin6_port
));
2178 #endif /* AF_INET6 */
2180 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2181 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2183 #endif /* AF_LOCAL */
2184 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2185 ntohs(lis
->address
.ipv4
.sin_port
));
2192 httpAddrFreeList(addrlist
);
2194 else if (!strcasecmp(line
, "BrowseAddress"))
2197 * Add a browse address to the list...
2200 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2203 if (NumBrowsers
== 0)
2204 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2206 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2210 cupsdLogMessage(CUPSD_LOG_ERROR
,
2211 "Unable to allocate BrowseAddress at line %d - %s.",
2212 linenum
, strerror(errno
));
2217 dira
+= NumBrowsers
;
2219 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2221 if (!strcasecmp(value
, "@LOCAL"))
2224 * Send browse data to all local interfaces...
2227 strcpy(dira
->iface
, "*");
2230 else if (!strncasecmp(value
, "@IF(", 4))
2233 * Send browse data to the named interface...
2236 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2238 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2244 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2247 * Only IPv4 addresses are supported...
2250 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2251 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2256 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2257 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2259 cupsdLogMessage(CUPSD_LOG_INFO
,
2260 "Sending browsing info to %s:%d (IPv4)",
2261 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2266 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2269 httpAddrFreeList(addrlist
);
2272 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2275 else if (!strcasecmp(line
, "BrowseOrder"))
2278 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2281 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2282 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2284 if (location
== NULL
)
2285 cupsdLogMessage(CUPSD_LOG_ERROR
,
2286 "Unable to initialize browse access control list!");
2287 else if (!strncasecmp(value
, "deny", 4))
2288 location
->order_type
= AUTH_ALLOW
;
2289 else if (!strncasecmp(value
, "allow", 5))
2290 location
->order_type
= AUTH_DENY
;
2292 cupsdLogMessage(CUPSD_LOG_ERROR
,
2293 "Unknown BrowseOrder value %s on line %d.",
2296 else if (!strcasecmp(line
, "BrowseProtocols") ||
2297 !strcasecmp(line
, "BrowseLocalProtocols") ||
2298 !strcasecmp(line
, "BrowseRemoteProtocols"))
2301 * "BrowseProtocols name [... name]"
2302 * "BrowseLocalProtocols name [... name]"
2303 * "BrowseRemoteProtocols name [... name]"
2306 int protocols
= parse_protocols(value
);
2310 cupsdLogMessage(CUPSD_LOG_ERROR
,
2311 "Unknown browse protocol \"%s\" on line %d.",
2316 if (strcasecmp(line
, "BrowseLocalProtocols"))
2317 BrowseRemoteProtocols
= protocols
;
2318 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2319 BrowseLocalProtocols
= protocols
;
2321 else if (!strcasecmp(line
, "BrowseAllow") ||
2322 !strcasecmp(line
, "BrowseDeny"))
2325 * BrowseAllow [From] host/ip...
2326 * BrowseDeny [From] host/ip...
2329 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2330 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2332 if (location
== NULL
)
2333 cupsdLogMessage(CUPSD_LOG_ERROR
,
2334 "Unable to initialize browse access control list!");
2337 if (!strncasecmp(value
, "from ", 5))
2340 * Strip leading "from"...
2345 while (isspace(*value
))
2350 * Figure out what form the allow/deny address takes:
2361 * nnn.nnn.nnn.nnn/mm
2362 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2365 if (!strcasecmp(value
, "all"))
2371 if (!strcasecmp(line
, "BrowseAllow"))
2372 cupsdAllowIP(location
, zeros
, zeros
);
2374 cupsdDenyIP(location
, zeros
, zeros
);
2376 else if (!strcasecmp(value
, "none"))
2382 if (!strcasecmp(line
, "BrowseAllow"))
2383 cupsdAllowIP(location
, ones
, zeros
);
2385 cupsdDenyIP(location
, ones
, zeros
);
2388 else if (value
[0] == '*' || value
[0] == '.' ||
2389 (!isdigit(value
[0] & 255) && value
[0] != '['))
2391 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2392 #endif /* AF_INET6 */
2395 * Host or domain name...
2398 if (value
[0] == '*')
2401 if (!strcasecmp(line
, "BrowseAllow"))
2402 cupsdAllowHost(location
, value
);
2404 cupsdDenyHost(location
, value
);
2409 * One of many IP address forms...
2412 if (!get_addr_and_mask(value
, ip
, mask
))
2414 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2419 if (!strcasecmp(line
, "BrowseAllow"))
2420 cupsdAllowIP(location
, ip
, mask
);
2422 cupsdDenyIP(location
, ip
, mask
);
2426 else if (!strcasecmp(line
, "BrowseRelay"))
2429 * BrowseRelay [from] source [to] destination
2433 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2435 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2439 cupsdLogMessage(CUPSD_LOG_ERROR
,
2440 "Unable to allocate BrowseRelay at line %d - %s.",
2441 linenum
, strerror(errno
));
2448 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2450 if (!strncasecmp(value
, "from ", 5))
2453 * Strip leading "from"...
2458 while (isspace(*value
))
2463 * Figure out what form the from address takes:
2472 * nnn.nnn.nnn.nnn/mm
2473 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2477 if (value
[0] == '*' || value
[0] == '.' ||
2478 (!isdigit(value
[0] & 255) && value
[0] != '['))
2480 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2481 #endif /* AF_INET6 */
2484 * Host or domain name...
2487 if (value
[0] == '*')
2490 strlcpy(temp
, value
, sizeof(temp
));
2491 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2494 relay
->from
.type
= AUTH_NAME
;
2495 relay
->from
.mask
.name
.name
= strdup(temp
);
2496 relay
->from
.mask
.name
.length
= strlen(temp
);
2501 * One of many IP address forms...
2504 if (!get_addr_and_mask(value
, ip
, mask
))
2506 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2511 relay
->from
.type
= AUTH_IP
;
2512 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2513 sizeof(relay
->from
.mask
.ip
.address
));
2514 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2515 sizeof(relay
->from
.mask
.ip
.netmask
));
2519 * Skip value and trailing whitespace...
2522 for (; *value
; value
++)
2523 if (isspace(*value
))
2526 while (isspace(*value
))
2529 if (!strncasecmp(value
, "to ", 3))
2532 * Strip leading "to"...
2537 while (isspace(*value
))
2542 * Get "to" address and port...
2545 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2548 * Only IPv4 addresses are supported...
2551 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2552 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2557 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2559 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2561 if (relay
->from
.type
== AUTH_IP
)
2562 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2563 relay
->from
.mask
.ip
.address
[0],
2564 relay
->from
.mask
.ip
.address
[1],
2565 relay
->from
.mask
.ip
.address
[2],
2566 relay
->from
.mask
.ip
.address
[3],
2567 relay
->from
.mask
.ip
.netmask
[0],
2568 relay
->from
.mask
.ip
.netmask
[1],
2569 relay
->from
.mask
.ip
.netmask
[2],
2570 relay
->from
.mask
.ip
.netmask
[3]);
2572 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2574 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2575 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2580 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2583 httpAddrFreeList(addrlist
);
2587 if (relay
->from
.type
== AUTH_NAME
)
2588 free(relay
->from
.mask
.name
.name
);
2590 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2594 else if (!strcasecmp(line
, "BrowsePoll"))
2597 * BrowsePoll address[:port]
2600 char *portname
; /* Port name */
2601 int portnum
; /* Port number */
2602 struct servent
*service
; /* Service */
2606 * Extract the port name from the address...
2609 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2613 if (isdigit(*portname
& 255))
2614 portnum
= atoi(portname
);
2615 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2616 portnum
= ntohs(service
->s_port
);
2619 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2625 portnum
= ippPort();
2628 * Add the poll entry...
2632 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2634 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2638 cupsdLogMessage(CUPSD_LOG_ERROR
,
2639 "Unable to allocate BrowsePoll at line %d - %s.",
2640 linenum
, strerror(errno
));
2648 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2650 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2651 pollp
->port
= portnum
;
2653 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2656 else if (!strcasecmp(line
, "DefaultAuthType"))
2659 * DefaultAuthType {basic,digest,basicdigest}
2662 if (!strcasecmp(value
, "basic"))
2663 DefaultAuthType
= AUTH_BASIC
;
2664 else if (!strcasecmp(value
, "digest"))
2665 DefaultAuthType
= AUTH_DIGEST
;
2666 else if (!strcasecmp(value
, "basicdigest"))
2667 DefaultAuthType
= AUTH_BASICDIGEST
;
2670 cupsdLogMessage(CUPSD_LOG_WARN
,
2671 "Unknown default authorization type %s on line %d.",
2677 else if (!strcasecmp(line
, "DefaultEncryption"))
2680 * DefaultEncryption {Never,IfRequested,Required}
2683 if (!value
|| !strcasecmp(value
, "never"))
2684 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2685 else if (!strcasecmp(value
, "required"))
2686 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2687 else if (!strcasecmp(value
, "ifrequested"))
2688 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2691 cupsdLogMessage(CUPSD_LOG_WARN
,
2692 "Unknown default encryption %s on line %d.",
2697 #endif /* HAVE_SSL */
2698 else if (!strcasecmp(line
, "User"))
2701 * User ID to run as...
2704 if (value
&& isdigit(value
[0] & 255))
2706 int uid
= atoi(value
);
2709 cupsdLogMessage(CUPSD_LOG_ERROR
,
2710 "Will not use User 0 as specified on line %d "
2711 "for security reasons. You must use a non-"
2712 "privileged account instead.",
2719 struct passwd
*p
; /* Password information */
2722 p
= getpwnam(value
);
2727 cupsdLogMessage(CUPSD_LOG_ERROR
,
2728 "Will not use User %s (UID=0) as specified on line "
2729 "%d for security reasons. You must use a non-"
2730 "privileged account instead.",
2736 cupsdLogMessage(CUPSD_LOG_ERROR
,
2737 "Unknown User \"%s\" on line %d, ignoring!",
2741 cupsdLogMessage(CUPSD_LOG_ERROR
,
2742 "User directive on line %d missing the username!",
2745 else if (!strcasecmp(line
, "Group"))
2748 * Group ID to run as...
2751 if (isdigit(value
[0]))
2752 Group
= atoi(value
);
2756 group
= getgrnam(value
);
2759 Group
= group
->gr_gid
;
2761 cupsdLogMessage(CUPSD_LOG_ERROR
,
2762 "Unknown Group \"%s\" on line %d, ignoring!",
2766 else if (!strcasecmp(line
, "SystemGroup"))
2769 * SystemGroup (admin) group(s)...
2772 if (!parse_groups(value
))
2773 cupsdLogMessage(CUPSD_LOG_ERROR
,
2774 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2777 else if (!strcasecmp(line
, "HostNameLookups"))
2780 * Do hostname lookups?
2783 if (!strcasecmp(value
, "off"))
2784 HostNameLookups
= 0;
2785 else if (!strcasecmp(value
, "on"))
2786 HostNameLookups
= 1;
2787 else if (!strcasecmp(value
, "double"))
2788 HostNameLookups
= 2;
2790 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2793 else if (!strcasecmp(line
, "LogLevel"))
2796 * Amount of logging to do...
2799 if (!strcasecmp(value
, "debug2"))
2800 LogLevel
= CUPSD_LOG_DEBUG2
;
2801 else if (!strcasecmp(value
, "debug"))
2802 LogLevel
= CUPSD_LOG_DEBUG
;
2803 else if (!strcasecmp(value
, "info"))
2804 LogLevel
= CUPSD_LOG_INFO
;
2805 else if (!strcasecmp(value
, "notice"))
2806 LogLevel
= CUPSD_LOG_NOTICE
;
2807 else if (!strcasecmp(value
, "warn"))
2808 LogLevel
= CUPSD_LOG_WARN
;
2809 else if (!strcasecmp(value
, "error"))
2810 LogLevel
= CUPSD_LOG_ERROR
;
2811 else if (!strcasecmp(value
, "crit"))
2812 LogLevel
= CUPSD_LOG_CRIT
;
2813 else if (!strcasecmp(value
, "alert"))
2814 LogLevel
= CUPSD_LOG_ALERT
;
2815 else if (!strcasecmp(value
, "emerg"))
2816 LogLevel
= CUPSD_LOG_EMERG
;
2817 else if (!strcasecmp(value
, "none"))
2818 LogLevel
= CUPSD_LOG_NONE
;
2820 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2823 else if (!strcasecmp(line
, "PrintcapFormat"))
2826 * Format of printcap file?
2829 if (!strcasecmp(value
, "bsd"))
2830 PrintcapFormat
= PRINTCAP_BSD
;
2831 else if (!strcasecmp(value
, "solaris"))
2832 PrintcapFormat
= PRINTCAP_SOLARIS
;
2834 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2837 else if (!strcasecmp(line
, "ServerTokens"))
2840 * Set the string used for the Server header...
2843 struct utsname plat
; /* Platform info */
2848 if (!strcasecmp(value
, "ProductOnly"))
2849 cupsdSetString(&ServerHeader
, "CUPS");
2850 else if (!strcasecmp(value
, "Major"))
2851 cupsdSetString(&ServerHeader
, "CUPS/1");
2852 else if (!strcasecmp(value
, "Minor"))
2853 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2854 else if (!strcasecmp(value
, "Minimal"))
2855 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2856 else if (!strcasecmp(value
, "OS"))
2857 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2858 else if (!strcasecmp(value
, "Full"))
2859 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2861 else if (!strcasecmp(value
, "None"))
2862 cupsdClearString(&ServerHeader
);
2864 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2867 else if (!strcasecmp(line
, "PassEnv"))
2870 * PassEnv variable [... variable]
2875 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2876 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2879 if (value
[valuelen
])
2881 value
[valuelen
] = '\0';
2885 cupsdSetEnv(value
, NULL
);
2887 for (value
+= valuelen
; *value
; value
++)
2888 if (!isspace(*value
) || *value
!= ',')
2892 else if (!strcasecmp(line
, "SetEnv"))
2895 * SetEnv variable value
2898 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2906 while (isspace(*valueptr
& 255))
2909 cupsdSetEnv(value
, valueptr
);
2912 cupsdLogMessage(CUPSD_LOG_ERROR
,
2913 "Missing value for SetEnv directive on line %d.",
2919 * Find a simple variable in the list...
2922 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2923 if (!strcasecmp(line
, var
->name
))
2929 * Unknown directive! Output an error message and continue...
2932 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2939 case CUPSD_VARTYPE_INTEGER
:
2941 cupsdLogMessage(CUPSD_LOG_ERROR
,
2942 "Missing integer value for %s on line %d!",
2947 char *units
; /* Units */
2950 n
= strtol(value
, &units
, 0);
2952 if (units
&& *units
)
2954 if (tolower(units
[0] & 255) == 'g')
2955 n
*= 1024 * 1024 * 1024;
2956 else if (tolower(units
[0] & 255) == 'm')
2958 else if (tolower(units
[0] & 255) == 'k')
2960 else if (tolower(units
[0] & 255) == 't')
2964 *((int *)var
->ptr
) = n
;
2968 case CUPSD_VARTYPE_BOOLEAN
:
2970 cupsdLogMessage(CUPSD_LOG_ERROR
,
2971 "Missing boolean value for %s on line %d!",
2973 else if (!strcasecmp(value
, "true") ||
2974 !strcasecmp(value
, "on") ||
2975 !strcasecmp(value
, "enabled") ||
2976 !strcasecmp(value
, "yes") ||
2978 *((int *)var
->ptr
) = TRUE
;
2979 else if (!strcasecmp(value
, "false") ||
2980 !strcasecmp(value
, "off") ||
2981 !strcasecmp(value
, "disabled") ||
2982 !strcasecmp(value
, "no") ||
2983 !strcasecmp(value
, "0"))
2984 *((int *)var
->ptr
) = FALSE
;
2986 cupsdLogMessage(CUPSD_LOG_ERROR
,
2987 "Unknown boolean value %s on line %d.",
2991 case CUPSD_VARTYPE_STRING
:
2992 cupsdSetString((char **)var
->ptr
, value
);
3003 * 'read_location()' - Read a <Location path> definition.
3006 static int /* O - New line number or 0 on error */
3007 read_location(cups_file_t
*fp
, /* I - Configuration file */
3008 char *location
, /* I - Location name/path */
3009 int linenum
) /* I - Current line number */
3011 cupsd_location_t
*loc
, /* New location */
3012 *parent
; /* Parent location */
3013 char line
[HTTP_MAX_BUFFER
],
3015 *value
, /* Value for directive */
3016 *valptr
; /* Pointer into value */
3019 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3022 parent
->limit
= AUTH_LIMIT_ALL
;
3025 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3028 * Decode the directive...
3031 if (!strcasecmp(line
, "</Location>"))
3033 else if (!strcasecmp(line
, "<Limit") ||
3034 !strcasecmp(line
, "<LimitExcept"))
3038 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3042 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3048 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3053 if (!strcmp(value
, "ALL"))
3054 loc
->limit
= AUTH_LIMIT_ALL
;
3055 else if (!strcmp(value
, "GET"))
3056 loc
->limit
|= AUTH_LIMIT_GET
;
3057 else if (!strcmp(value
, "HEAD"))
3058 loc
->limit
|= AUTH_LIMIT_HEAD
;
3059 else if (!strcmp(value
, "OPTIONS"))
3060 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3061 else if (!strcmp(value
, "POST"))
3062 loc
->limit
|= AUTH_LIMIT_POST
;
3063 else if (!strcmp(value
, "PUT"))
3064 loc
->limit
|= AUTH_LIMIT_PUT
;
3065 else if (!strcmp(value
, "TRACE"))
3066 loc
->limit
|= AUTH_LIMIT_TRACE
;
3068 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3071 for (value
= valptr
; isspace(*value
& 255); value
++);
3074 if (!strcasecmp(line
, "<LimitExcept"))
3075 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3077 parent
->limit
&= ~loc
->limit
;
3079 else if (!strcasecmp(line
, "</Limit>"))
3081 else if (!parse_aaa(loc
, line
, value
, linenum
))
3083 cupsdLogMessage(CUPSD_LOG_ERROR
,
3084 "Unknown Location directive %s on line %d.",
3090 cupsdLogMessage(CUPSD_LOG_ERROR
,
3091 "Unexpected end-of-file at line %d while reading location!",
3099 * 'read_policy()' - Read a <Policy name> definition.
3102 static int /* O - New line number or 0 on error */
3103 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3104 char *policy
, /* I - Location name/path */
3105 int linenum
) /* I - Current line number */
3107 int i
; /* Looping var */
3108 cupsd_policy_t
*pol
; /* Policy */
3109 cupsd_location_t
*op
; /* Policy operation */
3110 int num_ops
; /* Number of IPP operations */
3111 ipp_op_t ops
[100]; /* Operations */
3112 char line
[HTTP_MAX_BUFFER
],
3114 *value
, /* Value for directive */
3115 *valptr
; /* Pointer into value */
3119 * Create the policy...
3122 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3126 * Read from the file...
3132 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3135 * Decode the directive...
3138 if (!strcasecmp(line
, "</Policy>"))
3141 cupsdLogMessage(CUPSD_LOG_WARN
,
3142 "Missing </Limit> before </Policy> on line %d!",
3147 else if (!strcasecmp(line
, "<Limit") && !op
)
3151 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3156 * Scan for IPP operation names...
3163 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3168 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3170 if (!strcasecmp(value
, "All"))
3171 ops
[num_ops
] = IPP_ANY_OPERATION
;
3172 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3173 cupsdLogMessage(CUPSD_LOG_ERROR
,
3174 "Bad IPP operation name \"%s\" on line %d!",
3180 cupsdLogMessage(CUPSD_LOG_ERROR
,
3181 "Too many operations listed on line %d!",
3184 for (value
= valptr
; isspace(*value
& 255); value
++);
3188 * If none are specified, apply the policy to all operations...
3193 ops
[0] = IPP_ANY_OPERATION
;
3198 * Add a new policy for the first operation...
3201 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3203 else if (!strcasecmp(line
, "</Limit>") && op
)
3206 * Finish the current operation limit...
3212 * Copy the policy to the other operations...
3215 for (i
= 1; i
< num_ops
; i
++)
3216 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3223 cupsdLogMessage(CUPSD_LOG_ERROR
,
3224 "Missing <Limit ops> directive before %s on line %d.",
3228 else if (!parse_aaa(op
, line
, value
, linenum
))
3231 cupsdLogMessage(CUPSD_LOG_ERROR
,
3232 "Unknown Policy Limit directive %s on line %d.",
3235 cupsdLogMessage(CUPSD_LOG_ERROR
,
3236 "Unknown Policy directive %s on line %d.",
3243 cupsdLogMessage(CUPSD_LOG_ERROR
,
3244 "Unexpected end-of-file at line %d while reading policy \"%s\"!",