2 * "$Id: conf.c 5482 2006-05-02 18:13:40Z mike $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdReadConfiguration() - Read the cupsd.conf file.
27 * check_permissions() - Fix the mode and ownership of a file or
29 * get_address() - Get an address + port number from a line.
30 * get_addr_and_mask() - Get an IP address and netmask.
31 * parse_aaa() - Parse authentication, authorization, and
32 * access control lines.
33 * parse_groups() - Parse system group names in a string.
34 * parse_protocols() - Parse browse protocols in a string.
35 * read_configuration() - Read a configuration file.
36 * read_location() - Read a <Location path> definition.
37 * read_policy() - Read a <Policy name> definition.
41 * Include necessary headers...
47 #include <sys/utsname.h>
52 #endif /* HAVE_VSYSLOG */
56 * Possibly missing network definitions...
60 # define INADDR_NONE 0xffffffff
61 #endif /* !INADDR_NONE */
65 * Configuration variable structure...
70 CUPSD_VARTYPE_INTEGER
, /* Integer option */
71 CUPSD_VARTYPE_STRING
, /* String option */
72 CUPSD_VARTYPE_BOOLEAN
/* Boolean option */
77 char *name
; /* Name of variable */
78 void *ptr
; /* Pointer to variable */
79 cupsd_vartype_t type
; /* Type (int, string, address) */
87 static cupsd_var_t variables
[] =
89 { "AccessLog", &AccessLog
, CUPSD_VARTYPE_STRING
},
90 { "AutoPurgeJobs", &JobAutoPurge
, CUPSD_VARTYPE_BOOLEAN
},
91 { "BrowseInterval", &BrowseInterval
, CUPSD_VARTYPE_INTEGER
},
93 { "BrowseLDAPBindDN", &BrowseLDAPBindDN
, CUPSD_VARTYPE_STRING
},
94 { "BrowseLDAPDN", &BrowseLDAPDN
, CUPSD_VARTYPE_STRING
},
95 { "BrowseLDAPPassword", &BrowseLDAPPassword
, CUPSD_VARTYPE_STRING
},
96 { "BrowseLDAPServer", &BrowseLDAPServer
, CUPSD_VARTYPE_STRING
},
97 #endif /* HAVE_LDAP */
98 { "BrowseLocalOptions", &BrowseLocalOptions
, CUPSD_VARTYPE_STRING
},
99 { "BrowsePort", &BrowsePort
, CUPSD_VARTYPE_INTEGER
},
100 { "BrowseRemoteOptions", &BrowseRemoteOptions
, CUPSD_VARTYPE_STRING
},
101 { "BrowseShortNames", &BrowseShortNames
, CUPSD_VARTYPE_BOOLEAN
},
102 { "BrowseTimeout", &BrowseTimeout
, CUPSD_VARTYPE_INTEGER
},
103 { "Browsing", &Browsing
, CUPSD_VARTYPE_BOOLEAN
},
104 { "CacheDir", &CacheDir
, CUPSD_VARTYPE_STRING
},
105 { "Classification", &Classification
, CUPSD_VARTYPE_STRING
},
106 { "ClassifyOverride", &ClassifyOverride
, CUPSD_VARTYPE_BOOLEAN
},
107 { "ConfigFilePerm", &ConfigFilePerm
, CUPSD_VARTYPE_INTEGER
},
108 { "DataDir", &DataDir
, CUPSD_VARTYPE_STRING
},
109 { "DefaultCharset", &DefaultCharset
, CUPSD_VARTYPE_STRING
},
110 { "DefaultLanguage", &DefaultLanguage
, CUPSD_VARTYPE_STRING
},
111 { "DefaultLeaseDuration", &DefaultLeaseDuration
, CUPSD_VARTYPE_INTEGER
},
112 { "DefaultPolicy", &DefaultPolicy
, CUPSD_VARTYPE_STRING
},
113 { "DefaultShared", &DefaultShared
, CUPSD_VARTYPE_BOOLEAN
},
114 { "DocumentRoot", &DocumentRoot
, CUPSD_VARTYPE_STRING
},
115 { "ErrorLog", &ErrorLog
, CUPSD_VARTYPE_STRING
},
116 { "FileDevice", &FileDevice
, CUPSD_VARTYPE_BOOLEAN
},
117 { "FilterLimit", &FilterLimit
, CUPSD_VARTYPE_INTEGER
},
118 { "FilterNice", &FilterNice
, CUPSD_VARTYPE_INTEGER
},
119 { "FontPath", &FontPath
, CUPSD_VARTYPE_STRING
},
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 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...
345 group
= getgrnam(CUPS_DEFAULT_GROUP
);
349 Group
= group
->gr_gid
;
353 * Fallback to group "nobody"...
356 group
= getgrnam("nobody");
360 Group
= group
->gr_gid
;
364 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
365 * complement number...)
376 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
377 DefaultAuthType
= AUTH_BASIC
;
379 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
380 #endif /* HAVE_SSL */
382 JobRetryInterval
= 300;
387 HostNameLookups
= FALSE
;
388 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
389 ImplicitAnyClasses
= FALSE
;
390 HideImplicitMembers
= TRUE
;
392 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
393 ListenBackLog
= SOMAXCONN
;
394 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
395 LogLevel
= CUPSD_LOG_ERROR
;
397 MaxClientsPerHost
= 0;
398 MaxLogSize
= 1024 * 1024;
399 MaxPrinterHistory
= 10;
402 RootCertDuration
= 300;
403 Timeout
= DEFAULT_TIMEOUT
;
406 BrowseInterval
= DEFAULT_INTERVAL
;
407 BrowsePort
= ippPort();
408 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
409 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
410 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
411 BrowseTimeout
= DEFAULT_TIMEOUT
;
412 Browsing
= CUPS_DEFAULT_BROWSING
;
413 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
415 cupsdClearString(&BrowseLocalOptions
);
416 cupsdClearString(&BrowseRemoteOptions
);
419 cupsdClearString(&BrowseLDAPBindDN
);
420 cupsdClearString(&BrowseLDAPDN
);
421 cupsdClearString(&BrowseLDAPPassword
);
422 cupsdClearString(&BrowseLDAPServer
);
423 #endif /* HAVE_LDAP */
425 JobHistory
= DEFAULT_HISTORY
;
426 JobFiles
= DEFAULT_FILES
;
431 MaxJobsPerPrinter
= 0;
434 cupsdDeleteAllPolicies();
435 cupsdClearString(&DefaultPolicy
);
437 MaxSubscriptions
= 100;
438 MaxSubscriptionsPerJob
= 0;
439 MaxSubscriptionsPerPrinter
= 0;
440 MaxSubscriptionsPerUser
= 0;
441 DefaultLeaseDuration
= 86400;
442 MaxLeaseDuration
= 0;
445 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
446 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
447 #endif /* HAVE_LAUNCHD */
450 * Read the configuration file...
453 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
456 status
= read_configuration(fp
);
466 * Use the default system group if none was supplied in cupsd.conf...
469 if (NumSystemGroups
== 0)
471 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
474 * Find the group associated with GID 0...
481 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
483 cupsdSetString(&SystemGroups
[0], "unknown");
485 SystemGroupIDs
[0] = 0;
491 * Get the access control list for browsing...
494 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
497 * Open the system log for cupsd if necessary...
501 if (!strcmp(AccessLog
, "syslog") ||
502 !strcmp(ErrorLog
, "syslog") ||
503 !strcmp(PageLog
, "syslog"))
504 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
505 #endif /* HAVE_VSYSLOG */
508 * Log the configuration file that was used...
511 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
515 * Validate the Group and SystemGroup settings - they cannot be the same,
516 * otherwise the CGI programs will be able to authenticate as root without
522 for (i
= 0; i
< NumSystemGroups
; i
++)
523 if (Group
== SystemGroupIDs
[i
])
526 if (i
< NumSystemGroups
)
529 * Log the error and reset the group to a safe value...
532 cupsdLogMessage(CUPSD_LOG_NOTICE
,
533 "Group and SystemGroup cannot use the same groups!");
534 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
536 group
= getgrnam("nobody");
540 Group
= group
->gr_gid
;
544 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
545 * complement number...)
554 * Check that we have at least one listen/port line; if not, report this
555 * as an error and exit!
558 if (cupsArrayCount(Listeners
) == 0)
564 cupsdLogMessage(CUPSD_LOG_EMERG
,
565 "No valid Listen or Port lines were found in the configuration file!");
571 cupsdEndProcess(getpid(), 0);
575 * Set the default locale using the language and charset...
578 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
581 * Update all relative filenames to include the full path from ServerRoot...
584 if (DocumentRoot
[0] != '/')
585 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
587 if (RequestRoot
[0] != '/')
588 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
590 if (ServerBin
[0] != '/')
591 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
593 if (StateDir
[0] != '/')
594 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
596 if (CacheDir
[0] != '/')
597 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
600 if (ServerCertificate
[0] != '/')
601 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
603 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
605 chown(ServerCertificate
, RunUser
, Group
);
606 chmod(ServerCertificate
, 0600);
609 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
610 if (ServerKey
[0] != '/')
611 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
613 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
615 chown(ServerKey
, RunUser
, Group
);
616 chmod(ServerKey
, 0600);
618 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
619 #endif /* HAVE_SSL */
622 * Make sure that directories and config files are owned and
623 * writable by the user and group in the cupsd.conf file...
626 check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1);
627 /* check_permissions(CacheDir, "ppd", 0755, RunUser, Group, 1, 1);*/
629 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1);
630 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
631 SystemGroupIDs
[0], 1, 1);
633 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0);
634 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1);
635 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0);
636 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
, Group
,
638 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
, 0, 0);
639 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
, 0, 0);
640 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0);
643 * Update TempDir to the default if it hasn't been set already...
648 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
651 * TMPDIR is defined, see if it is OK for us to use...
654 if (stat(tmpdir
, &tmpinfo
))
655 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
656 tmpdir
, strerror(errno
));
657 else if (!S_ISDIR(tmpinfo
.st_mode
))
658 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
660 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
661 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
662 !(tmpinfo
.st_mode
& S_IWOTH
))
663 cupsdLogMessage(CUPSD_LOG_ERROR
,
664 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
666 cupsdSetString(&TempDir
, tmpdir
);
669 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
674 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
678 * Make sure the request and temporary directories have the right
682 check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1);
684 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
688 * Update ownership and permissions if the CUPS temp directory
689 * is under the spool directory or does not exist...
692 check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1);
695 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
698 * Clean out the temporary directory...
701 cups_dir_t
*dir
; /* Temporary directory */
702 cups_dentry_t
*dent
; /* Directory entry */
703 char tempfile
[1024]; /* Temporary filename */
706 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
708 cupsdLogMessage(CUPSD_LOG_INFO
,
709 "Cleaning out old temporary files in \"%s\"...", TempDir
);
711 while ((dent
= cupsDirRead(dir
)) != NULL
)
713 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
715 if (unlink(tempfile
))
716 cupsdLogMessage(CUPSD_LOG_ERROR
,
717 "Unable to remove temporary file \"%s\" - %s",
718 tempfile
, strerror(errno
));
720 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
727 cupsdLogMessage(CUPSD_LOG_ERROR
,
728 "Unable to open temporary directory \"%s\" - %s",
729 TempDir
, strerror(errno
));
733 * Setup environment variables...
739 * Check the MaxClients setting, and then allocate memory for it...
742 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
745 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
748 MaxClients
= MaxFDs
/ 3;
751 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
755 * Check the MaxActiveJobs setting; limit to 1/3 the available
756 * file descriptors, since we need a pipe for each job...
759 if (MaxActiveJobs
> (MaxFDs
/ 3))
760 MaxActiveJobs
= MaxFDs
/ 3;
762 if (Classification
&& strcasecmp(Classification
, "none") == 0)
763 cupsdClearString(&Classification
);
766 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
769 * Update the MaxClientsPerHost value, as needed...
772 if (MaxClientsPerHost
<= 0)
773 MaxClientsPerHost
= MaxClients
;
775 if (MaxClientsPerHost
> MaxClients
)
776 MaxClientsPerHost
= MaxClients
;
778 cupsdLogMessage(CUPSD_LOG_INFO
,
779 "Allowing up to %d client connections per host.",
783 * Update the default policy, as needed...
787 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
789 DefaultPolicyPtr
= NULL
;
791 if (!DefaultPolicyPtr
)
793 cupsd_policy_t
*p
; /* New policy */
794 cupsd_location_t
*po
; /* New policy operation */
798 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
801 cupsdSetString(&DefaultPolicy
, "default");
803 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
804 cupsdLogMessage(CUPSD_LOG_INFO
,
805 "Using policy \"default\" as the default!");
808 cupsdLogMessage(CUPSD_LOG_INFO
,
809 "Creating CUPS default administrative policy:");
811 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
813 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
814 cupsdLogMessage(CUPSD_LOG_INFO
,
815 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
816 "Release-Job Restart-Job Purge-Jobs "
817 "Set-Job-Attributes Create-Job-Subscription "
818 "Renew-Subscription Cancel-Subscription "
819 "Get-Notifications Reprocess-Job Cancel-Current-Job "
820 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
821 "CUPS-Authenticate-Job>");
822 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
824 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
825 po
->order_type
= AUTH_ALLOW
;
826 po
->level
= AUTH_USER
;
828 cupsdAddName(po
, "@OWNER");
829 cupsdAddName(po
, "@SYSTEM");
830 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
832 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
833 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
834 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
835 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
836 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
837 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
838 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
839 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
840 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
841 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
842 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
843 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
844 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
845 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
846 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
847 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
848 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
850 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
852 cupsdLogMessage(CUPSD_LOG_INFO
,
853 "<Limit Pause-Printer Resume-Printer "
854 "Set-Printer-Attributes Enable-Printer "
855 "Disable-Printer Pause-Printer-After-Current-Job "
856 "Hold-New-Jobs Release-Held-New-Jobs "
857 "Deactivate-Printer Activate-Printer Restart-Printer "
858 "Shutdown-Printer Startup-Printer Promote-Job "
859 "Schedule-Job-After CUPS-Add-Printer "
860 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
861 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
862 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
863 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
865 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
866 po
->order_type
= AUTH_ALLOW
;
867 po
->type
= AUTH_BASIC
;
868 po
->level
= AUTH_USER
;
870 cupsdAddName(po
, "@SYSTEM");
871 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
873 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
874 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
875 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
876 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
877 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
878 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
879 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
880 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
881 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
882 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
883 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
884 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
885 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
886 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
887 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
888 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
889 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
890 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
891 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
892 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
893 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
895 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
897 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
898 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
900 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
901 po
->order_type
= AUTH_ALLOW
;
903 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
904 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
908 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
910 for (i
= 0; i
< NumPolicies
; i
++)
911 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
912 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
916 * If we are doing a full reload or the server root has changed, flush
917 * the jobs, printers, etc. and start from scratch...
920 if (NeedReload
== RELOAD_ALL
||
921 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
922 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
924 mime_type_t
*type
; /* Current type */
925 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
929 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
935 cupsdDeleteAllSubscriptions();
937 cupsdDeleteAllClasses();
938 cupsdDeleteAllPrinters();
940 DefaultPrinter
= NULL
;
942 if (MimeDatabase
!= NULL
)
943 mimeDelete(MimeDatabase
);
947 for (i
= 0; i
< NumMimeTypes
; i
++)
948 _cupsStrFree(MimeTypes
[i
]);
954 * Read the MIME type and conversion database...
957 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
959 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
963 cupsdLogMessage(CUPSD_LOG_EMERG
,
964 "Unable to load MIME database from \'%s\'!", ServerRoot
);
968 cupsdLogMessage(CUPSD_LOG_INFO
,
969 "Loaded MIME database from \'%s\': %d types, %d filters...",
970 ServerRoot
, mimeNumTypes(MimeDatabase
),
971 mimeNumFilters(MimeDatabase
));
974 * Create a list of MIME types for the document-format-supported
978 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
979 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
982 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
984 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
986 i
++, type
= mimeNextType(MimeDatabase
))
988 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
990 MimeTypes
[i
] = _cupsStrAlloc(mimetype
);
993 if (i
< NumMimeTypes
)
994 MimeTypes
[i
] = _cupsStrAlloc("application/octet-stream");
996 if (LogLevel
== CUPSD_LOG_DEBUG2
)
998 mime_filter_t
*filter
; /* Current filter */
1001 for (type
= mimeFirstType(MimeDatabase
);
1003 type
= mimeNextType(MimeDatabase
))
1004 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
1005 type
->super
, type
->type
);
1007 for (filter
= mimeFirstFilter(MimeDatabase
);
1009 filter
= mimeNextFilter(MimeDatabase
))
1010 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1011 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
1012 filter
->src
->super
, filter
->src
->type
,
1013 filter
->dst
->super
, filter
->dst
->type
,
1014 filter
->cost
, filter
->filter
);
1021 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1022 cupsdLoadBanners(temp
);
1025 * Load printers and classes...
1028 cupsdLoadAllPrinters();
1029 cupsdLoadAllClasses();
1030 cupsdLoadRemoteCache();
1031 cupsdWritePrintcap();
1033 cupsdCreateCommonData();
1036 * Load queued jobs...
1042 * Load subscriptions...
1045 cupsdLoadAllSubscriptions();
1047 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1052 * Not a full reload, so recreate the common printer attributes...
1055 cupsdCreateCommonData();
1058 * Update all printers as needed...
1061 cupsdUpdatePrinters();
1062 cupsdWritePrintcap();
1064 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1068 * Reset the reload state...
1071 NeedReload
= RELOAD_NONE
;
1073 cupsdClearString(&old_serverroot
);
1074 cupsdClearString(&old_requestroot
);
1081 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1084 static int /* O - 0 on success, -1 on error */
1085 check_permissions(const char *filename
, /* I - File/directory name */
1086 const char *suffix
, /* I - Additional file/directory name */
1087 int mode
, /* I - Permissions */
1088 int user
, /* I - Owner */
1089 int group
, /* I - Group */
1090 int is_dir
, /* I - 1 = directory, 0 = file */
1091 int create_dir
)/* I - 1 = create directory, 0 = not */
1093 int dir_created
= 0; /* Did we create a directory? */
1094 char pathname
[1024]; /* File name with prefix */
1095 struct stat fileinfo
; /* Stat buffer */
1099 * Prepend the given root to the filename before testing it...
1104 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1105 filename
= pathname
;
1109 * See if we can stat the file/directory...
1112 if (stat(filename
, &fileinfo
))
1114 if (errno
== ENOENT
&& create_dir
)
1116 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1119 if (mkdir(filename
, mode
))
1121 cupsdLogMessage(CUPSD_LOG_ERROR
,
1122 "Unable to create directory \"%s\" - %s", filename
,
1134 * Make sure it's a regular file...
1137 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1139 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1143 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1145 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1150 * Fix owner, group, and mode as needed...
1153 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1155 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1157 if (chown(filename
, user
, group
))
1159 cupsdLogMessage(CUPSD_LOG_ERROR
,
1160 "Unable to change ownership of \"%s\" - %s", filename
,
1166 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
1168 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1170 if (chmod(filename
, mode
))
1172 cupsdLogMessage(CUPSD_LOG_ERROR
,
1173 "Unable to change permissions of \"%s\" - %s", filename
,
1180 * Everything is OK...
1188 * 'get_address()' - Get an address + port number from a line.
1191 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1192 get_address(const char *value
, /* I - Value string */
1193 int defport
) /* I - Default port */
1195 char buffer
[1024], /* Hostname + port number buffer */
1196 defpname
[255], /* Default port name */
1197 *hostname
, /* Hostname or IP */
1198 *portname
; /* Port number or name */
1199 http_addrlist_t
*addrlist
; /* Address list */
1203 * Check for an empty value...
1208 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1213 * Grab a hostname and port number; if there is no colon and the port name
1214 * is only digits, then we have a port number by itself...
1217 strlcpy(buffer
, value
, sizeof(buffer
));
1219 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1226 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1231 * Use the default port...
1234 sprintf(defpname
, "%d", defport
);
1235 portname
= defpname
;
1241 * The buffer contains just a port number...
1249 if (hostname
&& !strcmp(hostname
, "*"))
1253 * Now lookup the address using httpAddrGetList()...
1256 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1257 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1258 hostname
? hostname
: "(nil)");
1265 * 'get_addr_and_mask()' - Get an IP address and netmask.
1268 static int /* O - 1 on success, 0 on failure */
1269 get_addr_and_mask(const char *value
, /* I - String from config file */
1270 unsigned *ip
, /* O - Address value */
1271 unsigned *mask
) /* O - Mask value */
1273 int i
, j
, /* Looping vars */
1274 family
, /* Address family */
1275 ipcount
; /* Count of fields in address */
1276 unsigned ipval
; /* Value */
1277 const char *maskval
, /* Pointer to start of mask value */
1278 *ptr
, /* Pointer into value */
1280 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1282 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1283 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1284 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1285 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1288 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1290 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1291 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1292 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1293 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1294 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1295 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1296 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1297 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1299 #endif /* AF_INET6 */
1303 * Get the address...
1306 memset(ip
, 0, sizeof(unsigned) * 4);
1308 if ((maskval
= strchr(value
, '/')) != NULL
)
1311 maskval
= value
+ strlen(value
);
1315 * Check for an IPv6 address...
1321 * Parse hexadecimal IPv6 address...
1326 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1330 else if (!strncmp(ptr
, "::", 2))
1332 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1334 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1338 else if (isxdigit(*ptr
& 255))
1340 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1348 ip
[i
] |= ipval
<< 16;
1359 if (*ptr
&& *ptr
!= '/')
1363 #endif /* AF_INET6 */
1366 * Parse dotted-decimal IPv4 address...
1370 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1372 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1373 ip
[0] = ip
[1] = ip
[2] = 0;
1379 * Get the netmask value(s)...
1382 memset(mask
, 0, sizeof(unsigned) * 4);
1385 if (*maskval
== '[')
1388 * Get hexadecimal mask value...
1391 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1395 else if (!strncmp(ptr
, "::", 2))
1397 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1399 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1403 else if (isxdigit(*ptr
& 255))
1405 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1413 mask
[i
] |= ipval
<< 16;
1426 #endif /* AF_INET6 */
1427 if (strchr(maskval
, '.'))
1430 * Get dotted-decimal mask...
1433 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1436 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1437 mask
[0] = mask
[1] = mask
[2] = 0;
1442 * Get address/bits format...
1448 if (family
== AF_INET6
)
1453 mask
[0] = 0xffffffff;
1455 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1458 mask
[1] = 0xffffffff;
1462 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1465 mask
[2] = 0xffffffff;
1469 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1472 mask
[3] = 0xffffffff;
1476 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1479 #endif /* AF_INET6 */
1483 mask
[0] = 0xffffffff;
1484 mask
[1] = 0xffffffff;
1485 mask
[2] = 0xffffffff;
1488 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1490 mask
[3] = 0xffffffff;
1495 else if (family
== AF_INET6
)
1496 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1497 #endif /* AF_INET6 */
1499 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1501 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1502 "get_addr_and_mask(value=\"%s\", "
1503 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1504 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1508 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1511 if ((ip
[0] & ~mask
[0]) != 0 ||
1512 (ip
[1] & ~mask
[1]) != 0 ||
1513 (ip
[2] & ~mask
[2]) != 0 ||
1514 (ip
[3] & ~mask
[3]) != 0)
1522 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1525 static int /* O - 1 on success, 0 on failure */
1526 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1527 char *line
, /* I - Line from file */
1528 char *value
, /* I - Start of value data */
1529 int linenum
) /* I - Current line number */
1531 char *valptr
; /* Pointer into value */
1532 unsigned ip
[4], /* IP address components */
1533 mask
[4]; /* IP netmask components */
1536 if (!strcasecmp(line
, "Encryption"))
1539 * "Encryption xxx" - set required encryption level...
1542 if (!strcasecmp(value
, "never"))
1543 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1544 else if (!strcasecmp(value
, "always"))
1546 cupsdLogMessage(CUPSD_LOG_ERROR
,
1547 "Encryption value \"%s\" on line %d is invalid in this "
1548 "context. Using \"required\" instead.", value
, linenum
);
1550 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1552 else if (!strcasecmp(value
, "required"))
1553 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1554 else if (!strcasecmp(value
, "ifrequested"))
1555 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1558 cupsdLogMessage(CUPSD_LOG_ERROR
,
1559 "Unknown Encryption value %s on line %d.", value
, linenum
);
1563 else if (!strcasecmp(line
, "Order"))
1566 * "Order Deny,Allow" or "Order Allow,Deny"...
1569 if (!strncasecmp(value
, "deny", 4))
1570 loc
->order_type
= AUTH_ALLOW
;
1571 else if (!strncasecmp(value
, "allow", 5))
1572 loc
->order_type
= AUTH_DENY
;
1575 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1580 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1583 * Allow [From] host/ip...
1584 * Deny [From] host/ip...
1587 if (!strncasecmp(value
, "from", 4))
1590 * Strip leading "from"...
1595 while (isspace(*value
& 255))
1600 * Figure out what form the allow/deny address takes:
1611 * nnn.nnn.nnn.nnn/mm
1612 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1615 if (!strcasecmp(value
, "all"))
1621 if (!strcasecmp(line
, "Allow"))
1622 cupsdAllowIP(loc
, zeros
, zeros
);
1624 cupsdDenyIP(loc
, zeros
, zeros
);
1626 else if (!strcasecmp(value
, "none"))
1632 if (!strcasecmp(line
, "Allow"))
1633 cupsdAllowIP(loc
, ones
, zeros
);
1635 cupsdDenyIP(loc
, ones
, zeros
);
1637 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1640 * Host or domain name...
1643 if (value
[0] == '*')
1646 if (!strcasecmp(line
, "Allow"))
1647 cupsdAllowHost(loc
, value
);
1649 cupsdDenyHost(loc
, value
);
1654 * One of many IP address forms...
1657 if (!get_addr_and_mask(value
, ip
, mask
))
1659 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1664 if (!strcasecmp(line
, "Allow"))
1665 cupsdAllowIP(loc
, ip
, mask
);
1667 cupsdDenyIP(loc
, ip
, mask
);
1670 else if (!strcasecmp(line
, "AuthType"))
1673 * AuthType {none,basic,digest,basicdigest}
1676 if (!strcasecmp(value
, "none"))
1678 loc
->type
= AUTH_NONE
;
1679 loc
->level
= AUTH_ANON
;
1681 else if (!strcasecmp(value
, "basic"))
1683 loc
->type
= AUTH_BASIC
;
1685 if (loc
->level
== AUTH_ANON
)
1686 loc
->level
= AUTH_USER
;
1688 else if (!strcasecmp(value
, "digest"))
1690 loc
->type
= AUTH_DIGEST
;
1692 if (loc
->level
== AUTH_ANON
)
1693 loc
->level
= AUTH_USER
;
1695 else if (!strcasecmp(value
, "basicdigest"))
1697 loc
->type
= AUTH_BASICDIGEST
;
1699 if (loc
->level
== AUTH_ANON
)
1700 loc
->level
= AUTH_USER
;
1704 cupsdLogMessage(CUPSD_LOG_WARN
,
1705 "Unknown authorization type %s on line %d.",
1710 else if (!strcasecmp(line
, "AuthClass"))
1713 * AuthClass anonymous, user, system, group
1716 if (!strcasecmp(value
, "anonymous"))
1718 loc
->type
= AUTH_NONE
;
1719 loc
->level
= AUTH_ANON
;
1721 cupsdLogMessage(CUPSD_LOG_WARN
,
1722 "\"AuthClass %s\" is deprecated; consider removing "
1726 else if (!strcasecmp(value
, "user"))
1728 loc
->level
= AUTH_USER
;
1730 cupsdLogMessage(CUPSD_LOG_WARN
,
1731 "\"AuthClass %s\" is deprecated; consider using "
1732 "\"Require valid-user\" on line %d.",
1735 else if (!strcasecmp(value
, "group"))
1737 loc
->level
= AUTH_GROUP
;
1739 cupsdLogMessage(CUPSD_LOG_WARN
,
1740 "\"AuthClass %s\" is deprecated; consider using "
1741 "\"Require @groupname\" on line %d.",
1744 else if (!strcasecmp(value
, "system"))
1746 loc
->level
= AUTH_GROUP
;
1748 cupsdAddName(loc
, "@SYSTEM");
1750 cupsdLogMessage(CUPSD_LOG_WARN
,
1751 "\"AuthClass %s\" is deprecated; consider using "
1752 "\"Require @SYSTEM\" on line %d.",
1757 cupsdLogMessage(CUPSD_LOG_WARN
,
1758 "Unknown authorization class %s on line %d.",
1763 else if (!strcasecmp(line
, "AuthGroupName"))
1765 cupsdAddName(loc
, value
);
1767 cupsdLogMessage(CUPSD_LOG_WARN
,
1768 "\"AuthGroupName %s\" directive is deprecated; consider "
1769 "using \"Require @%s\" on line %d.",
1770 value
, value
, linenum
);
1772 else if (!strcasecmp(line
, "Require"))
1775 * Apache synonym for AuthClass and AuthGroupName...
1779 * Require valid-user
1780 * Require group names
1781 * Require user names
1784 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1789 if (!strcasecmp(value
, "valid-user") ||
1790 !strcasecmp(value
, "user"))
1791 loc
->level
= AUTH_USER
;
1792 else if (!strcasecmp(value
, "group"))
1793 loc
->level
= AUTH_GROUP
;
1796 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1802 * Get the list of names from the line...
1805 for (value
= valptr
; *value
;)
1807 while (isspace(*value
& 255))
1810 if (*value
== '\"' || *value
== '\'')
1813 * Grab quoted name...
1816 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1823 * Grab literal name.
1826 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1832 cupsdAddName(loc
, value
);
1834 for (value
= valptr
; isspace(*value
& 255); value
++);
1837 else if (!strcasecmp(line
, "Satisfy"))
1839 if (!strcasecmp(value
, "all"))
1840 loc
->satisfy
= AUTH_SATISFY_ALL
;
1841 else if (!strcasecmp(value
, "any"))
1842 loc
->satisfy
= AUTH_SATISFY_ANY
;
1845 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1858 * 'parse_groups()' - Parse system group names in a string.
1861 static int /* O - 1 on success, 0 on failure */
1862 parse_groups(const char *s
) /* I - Space-delimited groups */
1864 int status
; /* Return status */
1865 char value
[1024], /* Value string */
1866 *valstart
, /* Pointer into value */
1867 *valend
, /* End of value */
1868 quote
; /* Quote character */
1869 struct group
*group
; /* Group */
1873 * Make a copy of the string and parse out the groups...
1876 strlcpy(value
, s
, sizeof(value
));
1881 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1883 if (*valstart
== '\'' || *valstart
== '\"')
1886 * Scan quoted name...
1889 quote
= *valstart
++;
1891 for (valend
= valstart
; *valend
; valend
++)
1892 if (*valend
== quote
)
1898 * Scan space or comma-delimited name...
1901 for (valend
= valstart
; *valend
; valend
++)
1902 if (isspace(*valend
) || *valend
== ',')
1909 group
= getgrnam(valstart
);
1912 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1913 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1924 while (*valstart
== ',' || isspace(*valstart
))
1933 * 'parse_protocols()' - Parse browse protocols in a string.
1936 static int /* O - Browse protocol bits */
1937 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1939 int protocols
; /* Browse protocol bits */
1940 char value
[1024], /* Value string */
1941 *valstart
, /* Pointer into value */
1942 *valend
; /* End of value */
1946 * Loop through the value string,...
1949 strlcpy(value
, s
, sizeof(value
));
1953 for (valstart
= value
; *valstart
;)
1956 * Get the current space/comma-delimited protocol name...
1959 for (valend
= valstart
; *valend
; valend
++)
1960 if (isspace(*valend
& 255) || *valend
== ',')
1967 * Add the protocol to the bitmask...
1970 if (!strcasecmp(valstart
, "cups"))
1971 protocols
|= BROWSE_CUPS
;
1972 else if (!strcasecmp(valstart
, "slp"))
1973 protocols
|= BROWSE_SLP
;
1974 else if (!strcasecmp(valstart
, "ldap"))
1975 protocols
|= BROWSE_LDAP
;
1976 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
1977 protocols
|= BROWSE_DNSSD
;
1978 else if (!strcasecmp(valstart
, "all"))
1979 protocols
|= BROWSE_ALL
;
1983 for (valstart
= valend
; *valstart
; valstart
++)
1984 if (!isspace(*valstart
& 255) || *valstart
!= ',')
1993 * 'read_configuration()' - Read a configuration file.
1996 static int /* O - 1 on success, 0 on failure */
1997 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1999 int i
; /* Looping var */
2000 int linenum
; /* Current line number */
2001 char line
[HTTP_MAX_BUFFER
],
2002 /* Line from file */
2003 temp
[HTTP_MAX_BUFFER
],
2004 /* Temporary buffer for value */
2005 temp2
[HTTP_MAX_BUFFER
],
2006 /* Temporary buffer 2 for value */
2007 *ptr
, /* Pointer into line/temp */
2008 *value
, /* Pointer to value */
2009 *valueptr
; /* Pointer into value */
2010 int valuelen
; /* Length of value */
2011 cupsd_var_t
*var
; /* Current variable */
2012 http_addrlist_t
*addrlist
, /* Address list */
2013 *addr
; /* Current address */
2014 unsigned ip
[4], /* Address value */
2015 mask
[4]; /* Netmask value */
2016 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2017 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2018 cupsd_location_t
*location
; /* Browse location */
2019 cups_file_t
*incfile
; /* Include file */
2020 char incname
[1024]; /* Include filename */
2021 struct group
*group
; /* Group */
2025 * Loop through each line in the file...
2030 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2033 * Decode the directive...
2036 if (!strcasecmp(line
, "Include"))
2042 if (value
[0] == '/')
2043 strlcpy(incname
, value
, sizeof(incname
));
2045 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2047 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2048 cupsdLogMessage(CUPSD_LOG_ERROR
,
2049 "Unable to include config file \"%s\" - %s",
2050 incname
, strerror(errno
));
2053 read_configuration(incfile
);
2054 cupsFileClose(incfile
);
2057 else if (!strcasecmp(line
, "<Location"))
2065 linenum
= read_location(fp
, value
, linenum
);
2071 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2076 else if (!strcasecmp(line
, "<Policy"))
2084 linenum
= read_policy(fp
, value
, linenum
);
2090 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2094 else if (!strcasecmp(line
, "FaxRetryInterval"))
2098 JobRetryInterval
= atoi(value
);
2099 cupsdLogMessage(CUPSD_LOG_WARN
,
2100 "FaxRetryInterval is deprecated; use "
2101 "JobRetryInterval on line %d.", linenum
);
2105 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2109 else if (!strcasecmp(line
, "FaxRetryLimit"))
2113 JobRetryLimit
= atoi(value
);
2114 cupsdLogMessage(CUPSD_LOG_WARN
,
2115 "FaxRetryLimit is deprecated; use "
2116 "JobRetryLimit on line %d.", linenum
);
2120 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2124 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2126 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2127 #endif /* HAVE_SSL */
2131 * Add listening address(es) to the list...
2134 cupsd_listener_t
*lis
; /* New listeners array */
2138 * Get the address list...
2141 addrlist
= get_address(value
, IPP_PORT
);
2145 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2151 * Add each address...
2154 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2157 * Allocate another listener...
2161 Listeners
= cupsArrayNew(NULL
, NULL
);
2165 cupsdLogMessage(CUPSD_LOG_ERROR
,
2166 "Unable to allocate %s at line %d - %s.",
2167 line
, linenum
, strerror(errno
));
2171 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2173 cupsdLogMessage(CUPSD_LOG_ERROR
,
2174 "Unable to allocate %s at line %d - %s.",
2175 line
, linenum
, strerror(errno
));
2179 cupsArrayAdd(Listeners
, lis
);
2182 * Copy the current address and log it...
2185 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2189 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2190 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2191 #endif /* HAVE_SSL */
2193 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2196 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2197 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2198 ntohs(lis
->address
.ipv6
.sin6_port
));
2200 #endif /* AF_INET6 */
2202 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2203 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2205 #endif /* AF_LOCAL */
2206 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2207 ntohs(lis
->address
.ipv4
.sin_port
));
2214 httpAddrFreeList(addrlist
);
2216 else if (!strcasecmp(line
, "BrowseAddress"))
2219 * Add a browse address to the list...
2222 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2225 if (NumBrowsers
== 0)
2226 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2228 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2232 cupsdLogMessage(CUPSD_LOG_ERROR
,
2233 "Unable to allocate BrowseAddress at line %d - %s.",
2234 linenum
, strerror(errno
));
2239 dira
+= NumBrowsers
;
2241 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2243 if (!strcasecmp(value
, "@LOCAL"))
2246 * Send browse data to all local interfaces...
2249 strcpy(dira
->iface
, "*");
2252 else if (!strncasecmp(value
, "@IF(", 4))
2255 * Send browse data to the named interface...
2258 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2260 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2266 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2269 * Only IPv4 addresses are supported...
2272 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2273 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2278 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2279 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2281 cupsdLogMessage(CUPSD_LOG_INFO
,
2282 "Sending browsing info to %s:%d (IPv4)",
2283 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2288 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2291 httpAddrFreeList(addrlist
);
2294 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2297 else if (!strcasecmp(line
, "BrowseOrder"))
2300 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2303 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2304 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2306 if (location
== NULL
)
2307 cupsdLogMessage(CUPSD_LOG_ERROR
,
2308 "Unable to initialize browse access control list!");
2309 else if (!strncasecmp(value
, "deny", 4))
2310 location
->order_type
= AUTH_ALLOW
;
2311 else if (!strncasecmp(value
, "allow", 5))
2312 location
->order_type
= AUTH_DENY
;
2314 cupsdLogMessage(CUPSD_LOG_ERROR
,
2315 "Unknown BrowseOrder value %s on line %d.",
2318 else if (!strcasecmp(line
, "BrowseProtocols") ||
2319 !strcasecmp(line
, "BrowseLocalProtocols") ||
2320 !strcasecmp(line
, "BrowseRemoteProtocols"))
2323 * "BrowseProtocols name [... name]"
2324 * "BrowseLocalProtocols name [... name]"
2325 * "BrowseRemoteProtocols name [... name]"
2328 int protocols
= parse_protocols(value
);
2332 cupsdLogMessage(CUPSD_LOG_ERROR
,
2333 "Unknown browse protocol \"%s\" on line %d.",
2338 if (strcasecmp(line
, "BrowseLocalProtocols"))
2339 BrowseRemoteProtocols
= protocols
;
2340 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2341 BrowseLocalProtocols
= protocols
;
2343 else if (!strcasecmp(line
, "BrowseAllow") ||
2344 !strcasecmp(line
, "BrowseDeny"))
2347 * BrowseAllow [From] host/ip...
2348 * BrowseDeny [From] host/ip...
2351 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2352 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2354 if (location
== NULL
)
2355 cupsdLogMessage(CUPSD_LOG_ERROR
,
2356 "Unable to initialize browse access control list!");
2359 if (!strncasecmp(value
, "from ", 5))
2362 * Strip leading "from"...
2367 while (isspace(*value
))
2372 * Figure out what form the allow/deny address takes:
2383 * nnn.nnn.nnn.nnn/mm
2384 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2387 if (!strcasecmp(value
, "all"))
2393 if (!strcasecmp(line
, "BrowseAllow"))
2394 cupsdAllowIP(location
, zeros
, zeros
);
2396 cupsdDenyIP(location
, zeros
, zeros
);
2398 else if (!strcasecmp(value
, "none"))
2404 if (!strcasecmp(line
, "BrowseAllow"))
2405 cupsdAllowIP(location
, ones
, zeros
);
2407 cupsdDenyIP(location
, ones
, zeros
);
2409 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2412 * Host or domain name...
2415 if (value
[0] == '*')
2418 if (!strcasecmp(line
, "BrowseAllow"))
2419 cupsdAllowHost(location
, value
);
2421 cupsdDenyHost(location
, value
);
2426 * One of many IP address forms...
2429 if (!get_addr_and_mask(value
, ip
, mask
))
2431 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2436 if (!strcasecmp(line
, "BrowseAllow"))
2437 cupsdAllowIP(location
, ip
, mask
);
2439 cupsdDenyIP(location
, ip
, mask
);
2443 else if (!strcasecmp(line
, "BrowseRelay"))
2446 * BrowseRelay [from] source [to] destination
2450 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2452 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2456 cupsdLogMessage(CUPSD_LOG_ERROR
,
2457 "Unable to allocate BrowseRelay at line %d - %s.",
2458 linenum
, strerror(errno
));
2465 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2467 if (!strncasecmp(value
, "from ", 5))
2470 * Strip leading "from"...
2475 while (isspace(*value
))
2480 * Figure out what form the from address takes:
2489 * nnn.nnn.nnn.nnn/mm
2490 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2493 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2496 * Host or domain name...
2499 if (value
[0] == '*')
2502 strlcpy(temp
, value
, sizeof(temp
));
2503 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2506 relay
->from
.type
= AUTH_NAME
;
2507 relay
->from
.mask
.name
.name
= strdup(temp
);
2508 relay
->from
.mask
.name
.length
= strlen(temp
);
2513 * One of many IP address forms...
2516 if (!get_addr_and_mask(value
, ip
, mask
))
2518 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2523 relay
->from
.type
= AUTH_IP
;
2524 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2525 sizeof(relay
->from
.mask
.ip
.address
));
2526 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2527 sizeof(relay
->from
.mask
.ip
.netmask
));
2531 * Skip value and trailing whitespace...
2534 for (; *value
; value
++)
2535 if (isspace(*value
))
2538 while (isspace(*value
))
2541 if (!strncasecmp(value
, "to ", 3))
2544 * Strip leading "to"...
2549 while (isspace(*value
))
2554 * Get "to" address and port...
2557 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2560 * Only IPv4 addresses are supported...
2563 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2564 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2569 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2571 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2573 if (relay
->from
.type
== AUTH_IP
)
2574 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2575 relay
->from
.mask
.ip
.address
[0],
2576 relay
->from
.mask
.ip
.address
[1],
2577 relay
->from
.mask
.ip
.address
[2],
2578 relay
->from
.mask
.ip
.address
[3],
2579 relay
->from
.mask
.ip
.netmask
[0],
2580 relay
->from
.mask
.ip
.netmask
[1],
2581 relay
->from
.mask
.ip
.netmask
[2],
2582 relay
->from
.mask
.ip
.netmask
[3]);
2584 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2586 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2587 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2592 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2595 httpAddrFreeList(addrlist
);
2599 if (relay
->from
.type
== AUTH_NAME
)
2600 free(relay
->from
.mask
.name
.name
);
2602 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2606 else if (!strcasecmp(line
, "BrowsePoll"))
2609 * BrowsePoll address[:port]
2612 char *portname
; /* Port name */
2613 int portnum
; /* Port number */
2614 struct servent
*service
; /* Service */
2618 * Extract the port name from the address...
2621 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2625 if (isdigit(*portname
& 255))
2626 portnum
= atoi(portname
);
2627 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2628 portnum
= ntohs(service
->s_port
);
2631 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2637 portnum
= ippPort();
2640 * Add the poll entry...
2644 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2646 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2650 cupsdLogMessage(CUPSD_LOG_ERROR
,
2651 "Unable to allocate BrowsePoll at line %d - %s.",
2652 linenum
, strerror(errno
));
2660 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2662 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2663 pollp
->port
= portnum
;
2665 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2668 else if (!strcasecmp(line
, "DefaultAuthType"))
2671 * DefaultAuthType {basic,digest,basicdigest}
2674 if (!strcasecmp(value
, "basic"))
2675 DefaultAuthType
= AUTH_BASIC
;
2676 else if (!strcasecmp(value
, "digest"))
2677 DefaultAuthType
= AUTH_DIGEST
;
2678 else if (!strcasecmp(value
, "basicdigest"))
2679 DefaultAuthType
= AUTH_BASICDIGEST
;
2682 cupsdLogMessage(CUPSD_LOG_WARN
,
2683 "Unknown default authorization type %s on line %d.",
2689 else if (!strcasecmp(line
, "DefaultEncryption"))
2692 * DefaultEncryption {Never,IfRequested,Required}
2695 if (!value
|| !strcasecmp(value
, "never"))
2696 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2697 else if (!strcasecmp(value
, "required"))
2698 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2699 else if (!strcasecmp(value
, "ifrequested"))
2700 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2703 cupsdLogMessage(CUPSD_LOG_WARN
,
2704 "Unknown default encryption %s on line %d.",
2709 #endif /* HAVE_SSL */
2710 else if (!strcasecmp(line
, "User"))
2713 * User ID to run as...
2716 if (value
&& isdigit(value
[0] & 255))
2718 int uid
= atoi(value
);
2721 cupsdLogMessage(CUPSD_LOG_ERROR
,
2722 "Will not use User 0 as specified on line %d "
2723 "for security reasons. You must use a non-"
2724 "privileged account instead.",
2731 struct passwd
*p
; /* Password information */
2734 p
= getpwnam(value
);
2739 cupsdLogMessage(CUPSD_LOG_ERROR
,
2740 "Will not use User %s (UID=0) as specified on line "
2741 "%d for security reasons. You must use a non-"
2742 "privileged account instead.",
2748 cupsdLogMessage(CUPSD_LOG_ERROR
,
2749 "Unknown User \"%s\" on line %d, ignoring!",
2753 cupsdLogMessage(CUPSD_LOG_ERROR
,
2754 "User directive on line %d missing the username!",
2757 else if (!strcasecmp(line
, "Group"))
2760 * Group ID to run as...
2763 if (isdigit(value
[0]))
2764 Group
= atoi(value
);
2768 group
= getgrnam(value
);
2771 Group
= group
->gr_gid
;
2773 cupsdLogMessage(CUPSD_LOG_ERROR
,
2774 "Unknown Group \"%s\" on line %d, ignoring!",
2778 else if (!strcasecmp(line
, "SystemGroup"))
2781 * SystemGroup (admin) group(s)...
2784 if (!parse_groups(value
))
2785 cupsdLogMessage(CUPSD_LOG_ERROR
,
2786 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2789 else if (!strcasecmp(line
, "HostNameLookups"))
2792 * Do hostname lookups?
2795 if (!strcasecmp(value
, "off"))
2796 HostNameLookups
= 0;
2797 else if (!strcasecmp(value
, "on"))
2798 HostNameLookups
= 1;
2799 else if (!strcasecmp(value
, "double"))
2800 HostNameLookups
= 2;
2802 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2805 else if (!strcasecmp(line
, "LogLevel"))
2808 * Amount of logging to do...
2811 if (!strcasecmp(value
, "debug2"))
2812 LogLevel
= CUPSD_LOG_DEBUG2
;
2813 else if (!strcasecmp(value
, "debug"))
2814 LogLevel
= CUPSD_LOG_DEBUG
;
2815 else if (!strcasecmp(value
, "info"))
2816 LogLevel
= CUPSD_LOG_INFO
;
2817 else if (!strcasecmp(value
, "notice"))
2818 LogLevel
= CUPSD_LOG_NOTICE
;
2819 else if (!strcasecmp(value
, "warn"))
2820 LogLevel
= CUPSD_LOG_WARN
;
2821 else if (!strcasecmp(value
, "error"))
2822 LogLevel
= CUPSD_LOG_ERROR
;
2823 else if (!strcasecmp(value
, "crit"))
2824 LogLevel
= CUPSD_LOG_CRIT
;
2825 else if (!strcasecmp(value
, "alert"))
2826 LogLevel
= CUPSD_LOG_ALERT
;
2827 else if (!strcasecmp(value
, "emerg"))
2828 LogLevel
= CUPSD_LOG_EMERG
;
2829 else if (!strcasecmp(value
, "none"))
2830 LogLevel
= CUPSD_LOG_NONE
;
2832 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2835 else if (!strcasecmp(line
, "PrintcapFormat"))
2838 * Format of printcap file?
2841 if (!strcasecmp(value
, "bsd"))
2842 PrintcapFormat
= PRINTCAP_BSD
;
2843 else if (!strcasecmp(value
, "solaris"))
2844 PrintcapFormat
= PRINTCAP_SOLARIS
;
2846 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2849 else if (!strcasecmp(line
, "ServerTokens"))
2852 * Set the string used for the Server header...
2855 struct utsname plat
; /* Platform info */
2860 if (!strcasecmp(value
, "ProductOnly"))
2861 cupsdSetString(&ServerHeader
, "CUPS");
2862 else if (!strcasecmp(value
, "Major"))
2863 cupsdSetString(&ServerHeader
, "CUPS/1");
2864 else if (!strcasecmp(value
, "Minor"))
2865 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2866 else if (!strcasecmp(value
, "Minimal"))
2867 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2868 else if (!strcasecmp(value
, "OS"))
2869 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2870 else if (!strcasecmp(value
, "Full"))
2871 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2873 else if (!strcasecmp(value
, "None"))
2874 cupsdClearString(&ServerHeader
);
2876 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2879 else if (!strcasecmp(line
, "PassEnv"))
2882 * PassEnv variable [... variable]
2887 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2888 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2891 if (value
[valuelen
])
2893 value
[valuelen
] = '\0';
2897 cupsdSetEnv(value
, NULL
);
2899 for (value
+= valuelen
; *value
; value
++)
2900 if (!isspace(*value
) || *value
!= ',')
2904 else if (!strcasecmp(line
, "SetEnv"))
2907 * SetEnv variable value
2910 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2918 while (isspace(*valueptr
& 255))
2921 cupsdSetEnv(value
, valueptr
);
2924 cupsdLogMessage(CUPSD_LOG_ERROR
,
2925 "Missing value for SetEnv directive on line %d.",
2931 * Find a simple variable in the list...
2934 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2935 if (!strcasecmp(line
, var
->name
))
2941 * Unknown directive! Output an error message and continue...
2944 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2951 case CUPSD_VARTYPE_INTEGER
:
2953 cupsdLogMessage(CUPSD_LOG_ERROR
,
2954 "Missing integer value for %s on line %d!",
2959 char *units
; /* Units */
2962 n
= strtol(value
, &units
, 0);
2964 if (units
&& *units
)
2966 if (tolower(units
[0] & 255) == 'g')
2967 n
*= 1024 * 1024 * 1024;
2968 else if (tolower(units
[0] & 255) == 'm')
2970 else if (tolower(units
[0] & 255) == 'k')
2972 else if (tolower(units
[0] & 255) == 't')
2976 *((int *)var
->ptr
) = n
;
2980 case CUPSD_VARTYPE_BOOLEAN
:
2982 cupsdLogMessage(CUPSD_LOG_ERROR
,
2983 "Missing boolean value for %s on line %d!",
2985 else if (!strcasecmp(value
, "true") ||
2986 !strcasecmp(value
, "on") ||
2987 !strcasecmp(value
, "enabled") ||
2988 !strcasecmp(value
, "yes") ||
2990 *((int *)var
->ptr
) = TRUE
;
2991 else if (!strcasecmp(value
, "false") ||
2992 !strcasecmp(value
, "off") ||
2993 !strcasecmp(value
, "disabled") ||
2994 !strcasecmp(value
, "no") ||
2995 !strcasecmp(value
, "0"))
2996 *((int *)var
->ptr
) = FALSE
;
2998 cupsdLogMessage(CUPSD_LOG_ERROR
,
2999 "Unknown boolean value %s on line %d.",
3003 case CUPSD_VARTYPE_STRING
:
3004 cupsdSetString((char **)var
->ptr
, value
);
3015 * 'read_location()' - Read a <Location path> definition.
3018 static int /* O - New line number or 0 on error */
3019 read_location(cups_file_t
*fp
, /* I - Configuration file */
3020 char *location
, /* I - Location name/path */
3021 int linenum
) /* I - Current line number */
3023 cupsd_location_t
*loc
, /* New location */
3024 *parent
; /* Parent location */
3025 char line
[HTTP_MAX_BUFFER
],
3027 *value
, /* Value for directive */
3028 *valptr
; /* Pointer into value */
3031 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3034 parent
->limit
= AUTH_LIMIT_ALL
;
3037 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3040 * Decode the directive...
3043 if (!strcasecmp(line
, "</Location>"))
3045 else if (!strcasecmp(line
, "<Limit") ||
3046 !strcasecmp(line
, "<LimitExcept"))
3050 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3054 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3060 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3065 if (!strcmp(value
, "ALL"))
3066 loc
->limit
= AUTH_LIMIT_ALL
;
3067 else if (!strcmp(value
, "GET"))
3068 loc
->limit
|= AUTH_LIMIT_GET
;
3069 else if (!strcmp(value
, "HEAD"))
3070 loc
->limit
|= AUTH_LIMIT_HEAD
;
3071 else if (!strcmp(value
, "OPTIONS"))
3072 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3073 else if (!strcmp(value
, "POST"))
3074 loc
->limit
|= AUTH_LIMIT_POST
;
3075 else if (!strcmp(value
, "PUT"))
3076 loc
->limit
|= AUTH_LIMIT_PUT
;
3077 else if (!strcmp(value
, "TRACE"))
3078 loc
->limit
|= AUTH_LIMIT_TRACE
;
3080 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3083 for (value
= valptr
; isspace(*value
& 255); value
++);
3086 if (!strcasecmp(line
, "<LimitExcept"))
3087 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3089 parent
->limit
&= ~loc
->limit
;
3091 else if (!strcasecmp(line
, "</Limit>"))
3093 else if (!parse_aaa(loc
, line
, value
, linenum
))
3095 cupsdLogMessage(CUPSD_LOG_ERROR
,
3096 "Unknown Location directive %s on line %d.",
3102 cupsdLogMessage(CUPSD_LOG_ERROR
,
3103 "Unexpected end-of-file at line %d while reading location!",
3111 * 'read_policy()' - Read a <Policy name> definition.
3114 static int /* O - New line number or 0 on error */
3115 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3116 char *policy
, /* I - Location name/path */
3117 int linenum
) /* I - Current line number */
3119 int i
; /* Looping var */
3120 cupsd_policy_t
*pol
; /* Policy */
3121 cupsd_location_t
*op
; /* Policy operation */
3122 int num_ops
; /* Number of IPP operations */
3123 ipp_op_t ops
[100]; /* Operations */
3124 char line
[HTTP_MAX_BUFFER
],
3126 *value
, /* Value for directive */
3127 *valptr
; /* Pointer into value */
3131 * Create the policy...
3134 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3138 * Read from the file...
3144 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3147 * Decode the directive...
3150 if (!strcasecmp(line
, "</Policy>"))
3153 cupsdLogMessage(CUPSD_LOG_WARN
,
3154 "Missing </Limit> before </Policy> on line %d!",
3159 else if (!strcasecmp(line
, "<Limit") && !op
)
3163 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3168 * Scan for IPP operation names...
3175 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3180 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3182 if (!strcasecmp(value
, "All"))
3183 ops
[num_ops
] = IPP_ANY_OPERATION
;
3184 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3185 cupsdLogMessage(CUPSD_LOG_ERROR
,
3186 "Bad IPP operation name \"%s\" on line %d!",
3192 cupsdLogMessage(CUPSD_LOG_ERROR
,
3193 "Too many operations listed on line %d!",
3196 for (value
= valptr
; isspace(*value
& 255); value
++);
3200 * If none are specified, apply the policy to all operations...
3205 ops
[0] = IPP_ANY_OPERATION
;
3210 * Add a new policy for the first operation...
3213 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3215 else if (!strcasecmp(line
, "</Limit>") && op
)
3218 * Finish the current operation limit...
3224 * Copy the policy to the other operations...
3227 for (i
= 1; i
< num_ops
; i
++)
3228 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3235 cupsdLogMessage(CUPSD_LOG_ERROR
,
3236 "Missing <Limit ops> directive before %s on line %d.",
3240 else if (!parse_aaa(op
, line
, value
, linenum
))
3243 cupsdLogMessage(CUPSD_LOG_ERROR
,
3244 "Unknown Policy Limit directive %s on line %d.",
3247 cupsdLogMessage(CUPSD_LOG_ERROR
,
3248 "Unknown Policy directive %s on line %d.",
3255 cupsdLogMessage(CUPSD_LOG_ERROR
,
3256 "Unexpected end-of-file at line %d while reading policy \"%s\"!",
3264 * End of "$Id: conf.c 5482 2006-05-02 18:13:40Z mike $".