📄 conf.c
字号:
/* * "$Id: conf.c,v 1.152 2005/01/03 19:29:59 mike Exp $" * * Configuration routines for the Common UNIX Printing System (CUPS). * * Copyright 1997-2005 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 * * Contents: * * ReadConfiguration() - Read the cupsd.conf file. * read_configuration() - Read a configuration file. * read_location() - Read a <Location path> definition. * get_address() - Get an address + port number from a line. * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef * required by SSLSetCertificate. *//* * Include necessary headers... */#include "cupsd.h"#include <stdarg.h>#include <pwd.h>#include <grp.h>#include <sys/utsname.h>#ifdef HAVE_CDSASSL# include <Security/SecureTransport.h># include <Security/SecIdentitySearch.h>#endif /* HAVE_CDSASSL */#ifdef HAVE_VSYSLOG# include <syslog.h>#endif /* HAVE_VSYSLOG *//* * Possibly missing network definitions... */#ifndef INADDR_NONE# define INADDR_NONE 0xffffffff#endif /* !INADDR_NONE *//* * Configuration variable structure... */typedef struct{ char *name; /* Name of variable */ void *ptr; /* Pointer to variable */ int type; /* Type (int, string, address) */} var_t;#define VAR_INTEGER 0#define VAR_STRING 1#define VAR_BOOLEAN 2/* * Local globals... */static var_t variables[] ={ { "AccessLog", &AccessLog, VAR_STRING },#if 0 { "AutoPurgeJobs", &JobAutoPurge, VAR_BOOLEAN }, { "BrowseInterval", &BrowseInterval, VAR_INTEGER }, { "BrowsePort", &BrowsePort, VAR_INTEGER }, { "BrowseShortNames", &BrowseShortNames, VAR_BOOLEAN }, { "BrowseTimeout", &BrowseTimeout, VAR_INTEGER }, { "Browsing", &Browsing, VAR_BOOLEAN }, { "Classification", &Classification, VAR_STRING }, { "ClassifyOverride", &ClassifyOverride, VAR_BOOLEAN }, { "FaxRetryLimit", &FaxRetryLimit, VAR_INTEGER }, { "FaxRetryInterval", &FaxRetryInterval, VAR_INTEGER }, { "FileDevice", &FileDevice, VAR_BOOLEAN }, { "FilterLimit", &FilterLimit, VAR_INTEGER }, { "FilterNice", &FilterNice, VAR_INTEGER }, { "FontPath", &FontPath, VAR_STRING }, { "HideImplicitMembers", &HideImplicitMembers, VAR_BOOLEAN }, { "ImplicitClasses", &ImplicitClasses, VAR_BOOLEAN }, { "ImplicitAnyClasses", &ImplicitAnyClasses, VAR_BOOLEAN }, { "MaxJobs", &MaxJobs, VAR_INTEGER }, { "MaxJobsPerPrinter", &MaxJobsPerPrinter, VAR_INTEGER }, { "MaxJobsPerUser", &MaxJobsPerUser, VAR_INTEGER }, { "PageLog", &PageLog, VAR_STRING }, { "PreserveJobFiles", &JobFiles, VAR_BOOLEAN }, { "PreserveJobHistory", &JobHistory, VAR_BOOLEAN }, { "Printcap", &Printcap, VAR_STRING }, { "PrintcapGUI", &PrintcapGUI, VAR_STRING }, { "ReloadTimeout", &ReloadTimeout, VAR_INTEGER }, { "RootCertDuration", &RootCertDuration, VAR_INTEGER },#endif#ifdef HAVE_SSL { "ServerCertificate", &ServerCertificate, VAR_STRING },# if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS) { "ServerKey", &ServerKey, VAR_STRING },# endif /* HAVE_LIBSSL || HAVE_GNUTLS */#endif /* HAVE_SSL */ { "ConfigFilePerm", &ConfigFilePerm, VAR_INTEGER }, { "DataDir", &DataDir, VAR_STRING }, { "DefaultCharset", &DefaultCharset, VAR_STRING }, { "DefaultLanguage", &DefaultLanguage, VAR_STRING }, { "DocumentRoot", &DocumentRoot, VAR_STRING }, { "ErrorLog", &ErrorLog, VAR_STRING }, { "KeepAliveTimeout", &KeepAliveTimeout, VAR_INTEGER }, { "KeepAlive", &KeepAlive, VAR_BOOLEAN }, { "LimitRequestBody", &MaxRequestSize, VAR_INTEGER }, { "ListenBackLog", &ListenBackLog, VAR_INTEGER }, { "LogFilePerm", &LogFilePerm, VAR_INTEGER }, { "MaxClients", &MaxClients, VAR_INTEGER }, { "MaxClientsPerHost", &MaxClientsPerHost, VAR_INTEGER }, { "MaxCopies", &MaxCopies, VAR_INTEGER }, { "MaxLogSize", &MaxLogSize, VAR_INTEGER }, { "MaxPrinterHistory", &MaxPrinterHistory, VAR_INTEGER }, { "MaxRequestSize", &MaxRequestSize, VAR_INTEGER }, { "RemoteRoot", &RemoteRoot, VAR_STRING }, { "RequestRoot", &RequestRoot, VAR_STRING }, { "RIPCache", &RIPCache, VAR_STRING }, { "RunAsUser", &RunAsUser, VAR_BOOLEAN }, { "ServerAdmin", &ServerAdmin, VAR_STRING }, { "ServerBin", &ServerBin, VAR_STRING }, { "ServerName", &ServerName, VAR_STRING }, { "ServerRoot", &ServerRoot, VAR_STRING }, { "TempDir", &TempDir, VAR_STRING }, { "Timeout", &Timeout, VAR_INTEGER }};#define NUM_VARS (sizeof(variables) / sizeof(variables[0]))/* * Local functions... */static int read_configuration(cups_file_t *fp);static int get_address(char *value, unsigned defaddress, int defport, struct sockaddr_in *address);#ifdef HAVE_CDSASSLstatic CFArrayRef CDSAGetServerCerts();#endif /* HAVE_CDSASSL */#if 0static int read_location(cups_file_t *fp, char *name, int linenum);#endif/* * 'ReadConfiguration()' - Read the cupsd.conf file. */int /* O - 1 on success, 0 otherwise */ReadConfiguration(void){ cups_file_t *fp; /* Configuration file */ int status; /* Return status */ char temp[1024], /* Temporary buffer */ *slash; /* Directory separator */ char *language; /* Language string */ struct passwd *user; /* Default user */ struct group *group; /* Default group */ char *old_serverroot, /* Old ServerRoot */ *old_requestroot; /* Old RequestRoot */#if 0 int i; /* Looping var */ char type[MIME_MAX_SUPER + MIME_MAX_TYPE]; /* MIME type name */#endif /* * Shutdown the server... */ DEBUG_printf(("\nFunction ReadConfiguration() START...... \n")); StopServer(); /* * Save the old root paths... */ old_serverroot = NULL; SetString(&old_serverroot, ServerRoot); old_requestroot = NULL; SetString(&old_requestroot, RequestRoot);#if 0 /* * Reset the server configuration data... */ DeleteAllLocations(); if (NumBrowsers > 0) { free(Browsers); NumBrowsers = 0; } if (NumPolled > 0) { free(Polled); NumPolled = 0; } if (NumRelays > 0) { for (i = 0; i < NumRelays; i ++) if (Relays[i].from.type == AUTH_NAME) free(Relays[i].from.mask.name.name); free(Relays); NumRelays = 0; } if (NumListeners > 0) { free(Listeners); NumListeners = 0; }#endif /* * String options... */ gethostname(temp, sizeof(temp)); SetString(&ServerName, temp); SetStringf(&ServerAdmin, "root@%s", temp); SetString(&ServerBin, CUPS_SERVERBIN); SetString(&RequestRoot, CUPS_REQUESTS); SetString(&DocumentRoot, CUPS_DOCROOT); SetString(&DataDir, CUPS_DATADIR); SetString(&AccessLog, CUPS_LOGDIR "/access_log"); SetString(&ErrorLog, CUPS_LOGDIR "/error_log"); SetString(&PageLog, CUPS_LOGDIR "/page_log"); SetString(&Printcap, "/etc/printcap_ipp"); SetString(&PrintcapGUI, "/usr/bin/glpoptions"); SetString(&FontPath, CUPS_FONTPATH); SetString(&RemoteRoot, "remroot"); SetString(&ServerHeader, "CUPS/1.1"); strlcpy(temp, ConfigurationFile, sizeof(temp)); if ((slash = strrchr(temp, '/')) != NULL) *slash = '\0'; SetString(&ServerRoot, temp); ClearString(&Classification); ClassifyOverride = 0;#ifdef HAVE_SSL# ifdef HAVE_CDSASSL SetString(&ServerCertificate, "/var/root/Library/Keychains/CUPS");# else SetString(&ServerCertificate, "ssl/server.crt"); SetString(&ServerKey, "ssl/server.key");# endif /* HAVE_CDSASSL */#endif /* HAVE_SSL */ if ((language = DEFAULT_LANGUAGE) == NULL) language = "en"; else if (strcmp(language, "C") == 0 || strcmp(language, "POSIX") == 0) language = "en"; SetString(&DefaultLanguage, language); SetString(&DefaultCharset, DEFAULT_CHARSET); SetString(&RIPCache, "8m"); if (getenv("TMPDIR") == NULL) SetString(&TempDir, CUPS_REQUESTS "/tmp"); else SetString(&TempDir, getenv("TMPDIR")); /* * Find the default system group: "sys", "system", or "root"... */ group = getgrnam(CUPS_DEFAULT_GROUP); endgrent(); NumSystemGroups = 0; if (group != NULL) { SetString(&SystemGroups[0], CUPS_DEFAULT_GROUP); Group = group->gr_gid; } else { group = getgrgid(0); endgrent(); if (group != NULL) { SetString(&SystemGroups[0], group->gr_name); Group = 0; } else { SetString(&SystemGroups[0], "unknown"); Group = 0; } } /* * Find the default user... */ if ((user = getpwnam(CUPS_DEFAULT_USER)) == NULL) User = 1; /* Force to a non-priviledged account */ else User = user->pw_uid; endpwent(); /* * Numeric options... */ ConfigFilePerm = 0640; LogFilePerm = 0644;#if 0 FaxRetryLimit = 5; FaxRetryInterval = 300; FileDevice = FALSE; FilterLevel = 0; FilterLimit = 0; FilterNice = 0; HostNameLookups = FALSE; ImplicitClasses = TRUE; ImplicitAnyClasses = FALSE; HideImplicitMembers = TRUE; BrowseInterval = DEFAULT_INTERVAL; BrowsePort = ippPort(); BrowseProtocols = BROWSE_CUPS; BrowseShortNames = TRUE; BrowseTimeout = DEFAULT_TIMEOUT; Browsing = TRUE; JobHistory = DEFAULT_HISTORY; JobFiles = DEFAULT_FILES; JobAutoPurge = 0; MaxJobs = 500; MaxJobsPerUser = 0; MaxJobsPerPrinter = 0; MaxCopies = 100; #endif KeepAlive = TRUE; KeepAliveTimeout = DEFAULT_KEEPALIVE; ListenBackLog = SOMAXCONN; LogLevel = L_ERROR; MaxClients = 100; MaxClientsPerHost = 0; MaxLogSize = 1024 * 1024; MaxPrinterHistory = 10; MaxRequestSize = 0; ReloadTimeout = 60; RootCertDuration = 300; RunAsUser = FALSE; Timeout = DEFAULT_TIMEOUT; DEBUG_printf(("test 01\n")); /* * Read the configuration file... */ if ((fp = cupsFileOpen(ConfigurationFile, "r")) == NULL) { DEBUG_printf(("ERROR ConfigurationFile:%s open false\n", ConfigurationFile)); return (0); } status = read_configuration(fp); cupsFileClose(fp); if (!status) return (0); if (RunAsUser) RunUser = User; else RunUser = getuid(); /* * Use the default system group if none was supplied in cupsd.conf... */ if (NumSystemGroups == 0) NumSystemGroups ++;#if 0 /* * Get the access control list for browsing... */ BrowseACL = FindLocation("CUPS_INTERNAL_BROWSE_ACL");#endif /* * Open the system log for cupsd if necessary... */#ifdef HAVE_VSYSLOG if (strcmp(AccessLog, "syslog") == 0 || strcmp(ErrorLog, "syslog") == 0 || strcmp(PageLog, "syslog") == 0) openlog("cupsd", LOG_PID | LOG_NOWAIT | LOG_NDELAY, LOG_LPR);#endif /* HAVE_VSYSLOG */ /* * Log the configuration file that was used... */ LogMessage(L_INFO, "Loaded configuration file \"%s\"", ConfigurationFile); /* * Check that we have at least one listen/port line; if not, report this * as an error and exit! */ if (NumListeners == 0) { /* * No listeners! */ LogMessage(L_EMERG, "No valid Listen or Port lines were found in the configuration file!"); /* * Commit suicide... */ kill(getpid(), SIGTERM); } /* * Set the default locale using the language and charset... */ SetStringf(&DefaultLocale, "%s.%s", DefaultLanguage, DefaultCharset); /* * Update all relative filenames to include the full path from ServerRoot... */ if (DocumentRoot[0] != '/') SetStringf(&DocumentRoot, "%s/%s", ServerRoot, DocumentRoot); if (RequestRoot[0] != '/') SetStringf(&RequestRoot, "%s/%s", ServerRoot, RequestRoot); if (ServerBin[0] != '/') SetStringf(&ServerBin, "%s/%s", ServerRoot, ServerBin);#ifdef HAVE_SSL if (ServerCertificate[0] != '/') SetStringf(&ServerCertificate, "%s/%s", ServerRoot, ServerCertificate);# if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS) chown(ServerCertificate, RunUser, Group); chmod(ServerCertificate, ConfigFilePerm); if (ServerKey[0] != '/') SetStringf(&ServerKey, "%s/%s", ServerRoot, ServerKey); chown(ServerKey, RunUser, Group); chmod(ServerKey, ConfigFilePerm);# endif /* HAVE_LIBSSL || HAVE_GNUTLS */#endif /* HAVE_SSL */ /* * Make sure that ServerRoot and the config files are owned and * writable by the user and group in the cupsd.conf file... */ chown(ServerRoot, RunUser, Group); chmod(ServerRoot, 0775);#if 0 snprintf(temp, sizeof(temp), "%s/certs", ServerRoot); chown(temp, RunUser, Group); chmod(temp, 0711); snprintf(temp, sizeof(temp), "%s/ppd", ServerRoot); chown(temp, RunUser, Group); chmod(temp, 0755); snprintf(temp, sizeof(temp), "%s/ssl", ServerRoot); chown(temp, RunUser, Group); chmod(temp, 0700); snprintf(temp, sizeof(temp), "%s/classes.conf", ServerRoot); chown(temp, RunUser, Group);#ifdef __APPLE__ chmod(temp, 0600);#else chmod(temp, ConfigFilePerm);#endif /* __APPLE__ */ snprintf(temp, sizeof(temp), "%s/passwd.md5", ServerRoot); chown(temp, User, Group); chmod(temp, 0600);#endif snprintf(temp, sizeof(temp), "%s/cupsd.conf", ServerRoot); chown(temp, RunUser, Group); chmod(temp, ConfigFilePerm); snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot); chown(temp, RunUser, Group);#ifdef __APPLE__ chmod(temp, 0600);#else chmod(temp, ConfigFilePerm);#endif /* __APPLE__ */ /* * Make sure the request and temporary directories have the right * permissions... */ chown(RequestRoot, RunUser, Group); chmod(RequestRoot, 0710); if (strncmp(TempDir, RequestRoot, strlen(RequestRoot)) == 0) { /* * Only update ownership and permissions if the CUPS temp directory * is under the spool directory... */ chown(TempDir, RunUser, Group); chmod(TempDir, 01770); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -