/*
- * "$Id: conf.c 5008 2006-01-27 19:30:34Z mike $"
+ * "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $"
*
* Configuration routines for the Common UNIX Printing System (CUPS).
*
- * Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2009 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* Contents:
*
- * cupsdReadConfiguration() - Read the cupsd.conf file.
- * check_permissions() - Fix the mode and ownership of a file or
+ * cupsdCheckPermissions() - Fix the mode and ownership of a file or
* directory.
+ * cupsdReadConfiguration() - Read the cupsd.conf file.
* get_address() - Get an address + port number from a line.
* get_addr_and_mask() - Get an IP address and netmask.
* parse_aaa() - Parse authentication, authorization, and
* access control lines.
+ * parse_fatal_errors() - Parse FatalErrors values in a string.
+ * parse_groups() - Parse system group names in a string.
+ * parse_protocols() - Parse browse protocols in a string.
* read_configuration() - Read a configuration file.
* read_location() - Read a <Location path> definition.
* read_policy() - Read a <Policy name> definition.
#include <stdarg.h>
#include <grp.h>
#include <sys/utsname.h>
-#include <cups/dir.h>
-
-#ifdef HAVE_VSYSLOG
-# include <syslog.h>
-#endif /* HAVE_VSYSLOG */
+#include <syslog.h>
/*
{
CUPSD_VARTYPE_INTEGER, /* Integer option */
CUPSD_VARTYPE_STRING, /* String option */
- CUPSD_VARTYPE_BOOLEAN /* Boolean option */
+ CUPSD_VARTYPE_BOOLEAN, /* Boolean option */
+ CUPSD_VARTYPE_PATHNAME /* File/directory name option */
} cupsd_vartype_t;
typedef struct
* Local globals...
*/
-static cupsd_var_t variables[] =
+static const cupsd_var_t variables[] =
{
{ "AccessLog", &AccessLog, CUPSD_VARTYPE_STRING },
+#ifdef __APPLE__
+ { "AppleQuotas", &AppleQuotas, CUPSD_VARTYPE_BOOLEAN },
+#endif /* __APPLE__ */
{ "AutoPurgeJobs", &JobAutoPurge, CUPSD_VARTYPE_BOOLEAN },
{ "BrowseInterval", &BrowseInterval, CUPSD_VARTYPE_INTEGER },
+#ifdef HAVE_LDAP
+ { "BrowseLDAPBindDN", &BrowseLDAPBindDN, CUPSD_VARTYPE_STRING },
+# ifdef HAVE_LDAP_SSL
+ { "BrowseLDAPCACertFile", &BrowseLDAPCACertFile, CUPSD_VARTYPE_PATHNAME },
+# endif /* HAVE_LDAP_SSL */
+ { "BrowseLDAPDN", &BrowseLDAPDN, CUPSD_VARTYPE_STRING },
+ { "BrowseLDAPPassword", &BrowseLDAPPassword, CUPSD_VARTYPE_STRING },
+ { "BrowseLDAPServer", &BrowseLDAPServer, CUPSD_VARTYPE_STRING },
+#endif /* HAVE_LDAP */
{ "BrowseLocalOptions", &BrowseLocalOptions, CUPSD_VARTYPE_STRING },
{ "BrowsePort", &BrowsePort, CUPSD_VARTYPE_INTEGER },
{ "BrowseRemoteOptions", &BrowseRemoteOptions, CUPSD_VARTYPE_STRING },
{ "BrowseShortNames", &BrowseShortNames, CUPSD_VARTYPE_BOOLEAN },
{ "BrowseTimeout", &BrowseTimeout, CUPSD_VARTYPE_INTEGER },
+ { "BrowseWebIF", &BrowseWebIF, CUPSD_VARTYPE_BOOLEAN },
{ "Browsing", &Browsing, CUPSD_VARTYPE_BOOLEAN },
{ "CacheDir", &CacheDir, CUPSD_VARTYPE_STRING },
{ "Classification", &Classification, CUPSD_VARTYPE_STRING },
{ "DefaultCharset", &DefaultCharset, CUPSD_VARTYPE_STRING },
{ "DefaultLanguage", &DefaultLanguage, CUPSD_VARTYPE_STRING },
{ "DefaultLeaseDuration", &DefaultLeaseDuration, CUPSD_VARTYPE_INTEGER },
+ { "DefaultPaperSize", &DefaultPaperSize, CUPSD_VARTYPE_STRING },
{ "DefaultPolicy", &DefaultPolicy, CUPSD_VARTYPE_STRING },
{ "DefaultShared", &DefaultShared, CUPSD_VARTYPE_BOOLEAN },
+ { "DirtyCleanInterval", &DirtyCleanInterval, CUPSD_VARTYPE_INTEGER },
{ "DocumentRoot", &DocumentRoot, CUPSD_VARTYPE_STRING },
{ "ErrorLog", &ErrorLog, CUPSD_VARTYPE_STRING },
+ { "ErrorPolicy", &ErrorPolicy, CUPSD_VARTYPE_STRING },
{ "FileDevice", &FileDevice, CUPSD_VARTYPE_BOOLEAN },
{ "FilterLimit", &FilterLimit, CUPSD_VARTYPE_INTEGER },
{ "FilterNice", &FilterNice, CUPSD_VARTYPE_INTEGER },
{ "FontPath", &FontPath, CUPSD_VARTYPE_STRING },
+#ifdef HAVE_GSSAPI
+ { "GSSServiceName", &GSSServiceName, CUPSD_VARTYPE_STRING },
+#endif /* HAVE_GSSAPI */
{ "HideImplicitMembers", &HideImplicitMembers, CUPSD_VARTYPE_BOOLEAN },
{ "ImplicitClasses", &ImplicitClasses, CUPSD_VARTYPE_BOOLEAN },
{ "ImplicitAnyClasses", &ImplicitAnyClasses, CUPSD_VARTYPE_BOOLEAN },
{ "JobRetryInterval", &JobRetryInterval, CUPSD_VARTYPE_INTEGER },
{ "KeepAliveTimeout", &KeepAliveTimeout, CUPSD_VARTYPE_INTEGER },
{ "KeepAlive", &KeepAlive, CUPSD_VARTYPE_BOOLEAN },
+#ifdef HAVE_LAUNCHD
+ { "LaunchdTimeout", &LaunchdTimeout, CUPSD_VARTYPE_INTEGER },
+ { "LaunchdConf", &LaunchdConf, CUPSD_VARTYPE_STRING },
+#endif /* HAVE_LAUNCHD */
{ "LimitRequestBody", &MaxRequestSize, CUPSD_VARTYPE_INTEGER },
{ "ListenBackLog", &ListenBackLog, CUPSD_VARTYPE_INTEGER },
{ "LogFilePerm", &LogFilePerm, CUPSD_VARTYPE_INTEGER },
+ { "LPDConfigFile", &LPDConfigFile, CUPSD_VARTYPE_STRING },
{ "MaxActiveJobs", &MaxActiveJobs, CUPSD_VARTYPE_INTEGER },
{ "MaxClients", &MaxClients, CUPSD_VARTYPE_INTEGER },
{ "MaxClientsPerHost", &MaxClientsPerHost, CUPSD_VARTYPE_INTEGER },
{ "MaxSubscriptionsPerJob", &MaxSubscriptionsPerJob, CUPSD_VARTYPE_INTEGER },
{ "MaxSubscriptionsPerPrinter",&MaxSubscriptionsPerPrinter, CUPSD_VARTYPE_INTEGER },
{ "MaxSubscriptionsPerUser", &MaxSubscriptionsPerUser, CUPSD_VARTYPE_INTEGER },
+ { "MultipleOperationTimeout", &MultipleOperationTimeout, CUPSD_VARTYPE_INTEGER },
{ "PageLog", &PageLog, CUPSD_VARTYPE_STRING },
+ { "PageLogFormat", &PageLogFormat, CUPSD_VARTYPE_STRING },
{ "PreserveJobFiles", &JobFiles, CUPSD_VARTYPE_BOOLEAN },
{ "PreserveJobHistory", &JobHistory, CUPSD_VARTYPE_BOOLEAN },
{ "Printcap", &Printcap, CUPSD_VARTYPE_STRING },
{ "RemoteRoot", &RemoteRoot, CUPSD_VARTYPE_STRING },
{ "RequestRoot", &RequestRoot, CUPSD_VARTYPE_STRING },
{ "RIPCache", &RIPCache, CUPSD_VARTYPE_STRING },
- { "RunAsUser", &RunAsUser, CUPSD_VARTYPE_BOOLEAN },
{ "RootCertDuration", &RootCertDuration, CUPSD_VARTYPE_INTEGER },
{ "ServerAdmin", &ServerAdmin, CUPSD_VARTYPE_STRING },
- { "ServerBin", &ServerBin, CUPSD_VARTYPE_STRING },
+ { "ServerBin", &ServerBin, CUPSD_VARTYPE_PATHNAME },
#ifdef HAVE_SSL
- { "ServerCertificate", &ServerCertificate, CUPSD_VARTYPE_STRING },
+ { "ServerCertificate", &ServerCertificate, CUPSD_VARTYPE_PATHNAME },
# if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
- { "ServerKey", &ServerKey, CUPSD_VARTYPE_STRING },
+ { "ServerKey", &ServerKey, CUPSD_VARTYPE_PATHNAME },
# endif /* HAVE_LIBSSL || HAVE_GNUTLS */
#endif /* HAVE_SSL */
{ "ServerName", &ServerName, CUPSD_VARTYPE_STRING },
- { "ServerRoot", &ServerRoot, CUPSD_VARTYPE_STRING },
+ { "ServerRoot", &ServerRoot, CUPSD_VARTYPE_PATHNAME },
+ { "SMBConfigFile", &SMBConfigFile, CUPSD_VARTYPE_STRING },
{ "StateDir", &StateDir, CUPSD_VARTYPE_STRING },
- { "TempDir", &TempDir, CUPSD_VARTYPE_STRING },
- { "Timeout", &Timeout, CUPSD_VARTYPE_INTEGER }
+#ifdef HAVE_AUTHORIZATION_H
+ { "SystemGroupAuthKey", &SystemGroupAuthKey, CUPSD_VARTYPE_STRING },
+#endif /* HAVE_AUTHORIZATION_H */
+ { "TempDir", &TempDir, CUPSD_VARTYPE_PATHNAME },
+ { "Timeout", &Timeout, CUPSD_VARTYPE_INTEGER },
+ { "UseNetworkDefault", &UseNetworkDefault, CUPSD_VARTYPE_BOOLEAN }
};
#define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
-static unsigned ones[4] =
+static const unsigned ones[4] =
{
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
};
-static unsigned zeros[4] =
+static const unsigned zeros[4] =
{
0x00000000, 0x00000000, 0x00000000, 0x00000000
};
/*
* Local functions...
*/
-static int check_permissions(const char *filename,
- const char *suffix, int mode,
- int user, int group, int is_dir,
- int create_dir);
static http_addrlist_t *get_address(const char *value, int defport);
static int get_addr_and_mask(const char *value, unsigned *ip,
unsigned *mask);
static int parse_aaa(cupsd_location_t *loc, char *line,
char *value, int linenum);
+static int parse_fatal_errors(const char *s);
+static int parse_groups(const char *s);
+static int parse_protocols(const char *s);
static int read_configuration(cups_file_t *fp);
static int read_location(cups_file_t *fp, char *name, int linenum);
static int read_policy(cups_file_t *fp, char *name, int linenum);
+/*
+ * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
+ */
+
+int /* O - 0 on success, -1 on error, 1 on warning */
+cupsdCheckPermissions(
+ const char *filename, /* I - File/directory name */
+ const char *suffix, /* I - Additional file/directory name */
+ int mode, /* I - Permissions */
+ int user, /* I - Owner */
+ int group, /* I - Group */
+ int is_dir, /* I - 1 = directory, 0 = file */
+ int create_dir) /* I - 1 = create directory, -1 = create w/o logging, 0 = not */
+{
+ int dir_created = 0; /* Did we create a directory? */
+ char pathname[1024]; /* File name with prefix */
+ struct stat fileinfo; /* Stat buffer */
+ int is_symlink; /* Is "filename" a symlink? */
+
+
+ /*
+ * Prepend the given root to the filename before testing it...
+ */
+
+ if (suffix)
+ {
+ snprintf(pathname, sizeof(pathname), "%s/%s", filename, suffix);
+ filename = pathname;
+ }
+
+ /*
+ * See if we can stat the file/directory...
+ */
+
+ if (lstat(filename, &fileinfo))
+ {
+ if (errno == ENOENT && create_dir)
+ {
+ if (create_dir > 0)
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Creating missing directory \"%s\"",
+ filename);
+
+ if (mkdir(filename, mode))
+ {
+ if (create_dir > 0)
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to create directory \"%s\" - %s", filename,
+ strerror(errno));
+ else
+ syslog(LOG_ERR, "Unable to create directory \"%s\" - %s", filename,
+ strerror(errno));
+
+ return (-1);
+ }
+
+ dir_created = 1;
+ fileinfo.st_mode = mode | S_IFDIR;
+ }
+ else
+ return (create_dir ? -1 : 1);
+ }
+
+ if ((is_symlink = S_ISLNK(fileinfo.st_mode)) != 0)
+ {
+ if (stat(filename, &fileinfo))
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is a bad symlink - %s",
+ filename, strerror(errno));
+ return (-1);
+ }
+ }
+
+ /*
+ * Make sure it's a regular file or a directory as needed...
+ */
+
+ if (!dir_created && !is_dir && !S_ISREG(fileinfo.st_mode))
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a regular file!", filename);
+ return (-1);
+ }
+
+ if (!dir_created && is_dir && !S_ISDIR(fileinfo.st_mode))
+ {
+ if (create_dir >= 0)
+ cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory!", filename);
+ else
+ syslog(LOG_ERR, "\"%s\" is not a directory!", filename);
+
+ return (-1);
+ }
+
+ /*
+ * If the filename is a symlink, do not change permissions (STR #2937)...
+ */
+
+ if (is_symlink)
+ return (0);
+
+ /*
+ * Fix owner, group, and mode as needed...
+ */
+
+ if (dir_created || fileinfo.st_uid != user || fileinfo.st_gid != group)
+ {
+ if (create_dir >= 0)
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing ownership of \"%s\"",
+ filename);
+
+ if (chown(filename, user, group) && !getuid())
+ {
+ if (create_dir >= 0)
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to change ownership of \"%s\" - %s", filename,
+ strerror(errno));
+ else
+ syslog(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename,
+ strerror(errno));
+
+ return (1);
+ }
+ }
+
+ if (dir_created || (fileinfo.st_mode & 07777) != mode)
+ {
+ if (create_dir >= 0)
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing access permissions of \"%s\"",
+ filename);
+
+ if (chmod(filename, mode))
+ {
+ if (create_dir >= 0)
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to change permissions of \"%s\" - %s", filename,
+ strerror(errno));
+ else
+ syslog(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename,
+ strerror(errno));
+
+ return (1);
+ }
+ }
+
+ /*
+ * Everything is OK...
+ */
+
+ return (0);
+}
+
+
/*
* 'cupsdReadConfiguration()' - Read the cupsd.conf file.
*/
cups_file_t *fp; /* Configuration file */
int status; /* Return status */
char temp[1024], /* Temporary buffer */
+ mimedir[1024], /* MIME directory */
*slash; /* Directory separator */
cups_lang_t *language; /* Language */
struct passwd *user; /* Default user */
struct group *group; /* Default group */
char *old_serverroot, /* Old ServerRoot */
*old_requestroot; /* Old RequestRoot */
+ const char *tmpdir; /* TMPDIR environment variable */
+ struct stat tmpinfo; /* Temporary directory info */
+ cupsd_policy_t *p; /* Policy */
- /*
- * Shutdown the server...
- */
-
- cupsdStopServer();
/*
* Save the old root paths...
if (NumBrowsers > 0)
{
free(Browsers);
+ Browsers = NULL;
NumBrowsers = 0;
}
if (NumRelays > 0)
{
for (i = 0; i < NumRelays; i ++)
- if (Relays[i].from.type == AUTH_NAME)
+ if (Relays[i].from.type == CUPSD_AUTH_NAME)
free(Relays[i].from.mask.name.name);
free(Relays);
NumRelays = 0;
}
- if (NumListeners > 0)
- {
- free(Listeners);
- NumListeners = 0;
- }
+ cupsdDeleteAllListeners();
+
+ RemoteAccessEnabled = 0;
/*
* String options...
*/
- cupsdSetString(&ServerName, httpGetHostname(temp, sizeof(temp)));
- cupsdSetStringf(&ServerAdmin, "root@%s", temp);
+ cupsdClearString(&ServerName);
+ cupsdClearString(&ServerAdmin);
cupsdSetString(&ServerBin, CUPS_SERVERBIN);
cupsdSetString(&RequestRoot, CUPS_REQUESTS);
cupsdSetString(&CacheDir, CUPS_CACHEDIR);
cupsdSetString(&AccessLog, CUPS_LOGDIR "/access_log");
cupsdSetString(&ErrorLog, CUPS_LOGDIR "/error_log");
cupsdSetString(&PageLog, CUPS_LOGDIR "/page_log");
- cupsdSetString(&Printcap, "/etc/printcap");
+ cupsdSetString(&PageLogFormat,
+ "%p %j %u %T %P %C %{job-billing} "
+ "%{job-originating-host-name} %{job-name} %{media} %{sides}");
+ cupsdSetString(&Printcap, CUPS_DEFAULT_PRINTCAP);
cupsdSetString(&PrintcapGUI, "/usr/bin/glpoptions");
cupsdSetString(&FontPath, CUPS_FONTPATH);
cupsdSetString(&RemoteRoot, "remroot");
- cupsdSetString(&ServerHeader, "CUPS/1.1");
+ cupsdSetString(&ServerHeader, "CUPS/1.4");
cupsdSetString(&StateDir, CUPS_STATEDIR);
+#ifdef HAVE_GSSAPI
+ cupsdSetString(&GSSServiceName, CUPS_DEFAULT_GSSSERVICENAME);
+#endif /* HAVE_GSSAPI */
+
+ if (!strcmp(CUPS_DEFAULT_PRINTCAP, "/etc/printers.conf"))
+ PrintcapFormat = PRINTCAP_SOLARIS;
+ else if (!strcmp(CUPS_DEFAULT_PRINTCAP,
+ "/Library/Preferences/org.cups.printers.plist"))
+ PrintcapFormat = PRINTCAP_PLIST;
+ else
+ PrintcapFormat = PRINTCAP_BSD;
strlcpy(temp, ConfigurationFile, sizeof(temp));
if ((slash = strrchr(temp, '/')) != NULL)
cupsdSetString(&DefaultCharset, _cupsEncodingName(language->encoding));
- cupsdSetString(&RIPCache, "8m");
-
- if (getenv("TMPDIR") == NULL)
- cupsdSetString(&TempDir, CUPS_REQUESTS "/tmp");
- else
- cupsdSetString(&TempDir, getenv("TMPDIR"));
-
- /*
- * Find the default system group: "sys", "system", or "root"...
- */
-
- group = getgrnam(CUPS_DEFAULT_GROUP);
- endgrent();
-
- NumSystemGroups = 0;
-
- if (group != NULL)
- {
- /*
- * Found the group, use it!
- */
-
- cupsdSetString(&SystemGroups[0], CUPS_DEFAULT_GROUP);
+ cupsdClearString(&DefaultPaperSize);
- SystemGroupIDs[0] = group->gr_gid;
- }
- else
- {
- /*
- * Find the group associated with GID 0...
- */
-
- group = getgrgid(0);
- endgrent();
-
- if (group != NULL)
- cupsdSetString(&SystemGroups[0], group->gr_name);
- else
- cupsdSetString(&SystemGroups[0], "unknown");
+ cupsdSetString(&RIPCache, "8m");
- SystemGroupIDs[0] = 0;
- }
+ cupsdSetString(&TempDir, NULL);
/*
* Find the default user...
endpwent();
/*
- * Find the default group (nobody)...
+ * Find the default group...
*/
- group = getgrnam("nobody");
+ group = getgrnam(CUPS_DEFAULT_GROUP);
endgrent();
- if (group != NULL)
+ if (group)
Group = group->gr_gid;
else
{
/*
- * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
- * complement number...)
+ * Fallback to group "nobody"...
*/
- Group = 65534;
+ group = getgrnam("nobody");
+ endgrent();
+
+ if (group)
+ Group = group->gr_gid;
+ else
+ {
+ /*
+ * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
+ * complement number...)
+ */
+
+ Group = 65534;
+ }
}
/*
* Numeric options...
*/
- ConfigFilePerm = CUPS_DEFAULT_CONFIG_FILE_PERM;
- DefaultAuthType = AUTH_BASIC;
- JobRetryLimit = 5;
- JobRetryInterval = 300;
- FileDevice = FALSE;
- FilterLevel = 0;
- FilterLimit = 0;
- FilterNice = 0;
- HostNameLookups = FALSE;
- ImplicitClasses = CUPS_DEFAULT_IMPLICIT_CLASSES;
- ImplicitAnyClasses = FALSE;
- HideImplicitMembers = TRUE;
- KeepAlive = TRUE;
- KeepAliveTimeout = DEFAULT_KEEPALIVE;
- ListenBackLog = SOMAXCONN;
- LogFilePerm = CUPS_DEFAULT_LOG_FILE_PERM;
- LogLevel = CUPSD_LOG_ERROR;
- MaxClients = 100;
- MaxClientsPerHost = 0;
- MaxLogSize = 1024 * 1024;
- MaxPrinterHistory = 10;
- MaxRequestSize = 0;
- ReloadTimeout = 60;
- RootCertDuration = 300;
- RunAsUser = FALSE;
- Timeout = DEFAULT_TIMEOUT;
-
- BrowseInterval = DEFAULT_INTERVAL;
- BrowsePort = ippPort();
- BrowseLocalProtocols = BROWSE_CUPS; /* TODO: Use configure option */
- BrowseRemoteProtocols = BROWSE_CUPS; /* TODO: Use configure option */
- BrowseShortNames = CUPS_DEFAULT_BROWSE_SHORT_NAMES;
- BrowseTimeout = DEFAULT_TIMEOUT;
- Browsing = CUPS_DEFAULT_BROWSING;
- DefaultShared = CUPS_DEFAULT_DEFAULT_SHARED;
+ AccessLogLevel = CUPSD_ACCESSLOG_ACTIONS;
+ ConfigFilePerm = CUPS_DEFAULT_CONFIG_FILE_PERM;
+ FatalErrors = parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS);
+ DefaultAuthType = CUPSD_AUTH_BASIC;
+#ifdef HAVE_SSL
+ DefaultEncryption = HTTP_ENCRYPT_REQUIRED;
+ SSLOptions = CUPSD_SSL_NONE;
+#endif /* HAVE_SSL */
+ DirtyCleanInterval = DEFAULT_KEEPALIVE;
+ JobRetryLimit = 5;
+ JobRetryInterval = 300;
+ FileDevice = FALSE;
+ FilterLevel = 0;
+ FilterLimit = 0;
+ FilterNice = 0;
+ HostNameLookups = FALSE;
+ ImplicitClasses = CUPS_DEFAULT_IMPLICIT_CLASSES;
+ ImplicitAnyClasses = FALSE;
+ HideImplicitMembers = TRUE;
+ KeepAlive = TRUE;
+ KeepAliveTimeout = DEFAULT_KEEPALIVE;
+ ListenBackLog = SOMAXCONN;
+ LogFilePerm = CUPS_DEFAULT_LOG_FILE_PERM;
+ LogLevel = CUPSD_LOG_WARN;
+ LogTimeFormat = CUPSD_TIME_STANDARD;
+ MaxClients = 100;
+ MaxClientsPerHost = 0;
+ MaxLogSize = 1024 * 1024;
+ MaxPrinterHistory = 10;
+ MaxRequestSize = 0;
+ MultipleOperationTimeout = DEFAULT_TIMEOUT;
+ ReloadTimeout = DEFAULT_KEEPALIVE;
+ RootCertDuration = 300;
+ Timeout = DEFAULT_TIMEOUT;
+ NumSystemGroups = 0;
+
+ BrowseInterval = DEFAULT_INTERVAL;
+ BrowsePort = ippPort();
+ BrowseLocalProtocols = parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS);
+ BrowseRemoteProtocols = parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS);
+ BrowseShortNames = CUPS_DEFAULT_BROWSE_SHORT_NAMES;
+ BrowseTimeout = DEFAULT_TIMEOUT;
+ BrowseWebIF = FALSE;
+ Browsing = CUPS_DEFAULT_BROWSING;
+ DefaultShared = CUPS_DEFAULT_DEFAULT_SHARED;
+
+ cupsdSetString(&LPDConfigFile, CUPS_DEFAULT_LPD_CONFIG_FILE);
+ cupsdSetString(&SMBConfigFile, CUPS_DEFAULT_SMB_CONFIG_FILE);
cupsdClearString(&BrowseLocalOptions);
cupsdClearString(&BrowseRemoteOptions);
+ cupsdSetString(&ErrorPolicy, "stop-printer");
+
+#ifdef HAVE_LDAP
+ cupsdClearString(&BrowseLDAPBindDN);
+ cupsdClearString(&BrowseLDAPDN);
+ cupsdClearString(&BrowseLDAPPassword);
+ cupsdClearString(&BrowseLDAPServer);
+# ifdef HAVE_LDAP_SSL
+ cupsdClearString(&BrowseLDAPCACertFile);
+# endif /* HAVE_LDAP_SSL */
+#endif /* HAVE_LDAP */
+
JobHistory = DEFAULT_HISTORY;
JobFiles = DEFAULT_FILES;
JobAutoPurge = 0;
MaxActiveJobs = 0;
MaxJobsPerUser = 0;
MaxJobsPerPrinter = 0;
- MaxCopies = 100;
+ MaxCopies = CUPS_DEFAULT_MAX_COPIES;
cupsdDeleteAllPolicies();
cupsdClearString(&DefaultPolicy);
+#ifdef HAVE_AUTHORIZATION_H
+ cupsdClearString(&SystemGroupAuthKey);
+#endif /* HAVE_AUTHORIZATION_H */
+
MaxSubscriptions = 100;
MaxSubscriptionsPerJob = 0;
MaxSubscriptionsPerPrinter = 0;
DefaultLeaseDuration = 86400;
MaxLeaseDuration = 0;
+#ifdef HAVE_LAUNCHD
+ LaunchdTimeout = DEFAULT_TIMEOUT + 10;
+ cupsdSetString(&LaunchdConf, CUPS_DEFAULT_LAUNCHD_CONF);
+#endif /* HAVE_LAUNCHD */
+
+#ifdef __APPLE__
+ AppleQuotas = TRUE;
+#endif /* __APPLE__ */
+
/*
* Read the configuration file...
*/
if (!status)
return (0);
- if (RunAsUser)
- RunUser = User;
- else
- RunUser = getuid();
+ RunUser = getuid();
+
+ cupsdLogMessage(CUPSD_LOG_INFO, "Remote access is %s.",
+ RemoteAccessEnabled ? "enabled" : "disabled");
+
+ /*
+ * See if the ServerName is an IP address...
+ */
+
+ if (!ServerName)
+ {
+ if (HostNameLookups || RemoteAccessEnabled)
+ httpGetHostname(NULL, temp, sizeof(temp));
+ else if (gethostname(temp, sizeof(temp)))
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get hostname: %s",
+ strerror(errno));
+ strlcpy(temp, "localhost", sizeof(temp));
+ }
+
+ cupsdSetString(&ServerName, temp);
+ }
+
+ for (slash = ServerName; isdigit(*slash & 255) || *slash == '.'; slash ++);
+
+ ServerNameIsIP = !*slash;
+
+ /*
+ * Make sure ServerAdmin is initialized...
+ */
+
+ if (!ServerAdmin)
+ cupsdSetStringf(&ServerAdmin, "root@%s", ServerName);
/*
* Use the default system group if none was supplied in cupsd.conf...
*/
if (NumSystemGroups == 0)
- NumSystemGroups ++;
+ {
+ if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS))
+ {
+ /*
+ * Find the group associated with GID 0...
+ */
+
+ group = getgrgid(0);
+ endgrent();
+
+ if (group != NULL)
+ cupsdSetString(&SystemGroups[0], group->gr_name);
+ else
+ cupsdSetString(&SystemGroups[0], "unknown");
+
+ SystemGroupIDs[0] = 0;
+ NumSystemGroups = 1;
+ }
+ }
/*
* Get the access control list for browsing...
* as an error and exit!
*/
- if (NumListeners == 0)
+ if (cupsArrayCount(Listeners) == 0)
{
/*
* No listeners!
*/
cupsdLogMessage(CUPSD_LOG_EMERG,
- "No valid Listen or Port lines were found in the configuration file!");
+ "No valid Listen or Port lines were found in the "
+ "configuration file!");
/*
* Commit suicide...
if (ServerCertificate[0] != '/')
cupsdSetStringf(&ServerCertificate, "%s/%s", ServerRoot, ServerCertificate);
- if (!strncmp(ServerRoot, ServerCertificate, strlen(ServerRoot)))
- {
- chown(ServerCertificate, RunUser, Group);
- chmod(ServerCertificate, 0600);
- }
+ if (!strncmp(ServerRoot, ServerCertificate, strlen(ServerRoot)) &&
+ cupsdCheckPermissions(ServerCertificate, NULL, 0600, RunUser, Group,
+ 0, 0) < 0 &&
+ (FatalErrors & CUPSD_FATAL_PERMISSIONS))
+ return (0);
# if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
if (ServerKey[0] != '/')
cupsdSetStringf(&ServerKey, "%s/%s", ServerRoot, ServerKey);
- if (!strncmp(ServerRoot, ServerKey, strlen(ServerRoot)))
- {
- chown(ServerKey, RunUser, Group);
- chmod(ServerKey, 0600);
- }
+ if (!strncmp(ServerRoot, ServerKey, strlen(ServerRoot)) &&
+ cupsdCheckPermissions(ServerKey, NULL, 0600, RunUser, Group, 0, 0) < 0 &&
+ (FatalErrors & CUPSD_FATAL_PERMISSIONS))
+ return (0);
# endif /* HAVE_LIBSSL || HAVE_GNUTLS */
#endif /* HAVE_SSL */
* writable by the user and group in the cupsd.conf file...
*/
- check_permissions(CacheDir, NULL, 0775, RunUser, Group, 1, 1);
- check_permissions(CacheDir, "ppd", 0755, RunUser, Group, 1, 1);
+ snprintf(temp, sizeof(temp), "%s/rss", CacheDir);
+
+ if ((cupsdCheckPermissions(RequestRoot, NULL, 0710, RunUser,
+ Group, 1, 1) < 0 ||
+ cupsdCheckPermissions(CacheDir, NULL, 0775, RunUser,
+ Group, 1, 1) < 0 ||
+ cupsdCheckPermissions(temp, NULL, 0775, RunUser,
+ Group, 1, 1) < 0 ||
+ cupsdCheckPermissions(StateDir, NULL, 0755, RunUser,
+ Group, 1, 1) < 0 ||
+ cupsdCheckPermissions(StateDir, "certs", RunUser ? 0711 : 0511, User,
+ SystemGroupIDs[0], 1, 1) < 0 ||
+ cupsdCheckPermissions(ServerRoot, NULL, 0755, RunUser,
+ Group, 1, 0) < 0 ||
+ cupsdCheckPermissions(ServerRoot, "ppd", 0755, RunUser,
+ Group, 1, 1) < 0 ||
+ cupsdCheckPermissions(ServerRoot, "ssl", 0700, RunUser,
+ Group, 1, 0) < 0 ||
+ cupsdCheckPermissions(ServerRoot, "cupsd.conf", ConfigFilePerm, RunUser,
+ Group, 0, 0) < 0 ||
+ cupsdCheckPermissions(ServerRoot, "classes.conf", 0600, RunUser,
+ Group, 0, 0) < 0 ||
+ cupsdCheckPermissions(ServerRoot, "printers.conf", 0600, RunUser,
+ Group, 0, 0) < 0 ||
+ cupsdCheckPermissions(ServerRoot, "passwd.md5", 0600, User,
+ Group, 0, 0) < 0) &&
+ (FatalErrors & CUPSD_FATAL_PERMISSIONS))
+ return (0);
+
+ /*
+ * Update TempDir to the default if it hasn't been set already...
+ */
+
+ if (!TempDir)
+ {
+ if ((tmpdir = getenv("TMPDIR")) != NULL)
+ {
+ /*
+ * TMPDIR is defined, see if it is OK for us to use...
+ */
- check_permissions(StateDir, NULL, 0755, RunUser, Group, 1, 1);
- check_permissions(StateDir, "certs", RunUser ? 0711 : 0511, User,
- SystemGroupIDs[0], 1, 1);
+ if (stat(tmpdir, &tmpinfo))
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to access TMPDIR (%s): %s",
+ tmpdir, strerror(errno));
+ else if (!S_ISDIR(tmpinfo.st_mode))
+ cupsdLogMessage(CUPSD_LOG_ERROR, "TMPDIR (%s) is not a directory!",
+ tmpdir);
+ else if ((tmpinfo.st_uid != User || !(tmpinfo.st_mode & S_IWUSR)) &&
+ (tmpinfo.st_gid != Group || !(tmpinfo.st_mode & S_IWGRP)) &&
+ !(tmpinfo.st_mode & S_IWOTH))
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "TMPDIR (%s) has the wrong permissions!", tmpdir);
+ else
+ cupsdSetString(&TempDir, tmpdir);
+ }
- check_permissions(ServerRoot, NULL, 0755, RunUser, Group, 1, 0);
- check_permissions(ServerRoot, "ppd", 0755, RunUser, Group, 1, 1);
- check_permissions(ServerRoot, "ssl", 0700, RunUser, Group, 1, 0);
- check_permissions(ServerRoot, "cupsd.conf", ConfigFilePerm, RunUser, Group,
- 0, 0);
- check_permissions(ServerRoot, "classes.conf", 0600, RunUser, Group, 0, 0);
- check_permissions(ServerRoot, "printers.conf", 0600, RunUser, Group, 0, 0);
- check_permissions(ServerRoot, "passwd.md5", 0600, User, Group, 0, 0);
+ if (!TempDir)
+ {
+ cupsdLogMessage(CUPSD_LOG_INFO, "Using default TempDir of %s/tmp...",
+ RequestRoot);
+ cupsdSetStringf(&TempDir, "%s/tmp", RequestRoot);
+ }
+ }
/*
- * Make sure the request and temporary directories have the right
- * permissions...
+ * Make sure the temporary directory has the right permissions...
*/
- check_permissions(RequestRoot, NULL, 0710, RunUser, Group, 1, 1);
-
if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)) ||
access(TempDir, 0))
{
* is under the spool directory or does not exist...
*/
- check_permissions(TempDir, NULL, 01770, RunUser, Group, 1, 1);
+ if (cupsdCheckPermissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0 &&
+ (FatalErrors & CUPSD_FATAL_PERMISSIONS))
+ return (0);
}
- if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)))
- {
- /*
- * Clean out the temporary directory...
- */
-
- cups_dir_t *dir; /* Temporary directory */
- cups_dentry_t *dent; /* Directory entry */
- char tempfile[1024]; /* Temporary filename */
+ /*
+ * Setup environment variables...
+ */
+ cupsdInitEnv();
- if ((dir = cupsDirOpen(TempDir)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Cleaning out old temporary files in \"%s\"...", TempDir);
+ /*
+ * Update default paper size setting as needed...
+ */
- while ((dent = cupsDirRead(dir)) != NULL)
- {
- snprintf(tempfile, sizeof(tempfile), "%s/%s", TempDir, dent->filename);
+ if (!DefaultPaperSize)
+ {
+#ifdef HAVE_LIBPAPER
+ char *paper_result; /* Paper size name from libpaper */
- if (unlink(tempfile))
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to remove temporary file \"%s\" - %s",
- tempfile, strerror(errno));
- else
- cupsdLogMessage(CUPSD_LOG_DEBUG, "Removed temporary file \"%s\"...",
- tempfile);
- }
+ if ((paper_result = systempapername()) != NULL)
+ cupsdSetString(&DefaultPaperSize, paper_result);
+ else
+#endif /* HAVE_LIBPAPER */
+ if (!DefaultLanguage ||
+ !strcasecmp(DefaultLanguage, "C") ||
+ !strcasecmp(DefaultLanguage, "POSIX") ||
+ !strcasecmp(DefaultLanguage, "en") ||
+ !strncasecmp(DefaultLanguage, "en.", 3) ||
+ !strncasecmp(DefaultLanguage, "en_US", 5) ||
+ !strncasecmp(DefaultLanguage, "en_CA", 5) ||
+ !strncasecmp(DefaultLanguage, "fr_CA", 5))
+ {
+ /*
+ * These are the only locales that will default to "letter" size...
+ */
- cupsDirClose(dir);
+ cupsdSetString(&DefaultPaperSize, "Letter");
}
else
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to open temporary directory \"%s\" - %s",
- TempDir, strerror(errno));
+ cupsdSetString(&DefaultPaperSize, "A4");
}
/*
- * Setup environment variables...
+ * Update classification setting as needed...
*/
- cupsdInitEnv();
+ if (Classification && !strcasecmp(Classification, "none"))
+ cupsdClearString(&Classification);
+
+ if (Classification)
+ cupsdLogMessage(CUPSD_LOG_INFO, "Security set to \"%s\"", Classification);
/*
* Check the MaxClients setting, and then allocate memory for it...
if (MaxClients > (MaxFDs / 3) || MaxClients <= 0)
{
if (MaxClients > 0)
- cupsdLogMessage(CUPSD_LOG_INFO, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
- MaxFDs / 3, MaxFDs);
+ cupsdLogMessage(CUPSD_LOG_INFO,
+ "MaxClients limited to 1/3 (%d) of the file descriptor "
+ "limit (%d)...",
+ MaxFDs / 3, MaxFDs);
MaxClients = MaxFDs / 3;
}
- if ((Clients = calloc(sizeof(cupsd_client_t), MaxClients)) == NULL)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
- MaxClients, strerror(errno));
- exit(1);
- }
- else
- cupsdLogMessage(CUPSD_LOG_INFO, "Configured for up to %d clients.",
- MaxClients);
+ cupsdLogMessage(CUPSD_LOG_INFO, "Configured for up to %d clients.",
+ MaxClients);
/*
* Check the MaxActiveJobs setting; limit to 1/3 the available
if (MaxActiveJobs > (MaxFDs / 3))
MaxActiveJobs = MaxFDs / 3;
- if (Classification && strcasecmp(Classification, "none") == 0)
- cupsdClearString(&Classification);
-
- if (Classification)
- cupsdLogMessage(CUPSD_LOG_INFO, "Security set to \"%s\"", Classification);
-
/*
* Update the MaxClientsPerHost value, as needed...
*/
"Allowing up to %d client connections per host.",
MaxClientsPerHost);
+ /*
+ * Make sure that BrowseTimeout is at least twice the interval...
+ */
+
+ if (BrowseTimeout < (2 * BrowseInterval) || BrowseTimeout <= 0)
+ {
+ cupsdLogMessage(CUPSD_LOG_ALERT, "Invalid BrowseTimeout value %d!",
+ BrowseTimeout);
+
+ if (BrowseInterval)
+ BrowseTimeout = BrowseInterval * 2;
+ else
+ BrowseTimeout = DEFAULT_TIMEOUT;
+
+ cupsdLogMessage(CUPSD_LOG_ALERT, "Reset BrowseTimeout to %d!",
+ BrowseTimeout);
+ }
+
/*
* Update the default policy, as needed...
*/
if (!DefaultPolicyPtr)
{
- cupsd_policy_t *p; /* New policy */
cupsd_location_t *po; /* New policy operation */
cupsdLogMessage(CUPSD_LOG_ERROR, "Default policy \"%s\" not found!",
DefaultPolicy);
+ cupsdSetString(&DefaultPolicy, "default");
+
if ((DefaultPolicyPtr = cupsdFindPolicy("default")) != NULL)
cupsdLogMessage(CUPSD_LOG_INFO,
"Using policy \"default\" as the default!");
"Renew-Subscription Cancel-Subscription "
"Get-Notifications Reprocess-Job Cancel-Current-Job "
"Suspend-Current-Job Resume-Job CUPS-Move-Job "
- "CUPS-Authenticate-Job>");
+ "CUPS-Authenticate-Job CUPS-Get-Document>");
cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
po = cupsdAddPolicyOp(p, NULL, IPP_SEND_DOCUMENT);
- po->order_type = AUTH_ALLOW;
- po->level = AUTH_USER;
+ po->order_type = CUPSD_AUTH_ALLOW;
+ po->level = CUPSD_AUTH_USER;
cupsdAddName(po, "@OWNER");
cupsdAddName(po, "@SYSTEM");
cupsdAddPolicyOp(p, po, IPP_RESUME_JOB);
cupsdAddPolicyOp(p, po, CUPS_MOVE_JOB);
cupsdAddPolicyOp(p, po, CUPS_AUTHENTICATE_JOB);
+ cupsdAddPolicyOp(p, po, CUPS_GET_DOCUMENT);
cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
"CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class "
"CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>");
cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
- cupsdLogMessage(CUPSD_LOG_INFO, "AuthType Basic");
+ cupsdLogMessage(CUPSD_LOG_INFO, "AuthType Default");
po = cupsdAddPolicyOp(p, NULL, IPP_PAUSE_PRINTER);
- po->order_type = AUTH_ALLOW;
- po->type = AUTH_BASIC;
- po->level = AUTH_USER;
+ po->order_type = CUPSD_AUTH_ALLOW;
+ po->type = CUPSD_AUTH_DEFAULT;
+ po->level = CUPSD_AUTH_USER;
cupsdAddName(po, "@SYSTEM");
cupsdLogMessage(CUPSD_LOG_INFO, "Require user @SYSTEM");
cupsdLogMessage(CUPSD_LOG_INFO, "Order Deny,Allow");
po = cupsdAddPolicyOp(p, NULL, IPP_ANY_OPERATION);
- po->order_type = AUTH_ALLOW;
+ po->order_type = CUPSD_AUTH_ALLOW;
cupsdLogMessage(CUPSD_LOG_INFO, "</Limit>");
cupsdLogMessage(CUPSD_LOG_INFO, "</Policy>");
}
}
- cupsdLogMessage(CUPSD_LOG_DEBUG,"NumPolicies=%d", NumPolicies);
- for (i = 0; i < NumPolicies; i ++)
- cupsdLogMessage(CUPSD_LOG_DEBUG, "Policies[%d]=\"%s\"", i,
- Policies[i]->name);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: NumPolicies=%d",
+ cupsArrayCount(Policies));
+ for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies);
+ p;
+ i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies))
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdReadConfiguration: Policies[%d]=\"%s\"", i, p->name);
/*
* If we are doing a full reload or the server root has changed, flush
cupsdDeleteAllSubscriptions();
cupsdFreeAllJobs();
- cupsdDeleteAllClasses();
cupsdDeleteAllPrinters();
DefaultPrinter = NULL;
if (NumMimeTypes)
{
for (i = 0; i < NumMimeTypes; i ++)
- free((void *)MimeTypes[i]);
+ _cupsStrFree(MimeTypes[i]);
free(MimeTypes);
}
*/
snprintf(temp, sizeof(temp), "%s/filter", ServerBin);
+ snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir);
- MimeDatabase = mimeLoad(ServerRoot, temp);
+ MimeDatabase = mimeLoadTypes(NULL, mimedir);
+ MimeDatabase = mimeLoadTypes(MimeDatabase, ServerRoot);
+ MimeDatabase = mimeLoadFilters(MimeDatabase, mimedir, temp);
+ MimeDatabase = mimeLoadFilters(MimeDatabase, ServerRoot, temp);
if (!MimeDatabase)
{
cupsdLogMessage(CUPSD_LOG_EMERG,
- "Unable to load MIME database from \'%s\'!", ServerRoot);
- exit(errno);
+ "Unable to load MIME database from \"%s\" or \"%s\"!",
+ mimedir, ServerRoot);
+ if (FatalErrors & CUPSD_FATAL_CONFIG)
+ return (0);
}
cupsdLogMessage(CUPSD_LOG_INFO,
- "Loaded MIME database from \'%s\': %d types, %d filters...",
- ServerRoot, mimeNumTypes(MimeDatabase),
- mimeNumFilters(MimeDatabase));
+ "Loaded MIME database from \"%s\" and \"%s\": %d types, "
+ "%d filters...", mimedir, ServerRoot,
+ mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
/*
* Create a list of MIME types for the document-format-supported
if (!mimeType(MimeDatabase, "application", "octet-stream"))
NumMimeTypes ++;
- MimeTypes = calloc(NumMimeTypes, sizeof(const char *));
-
- for (i = 0, type = mimeFirstType(MimeDatabase);
- type;
- i ++, type = mimeNextType(MimeDatabase))
+ if ((MimeTypes = calloc(NumMimeTypes, sizeof(const char *))) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to allocate memory for %d MIME types!",
+ NumMimeTypes);
+ NumMimeTypes = 0;
+ }
+ else
{
- snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
+ for (i = 0, type = mimeFirstType(MimeDatabase);
+ type;
+ i ++, type = mimeNextType(MimeDatabase))
+ {
+ snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
- MimeTypes[i] = strdup(mimetype);
+ MimeTypes[i] = _cupsStrAlloc(mimetype);
+ }
+
+ if (i < NumMimeTypes)
+ MimeTypes[i] = _cupsStrAlloc("application/octet-stream");
}
- if (i < NumMimeTypes)
- MimeTypes[i] = strdup("application/octet-stream");
+ if (LogLevel == CUPSD_LOG_DEBUG2)
+ {
+ mime_filter_t *filter; /* Current filter */
+
+
+ for (type = mimeFirstType(MimeDatabase);
+ type;
+ type = mimeNextType(MimeDatabase))
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: type %s/%s",
+ type->super, type->type);
+
+ for (filter = mimeFirstFilter(MimeDatabase);
+ filter;
+ filter = mimeNextFilter(MimeDatabase))
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
+ filter->src->super, filter->src->type,
+ filter->dst->super, filter->dst->type,
+ filter->cost, filter->filter);
+ }
/*
* Load banners...
cupsdLoadAllPrinters();
cupsdLoadAllClasses();
cupsdLoadRemoteCache();
- cupsdWritePrintcap();
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
cupsdCreateCommonData();
*/
cupsdUpdatePrinters();
- cupsdWritePrintcap();
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
cupsdLogMessage(CUPSD_LOG_INFO, "Partial reload complete.");
}
cupsdClearString(&old_serverroot);
cupsdClearString(&old_requestroot);
- /*
- * Startup the server and return...
- */
-
- cupsdStartServer();
-
return (1);
}
-/*
- * 'check_permissions()' - Fix the mode and ownership of a file or directory.
- */
-
-static int /* O - 0 on success, -1 on error */
-check_permissions(const char *filename, /* I - File/directory name */
- const char *suffix, /* I - Additional file/directory name */
- int mode, /* I - Permissions */
- int user, /* I - Owner */
- int group, /* I - Group */
- int is_dir, /* I - 1 = directory, 0 = file */
- int create_dir)/* I - 1 = create directory, 0 = not */
-{
- int dir_created = 0; /* Did we create a directory? */
- char pathname[1024]; /* File name with prefix */
- struct stat fileinfo; /* Stat buffer */
-
-
- /*
- * Prepend the given root to the filename before testing it...
- */
-
- if (suffix)
- {
- snprintf(pathname, sizeof(pathname), "%s/%s", filename, suffix);
- filename = pathname;
- }
-
- /*
- * See if we can stat the file/directory...
- */
-
- if (stat(filename, &fileinfo))
- {
- if (errno == ENOENT && create_dir)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Creating missing directory \"%s\"",
- filename);
-
- if (mkdir(filename, mode))
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to create directory \"%s\" - %s", filename,
- strerror(errno));
- return (-1);
- }
-
- dir_created = 1;
- }
- else
- return (-1);
- }
-
- /*
- * Make sure it's a regular file...
- */
-
- if (!dir_created && !is_dir && !S_ISREG(fileinfo.st_mode))
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a regular file!", filename);
- return (-1);
- }
-
- if (!dir_created && is_dir && !S_ISDIR(fileinfo.st_mode))
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory!", filename);
- return (-1);
- }
-
- /*
- * Fix owner, group, and mode as needed...
- */
-
- if (dir_created || fileinfo.st_uid != user || fileinfo.st_gid != group)
- {
- cupsdLogMessage(CUPSD_LOG_WARN, "Repairing ownership of \"%s\"", filename);
-
- if (chown(filename, user, group))
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to change ownership of \"%s\" - %s", filename,
- strerror(errno));
- return (-1);
- }
- }
-
- if (dir_created || (fileinfo.st_mode & 0777) != mode)
- {
- cupsdLogMessage(CUPSD_LOG_WARN, "Repairing access permissions of \"%s\"", filename);
-
- if (chmod(filename, mode))
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to change permissions of \"%s\" - %s", filename,
- strerror(errno));
- return (-1);
- }
- }
-
- /*
- * Everything is OK...
- */
-
- return (0);
-}
-
-
/*
* 'get_address()' - Get an address + port number from a line.
*/
const char *maskval, /* Pointer to start of mask value */
*ptr, /* Pointer into value */
*ptr2; /* ... */
- static unsigned netmasks[4][4] = /* Standard IPv4 netmasks... */
- {
- { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
- { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
- { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
- { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
- };
-#ifdef AF_INET6
- static unsigned netmasks6[8][4] = /* Standard IPv6 netmasks... */
- {
- { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
- { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
- { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
- { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
- { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
- { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
- { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
- { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
- };
-#endif /* AF_INET6 */
/*
* Get the address...
*/
- memset(ip, 0, sizeof(unsigned) * 4);
+ ip[0] = ip[1] = ip[2] = ip[3] = 0x00000000;
+ mask[0] = mask[1] = mask[2] = mask[3] = 0xffffffff;
if ((maskval = strchr(value, '/')) != NULL)
maskval ++;
ptr2 = strchr(ptr2 + 1, ':'), j ++);
i = 7 - j;
+ ptr ++;
}
else if (isxdigit(*ptr & 255))
{
return (0);
if (i & 1)
- ip[i] |= ipval;
+ ip[i / 2] |= ipval;
else
- ip[i] |= ipval << 16;
+ ip[i / 2] |= ipval << 16;
}
else
return (0);
ptr ++;
}
- ipcount = i;
+ if (*ptr != ']')
+ return (0);
+
+ ptr ++;
if (*ptr && *ptr != '/')
return (0);
* Parse dotted-decimal IPv4 address...
*/
- family = AF_INET;
- ipcount = sscanf(value, "%u.%u.%u.%u", ip + 0, ip + 1, ip + 2, ip + 3);
+ unsigned val[4]; /* IPv4 address values */
- ip[3] |= ((((ip[0] << 8) | ip[1]) << 8) | ip[2]) << 8;
- ip[0] = ip[1] = ip[2] = 0;
- }
- if (*maskval)
- {
+ family = AF_INET;
+ ipcount = sscanf(value, "%u.%u.%u.%u", val + 0, val + 1, val + 2, val + 3);
+
/*
- * Get the netmask value(s)...
+ * Range check the IP numbers...
*/
- memset(mask, 0, sizeof(unsigned) * 4);
+ for (i = 0; i < ipcount; i ++)
+ if (val[i] > 255)
+ return (0);
-#ifdef AF_INET6
- if (*maskval == '[')
- {
- /*
- * Get hexadecimal mask value...
- */
+ /*
+ * Make sure the trailing values are zeroed, as some C libraries like
+ * glibc apparently like to fill the unused arguments with garbage...
+ */
- for (i = 0, ptr = maskval + 1; *ptr && i < 8; i ++)
- {
- if (*ptr == ']')
- break;
- else if (!strncmp(ptr, "::", 2))
- {
- for (ptr2 = strchr(ptr + 2, ':'), j = 0;
- ptr2;
- ptr2 = strchr(ptr2 + 1, ':'), j ++);
+ for (i = ipcount; i < 4; i ++)
+ val[i] = 0;
- i = 7 - j;
- }
- else if (isxdigit(*ptr & 255))
- {
- ipval = strtoul(ptr, (char **)&ptr, 16);
+ /*
+ * Merge everything into a 32-bit IPv4 address in ip[3]...
+ */
- if (ipval > 0xffff)
- return (0);
+ ip[3] = (((((val[0] << 8) | val[1]) << 8) | val[2]) << 8) | val[3];
- if (i & 1)
- mask[i] |= ipval;
- else
- mask[i] |= ipval << 16;
- }
- else
- return (0);
+ if (ipcount < 4)
+ mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff;
+ }
- while (*ptr == ':')
- ptr ++;
- }
+ if (*maskval)
+ {
+ /*
+ * Get the netmask value(s)...
+ */
+
+ memset(mask, 0, sizeof(unsigned) * 4);
- if (*ptr)
- return (0);
- }
- else
-#endif /* AF_INET6 */
if (strchr(maskval, '.'))
{
/*
* Get dotted-decimal mask...
*/
+ if (family != AF_INET)
+ return (0);
+
if (sscanf(maskval, "%u.%u.%u.%u", mask + 0, mask + 1, mask + 2, mask + 3) != 4)
return (0);
#ifdef AF_INET6
if (family == AF_INET6)
{
+ if (i > 128)
+ return (0);
+
i = 128 - i;
if (i <= 96)
else
#endif /* AF_INET6 */
{
- i = 32 - i;
+ if (i > 32)
+ return (0);
mask[0] = 0xffffffff;
mask[1] = 0xffffffff;
mask[2] = 0xffffffff;
- if (i > 0)
- mask[3] = (0xffffffff << i) & 0xffffffff;
+ if (i < 32)
+ mask[3] = (0xffffffff << (32 - i)) & 0xffffffff;
else
mask[3] = 0xffffffff;
}
}
}
-#ifdef AF_INET6
- else if (family == AF_INET6)
- memcpy(mask, netmasks6[ipcount - 1], sizeof(unsigned) * 4);
-#endif /* AF_INET6 */
- else
- memcpy(mask, netmasks[ipcount - 1], sizeof(unsigned) * 4);
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"get_addr_and_mask(value=\"%s\", "
- "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
+ "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
value, ip[0], ip[1], ip[2], ip[3], mask[0], mask[1], mask[2],
mask[3]);
*/
if (!strncasecmp(value, "deny", 4))
- loc->order_type = AUTH_ALLOW;
+ loc->order_type = CUPSD_AUTH_ALLOW;
else if (!strncasecmp(value, "allow", 5))
- loc->order_type = AUTH_DENY;
+ loc->order_type = CUPSD_AUTH_DENY;
else
{
cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown Order value %s on line %d.",
* Deny [From] host/ip...
*/
- if (!strncasecmp(value, "from", 4))
+ while (*value)
{
- /*
- * Strip leading "from"...
- */
+ if (!strncasecmp(value, "from", 4))
+ {
+ /*
+ * Strip leading "from"...
+ */
- value += 4;
+ value += 4;
- while (isspace(*value & 255))
- value ++;
- }
-
- /*
- * Figure out what form the allow/deny address takes:
- *
- * All
- * None
- * *.domain.com
- * .domain.com
- * host.domain.com
- * nnn.*
- * nnn.nnn.*
- * nnn.nnn.nnn.*
- * nnn.nnn.nnn.nnn
- * nnn.nnn.nnn.nnn/mm
- * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
- */
+ while (isspace(*value & 255))
+ value ++;
- if (!strcasecmp(value, "all"))
- {
- /*
- * All hosts...
- */
+ if (!*value)
+ break;
+ }
- if (!strcasecmp(line, "Allow"))
- cupsdAllowIP(loc, zeros, zeros);
- else
- cupsdDenyIP(loc, zeros, zeros);
- }
- else if (!strcasecmp(value, "none"))
- {
/*
- * No hosts...
+ * Find the end of the value...
*/
- if (!strcasecmp(line, "Allow"))
- cupsdAllowIP(loc, ones, zeros);
- else
- cupsdDenyIP(loc, ones, zeros);
- }
- else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
- {
- /*
- * Host or domain name...
- */
+ for (valptr = value; *valptr && !isspace(*valptr & 255); valptr ++);
- if (value[0] == '*')
- value ++;
+ while (isspace(*valptr & 255))
+ *valptr++ = '\0';
- if (!strcasecmp(line, "Allow"))
- cupsdAllowHost(loc, value);
- else
- cupsdDenyHost(loc, value);
- }
- else
- {
/*
- * One of many IP address forms...
+ * Figure out what form the allow/deny address takes:
+ *
+ * All
+ * None
+ * *.domain.com
+ * .domain.com
+ * host.domain.com
+ * nnn.*
+ * nnn.nnn.*
+ * nnn.nnn.nnn.*
+ * nnn.nnn.nnn.nnn
+ * nnn.nnn.nnn.nnn/mm
+ * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
*/
- if (!get_addr_and_mask(value, ip, mask))
+ if (!strcasecmp(value, "all"))
{
- cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.",
- value, linenum);
- return (0);
+ /*
+ * All hosts...
+ */
+
+ if (!strcasecmp(line, "Allow"))
+ cupsdAllowIP(loc, zeros, zeros);
+ else
+ cupsdDenyIP(loc, zeros, zeros);
+ }
+ else if (!strcasecmp(value, "none"))
+ {
+ /*
+ * No hosts...
+ */
+
+ if (!strcasecmp(line, "Allow"))
+ cupsdAllowIP(loc, ones, zeros);
+ else
+ cupsdDenyIP(loc, ones, zeros);
}
+#ifdef AF_INET6
+ else if (value[0] == '*' || value[0] == '.' ||
+ (!isdigit(value[0] & 255) && value[0] != '['))
+#else
+ else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
+#endif /* AF_INET6 */
+ {
+ /*
+ * Host or domain name...
+ */
+
+ if (value[0] == '*')
+ value ++;
- if (!strcasecmp(line, "Allow"))
- cupsdAllowIP(loc, ip, mask);
+ if (!strcasecmp(line, "Allow"))
+ cupsdAllowHost(loc, value);
+ else
+ cupsdDenyHost(loc, value);
+ }
else
- cupsdDenyIP(loc, ip, mask);
+ {
+ /*
+ * One of many IP address forms...
+ */
+
+ if (!get_addr_and_mask(value, ip, mask))
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.",
+ value, linenum);
+ return (0);
+ }
+
+ if (!strcasecmp(line, "Allow"))
+ cupsdAllowIP(loc, ip, mask);
+ else
+ cupsdDenyIP(loc, ip, mask);
+ }
+
+ /*
+ * Advance to next value...
+ */
+
+ value = valptr;
}
}
else if (!strcasecmp(line, "AuthType"))
{
/*
- * AuthType {none,basic,digest,basicdigest}
+ * AuthType {none,basic,digest,basicdigest,negotiate,default}
*/
if (!strcasecmp(value, "none"))
{
- loc->type = AUTH_NONE;
- loc->level = AUTH_ANON;
+ loc->type = CUPSD_AUTH_NONE;
+ loc->level = CUPSD_AUTH_ANON;
}
else if (!strcasecmp(value, "basic"))
{
- loc->type = AUTH_BASIC;
+ loc->type = CUPSD_AUTH_BASIC;
- if (loc->level == AUTH_ANON)
- loc->level = AUTH_USER;
+ if (loc->level == CUPSD_AUTH_ANON)
+ loc->level = CUPSD_AUTH_USER;
}
else if (!strcasecmp(value, "digest"))
{
- loc->type = AUTH_DIGEST;
+ loc->type = CUPSD_AUTH_DIGEST;
- if (loc->level == AUTH_ANON)
- loc->level = AUTH_USER;
+ if (loc->level == CUPSD_AUTH_ANON)
+ loc->level = CUPSD_AUTH_USER;
}
else if (!strcasecmp(value, "basicdigest"))
{
- loc->type = AUTH_BASICDIGEST;
+ loc->type = CUPSD_AUTH_BASICDIGEST;
+
+ if (loc->level == CUPSD_AUTH_ANON)
+ loc->level = CUPSD_AUTH_USER;
+ }
+ else if (!strcasecmp(value, "default"))
+ {
+ loc->type = CUPSD_AUTH_DEFAULT;
+
+ if (loc->level == CUPSD_AUTH_ANON)
+ loc->level = CUPSD_AUTH_USER;
+ }
+#ifdef HAVE_GSSAPI
+ else if (!strcasecmp(value, "negotiate"))
+ {
+ loc->type = CUPSD_AUTH_NEGOTIATE;
- if (loc->level == AUTH_ANON)
- loc->level = AUTH_USER;
+ if (loc->level == CUPSD_AUTH_ANON)
+ loc->level = CUPSD_AUTH_USER;
}
+#endif /* HAVE_GSSAPI */
else
{
cupsdLogMessage(CUPSD_LOG_WARN,
if (!strcasecmp(value, "anonymous"))
{
- loc->type = AUTH_NONE;
- loc->level = AUTH_ANON;
+ loc->type = CUPSD_AUTH_NONE;
+ loc->level = CUPSD_AUTH_ANON;
cupsdLogMessage(CUPSD_LOG_WARN,
"\"AuthClass %s\" is deprecated; consider removing "
}
else if (!strcasecmp(value, "user"))
{
- loc->level = AUTH_USER;
+ loc->level = CUPSD_AUTH_USER;
cupsdLogMessage(CUPSD_LOG_WARN,
"\"AuthClass %s\" is deprecated; consider using "
}
else if (!strcasecmp(value, "group"))
{
- loc->level = AUTH_GROUP;
+ loc->level = CUPSD_AUTH_GROUP;
cupsdLogMessage(CUPSD_LOG_WARN,
"\"AuthClass %s\" is deprecated; consider using "
- "\"Require @groupname\" on line %d.",
+ "\"Require user @groupname\" on line %d.",
value, linenum);
}
else if (!strcasecmp(value, "system"))
{
- loc->level = AUTH_GROUP;
+ loc->level = CUPSD_AUTH_GROUP;
cupsdAddName(loc, "@SYSTEM");
cupsdLogMessage(CUPSD_LOG_WARN,
"\"AuthClass %s\" is deprecated; consider using "
- "\"Require @SYSTEM\" on line %d.",
+ "\"Require user @SYSTEM\" on line %d.",
value, linenum);
}
else
cupsdLogMessage(CUPSD_LOG_WARN,
"\"AuthGroupName %s\" directive is deprecated; consider "
- "using \"Require @%s\" on line %d.",
+ "using \"Require user @%s\" on line %d.",
value, value, linenum);
}
else if (!strcasecmp(line, "Require"))
if (!strcasecmp(value, "valid-user") ||
!strcasecmp(value, "user"))
- loc->level = AUTH_USER;
+ loc->level = CUPSD_AUTH_USER;
else if (!strcasecmp(value, "group"))
- loc->level = AUTH_GROUP;
+ loc->level = CUPSD_AUTH_GROUP;
else
{
cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Require type %s on line %d.",
while (isspace(*value & 255))
value ++;
+#ifdef HAVE_AUTHORIZATION_H
+ if (!strncmp(value, "@AUTHKEY(", 9))
+ {
+ /*
+ * Grab "@AUTHKEY(name)" value...
+ */
+
+ for (valptr = value + 9; *valptr != ')' && *valptr; valptr ++);
+
+ if (*valptr)
+ *valptr++ = '\0';
+ }
+ else
+#endif /* HAVE_AUTHORIZATION_H */
if (*value == '\"' || *value == '\'')
{
/*
else if (!strcasecmp(line, "Satisfy"))
{
if (!strcasecmp(value, "all"))
- loc->satisfy = AUTH_SATISFY_ALL;
+ loc->satisfy = CUPSD_AUTH_SATISFY_ALL;
else if (!strcasecmp(value, "any"))
- loc->satisfy = AUTH_SATISFY_ANY;
+ loc->satisfy = CUPSD_AUTH_SATISFY_ANY;
else
{
cupsdLogMessage(CUPSD_LOG_WARN, "Unknown Satisfy value %s on line %d.",
}
+/*
+ * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
+ */
+
+static int /* O - FatalErrors bits */
+parse_fatal_errors(const char *s) /* I - FatalErrors string */
+{
+ int fatal; /* FatalErrors bits */
+ char value[1024], /* Value string */
+ *valstart, /* Pointer into value */
+ *valend; /* End of value */
+
+
+ /*
+ * Empty FatalErrors line yields NULL pointer...
+ */
+
+ if (!s)
+ return (CUPSD_FATAL_NONE);
+
+ /*
+ * Loop through the value string,...
+ */
+
+ strlcpy(value, s, sizeof(value));
+
+ fatal = CUPSD_FATAL_NONE;
+
+ for (valstart = value; *valstart;)
+ {
+ /*
+ * Get the current space/comma-delimited kind name...
+ */
+
+ for (valend = valstart; *valend; valend ++)
+ if (isspace(*valend & 255) || *valend == ',')
+ break;
+
+ if (*valend)
+ *valend++ = '\0';
+
+ /*
+ * Add the error to the bitmask...
+ */
+
+ if (!strcasecmp(valstart, "all"))
+ fatal = CUPSD_FATAL_ALL;
+ else if (!strcasecmp(valstart, "browse"))
+ fatal |= CUPSD_FATAL_BROWSE;
+ else if (!strcasecmp(valstart, "-browse"))
+ fatal &= ~CUPSD_FATAL_BROWSE;
+ else if (!strcasecmp(valstart, "config"))
+ fatal |= CUPSD_FATAL_CONFIG;
+ else if (!strcasecmp(valstart, "-config"))
+ fatal &= ~CUPSD_FATAL_CONFIG;
+ else if (!strcasecmp(valstart, "listen"))
+ fatal |= CUPSD_FATAL_LISTEN;
+ else if (!strcasecmp(valstart, "-listen"))
+ fatal &= ~CUPSD_FATAL_LISTEN;
+ else if (!strcasecmp(valstart, "log"))
+ fatal |= CUPSD_FATAL_LOG;
+ else if (!strcasecmp(valstart, "-log"))
+ fatal &= ~CUPSD_FATAL_LOG;
+ else if (!strcasecmp(valstart, "permissions"))
+ fatal |= CUPSD_FATAL_PERMISSIONS;
+ else if (!strcasecmp(valstart, "-permissions"))
+ fatal &= ~CUPSD_FATAL_PERMISSIONS;
+ else if (strcasecmp(valstart, "none"))
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unknown FatalErrors kind \"%s\" ignored!", valstart);
+
+ for (valstart = valend; *valstart; valstart ++)
+ if (!isspace(*valstart & 255) || *valstart != ',')
+ break;
+ }
+
+ return (fatal);
+}
+
+
+/*
+ * 'parse_groups()' - Parse system group names in a string.
+ */
+
+static int /* O - 1 on success, 0 on failure */
+parse_groups(const char *s) /* I - Space-delimited groups */
+{
+ int status; /* Return status */
+ char value[1024], /* Value string */
+ *valstart, /* Pointer into value */
+ *valend, /* End of value */
+ quote; /* Quote character */
+ struct group *group; /* Group */
+
+
+ /*
+ * Make a copy of the string and parse out the groups...
+ */
+
+ strlcpy(value, s, sizeof(value));
+
+ status = 1;
+ valstart = value;
+
+ while (*valstart && NumSystemGroups < MAX_SYSTEM_GROUPS)
+ {
+ if (*valstart == '\'' || *valstart == '\"')
+ {
+ /*
+ * Scan quoted name...
+ */
+
+ quote = *valstart++;
+
+ for (valend = valstart; *valend; valend ++)
+ if (*valend == quote)
+ break;
+ }
+ else
+ {
+ /*
+ * Scan space or comma-delimited name...
+ */
+
+ for (valend = valstart; *valend; valend ++)
+ if (isspace(*valend) || *valend == ',')
+ break;
+ }
+
+ if (*valend)
+ *valend++ = '\0';
+
+ group = getgrnam(valstart);
+ if (group)
+ {
+ cupsdSetString(SystemGroups + NumSystemGroups, valstart);
+ SystemGroupIDs[NumSystemGroups] = group->gr_gid;
+
+ NumSystemGroups ++;
+ }
+ else
+ status = 0;
+
+ endgrent();
+
+ valstart = valend;
+
+ while (*valstart == ',' || isspace(*valstart))
+ valstart ++;
+ }
+
+ return (status);
+}
+
+
+/*
+ * 'parse_protocols()' - Parse browse protocols in a string.
+ */
+
+static int /* O - Browse protocol bits */
+parse_protocols(const char *s) /* I - Space-delimited protocols */
+{
+ int protocols; /* Browse protocol bits */
+ char value[1024], /* Value string */
+ *valstart, /* Pointer into value */
+ *valend; /* End of value */
+
+
+ /*
+ * Empty protocol line yields NULL pointer...
+ */
+
+ if (!s)
+ return (0);
+
+ /*
+ * Loop through the value string,...
+ */
+
+ strlcpy(value, s, sizeof(value));
+
+ protocols = 0;
+
+ for (valstart = value; *valstart;)
+ {
+ /*
+ * Get the current space/comma-delimited protocol name...
+ */
+
+ for (valend = valstart; *valend; valend ++)
+ if (isspace(*valend & 255) || *valend == ',')
+ break;
+
+ if (*valend)
+ *valend++ = '\0';
+
+ /*
+ * Add the protocol to the bitmask...
+ */
+
+ if (!strcasecmp(valstart, "cups"))
+ protocols |= BROWSE_CUPS;
+ else if (!strcasecmp(valstart, "slp"))
+ protocols |= BROWSE_SLP;
+ else if (!strcasecmp(valstart, "ldap"))
+ protocols |= BROWSE_LDAP;
+ else if (!strcasecmp(valstart, "dnssd") ||
+ !strcasecmp(valstart, "dns-sd") ||
+ !strcasecmp(valstart, "bonjour"))
+ protocols |= BROWSE_DNSSD;
+ else if (!strcasecmp(valstart, "lpd"))
+ protocols |= BROWSE_LPD;
+ else if (!strcasecmp(valstart, "smb"))
+ protocols |= BROWSE_SMB;
+ else if (!strcasecmp(valstart, "all"))
+ protocols |= BROWSE_ALL;
+ else if (strcasecmp(valstart, "none"))
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unknown browse protocol \"%s\" ignored!", valstart);
+
+ for (valstart = valend; *valstart; valstart ++)
+ if (!isspace(*valstart & 255) || *valstart != ',')
+ break;
+ }
+
+ return (protocols);
+}
+
+
/*
* 'read_configuration()' - Read a configuration file.
*/
/* Temporary buffer 2 for value */
*ptr, /* Pointer into line/temp */
*value, /* Pointer to value */
- *valueptr, /* Pointer into value */
- quote; /* Quote character */
+ *valueptr; /* Pointer into value */
int valuelen; /* Length of value */
- cupsd_var_t *var; /* Current variable */
+ cupsd_var_t const *var; /* Current variable */
http_addrlist_t *addrlist, /* Address list */
*addr; /* Current address */
unsigned ip[4], /* Address value */
* Decode the directive...
*/
- if (!strcasecmp(line, "Include"))
+ if (!strcasecmp(line, "Include") && value)
{
/*
* Include filename
cupsFileClose(incfile);
}
}
- else if (!strcasecmp(line, "<Location"))
+ else if (!strcasecmp(line, "<Location") && value)
{
/*
* <Location path>
- */
-
- if (value)
- {
- linenum = read_location(fp, value, linenum);
- if (linenum == 0)
- return (0);
- }
- else
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.",
- linenum);
- return (0);
- }
+ */
+
+ linenum = read_location(fp, value, linenum);
+ if (linenum == 0)
+ return (0);
}
- else if (!strcasecmp(line, "<Policy"))
+ else if (!strcasecmp(line, "<Policy") && value)
{
/*
* <Policy name>
*/
- if (value)
- {
- linenum = read_policy(fp, value, linenum);
- if (linenum == 0)
- return (0);
- }
- else
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum);
- return (0);
- }
+ linenum = read_policy(fp, value, linenum);
+ if (linenum == 0)
+ return (0);
}
- else if (!strcasecmp(line, "FaxRetryInterval"))
+ else if (!strcasecmp(line, "FatalErrors"))
+ FatalErrors = parse_fatal_errors(value);
+ else if (!strcasecmp(line, "FaxRetryInterval") && value)
{
- if (value)
- {
- JobRetryInterval = atoi(value);
- cupsdLogMessage(CUPSD_LOG_WARN,
- "FaxRetryInterval is deprecated; use "
- "JobRetryInterval on line %d.", linenum);
- }
- else
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum);
- return (0);
- }
+ JobRetryInterval = atoi(value);
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "FaxRetryInterval is deprecated; use "
+ "JobRetryInterval on line %d.", linenum);
}
- else if (!strcasecmp(line, "FaxRetryLimit"))
+ else if (!strcasecmp(line, "FaxRetryLimit") && value)
{
- if (value)
- {
- JobRetryLimit = atoi(value);
- cupsdLogMessage(CUPSD_LOG_WARN,
- "FaxRetryLimit is deprecated; use "
- "JobRetryLimit on line %d.", linenum);
- }
- else
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum);
- return (0);
- }
+ JobRetryLimit = atoi(value);
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "FaxRetryLimit is deprecated; use "
+ "JobRetryLimit on line %d.", linenum);
}
else if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen")
#ifdef HAVE_SSL
for (addr = addrlist; addr; addr = addr->next)
{
+ /*
+ * See if this address is already present...
+ */
+
+ for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
+ lis;
+ lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
+ if (httpAddrEqual(&(addr->addr), &(lis->address)) &&
+ _httpAddrPort(&(addr->addr)) == _httpAddrPort(&(lis->address)))
+ break;
+
+ if (lis)
+ {
+ httpAddrString(&lis->address, temp, sizeof(temp));
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "Duplicate listen address \"%s\" ignored!", temp);
+ continue;
+ }
+
/*
* Allocate another listener...
*/
- if (NumListeners == 0)
- lis = malloc(sizeof(cupsd_listener_t));
- else
- lis = realloc(Listeners, (NumListeners + 1) * sizeof(cupsd_listener_t));
+ if (!Listeners)
+ Listeners = cupsArrayNew(NULL, NULL);
- if (!lis)
+ if (!Listeners)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unable to allocate %s at line %d - %s.",
break;
}
- Listeners = lis;
- lis += NumListeners;
+ if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to allocate %s at line %d - %s.",
+ line, linenum, strerror(errno));
+ break;
+ }
+
+ cupsArrayAdd(Listeners, lis);
/*
* Copy the current address and log it...
*/
- memset(lis, 0, sizeof(cupsd_listener_t));
memcpy(&(lis->address), &(addr->addr), sizeof(lis->address));
+ lis->fd = -1;
#ifdef HAVE_SSL
if (!strcasecmp(line, "SSLPort") || !strcasecmp(line, "SSLListen"))
lis->encryption = HTTP_ENCRYPT_ALWAYS;
#endif /* HAVE_SSL */
+ httpAddrString(&lis->address, temp, sizeof(temp));
+
#ifdef AF_INET6
if (lis->address.addr.sa_family == AF_INET6)
cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv6)", temp,
cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv4)", temp,
ntohs(lis->address.ipv4.sin_port));
- NumListeners ++;
+ if (!httpAddrLocalhost(&(lis->address)))
+ RemoteAccessEnabled = 1;
}
/*
httpAddrFreeList(addrlist);
}
- else if (!strcasecmp(line, "BrowseAddress"))
+ else if (!strcasecmp(line, "BrowseAddress") && value)
{
/*
* Add a browse address to the list...
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad BrowseAddress %s at line %d.",
value, linenum);
}
- else if (!strcasecmp(line, "BrowseOrder"))
+ else if (!strcasecmp(line, "BrowseOrder") && value)
{
/*
* "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unable to initialize browse access control list!");
else if (!strncasecmp(value, "deny", 4))
- location->order_type = AUTH_ALLOW;
+ location->order_type = CUPSD_AUTH_ALLOW;
else if (!strncasecmp(value, "allow", 5))
- location->order_type = AUTH_DENY;
+ location->order_type = CUPSD_AUTH_DENY;
else
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unknown BrowseOrder value %s on line %d.",
!strcasecmp(line, "BrowseRemoteProtocols"))
{
/*
- * "BrowseProtocol name [... name]"
+ * "BrowseProtocols name [... name]"
+ * "BrowseLocalProtocols name [... name]"
+ * "BrowseRemoteProtocols name [... name]"
*/
- if (strcasecmp(line, "BrowseLocalProtocols"))
- BrowseRemoteProtocols = 0;
- if (strcasecmp(line, "BrowseRemoteProtocols"))
- BrowseLocalProtocols = 0;
+ int protocols = parse_protocols(value);
- for (; *value;)
+ if (protocols < 0)
{
- for (valuelen = 0; value[valuelen]; valuelen ++)
- if (isspace(value[valuelen]) || value[valuelen] == ',')
- break;
-
- if (value[valuelen])
- {
- value[valuelen] = '\0';
- valuelen ++;
- }
-
- if (!strcasecmp(value, "cups"))
- {
- if (strcasecmp(line, "BrowseLocalProtocols"))
- BrowseRemoteProtocols |= BROWSE_CUPS;
- if (strcasecmp(line, "BrowseRemoteProtocols"))
- BrowseLocalProtocols |= BROWSE_CUPS;
- }
- else if (!strcasecmp(value, "slp"))
- {
- if (strcasecmp(line, "BrowseLocalProtocols"))
- BrowseRemoteProtocols |= BROWSE_SLP;
- if (strcasecmp(line, "BrowseRemoteProtocols"))
- BrowseLocalProtocols |= BROWSE_SLP;
- }
- else if (!strcasecmp(value, "ldap"))
- {
- if (strcasecmp(line, "BrowseLocalProtocols"))
- BrowseRemoteProtocols |= BROWSE_LDAP;
- if (strcasecmp(line, "BrowseRemoteProtocols"))
- BrowseLocalProtocols |= BROWSE_LDAP;
- }
- else if (!strcasecmp(value, "all"))
- {
- if (strcasecmp(line, "BrowseLocalProtocols"))
- BrowseRemoteProtocols |= BROWSE_ALL;
- if (strcasecmp(line, "BrowseRemoteProtocols"))
- BrowseLocalProtocols |= BROWSE_ALL;
- }
- else
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unknown browse protocol \"%s\" on line %d.",
- value, linenum);
- break;
- }
-
- for (value += valuelen; *value; value ++)
- if (!isspace(*value) || *value != ',')
- break;
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unknown browse protocol \"%s\" on line %d.",
+ value, linenum);
+ break;
}
+
+ if (strcasecmp(line, "BrowseLocalProtocols"))
+ BrowseRemoteProtocols = protocols;
+ if (strcasecmp(line, "BrowseRemoteProtocols"))
+ BrowseLocalProtocols = protocols;
}
- else if (!strcasecmp(line, "BrowseAllow") ||
- !strcasecmp(line, "BrowseDeny"))
+ else if ((!strcasecmp(line, "BrowseAllow") ||
+ !strcasecmp(line, "BrowseDeny")) && value)
{
/*
* BrowseAllow [From] host/ip...
"Unable to initialize browse access control list!");
else
{
- if (!strncasecmp(value, "from ", 5))
+ while (*value)
{
- /*
- * Strip leading "from"...
- */
-
- value += 5;
+ if (!strncasecmp(value, "from", 4))
+ {
+ /*
+ * Strip leading "from"...
+ */
- while (isspace(*value))
- value ++;
- }
+ value += 4;
- /*
- * Figure out what form the allow/deny address takes:
- *
- * All
- * None
- * *.domain.com
- * .domain.com
- * host.domain.com
- * nnn.*
- * nnn.nnn.*
- * nnn.nnn.nnn.*
- * nnn.nnn.nnn.nnn
- * nnn.nnn.nnn.nnn/mm
- * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
- */
+ while (isspace(*value & 255))
+ value ++;
- if (!strcasecmp(value, "all"))
- {
- /*
- * All hosts...
- */
+ if (!*value)
+ break;
+ }
- if (!strcasecmp(line, "BrowseAllow"))
- cupsdAllowIP(location, zeros, zeros);
- else
- cupsdDenyIP(location, zeros, zeros);
- }
- else if (!strcasecmp(value, "none"))
- {
/*
- * No hosts...
+ * Find the end of the value...
*/
- if (!strcasecmp(line, "BrowseAllow"))
- cupsdAllowIP(location, ones, zeros);
- else
- cupsdDenyIP(location, ones, zeros);
- }
- else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0]))
- {
- /*
- * Host or domain name...
- */
+ for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
- if (value[0] == '*')
- value ++;
+ while (isspace(*valueptr & 255))
+ *valueptr++ = '\0';
- if (!strcasecmp(line, "BrowseAllow"))
- cupsdAllowHost(location, value);
- else
- cupsdDenyHost(location, value);
- }
- else
- {
/*
- * One of many IP address forms...
+ * Figure out what form the allow/deny address takes:
+ *
+ * All
+ * None
+ * *.domain.com
+ * .domain.com
+ * host.domain.com
+ * nnn.*
+ * nnn.nnn.*
+ * nnn.nnn.nnn.*
+ * nnn.nnn.nnn.nnn
+ * nnn.nnn.nnn.nnn/mm
+ * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
*/
- if (!get_addr_and_mask(value, ip, mask))
+ if (!strcasecmp(value, "all"))
{
- cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.",
- value, linenum);
- break;
+ /*
+ * All hosts...
+ */
+
+ if (!strcasecmp(line, "BrowseAllow"))
+ cupsdAllowIP(location, zeros, zeros);
+ else
+ cupsdDenyIP(location, zeros, zeros);
+ }
+ else if (!strcasecmp(value, "none"))
+ {
+ /*
+ * No hosts...
+ */
+
+ if (!strcasecmp(line, "BrowseAllow"))
+ cupsdAllowIP(location, ones, zeros);
+ else
+ cupsdDenyIP(location, ones, zeros);
}
+#ifdef AF_INET6
+ else if (value[0] == '*' || value[0] == '.' ||
+ (!isdigit(value[0] & 255) && value[0] != '['))
+#else
+ else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
+#endif /* AF_INET6 */
+ {
+ /*
+ * Host or domain name...
+ */
- if (!strcasecmp(line, "BrowseAllow"))
- cupsdAllowIP(location, ip, mask);
+ if (value[0] == '*')
+ value ++;
+
+ if (!strcasecmp(line, "BrowseAllow"))
+ cupsdAllowHost(location, value);
+ else
+ cupsdDenyHost(location, value);
+ }
else
- cupsdDenyIP(location, ip, mask);
+ {
+ /*
+ * One of many IP address forms...
+ */
+
+ if (!get_addr_and_mask(value, ip, mask))
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Bad netmask value %s on line %d.",
+ value, linenum);
+ break;
+ }
+
+ if (!strcasecmp(line, "BrowseAllow"))
+ cupsdAllowIP(location, ip, mask);
+ else
+ cupsdDenyIP(location, ip, mask);
+ }
+
+ /*
+ * Advance to next value...
+ */
+
+ value = valueptr;
}
}
}
- else if (!strcasecmp(line, "BrowseRelay"))
+ else if (!strcasecmp(line, "BrowseRelay") && value)
{
/*
* BrowseRelay [from] source [to] destination
* nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
*/
- if (value[0] == '*' || value[0] == '.' || !isdigit(value[0]))
+#ifdef AF_INET6
+ if (value[0] == '*' || value[0] == '.' ||
+ (!isdigit(value[0] & 255) && value[0] != '['))
+#else
+ if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
+#endif /* AF_INET6 */
{
/*
* Host or domain name...
if ((ptr = strchr(temp, ' ')) != NULL)
*ptr = '\0';
- relay->from.type = AUTH_NAME;
- relay->from.mask.name.name = strdup(temp);
+ relay->from.type = CUPSD_AUTH_NAME;
+
+ if ((relay->from.mask.name.name = strdup(temp)) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to allocate BrowseRelay name at line %d - %s.",
+ linenum, strerror(errno));
+ continue;
+ }
+
relay->from.mask.name.length = strlen(temp);
}
else
break;
}
- relay->from.type = AUTH_IP;
+ relay->from.type = CUPSD_AUTH_IP;
memcpy(relay->from.mask.ip.address, ip,
sizeof(relay->from.mask.ip.address));
memcpy(relay->from.mask.ip.netmask, mask,
httpAddrString(&(relay->to), temp, sizeof(temp));
- if (relay->from.type == AUTH_IP)
+ if (relay->from.type == CUPSD_AUTH_IP)
snprintf(temp2, sizeof(temp2), "%u.%u.%u.%u/%u.%u.%u.%u",
- relay->from.mask.ip.address[0],
- relay->from.mask.ip.address[1],
- relay->from.mask.ip.address[2],
- relay->from.mask.ip.address[3],
- relay->from.mask.ip.netmask[0],
- relay->from.mask.ip.netmask[1],
- relay->from.mask.ip.netmask[2],
- relay->from.mask.ip.netmask[3]);
+ relay->from.mask.ip.address[0] >> 24,
+ (relay->from.mask.ip.address[0] >> 16) & 255,
+ (relay->from.mask.ip.address[0] >> 8) & 255,
+ relay->from.mask.ip.address[0] & 255,
+ relay->from.mask.ip.netmask[0] >> 24,
+ (relay->from.mask.ip.netmask[0] >> 16) & 255,
+ (relay->from.mask.ip.netmask[0] >> 8) & 255,
+ relay->from.mask.ip.netmask[0] & 255);
else
strlcpy(temp2, relay->from.mask.name.name, sizeof(temp2));
cupsdLogMessage(CUPSD_LOG_INFO, "Relaying from %s to %s:%d (IPv4)",
- temp, temp2, ntohs(relay->to.ipv4.sin_port));
+ temp2, temp, ntohs(relay->to.ipv4.sin_port));
NumRelays ++;
}
}
else
{
- if (relay->from.type == AUTH_NAME)
+ if (relay->from.type == CUPSD_AUTH_NAME)
free(relay->from.mask.name.name);
cupsdLogMessage(CUPSD_LOG_ERROR, "Bad relay address %s at line %d.",
value, linenum);
}
}
- else if (!strcasecmp(line, "BrowsePoll"))
+ else if (!strcasecmp(line, "BrowsePoll") && value)
{
/*
* BrowsePoll address[:port]
cupsdLogMessage(CUPSD_LOG_INFO, "Polling %s:%d", pollp->hostname,
pollp->port);
}
- else if (!strcasecmp(line, "DefaultAuthType"))
+ else if (!strcasecmp(line, "DefaultAuthType") && value)
{
/*
- * DefaultAuthType {basic,digest,basicdigest}
+ * DefaultAuthType {basic,digest,basicdigest,negotiate}
*/
- if (!strcasecmp(value, "basic"))
- DefaultAuthType = AUTH_BASIC;
+ if (!strcasecmp(value, "none"))
+ DefaultAuthType = CUPSD_AUTH_NONE;
+ else if (!strcasecmp(value, "basic"))
+ DefaultAuthType = CUPSD_AUTH_BASIC;
else if (!strcasecmp(value, "digest"))
- DefaultAuthType = AUTH_DIGEST;
+ DefaultAuthType = CUPSD_AUTH_DIGEST;
else if (!strcasecmp(value, "basicdigest"))
- DefaultAuthType = AUTH_BASICDIGEST;
+ DefaultAuthType = CUPSD_AUTH_BASICDIGEST;
+#ifdef HAVE_GSSAPI
+ else if (!strcasecmp(value, "negotiate"))
+ DefaultAuthType = CUPSD_AUTH_NEGOTIATE;
+#endif /* HAVE_GSSAPI */
else
{
cupsdLogMessage(CUPSD_LOG_WARN,
"Unknown default authorization type %s on line %d.",
value, linenum);
- return (0);
+ if (FatalErrors & CUPSD_FATAL_CONFIG)
+ return (0);
}
}
- else if (!strcasecmp(line, "User"))
+#ifdef HAVE_SSL
+ else if (!strcasecmp(line, "DefaultEncryption"))
+ {
+ /*
+ * DefaultEncryption {Never,IfRequested,Required}
+ */
+
+ if (!value || !strcasecmp(value, "never"))
+ DefaultEncryption = HTTP_ENCRYPT_NEVER;
+ else if (!strcasecmp(value, "required"))
+ DefaultEncryption = HTTP_ENCRYPT_REQUIRED;
+ else if (!strcasecmp(value, "ifrequested"))
+ DefaultEncryption = HTTP_ENCRYPT_IF_REQUESTED;
+ else
+ {
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "Unknown default encryption %s on line %d.",
+ value, linenum);
+ if (FatalErrors & CUPSD_FATAL_CONFIG)
+ return (0);
+ }
+ }
+#endif /* HAVE_SSL */
+#ifdef HAVE_GSSAPI
+ else if (!strcasecmp(line, "Krb5Keytab") && value)
+ {
+ cupsdSetStringf(&Krb5Keytab, "KRB5_KTNAME=%s", value);
+ putenv(Krb5Keytab);
+
+# ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
+ gsskrb5_register_acceptor_identity(value);
+# else
+ cupsdSetEnv("KRB5_KTNAME", value);
+# endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
+ }
+#endif /* HAVE_GSSAPI */
+ else if (!strcasecmp(line, "User") && value)
{
/*
* User ID to run as...
*/
- if (value && isdigit(value[0] & 255))
+ if (isdigit(value[0] & 255))
{
int uid = atoi(value);
else
User = atoi(value);
}
- else if (value)
+ else
{
struct passwd *p; /* Password information */
"Unknown User \"%s\" on line %d, ignoring!",
value, linenum);
}
- else
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "User directive on line %d missing the username!",
- linenum);
}
- else if (!strcasecmp(line, "Group"))
+ else if (!strcasecmp(line, "Group") && value)
{
/*
* Group ID to run as...
value, linenum);
}
}
- else if (!strcasecmp(line, "SystemGroup"))
+ else if (!strcasecmp(line, "SystemGroup") && value)
{
/*
- * System (admin) group(s)...
+ * SystemGroup (admin) group(s)...
*/
- for (i = NumSystemGroups; *value && i < MAX_SYSTEM_GROUPS;)
- {
- if (*value == '\'' || *value == '\"')
- {
- /*
- * Scan quoted name...
- */
-
- quote = *value++;
-
- for (valueptr = value; *valueptr; valueptr ++)
- if (*valueptr == quote)
- break;
- }
- else
- {
- /*
- * Scan space or comma-delimited name...
- */
-
- for (valueptr = value; *valueptr; valueptr ++)
- if (isspace(*valueptr) || *valueptr == ',')
- break;
- }
-
- if (*valueptr)
- *valueptr++ = '\0';
-
- group = getgrnam(value);
- if (group)
- {
- cupsdSetString(SystemGroups + i, value);
- SystemGroupIDs[i] = group->gr_gid;
-
- i ++;
- }
- else
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unknown SystemGroup \"%s\" on line %d, ignoring!",
- value, linenum);
-
- endgrent();
-
- value = valueptr;
-
- while (*value == ',' || isspace(*value))
- value ++;
- }
-
- if (i)
- NumSystemGroups = i;
+ if (!parse_groups(value))
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unknown SystemGroup \"%s\" on line %d, ignoring!",
+ value, linenum);
}
- else if (!strcasecmp(line, "HostNameLookups"))
+ else if (!strcasecmp(line, "HostNameLookups") && value)
{
/*
* Do hostname lookups?
*/
- if (!strcasecmp(value, "off"))
+ if (!strcasecmp(value, "off") || !strcasecmp(value, "no") ||
+ !strcasecmp(value, "false"))
HostNameLookups = 0;
- else if (!strcasecmp(value, "on"))
+ else if (!strcasecmp(value, "on") || !strcasecmp(value, "yes") ||
+ !strcasecmp(value, "true"))
HostNameLookups = 1;
else if (!strcasecmp(value, "double"))
HostNameLookups = 2;
cupsdLogMessage(CUPSD_LOG_WARN, "Unknown HostNameLookups %s on line %d.",
value, linenum);
}
- else if (!strcasecmp(line, "LogLevel"))
+ else if (!strcasecmp(line, "AccessLogLevel") && value)
+ {
+ /*
+ * Amount of logging to do to access log...
+ */
+
+ if (!strcasecmp(value, "all"))
+ AccessLogLevel = CUPSD_ACCESSLOG_ALL;
+ else if (!strcasecmp(value, "actions"))
+ AccessLogLevel = CUPSD_ACCESSLOG_ACTIONS;
+ else if (!strcasecmp(value, "config"))
+ AccessLogLevel = CUPSD_ACCESSLOG_CONFIG;
+ else
+ cupsdLogMessage(CUPSD_LOG_WARN, "Unknown AccessLogLevel %s on line %d.",
+ value, linenum);
+ }
+ else if (!strcasecmp(line, "LogLevel") && value)
{
/*
- * Amount of logging to do...
+ * Amount of logging to do to error log...
*/
if (!strcasecmp(value, "debug2"))
cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogLevel %s on line %d.",
value, linenum);
}
- else if (!strcasecmp(line, "PrintcapFormat"))
+ else if (!strcasecmp(line, "LogTimeFormat") && value)
+ {
+ /*
+ * Amount of logging to do to error log...
+ */
+
+ if (!strcasecmp(value, "standard"))
+ LogTimeFormat = CUPSD_TIME_STANDARD;
+ else if (!strcasecmp(value, "usecs"))
+ LogTimeFormat = CUPSD_TIME_USECS;
+ else
+ cupsdLogMessage(CUPSD_LOG_WARN, "Unknown LogTimeFormat %s on line %d.",
+ value, linenum);
+ }
+ else if (!strcasecmp(line, "PrintcapFormat") && value)
{
/*
* Format of printcap file?
if (!strcasecmp(value, "bsd"))
PrintcapFormat = PRINTCAP_BSD;
+ else if (!strcasecmp(value, "plist"))
+ PrintcapFormat = PRINTCAP_PLIST;
else if (!strcasecmp(value, "solaris"))
PrintcapFormat = PRINTCAP_SOLARIS;
else
cupsdLogMessage(CUPSD_LOG_WARN, "Unknown PrintcapFormat %s on line %d.",
value, linenum);
}
- else if (!strcasecmp(line, "ServerTokens"))
+ else if (!strcasecmp(line, "ServerTokens") && value)
{
/*
* Set the string used for the Server header...
else if (!strcasecmp(value, "Major"))
cupsdSetString(&ServerHeader, "CUPS/1");
else if (!strcasecmp(value, "Minor"))
- cupsdSetString(&ServerHeader, "CUPS/1.1");
+ cupsdSetString(&ServerHeader, "CUPS/1.4");
else if (!strcasecmp(value, "Minimal"))
cupsdSetString(&ServerHeader, CUPS_MINIMAL);
else if (!strcasecmp(value, "OS"))
cupsdLogMessage(CUPSD_LOG_WARN, "Unknown ServerTokens %s on line %d.",
value, linenum);
}
- else if (!strcasecmp(line, "PassEnv"))
+ else if (!strcasecmp(line, "PassEnv") && value)
{
/*
* PassEnv variable [... variable]
break;
}
}
- else if (!strcasecmp(line, "SetEnv"))
+ else if (!strcasecmp(line, "SetEnv") && value)
{
/*
* SetEnv variable value
"Missing value for SetEnv directive on line %d.",
linenum);
}
+#ifdef HAVE_SSL
+ else if (!strcasecmp(line, "SSLOptions"))
+ {
+ /*
+ * SSLOptions options
+ */
+
+ if (!value || !strcasecmp(value, "none"))
+ SSLOptions = CUPSD_SSL_NONE;
+ else if (!strcasecmp(value, "noemptyfragments"))
+ SSLOptions = CUPSD_SSL_NOEMPTY;
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unknown value \"%s\" for SSLOptions directive on "
+ "line %d.", value, linenum);
+ }
+#endif /* HAVE_SSL */
else
{
/*
* Unknown directive! Output an error message and continue...
*/
- cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown directive %s on line %d.",
- line, linenum);
+ if (!value)
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Missing value for %s on line %d.",
+ line, linenum);
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown directive %s on line %d.",
+ line, linenum);
continue;
}
switch (var->type)
{
case CUPSD_VARTYPE_INTEGER :
+ if (!value)
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Missing integer value for %s on line %d!",
+ line, linenum);
+ else
{
int n; /* Number */
char *units; /* Units */
n *= 262144;
}
- *((int *)var->ptr) = n;
+ if (n < 0)
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Bad negative integer value for %s on line %d!",
+ line, linenum);
+ else
+ *((int *)var->ptr) = n;
}
break;
case CUPSD_VARTYPE_BOOLEAN :
- if (!strcasecmp(value, "true") ||
- !strcasecmp(value, "on") ||
- !strcasecmp(value, "enabled") ||
- !strcasecmp(value, "yes") ||
- atoi(value) != 0)
+ if (!value)
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Missing boolean value for %s on line %d!",
+ line, linenum);
+ else if (!strcasecmp(value, "true") ||
+ !strcasecmp(value, "on") ||
+ !strcasecmp(value, "enabled") ||
+ !strcasecmp(value, "yes") ||
+ atoi(value) != 0)
*((int *)var->ptr) = TRUE;
else if (!strcasecmp(value, "false") ||
!strcasecmp(value, "off") ||
value, linenum);
break;
+ case CUPSD_VARTYPE_PATHNAME :
+ if (!value)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Missing pathname value for %s on line %d!",
+ line, linenum);
+ break;
+ }
+
+ if (value[0] == '/')
+ strlcpy(temp, value, sizeof(temp));
+ else
+ snprintf(temp, sizeof(temp), "%s/%s", ServerRoot, value);
+
+ if (access(temp, 0))
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "File or directory for \"%s %s\" on line %d "
+ "does not exist!", line, value, linenum);
+ break;
+ }
+
case CUPSD_VARTYPE_STRING :
cupsdSetString((char **)var->ptr, value);
break;
if ((parent = cupsdAddLocation(location)) == NULL)
return (0);
- parent->limit = AUTH_LIMIT_ALL;
+ parent->limit = CUPSD_AUTH_LIMIT_ALL;
loc = parent;
while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
if (!value)
{
cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum);
- return (0);
+ if (FatalErrors & CUPSD_FATAL_CONFIG)
+ return (0);
+ else
+ continue;
}
if ((loc = cupsdCopyLocation(&parent)) == NULL)
*valptr++ = '\0';
if (!strcmp(value, "ALL"))
- loc->limit = AUTH_LIMIT_ALL;
+ loc->limit = CUPSD_AUTH_LIMIT_ALL;
else if (!strcmp(value, "GET"))
- loc->limit |= AUTH_LIMIT_GET;
+ loc->limit |= CUPSD_AUTH_LIMIT_GET;
else if (!strcmp(value, "HEAD"))
- loc->limit |= AUTH_LIMIT_HEAD;
+ loc->limit |= CUPSD_AUTH_LIMIT_HEAD;
else if (!strcmp(value, "OPTIONS"))
- loc->limit |= AUTH_LIMIT_OPTIONS;
+ loc->limit |= CUPSD_AUTH_LIMIT_OPTIONS;
else if (!strcmp(value, "POST"))
- loc->limit |= AUTH_LIMIT_POST;
+ loc->limit |= CUPSD_AUTH_LIMIT_POST;
else if (!strcmp(value, "PUT"))
- loc->limit |= AUTH_LIMIT_PUT;
+ loc->limit |= CUPSD_AUTH_LIMIT_PUT;
else if (!strcmp(value, "TRACE"))
- loc->limit |= AUTH_LIMIT_TRACE;
+ loc->limit |= CUPSD_AUTH_LIMIT_TRACE;
else
cupsdLogMessage(CUPSD_LOG_WARN, "Unknown request type %s on line %d!",
value, linenum);
}
if (!strcasecmp(line, "<LimitExcept"))
- loc->limit = AUTH_LIMIT_ALL ^ loc->limit;
+ loc->limit = CUPSD_AUTH_LIMIT_ALL ^ loc->limit;
parent->limit &= ~loc->limit;
}
- else if (!strcasecmp(line, "</Limit>"))
+ else if (!strcasecmp(line, "</Limit>") ||
+ !strcasecmp(line, "</LimitExcept>"))
loc = parent;
else if (!parse_aaa(loc, line, value, linenum))
{
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unknown Location directive %s on line %d.",
line, linenum);
- return (0);
+ if (FatalErrors & CUPSD_FATAL_CONFIG)
+ return (0);
}
}
"Unexpected end-of-file at line %d while reading location!",
linenum);
- return (0);
+ return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
}
"Missing </Limit> before </Policy> on line %d!",
linenum);
+ /*
+ * Verify that we have an explicit policy for CUPS-Get-Document
+ * (ensures that upgrades do not introduce new security issues...)
+ */
+
+ if ((op = cupsdFindPolicyOp(pol, CUPS_GET_DOCUMENT)) == NULL ||
+ op->op == IPP_ANY_OPERATION)
+ {
+ if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
+ op->op != IPP_ANY_OPERATION)
+ {
+ /*
+ * Add a new limit for CUPS-Get-Document using the Send-Document
+ * limit as a template...
+ */
+
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "No limit for CUPS-Get-Document defined in policy %s "
+ "- using Send-Document's policy", pol->name);
+
+ cupsdAddPolicyOp(pol, op, CUPS_GET_DOCUMENT);
+ }
+ }
+
return (linenum);
}
else if (!strcasecmp(line, "<Limit") && !op)
if (!value)
{
cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum);
- return (0);
+ if (FatalErrors & CUPSD_FATAL_CONFIG)
+ return (0);
+ else
+ continue;
}
/*
cupsdLogMessage(CUPSD_LOG_ERROR,
"Missing <Limit ops> directive before %s on line %d.",
line, linenum);
- return (0);
+ if (FatalErrors & CUPSD_FATAL_CONFIG)
+ return (0);
}
else if (!parse_aaa(op, line, value, linenum))
{
"Unknown Policy directive %s on line %d.",
line, linenum);
- return (0);
+ if (FatalErrors & CUPSD_FATAL_CONFIG)
+ return (0);
}
}
"Unexpected end-of-file at line %d while reading policy \"%s\"!",
linenum, policy);
- return (0);
+ return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
}
/*
- * End of "$Id: conf.c 5008 2006-01-27 19:30:34Z mike $".
+ * End of "$Id: conf.c 7952 2008-09-17 00:56:20Z mike $".
*/