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();
259 for (i
= 0; i
< NumRelays
; i
++)
260 if (Relays
[i
].from
.type
== AUTH_NAME
)
261 free(Relays
[i
].from
.mask
.name
.name
);
268 cupsdDeleteAllListeners();
274 cupsdSetString(&ServerName
, httpGetHostname(temp
, sizeof(temp
)));
275 cupsdSetStringf(&ServerAdmin
, "root@%s", temp
);
276 cupsdSetString(&ServerBin
, CUPS_SERVERBIN
);
277 cupsdSetString(&RequestRoot
, CUPS_REQUESTS
);
278 cupsdSetString(&CacheDir
, CUPS_CACHEDIR
);
279 cupsdSetString(&DataDir
, CUPS_DATADIR
);
280 cupsdSetString(&DocumentRoot
, CUPS_DOCROOT
);
281 cupsdSetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
282 cupsdSetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
283 cupsdSetString(&PageLog
, CUPS_LOGDIR
"/page_log");
284 cupsdSetString(&Printcap
, "/etc/printcap");
285 cupsdSetString(&PrintcapGUI
, "/usr/bin/glpoptions");
286 cupsdSetString(&FontPath
, CUPS_FONTPATH
);
287 cupsdSetString(&RemoteRoot
, "remroot");
288 cupsdSetString(&ServerHeader
, "CUPS/1.2");
289 cupsdSetString(&StateDir
, CUPS_STATEDIR
);
291 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
292 if ((slash
= strrchr(temp
, '/')) != NULL
)
295 cupsdSetString(&ServerRoot
, temp
);
297 cupsdClearString(&Classification
);
298 ClassifyOverride
= 0;
302 cupsdSetString(&ServerCertificate
, "/Library/Keychains/System.keychain");
304 cupsdSetString(&ServerCertificate
, "ssl/server.crt");
305 cupsdSetString(&ServerKey
, "ssl/server.key");
306 # endif /* HAVE_CDSASSL */
307 #endif /* HAVE_SSL */
309 language
= cupsLangDefault();
311 if (!strcmp(language
->language
, "C") || !strcmp(language
->language
, "POSIX"))
312 cupsdSetString(&DefaultLanguage
, "en");
314 cupsdSetString(&DefaultLanguage
, language
->language
);
316 cupsdSetString(&DefaultCharset
, _cupsEncodingName(language
->encoding
));
318 cupsdSetString(&RIPCache
, "8m");
320 cupsdSetString(&TempDir
, NULL
);
323 * Find the default user...
326 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) != NULL
)
331 * Use the (historical) NFS nobody user ID (-2 as a 16-bit twos-
332 * complement number...)
341 * Find the default group (nobody)...
344 group
= getgrnam("nobody");
348 Group
= group
->gr_gid
;
352 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
353 * complement number...)
363 ConfigFilePerm
= CUPS_DEFAULT_CONFIG_FILE_PERM
;
364 DefaultAuthType
= AUTH_BASIC
;
366 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
367 #endif /* HAVE_SSL */
369 JobRetryInterval
= 300;
374 HostNameLookups
= FALSE
;
375 ImplicitClasses
= CUPS_DEFAULT_IMPLICIT_CLASSES
;
376 ImplicitAnyClasses
= FALSE
;
377 HideImplicitMembers
= TRUE
;
379 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
380 ListenBackLog
= SOMAXCONN
;
381 LogFilePerm
= CUPS_DEFAULT_LOG_FILE_PERM
;
382 LogLevel
= CUPSD_LOG_ERROR
;
384 MaxClientsPerHost
= 0;
385 MaxLogSize
= 1024 * 1024;
386 MaxPrinterHistory
= 10;
389 RootCertDuration
= 300;
390 Timeout
= DEFAULT_TIMEOUT
;
393 BrowseInterval
= DEFAULT_INTERVAL
;
394 BrowsePort
= ippPort();
395 BrowseLocalProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS
);
396 BrowseRemoteProtocols
= parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS
);
397 BrowseShortNames
= CUPS_DEFAULT_BROWSE_SHORT_NAMES
;
398 BrowseTimeout
= DEFAULT_TIMEOUT
;
399 Browsing
= CUPS_DEFAULT_BROWSING
;
400 DefaultShared
= CUPS_DEFAULT_DEFAULT_SHARED
;
402 cupsdClearString(&BrowseLocalOptions
);
403 cupsdClearString(&BrowseRemoteOptions
);
406 cupsdClearString(&BrowseLDAPBindDN
);
407 cupsdClearString(&BrowseLDAPDN
);
408 cupsdClearString(&BrowseLDAPPassword
);
409 cupsdClearString(&BrowseLDAPServer
);
410 #endif /* HAVE_LDAP */
412 JobHistory
= DEFAULT_HISTORY
;
413 JobFiles
= DEFAULT_FILES
;
418 MaxJobsPerPrinter
= 0;
421 cupsdDeleteAllPolicies();
422 cupsdClearString(&DefaultPolicy
);
424 MaxSubscriptions
= 100;
425 MaxSubscriptionsPerJob
= 0;
426 MaxSubscriptionsPerPrinter
= 0;
427 MaxSubscriptionsPerUser
= 0;
428 DefaultLeaseDuration
= 86400;
429 MaxLeaseDuration
= 0;
432 LaunchdTimeout
= DEFAULT_TIMEOUT
+ 10;
433 cupsdSetString(&LaunchdConf
, CUPS_DEFAULT_LAUNCHD_CONF
);
434 #endif /* HAVE_LAUNCHD */
437 * Read the configuration file...
440 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
443 status
= read_configuration(fp
);
453 * Use the default system group if none was supplied in cupsd.conf...
456 if (NumSystemGroups
== 0)
458 if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS
))
461 * Find the group associated with GID 0...
468 cupsdSetString(&SystemGroups
[0], group
->gr_name
);
470 cupsdSetString(&SystemGroups
[0], "unknown");
472 SystemGroupIDs
[0] = 0;
478 * Get the access control list for browsing...
481 BrowseACL
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL");
484 * Open the system log for cupsd if necessary...
488 if (!strcmp(AccessLog
, "syslog") ||
489 !strcmp(ErrorLog
, "syslog") ||
490 !strcmp(PageLog
, "syslog"))
491 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
492 #endif /* HAVE_VSYSLOG */
495 * Log the configuration file that was used...
498 cupsdLogMessage(CUPSD_LOG_INFO
, "Loaded configuration file \"%s\"",
502 * Validate the Group and SystemGroup settings - they cannot be the same,
503 * otherwise the CGI programs will be able to authenticate as root without
509 for (i
= 0; i
< NumSystemGroups
; i
++)
510 if (Group
== SystemGroupIDs
[i
])
513 if (i
< NumSystemGroups
)
516 * Log the error and reset the group to a safe value...
519 cupsdLogMessage(CUPSD_LOG_NOTICE
,
520 "Group and SystemGroup cannot use the same groups!");
521 cupsdLogMessage(CUPSD_LOG_INFO
, "Resetting Group to \"nobody\"...");
523 group
= getgrnam("nobody");
527 Group
= group
->gr_gid
;
531 * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
532 * complement number...)
541 * Check that we have at least one listen/port line; if not, report this
542 * as an error and exit!
545 if (cupsArrayCount(Listeners
) == 0)
551 cupsdLogMessage(CUPSD_LOG_EMERG
,
552 "No valid Listen or Port lines were found in the configuration file!");
558 cupsdEndProcess(getpid(), 0);
562 * Set the default locale using the language and charset...
565 cupsdSetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
568 * Update all relative filenames to include the full path from ServerRoot...
571 if (DocumentRoot
[0] != '/')
572 cupsdSetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
574 if (RequestRoot
[0] != '/')
575 cupsdSetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
577 if (ServerBin
[0] != '/')
578 cupsdSetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
580 if (StateDir
[0] != '/')
581 cupsdSetStringf(&StateDir
, "%s/%s", ServerRoot
, StateDir
);
583 if (CacheDir
[0] != '/')
584 cupsdSetStringf(&CacheDir
, "%s/%s", ServerRoot
, CacheDir
);
587 if (ServerCertificate
[0] != '/')
588 cupsdSetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
590 if (!strncmp(ServerRoot
, ServerCertificate
, strlen(ServerRoot
)))
592 chown(ServerCertificate
, RunUser
, Group
);
593 chmod(ServerCertificate
, 0600);
596 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
597 if (ServerKey
[0] != '/')
598 cupsdSetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
600 if (!strncmp(ServerRoot
, ServerKey
, strlen(ServerRoot
)))
602 chown(ServerKey
, RunUser
, Group
);
603 chmod(ServerKey
, 0600);
605 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
606 #endif /* HAVE_SSL */
609 * Make sure that directories and config files are owned and
610 * writable by the user and group in the cupsd.conf file...
613 check_permissions(CacheDir
, NULL
, 0775, RunUser
, Group
, 1, 1);
614 /* check_permissions(CacheDir, "ppd", 0755, RunUser, Group, 1, 1);*/
616 check_permissions(StateDir
, NULL
, 0755, RunUser
, Group
, 1, 1);
617 check_permissions(StateDir
, "certs", RunUser
? 0711 : 0511, User
,
618 SystemGroupIDs
[0], 1, 1);
620 check_permissions(ServerRoot
, NULL
, 0755, RunUser
, Group
, 1, 0);
621 check_permissions(ServerRoot
, "ppd", 0755, RunUser
, Group
, 1, 1);
622 check_permissions(ServerRoot
, "ssl", 0700, RunUser
, Group
, 1, 0);
623 check_permissions(ServerRoot
, "cupsd.conf", ConfigFilePerm
, RunUser
, Group
,
625 check_permissions(ServerRoot
, "classes.conf", 0600, RunUser
, Group
, 0, 0);
626 check_permissions(ServerRoot
, "printers.conf", 0600, RunUser
, Group
, 0, 0);
627 check_permissions(ServerRoot
, "passwd.md5", 0600, User
, Group
, 0, 0);
630 * Update TempDir to the default if it hasn't been set already...
635 if ((tmpdir
= getenv("TMPDIR")) != NULL
)
638 * TMPDIR is defined, see if it is OK for us to use...
641 if (stat(tmpdir
, &tmpinfo
))
642 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to access TMPDIR (%s): %s",
643 tmpdir
, strerror(errno
));
644 else if (!S_ISDIR(tmpinfo
.st_mode
))
645 cupsdLogMessage(CUPSD_LOG_ERROR
, "TMPDIR (%s) is not a directory!",
647 else if ((tmpinfo
.st_uid
!= User
|| !(tmpinfo
.st_mode
& S_IWUSR
)) &&
648 (tmpinfo
.st_gid
!= Group
|| !(tmpinfo
.st_mode
& S_IWGRP
)) &&
649 !(tmpinfo
.st_mode
& S_IWOTH
))
650 cupsdLogMessage(CUPSD_LOG_ERROR
,
651 "TMPDIR (%s) has the wrong permissions!", tmpdir
);
653 cupsdSetString(&TempDir
, tmpdir
);
656 cupsdLogMessage(CUPSD_LOG_INFO
, "Using default TempDir of %s/tmp...",
661 cupsdSetStringf(&TempDir
, "%s/tmp", RequestRoot
);
665 * Make sure the request and temporary directories have the right
669 check_permissions(RequestRoot
, NULL
, 0710, RunUser
, Group
, 1, 1);
671 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
675 * Update ownership and permissions if the CUPS temp directory
676 * is under the spool directory or does not exist...
679 check_permissions(TempDir
, NULL
, 01770, RunUser
, Group
, 1, 1);
682 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
685 * Clean out the temporary directory...
688 cups_dir_t
*dir
; /* Temporary directory */
689 cups_dentry_t
*dent
; /* Directory entry */
690 char tempfile
[1024]; /* Temporary filename */
693 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
695 cupsdLogMessage(CUPSD_LOG_INFO
,
696 "Cleaning out old temporary files in \"%s\"...", TempDir
);
698 while ((dent
= cupsDirRead(dir
)) != NULL
)
700 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
702 if (unlink(tempfile
))
703 cupsdLogMessage(CUPSD_LOG_ERROR
,
704 "Unable to remove temporary file \"%s\" - %s",
705 tempfile
, strerror(errno
));
707 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removed temporary file \"%s\"...",
714 cupsdLogMessage(CUPSD_LOG_ERROR
,
715 "Unable to open temporary directory \"%s\" - %s",
716 TempDir
, strerror(errno
));
720 * Setup environment variables...
726 * Check the MaxClients setting, and then allocate memory for it...
729 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
732 cupsdLogMessage(CUPSD_LOG_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
735 MaxClients
= MaxFDs
/ 3;
738 cupsdLogMessage(CUPSD_LOG_INFO
, "Configured for up to %d clients.",
742 * Check the MaxActiveJobs setting; limit to 1/3 the available
743 * file descriptors, since we need a pipe for each job...
746 if (MaxActiveJobs
> (MaxFDs
/ 3))
747 MaxActiveJobs
= MaxFDs
/ 3;
749 if (Classification
&& strcasecmp(Classification
, "none") == 0)
750 cupsdClearString(&Classification
);
753 cupsdLogMessage(CUPSD_LOG_INFO
, "Security set to \"%s\"", Classification
);
756 * Update the MaxClientsPerHost value, as needed...
759 if (MaxClientsPerHost
<= 0)
760 MaxClientsPerHost
= MaxClients
;
762 if (MaxClientsPerHost
> MaxClients
)
763 MaxClientsPerHost
= MaxClients
;
765 cupsdLogMessage(CUPSD_LOG_INFO
,
766 "Allowing up to %d client connections per host.",
770 * Update the default policy, as needed...
774 DefaultPolicyPtr
= cupsdFindPolicy(DefaultPolicy
);
776 DefaultPolicyPtr
= NULL
;
778 if (!DefaultPolicyPtr
)
780 cupsd_policy_t
*p
; /* New policy */
781 cupsd_location_t
*po
; /* New policy operation */
785 cupsdLogMessage(CUPSD_LOG_ERROR
, "Default policy \"%s\" not found!",
788 if ((DefaultPolicyPtr
= cupsdFindPolicy("default")) != NULL
)
789 cupsdLogMessage(CUPSD_LOG_INFO
,
790 "Using policy \"default\" as the default!");
793 cupsdLogMessage(CUPSD_LOG_INFO
,
794 "Creating CUPS default administrative policy:");
796 DefaultPolicyPtr
= p
= cupsdAddPolicy("default");
798 cupsdLogMessage(CUPSD_LOG_INFO
, "<Policy default>");
799 cupsdLogMessage(CUPSD_LOG_INFO
,
800 "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
801 "Release-Job Restart-Job Purge-Jobs "
802 "Set-Job-Attributes Create-Job-Subscription "
803 "Renew-Subscription Cancel-Subscription "
804 "Get-Notifications Reprocess-Job Cancel-Current-Job "
805 "Suspend-Current-Job Resume-Job CUPS-Move-Job "
806 "CUPS-Authenticate-Job>");
807 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
809 po
= cupsdAddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
810 po
->order_type
= AUTH_ALLOW
;
811 po
->level
= AUTH_USER
;
813 cupsdAddName(po
, "@OWNER");
814 cupsdAddName(po
, "@SYSTEM");
815 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @OWNER @SYSTEM");
817 cupsdAddPolicyOp(p
, po
, IPP_SEND_URI
);
818 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
819 cupsdAddPolicyOp(p
, po
, IPP_HOLD_JOB
);
820 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
821 cupsdAddPolicyOp(p
, po
, IPP_RESTART_JOB
);
822 cupsdAddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
823 cupsdAddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
824 cupsdAddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
825 cupsdAddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
826 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
827 cupsdAddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
828 cupsdAddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
829 cupsdAddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
830 cupsdAddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
831 cupsdAddPolicyOp(p
, po
, IPP_RESUME_JOB
);
832 cupsdAddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
833 cupsdAddPolicyOp(p
, po
, CUPS_AUTHENTICATE_JOB
);
835 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
837 cupsdLogMessage(CUPSD_LOG_INFO
,
838 "<Limit Pause-Printer Resume-Printer "
839 "Set-Printer-Attributes Enable-Printer "
840 "Disable-Printer Pause-Printer-After-Current-Job "
841 "Hold-New-Jobs Release-Held-New-Jobs "
842 "Deactivate-Printer Activate-Printer Restart-Printer "
843 "Shutdown-Printer Startup-Printer Promote-Job "
844 "Schedule-Job-After CUPS-Add-Printer "
845 "CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
846 "CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
847 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
848 cupsdLogMessage(CUPSD_LOG_INFO
, "AuthType Basic");
850 po
= cupsdAddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
851 po
->order_type
= AUTH_ALLOW
;
852 po
->type
= AUTH_BASIC
;
853 po
->level
= AUTH_USER
;
855 cupsdAddName(po
, "@SYSTEM");
856 cupsdLogMessage(CUPSD_LOG_INFO
, "Require user @SYSTEM");
858 cupsdAddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
859 cupsdAddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
860 cupsdAddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
861 cupsdAddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
862 cupsdAddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
863 cupsdAddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
864 cupsdAddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
865 cupsdAddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
866 cupsdAddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
867 cupsdAddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
868 cupsdAddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
869 cupsdAddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
870 cupsdAddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
871 cupsdAddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
872 cupsdAddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
873 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
874 cupsdAddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
875 cupsdAddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
876 cupsdAddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
877 cupsdAddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
878 cupsdAddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
880 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
882 cupsdLogMessage(CUPSD_LOG_INFO
, "<Limit All>");
883 cupsdLogMessage(CUPSD_LOG_INFO
, "Order Deny,Allow");
885 po
= cupsdAddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
886 po
->order_type
= AUTH_ALLOW
;
888 cupsdLogMessage(CUPSD_LOG_INFO
, "</Limit>");
889 cupsdLogMessage(CUPSD_LOG_INFO
, "</Policy>");
893 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: NumPolicies=%d",
895 for (i
= 0; i
< NumPolicies
; i
++)
896 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
897 "cupsdReadConfiguration: Policies[%d]=\"%s\"", i
,
901 * If we are doing a full reload or the server root has changed, flush
902 * the jobs, printers, etc. and start from scratch...
905 if (NeedReload
== RELOAD_ALL
||
906 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
907 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
909 mime_type_t
*type
; /* Current type */
910 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
914 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload is required.");
920 cupsdDeleteAllSubscriptions();
922 cupsdDeleteAllClasses();
923 cupsdDeleteAllPrinters();
925 DefaultPrinter
= NULL
;
927 if (MimeDatabase
!= NULL
)
928 mimeDelete(MimeDatabase
);
932 for (i
= 0; i
< NumMimeTypes
; i
++)
933 _cups_sp_free(MimeTypes
[i
]);
939 * Read the MIME type and conversion database...
942 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
944 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
948 cupsdLogMessage(CUPSD_LOG_EMERG
,
949 "Unable to load MIME database from \'%s\'!", ServerRoot
);
953 cupsdLogMessage(CUPSD_LOG_INFO
,
954 "Loaded MIME database from \'%s\': %d types, %d filters...",
955 ServerRoot
, mimeNumTypes(MimeDatabase
),
956 mimeNumFilters(MimeDatabase
));
959 * Create a list of MIME types for the document-format-supported
963 NumMimeTypes
= mimeNumTypes(MimeDatabase
);
964 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
967 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
969 for (i
= 0, type
= mimeFirstType(MimeDatabase
);
971 i
++, type
= mimeNextType(MimeDatabase
))
973 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
975 MimeTypes
[i
] = _cups_sp_alloc(mimetype
);
978 if (i
< NumMimeTypes
)
979 MimeTypes
[i
] = _cups_sp_alloc("application/octet-stream");
981 if (LogLevel
== CUPSD_LOG_DEBUG2
)
983 mime_filter_t
*filter
; /* Current filter */
986 for (type
= mimeFirstType(MimeDatabase
);
988 type
= mimeNextType(MimeDatabase
))
989 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdReadConfiguration: type %s/%s",
990 type
->super
, type
->type
);
992 for (filter
= mimeFirstFilter(MimeDatabase
);
994 filter
= mimeNextFilter(MimeDatabase
))
995 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
996 "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
997 filter
->src
->super
, filter
->src
->type
,
998 filter
->dst
->super
, filter
->dst
->type
,
999 filter
->cost
, filter
->filter
);
1006 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
1007 cupsdLoadBanners(temp
);
1010 * Load printers and classes...
1013 cupsdLoadAllPrinters();
1014 cupsdLoadAllClasses();
1015 cupsdLoadRemoteCache();
1016 cupsdWritePrintcap();
1018 cupsdCreateCommonData();
1021 * Load queued jobs...
1027 * Load subscriptions...
1030 cupsdLoadAllSubscriptions();
1032 cupsdLogMessage(CUPSD_LOG_INFO
, "Full reload complete.");
1037 * Not a full reload, so recreate the common printer attributes...
1040 cupsdCreateCommonData();
1043 * Update all printers as needed...
1046 cupsdUpdatePrinters();
1047 cupsdWritePrintcap();
1049 cupsdLogMessage(CUPSD_LOG_INFO
, "Partial reload complete.");
1053 * Reset the reload state...
1056 NeedReload
= RELOAD_NONE
;
1058 cupsdClearString(&old_serverroot
);
1059 cupsdClearString(&old_requestroot
);
1066 * 'check_permissions()' - Fix the mode and ownership of a file or directory.
1069 static int /* O - 0 on success, -1 on error */
1070 check_permissions(const char *filename
, /* I - File/directory name */
1071 const char *suffix
, /* I - Additional file/directory name */
1072 int mode
, /* I - Permissions */
1073 int user
, /* I - Owner */
1074 int group
, /* I - Group */
1075 int is_dir
, /* I - 1 = directory, 0 = file */
1076 int create_dir
)/* I - 1 = create directory, 0 = not */
1078 int dir_created
= 0; /* Did we create a directory? */
1079 char pathname
[1024]; /* File name with prefix */
1080 struct stat fileinfo
; /* Stat buffer */
1084 * Prepend the given root to the filename before testing it...
1089 snprintf(pathname
, sizeof(pathname
), "%s/%s", filename
, suffix
);
1090 filename
= pathname
;
1094 * See if we can stat the file/directory...
1097 if (stat(filename
, &fileinfo
))
1099 if (errno
== ENOENT
&& create_dir
)
1101 cupsdLogMessage(CUPSD_LOG_ERROR
, "Creating missing directory \"%s\"",
1104 if (mkdir(filename
, mode
))
1106 cupsdLogMessage(CUPSD_LOG_ERROR
,
1107 "Unable to create directory \"%s\" - %s", filename
,
1119 * Make sure it's a regular file...
1122 if (!dir_created
&& !is_dir
&& !S_ISREG(fileinfo
.st_mode
))
1124 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a regular file!", filename
);
1128 if (!dir_created
&& is_dir
&& !S_ISDIR(fileinfo
.st_mode
))
1130 cupsdLogMessage(CUPSD_LOG_ERROR
, "\"%s\" is not a directory!", filename
);
1135 * Fix owner, group, and mode as needed...
1138 if (dir_created
|| fileinfo
.st_uid
!= user
|| fileinfo
.st_gid
!= group
)
1140 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing ownership of \"%s\"", filename
);
1142 if (chown(filename
, user
, group
))
1144 cupsdLogMessage(CUPSD_LOG_ERROR
,
1145 "Unable to change ownership of \"%s\" - %s", filename
,
1151 if (dir_created
|| (fileinfo
.st_mode
& 07777) != mode
)
1153 cupsdLogMessage(CUPSD_LOG_WARN
, "Repairing access permissions of \"%s\"", filename
);
1155 if (chmod(filename
, mode
))
1157 cupsdLogMessage(CUPSD_LOG_ERROR
,
1158 "Unable to change permissions of \"%s\" - %s", filename
,
1165 * Everything is OK...
1173 * 'get_address()' - Get an address + port number from a line.
1176 static http_addrlist_t
* /* O - Pointer to list if address good, NULL if bad */
1177 get_address(const char *value
, /* I - Value string */
1178 int defport
) /* I - Default port */
1180 char buffer
[1024], /* Hostname + port number buffer */
1181 defpname
[255], /* Default port name */
1182 *hostname
, /* Hostname or IP */
1183 *portname
; /* Port number or name */
1184 http_addrlist_t
*addrlist
; /* Address list */
1188 * Check for an empty value...
1193 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad (empty) address!");
1198 * Grab a hostname and port number; if there is no colon and the port name
1199 * is only digits, then we have a port number by itself...
1202 strlcpy(buffer
, value
, sizeof(buffer
));
1204 if ((portname
= strrchr(buffer
, ':')) != NULL
&& !strchr(portname
, ']'))
1211 for (portname
= buffer
; isdigit(*portname
& 255); portname
++);
1216 * Use the default port...
1219 sprintf(defpname
, "%d", defport
);
1220 portname
= defpname
;
1226 * The buffer contains just a port number...
1234 if (hostname
&& !strcmp(hostname
, "*"))
1238 * Now lookup the address using httpAddrGetList()...
1241 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
1242 cupsdLogMessage(CUPSD_LOG_ERROR
, "Hostname lookup for \"%s\" failed!",
1243 hostname
? hostname
: "(nil)");
1250 * 'get_addr_and_mask()' - Get an IP address and netmask.
1253 static int /* O - 1 on success, 0 on failure */
1254 get_addr_and_mask(const char *value
, /* I - String from config file */
1255 unsigned *ip
, /* O - Address value */
1256 unsigned *mask
) /* O - Mask value */
1258 int i
, j
, /* Looping vars */
1259 family
, /* Address family */
1260 ipcount
; /* Count of fields in address */
1261 unsigned ipval
; /* Value */
1262 const char *maskval
, /* Pointer to start of mask value */
1263 *ptr
, /* Pointer into value */
1265 static unsigned netmasks
[4][4] = /* Standard IPv4 netmasks... */
1267 { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
1268 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1269 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
1270 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1273 static unsigned netmasks6
[8][4] = /* Standard IPv6 netmasks... */
1275 { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
1276 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
1277 { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
1278 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
1279 { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
1280 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
1281 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
1282 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
1284 #endif /* AF_INET6 */
1288 * Get the address...
1291 memset(ip
, 0, sizeof(unsigned) * 4);
1293 if ((maskval
= strchr(value
, '/')) != NULL
)
1296 maskval
= value
+ strlen(value
);
1300 * Check for an IPv6 address...
1306 * Parse hexadecimal IPv6 address...
1311 for (i
= 0, ptr
= value
+ 1; *ptr
&& i
< 8; i
++)
1315 else if (!strncmp(ptr
, "::", 2))
1317 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1319 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1323 else if (isxdigit(*ptr
& 255))
1325 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1333 ip
[i
] |= ipval
<< 16;
1344 if (*ptr
&& *ptr
!= '/')
1348 #endif /* AF_INET6 */
1351 * Parse dotted-decimal IPv4 address...
1355 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1357 ip
[3] |= ((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8;
1358 ip
[0] = ip
[1] = ip
[2] = 0;
1364 * Get the netmask value(s)...
1367 memset(mask
, 0, sizeof(unsigned) * 4);
1370 if (*maskval
== '[')
1373 * Get hexadecimal mask value...
1376 for (i
= 0, ptr
= maskval
+ 1; *ptr
&& i
< 8; i
++)
1380 else if (!strncmp(ptr
, "::", 2))
1382 for (ptr2
= strchr(ptr
+ 2, ':'), j
= 0;
1384 ptr2
= strchr(ptr2
+ 1, ':'), j
++);
1388 else if (isxdigit(*ptr
& 255))
1390 ipval
= strtoul(ptr
, (char **)&ptr
, 16);
1398 mask
[i
] |= ipval
<< 16;
1411 #endif /* AF_INET6 */
1412 if (strchr(maskval
, '.'))
1415 * Get dotted-decimal mask...
1418 if (sscanf(maskval
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1, mask
+ 2, mask
+ 3) != 4)
1421 mask
[3] |= ((((mask
[0] << 8) | mask
[1]) << 8) | mask
[2]) << 8;
1422 mask
[0] = mask
[1] = mask
[2] = 0;
1427 * Get address/bits format...
1433 if (family
== AF_INET6
)
1438 mask
[0] = 0xffffffff;
1440 mask
[0] = (0xffffffff << (i
- 96)) & 0xffffffff;
1443 mask
[1] = 0xffffffff;
1447 mask
[1] = (0xffffffff << (i
- 64)) & 0xffffffff;
1450 mask
[2] = 0xffffffff;
1454 mask
[2] = (0xffffffff << (i
- 32)) & 0xffffffff;
1457 mask
[3] = 0xffffffff;
1461 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1464 #endif /* AF_INET6 */
1468 mask
[0] = 0xffffffff;
1469 mask
[1] = 0xffffffff;
1470 mask
[2] = 0xffffffff;
1473 mask
[3] = (0xffffffff << i
) & 0xffffffff;
1475 mask
[3] = 0xffffffff;
1480 else if (family
== AF_INET6
)
1481 memcpy(mask
, netmasks6
[ipcount
- 1], sizeof(unsigned) * 4);
1482 #endif /* AF_INET6 */
1484 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
1486 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1487 "get_addr_and_mask(value=\"%s\", "
1488 "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
1489 value
, ip
[0], ip
[1], ip
[2], ip
[3], mask
[0], mask
[1], mask
[2],
1493 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
1496 if ((ip
[0] & ~mask
[0]) != 0 ||
1497 (ip
[1] & ~mask
[1]) != 0 ||
1498 (ip
[2] & ~mask
[2]) != 0 ||
1499 (ip
[3] & ~mask
[3]) != 0)
1507 * 'parse_aaa()' - Parse authentication, authorization, and access control lines.
1510 static int /* O - 1 on success, 0 on failure */
1511 parse_aaa(cupsd_location_t
*loc
, /* I - Location */
1512 char *line
, /* I - Line from file */
1513 char *value
, /* I - Start of value data */
1514 int linenum
) /* I - Current line number */
1516 char *valptr
; /* Pointer into value */
1517 unsigned ip
[4], /* IP address components */
1518 mask
[4]; /* IP netmask components */
1521 if (!strcasecmp(line
, "Encryption"))
1524 * "Encryption xxx" - set required encryption level...
1527 if (!strcasecmp(value
, "never"))
1528 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1529 else if (!strcasecmp(value
, "always"))
1531 cupsdLogMessage(CUPSD_LOG_ERROR
,
1532 "Encryption value \"%s\" on line %d is invalid in this "
1533 "context. Using \"required\" instead.", value
, linenum
);
1535 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1537 else if (!strcasecmp(value
, "required"))
1538 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1539 else if (!strcasecmp(value
, "ifrequested"))
1540 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1543 cupsdLogMessage(CUPSD_LOG_ERROR
,
1544 "Unknown Encryption value %s on line %d.", value
, linenum
);
1548 else if (!strcasecmp(line
, "Order"))
1551 * "Order Deny,Allow" or "Order Allow,Deny"...
1554 if (!strncasecmp(value
, "deny", 4))
1555 loc
->order_type
= AUTH_ALLOW
;
1556 else if (!strncasecmp(value
, "allow", 5))
1557 loc
->order_type
= AUTH_DENY
;
1560 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown Order value %s on line %d.",
1565 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1568 * Allow [From] host/ip...
1569 * Deny [From] host/ip...
1572 if (!strncasecmp(value
, "from", 4))
1575 * Strip leading "from"...
1580 while (isspace(*value
& 255))
1585 * Figure out what form the allow/deny address takes:
1596 * nnn.nnn.nnn.nnn/mm
1597 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1600 if (!strcasecmp(value
, "all"))
1606 if (!strcasecmp(line
, "Allow"))
1607 cupsdAllowIP(loc
, zeros
, zeros
);
1609 cupsdDenyIP(loc
, zeros
, zeros
);
1611 else if (!strcasecmp(value
, "none"))
1617 if (!strcasecmp(line
, "Allow"))
1618 cupsdAllowIP(loc
, ones
, zeros
);
1620 cupsdDenyIP(loc
, ones
, zeros
);
1622 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1625 * Host or domain name...
1628 if (value
[0] == '*')
1631 if (!strcasecmp(line
, "Allow"))
1632 cupsdAllowHost(loc
, value
);
1634 cupsdDenyHost(loc
, value
);
1639 * One of many IP address forms...
1642 if (!get_addr_and_mask(value
, ip
, mask
))
1644 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
1649 if (!strcasecmp(line
, "Allow"))
1650 cupsdAllowIP(loc
, ip
, mask
);
1652 cupsdDenyIP(loc
, ip
, mask
);
1655 else if (!strcasecmp(line
, "AuthType"))
1658 * AuthType {none,basic,digest,basicdigest}
1661 if (!strcasecmp(value
, "none"))
1663 loc
->type
= AUTH_NONE
;
1664 loc
->level
= AUTH_ANON
;
1666 else if (!strcasecmp(value
, "basic"))
1668 loc
->type
= AUTH_BASIC
;
1670 if (loc
->level
== AUTH_ANON
)
1671 loc
->level
= AUTH_USER
;
1673 else if (!strcasecmp(value
, "digest"))
1675 loc
->type
= AUTH_DIGEST
;
1677 if (loc
->level
== AUTH_ANON
)
1678 loc
->level
= AUTH_USER
;
1680 else if (!strcasecmp(value
, "basicdigest"))
1682 loc
->type
= AUTH_BASICDIGEST
;
1684 if (loc
->level
== AUTH_ANON
)
1685 loc
->level
= AUTH_USER
;
1689 cupsdLogMessage(CUPSD_LOG_WARN
,
1690 "Unknown authorization type %s on line %d.",
1695 else if (!strcasecmp(line
, "AuthClass"))
1698 * AuthClass anonymous, user, system, group
1701 if (!strcasecmp(value
, "anonymous"))
1703 loc
->type
= AUTH_NONE
;
1704 loc
->level
= AUTH_ANON
;
1706 cupsdLogMessage(CUPSD_LOG_WARN
,
1707 "\"AuthClass %s\" is deprecated; consider removing "
1711 else if (!strcasecmp(value
, "user"))
1713 loc
->level
= AUTH_USER
;
1715 cupsdLogMessage(CUPSD_LOG_WARN
,
1716 "\"AuthClass %s\" is deprecated; consider using "
1717 "\"Require valid-user\" on line %d.",
1720 else if (!strcasecmp(value
, "group"))
1722 loc
->level
= AUTH_GROUP
;
1724 cupsdLogMessage(CUPSD_LOG_WARN
,
1725 "\"AuthClass %s\" is deprecated; consider using "
1726 "\"Require @groupname\" on line %d.",
1729 else if (!strcasecmp(value
, "system"))
1731 loc
->level
= AUTH_GROUP
;
1733 cupsdAddName(loc
, "@SYSTEM");
1735 cupsdLogMessage(CUPSD_LOG_WARN
,
1736 "\"AuthClass %s\" is deprecated; consider using "
1737 "\"Require @SYSTEM\" on line %d.",
1742 cupsdLogMessage(CUPSD_LOG_WARN
,
1743 "Unknown authorization class %s on line %d.",
1748 else if (!strcasecmp(line
, "AuthGroupName"))
1750 cupsdAddName(loc
, value
);
1752 cupsdLogMessage(CUPSD_LOG_WARN
,
1753 "\"AuthGroupName %s\" directive is deprecated; consider "
1754 "using \"Require @%s\" on line %d.",
1755 value
, value
, linenum
);
1757 else if (!strcasecmp(line
, "Require"))
1760 * Apache synonym for AuthClass and AuthGroupName...
1764 * Require valid-user
1765 * Require group names
1766 * Require user names
1769 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1774 if (!strcasecmp(value
, "valid-user") ||
1775 !strcasecmp(value
, "user"))
1776 loc
->level
= AUTH_USER
;
1777 else if (!strcasecmp(value
, "group"))
1778 loc
->level
= AUTH_GROUP
;
1781 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Require type %s on line %d.",
1787 * Get the list of names from the line...
1790 for (value
= valptr
; *value
;)
1792 while (isspace(*value
& 255))
1795 if (*value
== '\"' || *value
== '\'')
1798 * Grab quoted name...
1801 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
1808 * Grab literal name.
1811 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1817 cupsdAddName(loc
, value
);
1819 for (value
= valptr
; isspace(*value
& 255); value
++);
1822 else if (!strcasecmp(line
, "Satisfy"))
1824 if (!strcasecmp(value
, "all"))
1825 loc
->satisfy
= AUTH_SATISFY_ALL
;
1826 else if (!strcasecmp(value
, "any"))
1827 loc
->satisfy
= AUTH_SATISFY_ANY
;
1830 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown Satisfy value %s on line %d.",
1843 * 'parse_groups()' - Parse system group names in a string.
1846 static int /* O - 1 on success, 0 on failure */
1847 parse_groups(const char *s
) /* I - Space-delimited groups */
1849 int status
; /* Return status */
1850 char value
[1024], /* Value string */
1851 *valstart
, /* Pointer into value */
1852 *valend
, /* End of value */
1853 quote
; /* Quote character */
1854 struct group
*group
; /* Group */
1858 * Make a copy of the string and parse out the groups...
1861 strlcpy(value
, s
, sizeof(value
));
1866 while (*valstart
&& NumSystemGroups
< MAX_SYSTEM_GROUPS
)
1868 if (*valstart
== '\'' || *valstart
== '\"')
1871 * Scan quoted name...
1874 quote
= *valstart
++;
1876 for (valend
= valstart
; *valend
; valend
++)
1877 if (*valend
== quote
)
1883 * Scan space or comma-delimited name...
1886 for (valend
= valstart
; *valend
; valend
++)
1887 if (isspace(*valend
) || *valend
== ',')
1894 group
= getgrnam(valstart
);
1897 cupsdSetString(SystemGroups
+ NumSystemGroups
, valstart
);
1898 SystemGroupIDs
[NumSystemGroups
] = group
->gr_gid
;
1909 while (*valstart
== ',' || isspace(*valstart
))
1918 * 'parse_protocols()' - Parse browse protocols in a string.
1921 static int /* O - Browse protocol bits */
1922 parse_protocols(const char *s
) /* I - Space-delimited protocols */
1924 int protocols
; /* Browse protocol bits */
1925 char value
[1024], /* Value string */
1926 *valstart
, /* Pointer into value */
1927 *valend
; /* End of value */
1931 * Loop through the value string,...
1934 strlcpy(value
, s
, sizeof(value
));
1938 for (valstart
= value
; *valstart
;)
1941 * Get the current space/comma-delimited protocol name...
1944 for (valend
= valstart
; *valend
; valend
++)
1945 if (isspace(*valend
& 255) || *valend
== ',')
1952 * Add the protocol to the bitmask...
1955 if (!strcasecmp(valstart
, "cups"))
1956 protocols
|= BROWSE_CUPS
;
1957 else if (!strcasecmp(valstart
, "slp"))
1958 protocols
|= BROWSE_SLP
;
1959 else if (!strcasecmp(valstart
, "ldap"))
1960 protocols
|= BROWSE_LDAP
;
1961 else if (!strcasecmp(valstart
, "dnssd") || !strcasecmp(valstart
, "bonjour"))
1962 protocols
|= BROWSE_DNSSD
;
1963 else if (!strcasecmp(valstart
, "all"))
1964 protocols
|= BROWSE_ALL
;
1968 for (valstart
= valend
; *valstart
; valstart
++)
1969 if (!isspace(*valstart
& 255) || *valstart
!= ',')
1978 * 'read_configuration()' - Read a configuration file.
1981 static int /* O - 1 on success, 0 on failure */
1982 read_configuration(cups_file_t
*fp
) /* I - File to read from */
1984 int i
; /* Looping var */
1985 int linenum
; /* Current line number */
1986 char line
[HTTP_MAX_BUFFER
],
1987 /* Line from file */
1988 temp
[HTTP_MAX_BUFFER
],
1989 /* Temporary buffer for value */
1990 temp2
[HTTP_MAX_BUFFER
],
1991 /* Temporary buffer 2 for value */
1992 *ptr
, /* Pointer into line/temp */
1993 *value
, /* Pointer to value */
1994 *valueptr
; /* Pointer into value */
1995 int valuelen
; /* Length of value */
1996 cupsd_var_t
*var
; /* Current variable */
1997 http_addrlist_t
*addrlist
, /* Address list */
1998 *addr
; /* Current address */
1999 unsigned ip
[4], /* Address value */
2000 mask
[4]; /* Netmask value */
2001 cupsd_dirsvc_relay_t
*relay
; /* Relay data */
2002 cupsd_dirsvc_poll_t
*pollp
; /* Polling data */
2003 cupsd_location_t
*location
; /* Browse location */
2004 cups_file_t
*incfile
; /* Include file */
2005 char incname
[1024]; /* Include filename */
2006 struct group
*group
; /* Group */
2010 * Loop through each line in the file...
2015 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2018 * Decode the directive...
2021 if (!strcasecmp(line
, "Include"))
2027 if (value
[0] == '/')
2028 strlcpy(incname
, value
, sizeof(incname
));
2030 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
2032 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
2033 cupsdLogMessage(CUPSD_LOG_ERROR
,
2034 "Unable to include config file \"%s\" - %s",
2035 incname
, strerror(errno
));
2038 read_configuration(incfile
);
2039 cupsFileClose(incfile
);
2042 else if (!strcasecmp(line
, "<Location"))
2050 linenum
= read_location(fp
, value
, linenum
);
2056 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.",
2061 else if (!strcasecmp(line
, "<Policy"))
2069 linenum
= read_policy(fp
, value
, linenum
);
2075 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2079 else if (!strcasecmp(line
, "FaxRetryInterval"))
2083 JobRetryInterval
= atoi(value
);
2084 cupsdLogMessage(CUPSD_LOG_WARN
,
2085 "FaxRetryInterval is deprecated; use "
2086 "JobRetryInterval on line %d.", linenum
);
2090 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2094 else if (!strcasecmp(line
, "FaxRetryLimit"))
2098 JobRetryLimit
= atoi(value
);
2099 cupsdLogMessage(CUPSD_LOG_WARN
,
2100 "FaxRetryLimit is deprecated; use "
2101 "JobRetryLimit on line %d.", linenum
);
2105 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
2109 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen")
2111 || !strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen")
2112 #endif /* HAVE_SSL */
2116 * Add listening address(es) to the list...
2119 cupsd_listener_t
*lis
; /* New listeners array */
2123 * Get the address list...
2126 addrlist
= get_address(value
, IPP_PORT
);
2130 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad %s address %s at line %d.", line
,
2136 * Add each address...
2139 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2142 * Allocate another listener...
2146 Listeners
= cupsArrayNew(NULL
, NULL
);
2150 cupsdLogMessage(CUPSD_LOG_ERROR
,
2151 "Unable to allocate %s at line %d - %s.",
2152 line
, linenum
, strerror(errno
));
2156 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
2158 cupsdLogMessage(CUPSD_LOG_ERROR
,
2159 "Unable to allocate %s at line %d - %s.",
2160 line
, linenum
, strerror(errno
));
2164 cupsArrayAdd(Listeners
, lis
);
2167 * Copy the current address and log it...
2170 memcpy(&(lis
->address
), &(addr
->addr
), sizeof(lis
->address
));
2174 if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
2175 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
2176 #endif /* HAVE_SSL */
2178 httpAddrString(&lis
->address
, temp
, sizeof(temp
));
2181 if (lis
->address
.addr
.sa_family
== AF_INET6
)
2182 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv6)", temp
,
2183 ntohs(lis
->address
.ipv6
.sin6_port
));
2185 #endif /* AF_INET6 */
2187 if (lis
->address
.addr
.sa_family
== AF_LOCAL
)
2188 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s (Domain)", temp
);
2190 #endif /* AF_LOCAL */
2191 cupsdLogMessage(CUPSD_LOG_INFO
, "Listening to %s:%d (IPv4)", temp
,
2192 ntohs(lis
->address
.ipv4
.sin_port
));
2199 httpAddrFreeList(addrlist
);
2201 else if (!strcasecmp(line
, "BrowseAddress"))
2204 * Add a browse address to the list...
2207 cupsd_dirsvc_addr_t
*dira
; /* New browse address array */
2210 if (NumBrowsers
== 0)
2211 dira
= malloc(sizeof(cupsd_dirsvc_addr_t
));
2213 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(cupsd_dirsvc_addr_t
));
2217 cupsdLogMessage(CUPSD_LOG_ERROR
,
2218 "Unable to allocate BrowseAddress at line %d - %s.",
2219 linenum
, strerror(errno
));
2224 dira
+= NumBrowsers
;
2226 memset(dira
, 0, sizeof(cupsd_dirsvc_addr_t
));
2228 if (!strcasecmp(value
, "@LOCAL"))
2231 * Send browse data to all local interfaces...
2234 strcpy(dira
->iface
, "*");
2237 else if (!strncasecmp(value
, "@IF(", 4))
2240 * Send browse data to the named interface...
2243 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
2245 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
2251 else if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2254 * Only IPv4 addresses are supported...
2257 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2258 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2263 memcpy(&(dira
->to
), &(addrlist
->addr
), sizeof(dira
->to
));
2264 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
2266 cupsdLogMessage(CUPSD_LOG_INFO
,
2267 "Sending browsing info to %s:%d (IPv4)",
2268 temp
, ntohs(dira
->to
.ipv4
.sin_port
));
2273 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2276 httpAddrFreeList(addrlist
);
2279 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad BrowseAddress %s at line %d.",
2282 else if (!strcasecmp(line
, "BrowseOrder"))
2285 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
2288 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2289 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2291 if (location
== NULL
)
2292 cupsdLogMessage(CUPSD_LOG_ERROR
,
2293 "Unable to initialize browse access control list!");
2294 else if (!strncasecmp(value
, "deny", 4))
2295 location
->order_type
= AUTH_ALLOW
;
2296 else if (!strncasecmp(value
, "allow", 5))
2297 location
->order_type
= AUTH_DENY
;
2299 cupsdLogMessage(CUPSD_LOG_ERROR
,
2300 "Unknown BrowseOrder value %s on line %d.",
2303 else if (!strcasecmp(line
, "BrowseProtocols") ||
2304 !strcasecmp(line
, "BrowseLocalProtocols") ||
2305 !strcasecmp(line
, "BrowseRemoteProtocols"))
2308 * "BrowseProtocols name [... name]"
2309 * "BrowseLocalProtocols name [... name]"
2310 * "BrowseRemoteProtocols name [... name]"
2313 int protocols
= parse_protocols(value
);
2317 cupsdLogMessage(CUPSD_LOG_ERROR
,
2318 "Unknown browse protocol \"%s\" on line %d.",
2323 if (strcasecmp(line
, "BrowseLocalProtocols"))
2324 BrowseRemoteProtocols
= protocols
;
2325 if (strcasecmp(line
, "BrowseRemoteProtocols"))
2326 BrowseLocalProtocols
= protocols
;
2328 else if (!strcasecmp(line
, "BrowseAllow") ||
2329 !strcasecmp(line
, "BrowseDeny"))
2332 * BrowseAllow [From] host/ip...
2333 * BrowseDeny [From] host/ip...
2336 if ((location
= cupsdFindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
2337 location
= cupsdAddLocation("CUPS_INTERNAL_BROWSE_ACL");
2339 if (location
== NULL
)
2340 cupsdLogMessage(CUPSD_LOG_ERROR
,
2341 "Unable to initialize browse access control list!");
2344 if (!strncasecmp(value
, "from ", 5))
2347 * Strip leading "from"...
2352 while (isspace(*value
))
2357 * Figure out what form the allow/deny address takes:
2368 * nnn.nnn.nnn.nnn/mm
2369 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2372 if (!strcasecmp(value
, "all"))
2378 if (!strcasecmp(line
, "BrowseAllow"))
2379 cupsdAllowIP(location
, zeros
, zeros
);
2381 cupsdDenyIP(location
, zeros
, zeros
);
2383 else if (!strcasecmp(value
, "none"))
2389 if (!strcasecmp(line
, "BrowseAllow"))
2390 cupsdAllowIP(location
, ones
, zeros
);
2392 cupsdDenyIP(location
, ones
, zeros
);
2394 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2397 * Host or domain name...
2400 if (value
[0] == '*')
2403 if (!strcasecmp(line
, "BrowseAllow"))
2404 cupsdAllowHost(location
, value
);
2406 cupsdDenyHost(location
, value
);
2411 * One of many IP address forms...
2414 if (!get_addr_and_mask(value
, ip
, mask
))
2416 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2421 if (!strcasecmp(line
, "BrowseAllow"))
2422 cupsdAllowIP(location
, ip
, mask
);
2424 cupsdDenyIP(location
, ip
, mask
);
2428 else if (!strcasecmp(line
, "BrowseRelay"))
2431 * BrowseRelay [from] source [to] destination
2435 relay
= malloc(sizeof(cupsd_dirsvc_relay_t
));
2437 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(cupsd_dirsvc_relay_t
));
2441 cupsdLogMessage(CUPSD_LOG_ERROR
,
2442 "Unable to allocate BrowseRelay at line %d - %s.",
2443 linenum
, strerror(errno
));
2450 memset(relay
, 0, sizeof(cupsd_dirsvc_relay_t
));
2452 if (!strncasecmp(value
, "from ", 5))
2455 * Strip leading "from"...
2460 while (isspace(*value
))
2465 * Figure out what form the from address takes:
2474 * nnn.nnn.nnn.nnn/mm
2475 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
2478 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
2481 * Host or domain name...
2484 if (value
[0] == '*')
2487 strlcpy(temp
, value
, sizeof(temp
));
2488 if ((ptr
= strchr(temp
, ' ')) != NULL
)
2491 relay
->from
.type
= AUTH_NAME
;
2492 relay
->from
.mask
.name
.name
= strdup(temp
);
2493 relay
->from
.mask
.name
.length
= strlen(temp
);
2498 * One of many IP address forms...
2501 if (!get_addr_and_mask(value
, ip
, mask
))
2503 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad netmask value %s on line %d.",
2508 relay
->from
.type
= AUTH_IP
;
2509 memcpy(relay
->from
.mask
.ip
.address
, ip
,
2510 sizeof(relay
->from
.mask
.ip
.address
));
2511 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
2512 sizeof(relay
->from
.mask
.ip
.netmask
));
2516 * Skip value and trailing whitespace...
2519 for (; *value
; value
++)
2520 if (isspace(*value
))
2523 while (isspace(*value
))
2526 if (!strncasecmp(value
, "to ", 3))
2529 * Strip leading "to"...
2534 while (isspace(*value
))
2539 * Get "to" address and port...
2542 if ((addrlist
= get_address(value
, BrowsePort
)) != NULL
)
2545 * Only IPv4 addresses are supported...
2548 for (addr
= addrlist
; addr
; addr
= addr
->next
)
2549 if (addr
->addr
.addr
.sa_family
== AF_INET
)
2554 memcpy(&(relay
->to
), &(addrlist
->addr
), sizeof(relay
->to
));
2556 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
2558 if (relay
->from
.type
== AUTH_IP
)
2559 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
2560 relay
->from
.mask
.ip
.address
[0],
2561 relay
->from
.mask
.ip
.address
[1],
2562 relay
->from
.mask
.ip
.address
[2],
2563 relay
->from
.mask
.ip
.address
[3],
2564 relay
->from
.mask
.ip
.netmask
[0],
2565 relay
->from
.mask
.ip
.netmask
[1],
2566 relay
->from
.mask
.ip
.netmask
[2],
2567 relay
->from
.mask
.ip
.netmask
[3]);
2569 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
2571 cupsdLogMessage(CUPSD_LOG_INFO
, "Relaying from %s to %s:%d (IPv4)",
2572 temp
, temp2
, ntohs(relay
->to
.ipv4
.sin_port
));
2577 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2580 httpAddrFreeList(addrlist
);
2584 if (relay
->from
.type
== AUTH_NAME
)
2585 free(relay
->from
.mask
.name
.name
);
2587 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad relay address %s at line %d.",
2591 else if (!strcasecmp(line
, "BrowsePoll"))
2594 * BrowsePoll address[:port]
2597 char *portname
; /* Port name */
2598 int portnum
; /* Port number */
2599 struct servent
*service
; /* Service */
2603 * Extract the port name from the address...
2606 if ((portname
= strrchr(value
, ':')) != NULL
&& !strchr(portname
, ']'))
2610 if (isdigit(*portname
& 255))
2611 portnum
= atoi(portname
);
2612 else if ((service
= getservbyname(portname
, NULL
)) != NULL
)
2613 portnum
= ntohs(service
->s_port
);
2616 cupsdLogMessage(CUPSD_LOG_ERROR
, "Lookup of service \"%s\" failed!",
2622 portnum
= ippPort();
2625 * Add the poll entry...
2629 pollp
= malloc(sizeof(cupsd_dirsvc_poll_t
));
2631 pollp
= realloc(Polled
, (NumPolled
+ 1) * sizeof(cupsd_dirsvc_poll_t
));
2635 cupsdLogMessage(CUPSD_LOG_ERROR
,
2636 "Unable to allocate BrowsePoll at line %d - %s.",
2637 linenum
, strerror(errno
));
2645 memset(pollp
, 0, sizeof(cupsd_dirsvc_poll_t
));
2647 strlcpy(pollp
->hostname
, value
, sizeof(pollp
->hostname
));
2648 pollp
->port
= portnum
;
2650 cupsdLogMessage(CUPSD_LOG_INFO
, "Polling %s:%d", pollp
->hostname
,
2653 else if (!strcasecmp(line
, "DefaultAuthType"))
2656 * DefaultAuthType {basic,digest,basicdigest}
2659 if (!strcasecmp(value
, "basic"))
2660 DefaultAuthType
= AUTH_BASIC
;
2661 else if (!strcasecmp(value
, "digest"))
2662 DefaultAuthType
= AUTH_DIGEST
;
2663 else if (!strcasecmp(value
, "basicdigest"))
2664 DefaultAuthType
= AUTH_BASICDIGEST
;
2667 cupsdLogMessage(CUPSD_LOG_WARN
,
2668 "Unknown default authorization type %s on line %d.",
2674 else if (!strcasecmp(line
, "DefaultEncryption"))
2677 * DefaultEncryption {Never,IfRequested,Required}
2680 if (!value
|| !strcasecmp(value
, "never"))
2681 DefaultEncryption
= HTTP_ENCRYPT_NEVER
;
2682 else if (!strcasecmp(value
, "required"))
2683 DefaultEncryption
= HTTP_ENCRYPT_REQUIRED
;
2684 else if (!strcasecmp(value
, "ifrequested"))
2685 DefaultEncryption
= HTTP_ENCRYPT_IF_REQUESTED
;
2688 cupsdLogMessage(CUPSD_LOG_WARN
,
2689 "Unknown default encryption %s on line %d.",
2694 #endif /* HAVE_SSL */
2695 else if (!strcasecmp(line
, "User"))
2698 * User ID to run as...
2701 if (value
&& isdigit(value
[0] & 255))
2703 int uid
= atoi(value
);
2706 cupsdLogMessage(CUPSD_LOG_ERROR
,
2707 "Will not use User 0 as specified on line %d "
2708 "for security reasons. You must use a non-"
2709 "privileged account instead.",
2716 struct passwd
*p
; /* Password information */
2719 p
= getpwnam(value
);
2724 cupsdLogMessage(CUPSD_LOG_ERROR
,
2725 "Will not use User %s (UID=0) as specified on line "
2726 "%d for security reasons. You must use a non-"
2727 "privileged account instead.",
2733 cupsdLogMessage(CUPSD_LOG_ERROR
,
2734 "Unknown User \"%s\" on line %d, ignoring!",
2738 cupsdLogMessage(CUPSD_LOG_ERROR
,
2739 "User directive on line %d missing the username!",
2742 else if (!strcasecmp(line
, "Group"))
2745 * Group ID to run as...
2748 if (isdigit(value
[0]))
2749 Group
= atoi(value
);
2753 group
= getgrnam(value
);
2756 Group
= group
->gr_gid
;
2758 cupsdLogMessage(CUPSD_LOG_ERROR
,
2759 "Unknown Group \"%s\" on line %d, ignoring!",
2763 else if (!strcasecmp(line
, "SystemGroup"))
2766 * SystemGroup (admin) group(s)...
2769 if (!parse_groups(value
))
2770 cupsdLogMessage(CUPSD_LOG_ERROR
,
2771 "Unknown SystemGroup \"%s\" on line %d, ignoring!",
2774 else if (!strcasecmp(line
, "HostNameLookups"))
2777 * Do hostname lookups?
2780 if (!strcasecmp(value
, "off"))
2781 HostNameLookups
= 0;
2782 else if (!strcasecmp(value
, "on"))
2783 HostNameLookups
= 1;
2784 else if (!strcasecmp(value
, "double"))
2785 HostNameLookups
= 2;
2787 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown HostNameLookups %s on line %d.",
2790 else if (!strcasecmp(line
, "LogLevel"))
2793 * Amount of logging to do...
2796 if (!strcasecmp(value
, "debug2"))
2797 LogLevel
= CUPSD_LOG_DEBUG2
;
2798 else if (!strcasecmp(value
, "debug"))
2799 LogLevel
= CUPSD_LOG_DEBUG
;
2800 else if (!strcasecmp(value
, "info"))
2801 LogLevel
= CUPSD_LOG_INFO
;
2802 else if (!strcasecmp(value
, "notice"))
2803 LogLevel
= CUPSD_LOG_NOTICE
;
2804 else if (!strcasecmp(value
, "warn"))
2805 LogLevel
= CUPSD_LOG_WARN
;
2806 else if (!strcasecmp(value
, "error"))
2807 LogLevel
= CUPSD_LOG_ERROR
;
2808 else if (!strcasecmp(value
, "crit"))
2809 LogLevel
= CUPSD_LOG_CRIT
;
2810 else if (!strcasecmp(value
, "alert"))
2811 LogLevel
= CUPSD_LOG_ALERT
;
2812 else if (!strcasecmp(value
, "emerg"))
2813 LogLevel
= CUPSD_LOG_EMERG
;
2814 else if (!strcasecmp(value
, "none"))
2815 LogLevel
= CUPSD_LOG_NONE
;
2817 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown LogLevel %s on line %d.",
2820 else if (!strcasecmp(line
, "PrintcapFormat"))
2823 * Format of printcap file?
2826 if (!strcasecmp(value
, "bsd"))
2827 PrintcapFormat
= PRINTCAP_BSD
;
2828 else if (!strcasecmp(value
, "solaris"))
2829 PrintcapFormat
= PRINTCAP_SOLARIS
;
2831 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown PrintcapFormat %s on line %d.",
2834 else if (!strcasecmp(line
, "ServerTokens"))
2837 * Set the string used for the Server header...
2840 struct utsname plat
; /* Platform info */
2845 if (!strcasecmp(value
, "ProductOnly"))
2846 cupsdSetString(&ServerHeader
, "CUPS");
2847 else if (!strcasecmp(value
, "Major"))
2848 cupsdSetString(&ServerHeader
, "CUPS/1");
2849 else if (!strcasecmp(value
, "Minor"))
2850 cupsdSetString(&ServerHeader
, "CUPS/1.2");
2851 else if (!strcasecmp(value
, "Minimal"))
2852 cupsdSetString(&ServerHeader
, CUPS_MINIMAL
);
2853 else if (!strcasecmp(value
, "OS"))
2854 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
2855 else if (!strcasecmp(value
, "Full"))
2856 cupsdSetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1",
2858 else if (!strcasecmp(value
, "None"))
2859 cupsdClearString(&ServerHeader
);
2861 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown ServerTokens %s on line %d.",
2864 else if (!strcasecmp(line
, "PassEnv"))
2867 * PassEnv variable [... variable]
2872 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
2873 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
2876 if (value
[valuelen
])
2878 value
[valuelen
] = '\0';
2882 cupsdSetEnv(value
, NULL
);
2884 for (value
+= valuelen
; *value
; value
++)
2885 if (!isspace(*value
) || *value
!= ',')
2889 else if (!strcasecmp(line
, "SetEnv"))
2892 * SetEnv variable value
2895 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
2903 while (isspace(*valueptr
& 255))
2906 cupsdSetEnv(value
, valueptr
);
2909 cupsdLogMessage(CUPSD_LOG_ERROR
,
2910 "Missing value for SetEnv directive on line %d.",
2916 * Find a simple variable in the list...
2919 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
2920 if (!strcasecmp(line
, var
->name
))
2926 * Unknown directive! Output an error message and continue...
2929 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unknown directive %s on line %d.",
2936 case CUPSD_VARTYPE_INTEGER
:
2939 char *units
; /* Units */
2942 n
= strtol(value
, &units
, 0);
2944 if (units
&& *units
)
2946 if (tolower(units
[0] & 255) == 'g')
2947 n
*= 1024 * 1024 * 1024;
2948 else if (tolower(units
[0] & 255) == 'm')
2950 else if (tolower(units
[0] & 255) == 'k')
2952 else if (tolower(units
[0] & 255) == 't')
2956 *((int *)var
->ptr
) = n
;
2960 case CUPSD_VARTYPE_BOOLEAN
:
2961 if (!strcasecmp(value
, "true") ||
2962 !strcasecmp(value
, "on") ||
2963 !strcasecmp(value
, "enabled") ||
2964 !strcasecmp(value
, "yes") ||
2966 *((int *)var
->ptr
) = TRUE
;
2967 else if (!strcasecmp(value
, "false") ||
2968 !strcasecmp(value
, "off") ||
2969 !strcasecmp(value
, "disabled") ||
2970 !strcasecmp(value
, "no") ||
2971 !strcasecmp(value
, "0"))
2972 *((int *)var
->ptr
) = FALSE
;
2974 cupsdLogMessage(CUPSD_LOG_ERROR
,
2975 "Unknown boolean value %s on line %d.",
2979 case CUPSD_VARTYPE_STRING
:
2980 cupsdSetString((char **)var
->ptr
, value
);
2991 * 'read_location()' - Read a <Location path> definition.
2994 static int /* O - New line number or 0 on error */
2995 read_location(cups_file_t
*fp
, /* I - Configuration file */
2996 char *location
, /* I - Location name/path */
2997 int linenum
) /* I - Current line number */
2999 cupsd_location_t
*loc
, /* New location */
3000 *parent
; /* Parent location */
3001 char line
[HTTP_MAX_BUFFER
],
3003 *value
, /* Value for directive */
3004 *valptr
; /* Pointer into value */
3007 if ((parent
= cupsdAddLocation(location
)) == NULL
)
3010 parent
->limit
= AUTH_LIMIT_ALL
;
3013 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3016 * Decode the directive...
3019 if (!strcasecmp(line
, "</Location>"))
3021 else if (!strcasecmp(line
, "<Limit") ||
3022 !strcasecmp(line
, "<LimitExcept"))
3026 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3030 if ((loc
= cupsdCopyLocation(&parent
)) == NULL
)
3036 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3041 if (!strcmp(value
, "ALL"))
3042 loc
->limit
= AUTH_LIMIT_ALL
;
3043 else if (!strcmp(value
, "GET"))
3044 loc
->limit
|= AUTH_LIMIT_GET
;
3045 else if (!strcmp(value
, "HEAD"))
3046 loc
->limit
|= AUTH_LIMIT_HEAD
;
3047 else if (!strcmp(value
, "OPTIONS"))
3048 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
3049 else if (!strcmp(value
, "POST"))
3050 loc
->limit
|= AUTH_LIMIT_POST
;
3051 else if (!strcmp(value
, "PUT"))
3052 loc
->limit
|= AUTH_LIMIT_PUT
;
3053 else if (!strcmp(value
, "TRACE"))
3054 loc
->limit
|= AUTH_LIMIT_TRACE
;
3056 cupsdLogMessage(CUPSD_LOG_WARN
, "Unknown request type %s on line %d!",
3059 for (value
= valptr
; isspace(*value
& 255); value
++);
3062 if (!strcasecmp(line
, "<LimitExcept"))
3063 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
3065 parent
->limit
&= ~loc
->limit
;
3067 else if (!strcasecmp(line
, "</Limit>"))
3069 else if (!parse_aaa(loc
, line
, value
, linenum
))
3071 cupsdLogMessage(CUPSD_LOG_ERROR
,
3072 "Unknown Location directive %s on line %d.",
3078 cupsdLogMessage(CUPSD_LOG_ERROR
,
3079 "Unexpected end-of-file at line %d while reading location!",
3087 * 'read_policy()' - Read a <Policy name> definition.
3090 static int /* O - New line number or 0 on error */
3091 read_policy(cups_file_t
*fp
, /* I - Configuration file */
3092 char *policy
, /* I - Location name/path */
3093 int linenum
) /* I - Current line number */
3095 int i
; /* Looping var */
3096 cupsd_policy_t
*pol
; /* Policy */
3097 cupsd_location_t
*op
; /* Policy operation */
3098 int num_ops
; /* Number of IPP operations */
3099 ipp_op_t ops
[100]; /* Operations */
3100 char line
[HTTP_MAX_BUFFER
],
3102 *value
, /* Value for directive */
3103 *valptr
; /* Pointer into value */
3107 * Create the policy...
3110 if ((pol
= cupsdAddPolicy(policy
)) == NULL
)
3114 * Read from the file...
3120 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
3123 * Decode the directive...
3126 if (!strcasecmp(line
, "</Policy>"))
3129 cupsdLogMessage(CUPSD_LOG_WARN
,
3130 "Missing </Limit> before </Policy> on line %d!",
3135 else if (!strcasecmp(line
, "<Limit") && !op
)
3139 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d.", linenum
);
3144 * Scan for IPP operation names...
3151 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
3156 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
3158 if (!strcasecmp(value
, "All"))
3159 ops
[num_ops
] = IPP_ANY_OPERATION
;
3160 else if ((ops
[num_ops
] = ippOpValue(value
)) == IPP_BAD_OPERATION
)
3161 cupsdLogMessage(CUPSD_LOG_ERROR
,
3162 "Bad IPP operation name \"%s\" on line %d!",
3168 cupsdLogMessage(CUPSD_LOG_ERROR
,
3169 "Too many operations listed on line %d!",
3172 for (value
= valptr
; isspace(*value
& 255); value
++);
3176 * If none are specified, apply the policy to all operations...
3181 ops
[0] = IPP_ANY_OPERATION
;
3186 * Add a new policy for the first operation...
3189 op
= cupsdAddPolicyOp(pol
, NULL
, ops
[0]);
3191 else if (!strcasecmp(line
, "</Limit>") && op
)
3194 * Finish the current operation limit...
3200 * Copy the policy to the other operations...
3203 for (i
= 1; i
< num_ops
; i
++)
3204 cupsdAddPolicyOp(pol
, op
, ops
[i
]);
3211 cupsdLogMessage(CUPSD_LOG_ERROR
,
3212 "Missing <Limit ops> directive before %s on line %d.",
3216 else if (!parse_aaa(op
, line
, value
, linenum
))
3219 cupsdLogMessage(CUPSD_LOG_ERROR
,
3220 "Unknown Policy Limit directive %s on line %d.",
3223 cupsdLogMessage(CUPSD_LOG_ERROR
,
3224 "Unknown Policy directive %s on line %d.",
3231 cupsdLogMessage(CUPSD_LOG_ERROR
,
3232 "Unexpected end-of-file at line %d while reading policy \"%s\"!",