CHANGES IN CUPS V1.1.19
+ - Revamped how strings are stored in the scheduler,
+ providing a substantial improvement in memory usage
+ for systems with large numbers of printers.
- The PostScript filter now supports binary PostScript
files and files beginning with the PJL language escape
sequence.
/*
- * "$Id: classes.c,v 1.34.2.9 2003/01/24 18:00:54 mike Exp $"
+ * "$Id: classes.c,v 1.34.2.10 2003/01/29 20:08:20 mike Exp $"
*
* Printer class routines for the Common UNIX Printing System (CUPS).
*
#ifdef AF_INET6
if (Listeners[0].address.addr.sa_family == AF_INET6)
- snprintf(c->uri, sizeof(c->uri), "ipp://%s:%d/classes/%s", ServerName,
- ntohs(Listeners[0].address.ipv6.sin6_port), name);
+ SetStringf(&c->uri, "ipp://%s:%d/classes/%s", ServerName,
+ ntohs(Listeners[0].address.ipv6.sin6_port), name);
else
#endif /* AF_INET6 */
- snprintf(c->uri, sizeof(c->uri), "ipp://%s:%d/classes/%s", ServerName,
- ntohs(Listeners[0].address.ipv4.sin_port), name);
+ SetStringf(&c->uri, "ipp://%s:%d/classes/%s", ServerName,
+ ntohs(Listeners[0].address.ipv4.sin_port), name);
}
return (c);
}
else if (strcmp(name, "Info") == 0)
- strlcpy(p->info, value, sizeof(p->info));
+ SetString(&p->info, value);
else if (strcmp(name, "Location") == 0)
- strlcpy(p->location, value, sizeof(p->location));
+ SetString(&p->location, value);
else if (strcmp(name, "Printer") == 0)
{
- if ((temp = FindPrinter(value)) != NULL)
- AddPrinterToClass(p, temp);
- else
+ if ((temp = FindPrinter(value)) == NULL)
+ {
LogMessage(L_WARN, "Unknown printer %s on line %d of classes.conf.",
value, linenum);
+
+ /*
+ * Add the missing remote printer...
+ */
+
+ temp = AddPrinter(value);
+ strcpy(temp->make_model, "Remote Printer on unknown");
+
+ temp->state = IPP_PRINTER_STOPPED;
+ temp->type |= CUPS_PRINTER_REMOTE;
+ temp->browse_time = 2147483647;
+
+ SetString(&temp->location, "Location Unknown");
+ SetString(&temp->info, "No Information Available");
+ temp->hostname[0] = '\0';
+
+ SetPrinterAttrs(temp);
+ }
+
+ if (temp)
+ AddPrinterToClass(p, temp);
}
else if (strcmp(name, "State") == 0)
{
if (*valueptr)
*valueptr++ = '\0';
- strlcpy(p->job_sheets[0], value, sizeof(p->job_sheets[0]));
+ SetString(&p->job_sheets[0], value);
while (isspace(*valueptr))
valueptr ++;
if (*valueptr)
*valueptr++ = '\0';
- strlcpy(p->job_sheets[1], value, sizeof(p->job_sheets[1]));
+ SetString(&p->job_sheets[1], value);
}
}
else if (strcmp(name, "AllowUser") == 0)
else
fprintf(fp, "<Class %s>\n", pclass->name);
- if (pclass->info[0])
+ if (pclass->info)
fprintf(fp, "Info %s\n", pclass->info);
- if (pclass->location[0])
+ if (pclass->location)
fprintf(fp, "Location %s\n", pclass->location);
if (pclass->state == IPP_PRINTER_STOPPED)
/*
- * End of "$Id: classes.c,v 1.34.2.9 2003/01/24 18:00:54 mike Exp $".
+ * End of "$Id: classes.c,v 1.34.2.10 2003/01/29 20:08:20 mike Exp $".
*/
/*
- * "$Id: conf.c,v 1.77.2.23 2003/01/29 15:38:45 mike Exp $"
+ * "$Id: conf.c,v 1.77.2.24 2003/01/29 20:08:20 mike Exp $"
*
* Configuration routines for the Common UNIX Printing System (CUPS).
*
{
char *name; /* Name of variable */
void *ptr; /* Pointer to variable */
- int type, /* Type (int, string, address) */
- size; /* Size of string */
+ int type; /* Type (int, string, address) */
} var_t;
#define VAR_INTEGER 0
static var_t variables[] =
{
- { "AccessLog", AccessLog, VAR_STRING, sizeof(AccessLog) },
- { "AutoPurgeJobs", &JobAutoPurge, VAR_BOOLEAN, 0 },
- { "BrowseInterval", &BrowseInterval, VAR_INTEGER, 0 },
- { "BrowsePort", &BrowsePort, VAR_INTEGER, 0 },
- { "BrowseShortNames", &BrowseShortNames, VAR_BOOLEAN, 0 },
- { "BrowseTimeout", &BrowseTimeout, VAR_INTEGER, 0 },
- { "Browsing", &Browsing, VAR_BOOLEAN, 0 },
- { "Classification", Classification, VAR_STRING, sizeof(Classification) },
- { "ClassifyOverride", &ClassifyOverride, VAR_BOOLEAN, 0 },
- { "ConfigFilePerm", &ConfigFilePerm, VAR_INTEGER, 0 },
- { "DataDir", DataDir, VAR_STRING, sizeof(DataDir) },
- { "DefaultCharset", DefaultCharset, VAR_STRING, sizeof(DefaultCharset) },
- { "DefaultLanguage", DefaultLanguage, VAR_STRING, sizeof(DefaultLanguage) },
- { "DocumentRoot", DocumentRoot, VAR_STRING, sizeof(DocumentRoot) },
- { "ErrorLog", ErrorLog, VAR_STRING, sizeof(ErrorLog) },
- { "FileDevice", &FileDevice, VAR_BOOLEAN, 0 },
- { "FilterLimit", &FilterLimit, VAR_INTEGER, 0 },
- { "FilterNice", &FilterNice, VAR_INTEGER, 0 },
- { "FontPath", FontPath, VAR_STRING, sizeof(FontPath) },
- { "HideImplicitMembers", &HideImplicitMembers, VAR_BOOLEAN, 0 },
- { "ImplicitClasses", &ImplicitClasses, VAR_BOOLEAN, 0 },
- { "ImplicitAnyClasses", &ImplicitAnyClasses, VAR_BOOLEAN, 0 },
- { "KeepAliveTimeout", &KeepAliveTimeout, VAR_INTEGER, 0 },
- { "KeepAlive", &KeepAlive, VAR_BOOLEAN, 0 },
- { "LimitRequestBody", &MaxRequestSize, VAR_INTEGER, 0 },
- { "ListenBackLog", &ListenBackLog, VAR_INTEGER, 0 },
- { "LogFilePerm", &LogFilePerm, VAR_INTEGER, 0 },
- { "MaxActiveJobs", &MaxActiveJobs, VAR_INTEGER, 0 },
- { "MaxClients", &MaxClients, VAR_INTEGER, 0 },
- { "MaxClientsPerHost",&MaxClientsPerHost, VAR_INTEGER, 0 },
- { "MaxCopies", &MaxCopies, VAR_INTEGER, 0 },
- { "MaxJobs", &MaxJobs, VAR_INTEGER, 0 },
- { "MaxJobsPerPrinter",&MaxJobsPerPrinter, VAR_INTEGER, 0 },
- { "MaxJobsPerUser", &MaxJobsPerUser, VAR_INTEGER, 0 },
- { "MaxLogSize", &MaxLogSize, VAR_INTEGER, 0 },
- { "MaxRequestSize", &MaxRequestSize, VAR_INTEGER, 0 },
- { "PageLog", PageLog, VAR_STRING, sizeof(PageLog) },
- { "PreserveJobFiles", &JobFiles, VAR_BOOLEAN, 0 },
- { "PreserveJobHistory", &JobHistory, VAR_BOOLEAN, 0 },
- { "Printcap", Printcap, VAR_STRING, sizeof(Printcap) },
- { "PrintcapGUI", PrintcapGUI, VAR_STRING, sizeof(PrintcapGUI) },
- { "RemoteRoot", RemoteRoot, VAR_STRING, sizeof(RemoteRoot) },
- { "RequestRoot", RequestRoot, VAR_STRING, sizeof(RequestRoot) },
- { "RIPCache", RIPCache, VAR_STRING, sizeof(RIPCache) },
- { "RunAsUser", &RunAsUser, VAR_BOOLEAN, 0 },
- { "RootCertDuration", &RootCertDuration, VAR_INTEGER, 0 },
- { "ServerAdmin", ServerAdmin, VAR_STRING, sizeof(ServerAdmin) },
- { "ServerBin", ServerBin, VAR_STRING, sizeof(ServerBin) },
+ { "AccessLog", &AccessLog, VAR_STRING },
+ { "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 },
+ { "ConfigFilePerm", &ConfigFilePerm, VAR_INTEGER },
+ { "DataDir", &DataDir, VAR_STRING },
+ { "DefaultCharset", &DefaultCharset, VAR_STRING },
+ { "DefaultLanguage", &DefaultLanguage, VAR_STRING },
+ { "DocumentRoot", &DocumentRoot, VAR_STRING },
+ { "ErrorLog", &ErrorLog, VAR_STRING },
+ { "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 },
+ { "KeepAliveTimeout", &KeepAliveTimeout, VAR_INTEGER },
+ { "KeepAlive", &KeepAlive, VAR_BOOLEAN },
+ { "LimitRequestBody", &MaxRequestSize, VAR_INTEGER },
+ { "ListenBackLog", &ListenBackLog, VAR_INTEGER },
+ { "LogFilePerm", &LogFilePerm, VAR_INTEGER },
+ { "MaxActiveJobs", &MaxActiveJobs, VAR_INTEGER },
+ { "MaxClients", &MaxClients, VAR_INTEGER },
+ { "MaxClientsPerHost", &MaxClientsPerHost, VAR_INTEGER },
+ { "MaxCopies", &MaxCopies, VAR_INTEGER },
+ { "MaxJobs", &MaxJobs, VAR_INTEGER },
+ { "MaxJobsPerPrinter", &MaxJobsPerPrinter, VAR_INTEGER },
+ { "MaxJobsPerUser", &MaxJobsPerUser, VAR_INTEGER },
+ { "MaxLogSize", &MaxLogSize, VAR_INTEGER },
+ { "MaxRequestSize", &MaxRequestSize, VAR_INTEGER },
+ { "PageLog", &PageLog, VAR_STRING },
+ { "PreserveJobFiles", &JobFiles, VAR_BOOLEAN },
+ { "PreserveJobHistory", &JobHistory, VAR_BOOLEAN },
+ { "Printcap", &Printcap, VAR_STRING },
+ { "PrintcapGUI", &PrintcapGUI, VAR_STRING },
+ { "RemoteRoot", &RemoteRoot, VAR_STRING },
+ { "RequestRoot", &RequestRoot, VAR_STRING },
+ { "RIPCache", &RIPCache, VAR_STRING },
+ { "RunAsUser", &RunAsUser, VAR_BOOLEAN },
+ { "RootCertDuration", &RootCertDuration, VAR_INTEGER },
+ { "ServerAdmin", &ServerAdmin, VAR_STRING },
+ { "ServerBin", &ServerBin, VAR_STRING },
#ifdef HAVE_SSL
- { "ServerCertificate",ServerCertificate, VAR_STRING, sizeof(ServerCertificate) },
- { "ServerKey", ServerKey, VAR_STRING, sizeof(ServerKey) },
+ { "ServerCertificate", &ServerCertificate, VAR_STRING },
+ { "ServerKey", &ServerKey, VAR_STRING },
#endif /* HAVE_SSL */
- { "ServerName", ServerName, VAR_STRING, sizeof(ServerName) },
- { "ServerRoot", ServerRoot, VAR_STRING, sizeof(ServerRoot) },
- { "TempDir", TempDir, VAR_STRING, sizeof(TempDir) },
- { "Timeout", &Timeout, VAR_INTEGER, 0 }
+ { "ServerName", &ServerName, VAR_STRING },
+ { "ServerRoot", &ServerRoot, VAR_STRING },
+ { "TempDir", &TempDir, VAR_STRING },
+ { "Timeout", &Timeout, VAR_INTEGER }
};
#define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
+
static unsigned ones[4] =
{
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
* 'ReadConfiguration()' - Read the cupsd.conf file.
*/
-int /* O - 1 if file read successfully, 0 otherwise */
+int /* O - 1 on success, 0 otherwise */
ReadConfiguration(void)
{
- int i; /* Looping var */
- FILE *fp; /* Configuration file */
- int status; /* Return status */
- char directory[1024],/* Configuration directory */
- *slash; /* Directory separator */
+ int i; /* Looping var */
+ FILE *fp; /* Configuration file */
+ int status; /* Return status */
+ char temp[1024], /* Temporary buffer */
+ *slash; /* Directory separator */
char type[MIME_MAX_SUPER + MIME_MAX_TYPE];
- /* MIME type name */
- struct rlimit limit; /* Runtime limit */
- char *language; /* Language string */
- struct passwd *user; /* Default user */
- struct group *group; /* Default group */
+ /* MIME type name */
+ struct rlimit limit; /* Runtime limit */
+ char *language; /* Language string */
+ struct passwd *user; /* Default user */
+ struct group *group; /* Default group */
+ int run_user; /* User that will be running cupsd */
/*
* String options...
*/
- gethostname(ServerName, sizeof(ServerName));
- snprintf(ServerAdmin, sizeof(ServerAdmin), "root@%s", ServerName);
- strcpy(ServerBin, CUPS_SERVERBIN);
- strcpy(RequestRoot, CUPS_REQUESTS);
- strcpy(DocumentRoot, CUPS_DOCROOT);
- strcpy(DataDir, CUPS_DATADIR);
- strcpy(AccessLog, CUPS_LOGDIR "/access_log");
- strcpy(ErrorLog, CUPS_LOGDIR "/error_log");
- strcpy(PageLog, CUPS_LOGDIR "/page_log");
- strcpy(Printcap, "/etc/printcap");
- strcpy(PrintcapGUI, "/usr/bin/glpoptions");
- strcpy(FontPath, CUPS_FONTPATH);
- strcpy(RemoteRoot, "remroot");
-
- strcpy(ServerRoot, ConfigurationFile);
- if ((slash = strrchr(ServerRoot, '/')) != NULL)
+ 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");
+ SetString(&PrintcapGUI, "/usr/bin/glpoptions");
+ SetString(&FontPath, CUPS_FONTPATH);
+ SetString(&RemoteRoot, "remroot");
+
+ strlcpy(temp, ConfigurationFile, sizeof(temp));
+ if ((slash = strrchr(temp, '/')) != NULL)
*slash = '\0';
- Classification[0] = '\0';
+ SetString(&ServerRoot, temp);
+
+ ClearString(&Classification);
ClassifyOverride = 0;
#ifdef HAVE_SSL
ServerCertificatesArray = NULL;
}
- strcpy(ServerCertificate, "/var/root/Library/Keychains/CUPS");
+ SetString(&ServerCertificate, "/var/root/Library/Keychains/CUPS");
# else
- strcpy(ServerCertificate, "ssl/server.crt");
- strcpy(ServerKey, "ssl/server.key");
+ SetString(&ServerCertificate, "ssl/server.crt");
+ SetString(&ServerKey, "ssl/server.key");
# endif /* HAVE_CDSASSL */
#endif /* HAVE_SSL */
else if (strcmp(language, "C") == 0 || strcmp(language, "POSIX") == 0)
language = "en";
- strlcpy(DefaultLanguage, language, sizeof(DefaultLanguage));
+ SetString(&DefaultLanguage, language);
+ SetString(&DefaultCharset, DEFAULT_CHARSET);
- strcpy(DefaultCharset, DEFAULT_CHARSET);
-
- strcpy(RIPCache, "8m");
+ SetString(&RIPCache, "8m");
if (getenv("TMPDIR") == NULL)
- strcpy(TempDir, CUPS_REQUESTS "/tmp");
+ SetStringf(&TempDir, "TMPDIR=%s", CUPS_REQUESTS "/tmp");
else
- strlcpy(TempDir, getenv("TMPDIR"), sizeof(TempDir));
+ SetStringf(&TempDir, "TMPDIR=%s", getenv("TMPDIR"));
/*
* Find the default system group: "sys", "system", or "root"...
if (group != NULL)
{
- strcpy(SystemGroups[0], CUPS_DEFAULT_GROUP);
+ SetString(&SystemGroups[0], CUPS_DEFAULT_GROUP);
Group = group->gr_gid;
}
else
if (group != NULL)
{
- strcpy(SystemGroups[0], group->gr_name);
+ SetString(&SystemGroups[0], group->gr_name);
Group = 0;
}
else
{
- strcpy(SystemGroups[0], "unknown");
+ SetString(&SystemGroups[0], "unknown");
Group = 0;
}
}
* Numeric options...
*/
- ConfigFilePerm = 0600;
- LogFilePerm = 0644;
-
- FileDevice = FALSE;
- FilterLevel = 0;
- FilterLimit = 0;
- FilterNice = 0;
- HostNameLookups = FALSE;
- ImplicitClasses = TRUE;
- KeepAlive = TRUE;
- KeepAliveTimeout = DEFAULT_KEEPALIVE;
- ListenBackLog = SOMAXCONN;
- LogLevel = L_ERROR;
- MaxClients = 100;
- MaxClientsPerHost = 0;
- MaxLogSize = 1024 * 1024;
- MaxRequestSize = 0;
- RootCertDuration = 300;
- RunAsUser = FALSE;
- Timeout = DEFAULT_TIMEOUT;
-
- BrowseInterval = DEFAULT_INTERVAL;
- BrowsePort = ippPort();
- BrowseShortNames = TRUE;
- BrowseTimeout = DEFAULT_TIMEOUT;
- Browsing = TRUE;
- NumBrowsers = 0;
- NumPolled = 0;
-
- NumListeners = 0;
-
- JobHistory = DEFAULT_HISTORY;
- JobFiles = DEFAULT_FILES;
- JobAutoPurge = 0;
-
- MaxJobs = 0;
- MaxActiveJobs = 0;
- MaxJobsPerPrinter = 0;
- MaxJobsPerUser = 0;
- MaxCopies = 100;
+ ConfigFilePerm = 0640;
+ LogFilePerm = 0644;
+
+ FileDevice = FALSE;
+ FilterLevel = 0;
+ FilterLimit = 0;
+ FilterNice = 0;
+ HostNameLookups = FALSE;
+ ImplicitClasses = TRUE;
+ ImplicitAnyClasses = FALSE;
+ HideImplicitMembers = TRUE;
+ KeepAlive = TRUE;
+ KeepAliveTimeout = DEFAULT_KEEPALIVE;
+ ListenBackLog = SOMAXCONN;
+ LogLevel = L_ERROR;
+ MaxClients = 100;
+ MaxClientsPerHost = 0;
+ MaxLogSize = 1024 * 1024;
+ MaxRequestSize = 0;
+ RootCertDuration = 300;
+ RunAsUser = FALSE;
+ Timeout = DEFAULT_TIMEOUT;
+
+ BrowseInterval = DEFAULT_INTERVAL;
+ BrowsePort = ippPort();
+ BrowseProtocols = BROWSE_CUPS;
+ BrowseShortNames = TRUE;
+ BrowseTimeout = DEFAULT_TIMEOUT;
+ Browsing = TRUE;
+ NumBrowsers = 0;
+ NumPolled = 0;
+
+ NumListeners = 0;
+
+ JobHistory = DEFAULT_HISTORY;
+ JobFiles = DEFAULT_FILES;
+ JobAutoPurge = 0;
+ MaxJobs = 0;
+ MaxActiveJobs = 0;
+ MaxJobsPerPrinter = 0;
+ MaxJobsPerUser = 0;
+ MaxCopies = 100;
/*
* Read the configuration file...
if (!status)
return (0);
+ if (RunAsUser)
+ run_user = User;
+ else
+ run_user = getuid();
+
/*
* Use the default system group if none was supplied in cupsd.conf...
*/
*/
if (DocumentRoot[0] != '/')
- {
- snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, DocumentRoot);
- strlcpy(DocumentRoot, directory, sizeof(DocumentRoot));
- }
+ SetStringf(&DocumentRoot, "%s/%s", ServerRoot, DocumentRoot);
if (RequestRoot[0] != '/')
- {
- snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, RequestRoot);
- strlcpy(RequestRoot, directory, sizeof(RequestRoot));
- }
+ SetStringf(&RequestRoot, "%s/%s", ServerRoot, RequestRoot);
if (ServerBin[0] != '/')
- {
- snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, ServerBin);
- strlcpy(ServerBin, directory, sizeof(ServerBin));
- }
+ SetStringf(&ServerBin, "%s/%s", ServerRoot, ServerBin);
#ifdef HAVE_SSL
if (ServerCertificate[0] != '/')
- {
- snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, ServerCertificate);
- strlcpy(ServerCertificate, directory, sizeof(ServerCertificate));
- }
+ SetStringf(&ServerCertificate, "%s/%s", ServerRoot, ServerCertificate);
- chown(ServerCertificate, User, Group);
+ chown(ServerCertificate, run_user, Group);
chmod(ServerCertificate, ConfigFilePerm);
if (ServerKey[0] != '/')
- {
- snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, ServerKey);
- strlcpy(ServerKey, directory, sizeof(ServerKey));
- }
+ SetStringf(&ServerKey, "%s/%s", ServerRoot, ServerKey);
- chown(ServerKey, User, Group);
+ chown(ServerKey, run_user, Group);
chmod(ServerKey, ConfigFilePerm);
#endif /* HAVE_SSL */
* writable by the user and group in the cupsd.conf file...
*/
- chown(ServerRoot, User, Group);
+ chown(ServerRoot, run_user, Group);
chmod(ServerRoot, 0755);
- snprintf(directory, sizeof(directory), "%s/certs", ServerRoot);
- chown(directory, User, Group);
- chmod(directory, 0711);
+ snprintf(temp, sizeof(temp), "%s/certs", ServerRoot);
+ chown(temp, run_user, Group);
+ chmod(temp, 0711);
- snprintf(directory, sizeof(directory), "%s/ppd", ServerRoot);
- chown(directory, User, Group);
- chmod(directory, 0755);
+ snprintf(temp, sizeof(temp), "%s/ppd", ServerRoot);
+ chown(temp, User, Group);
+ chmod(temp, 0755);
- snprintf(directory, sizeof(directory), "%s/ssl", ServerRoot);
- chown(directory, User, Group);
- chmod(directory, 0700);
+ snprintf(temp, sizeof(temp), "%s/ssl", ServerRoot);
+ chown(temp, run_user, Group);
+ chmod(temp, 0700);
- snprintf(directory, sizeof(directory), "%s/cupsd.conf", ServerRoot);
- chown(directory, User, Group);
- chmod(directory, ConfigFilePerm);
+ snprintf(temp, sizeof(temp), "%s/cupsd.conf", ServerRoot);
+ chown(temp, run_user, Group);
+ chmod(temp, ConfigFilePerm);
- snprintf(directory, sizeof(directory), "%s/classes.conf", ServerRoot);
- chown(directory, User, Group);
- chmod(directory, ConfigFilePerm);
+ snprintf(temp, sizeof(temp), "%s/classes.conf", ServerRoot);
+ chown(temp, run_user, Group);
+ chmod(temp, ConfigFilePerm);
- snprintf(directory, sizeof(directory), "%s/printers.conf", ServerRoot);
- chown(directory, User, Group);
- chmod(directory, ConfigFilePerm);
+ snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot);
+ chown(temp, run_user, Group);
+ chmod(temp, ConfigFilePerm);
- snprintf(directory, sizeof(directory), "%s/passwd.md5", ServerRoot);
- chown(directory, User, Group);
- chmod(directory, 0600);
+ snprintf(temp, sizeof(temp), "%s/passwd.md5", ServerRoot);
+ chown(temp, User, Group);
+ chmod(temp, 0600);
/*
* Make sure the request and temporary directories have the right
* permissions...
*/
- chown(RequestRoot, User, Group);
+ chown(RequestRoot, run_user, Group);
chmod(RequestRoot, 0700);
if (strncmp(TempDir, RequestRoot, strlen(RequestRoot)) == 0)
* is under the spool directory...
*/
- chown(TempDir, User, Group);
- chmod(TempDir, 01700);
+ chown(TempDir, run_user, Group);
+ chmod(TempDir, 01770);
}
/*
if (MaxActiveJobs > (limit.rlim_max / 3))
MaxActiveJobs = limit.rlim_max / 3;
- if (strcasecmp(Classification, "none") == 0)
- Classification[0] = '\0';
+ if (Classification && strcasecmp(Classification, "none") == 0)
+ ClearString(&Classification);
- if (Classification[0])
+ if (Classification)
LogMessage(L_INFO, "Security set to \"%s\"", Classification);
/*
*/
if (MaxClientsPerHost <= 0)
- {
- MaxClientsPerHost = MaxClients / 10;
-
- if (MaxClientsPerHost < 4)
- MaxClientsPerHost = 4;
- }
+ MaxClientsPerHost = MaxClients;
if (MaxClientsPerHost > MaxClients)
MaxClientsPerHost = MaxClients;
* Read the MIME type and conversion database...
*/
- snprintf(directory, sizeof(directory), "%s/filter", ServerBin);
+ snprintf(temp, sizeof(temp), "%s/filter", ServerBin);
MimeDatabase = mimeNew();
- mimeMerge(MimeDatabase, ServerRoot, directory);
+ mimeMerge(MimeDatabase, ServerRoot, temp);
/*
* Create a list of MIME types for the document-format-supported
* Load banners...
*/
- snprintf(directory, sizeof(directory), "%s/banners", DataDir);
- LoadBanners(directory);
+ snprintf(temp, sizeof(temp), "%s/banners", DataDir);
+ LoadBanners(temp);
/*
* Load printers and classes...
* Load devices and PPDs...
*/
- snprintf(directory, sizeof(directory), "%s/model", DataDir);
- LoadPPDs(directory);
+ snprintf(temp, sizeof(temp), "%s/model", DataDir);
+ LoadPPDs(temp);
- snprintf(directory, sizeof(directory), "%s/backend", ServerBin);
- LoadDevices(directory);
+ snprintf(temp, sizeof(temp), "%s/backend", ServerBin);
+ LoadDevices(temp);
#ifdef HAVE_CDSASSL
ServerCertificatesArray = CDSAGetServerCerts();
char *valueptr; /* Pointer into value */
- for (i = 0; i < MAX_SYSTEM_GROUPS; i ++)
+ for (i = NumSystemGroups; i < MAX_SYSTEM_GROUPS; i ++)
{
for (valueptr = value; *valueptr; valueptr ++)
if (isspace(*valueptr) || *valueptr == ',')
if (*valueptr)
*valueptr++ = '\0';
- strlcpy(SystemGroups[i], value, sizeof(SystemGroups[0]));
+ SetString(SystemGroups + i, value);
while (*value == ',' || isspace(*value))
value ++;
break;
case VAR_STRING :
- strlcpy((char *)var->ptr, value, var->size);
+ SetString((char **)var->ptr, value);
break;
}
}
/*
- * End of "$Id: conf.c,v 1.77.2.23 2003/01/29 15:38:45 mike Exp $".
+ * End of "$Id: conf.c,v 1.77.2.24 2003/01/29 20:08:20 mike Exp $".
*/
/*
- * "$Id: conf.h,v 1.36.2.13 2003/01/24 19:19:46 mike Exp $"
+ * "$Id: conf.h,v 1.36.2.14 2003/01/29 20:08:21 mike Exp $"
*
* Configuration file definitions for the Common UNIX Printing System (CUPS)
* scheduler.
* Globals...
*/
-VAR char ConfigurationFile[256] VALUE(CUPS_SERVERROOT "/cupsd.conf"),
+VAR char *ConfigurationFile VALUE(NULL),
/* Configuration file to use */
- ServerName[256] VALUE(""),
+ *ServerName VALUE(NULL),
/* FQDN for server */
- ServerAdmin[256] VALUE(""),
+ *ServerAdmin VALUE(NULL),
/* Administrator's email */
- ServerRoot[1024] VALUE(CUPS_SERVERROOT),
+ *ServerRoot VALUE(NULL),
/* Root directory for scheduler */
- ServerBin[1024] VALUE(CUPS_SERVERBIN),
+ *ServerBin VALUE(NULL),
/* Root directory for binaries */
- RequestRoot[1024] VALUE(CUPS_REQUESTS),
+ *RequestRoot VALUE(NULL),
/* Directory for request files */
- DocumentRoot[1024] VALUE(CUPS_DOCROOT);
+ *DocumentRoot VALUE(NULL);
/* Root directory for documents */
VAR int NumSystemGroups VALUE(0);
/* Number of system group names */
-VAR char SystemGroups[MAX_SYSTEM_GROUPS][32],
+VAR char *SystemGroups[MAX_SYSTEM_GROUPS],
/* System group names */
- AccessLog[1024] VALUE(CUPS_LOGDIR "/access_log"),
+ *AccessLog VALUE(NULL),
/* Access log filename */
- ErrorLog[1024] VALUE(CUPS_LOGDIR "/error_log"),
+ *ErrorLog VALUE(NULL),
/* Error log filename */
- PageLog[1024] VALUE(CUPS_LOGDIR "/page_log"),
+ *PageLog VALUE(NULL),
/* Page log filename */
- DataDir[1024] VALUE(CUPS_DATADIR),
+ *DataDir VALUE(NULL),
/* Data file directory */
- DefaultLanguage[32] VALUE("C"),
+ *DefaultLanguage VALUE(NULL),
/* Default language encoding */
- DefaultCharset[32] VALUE(DEFAULT_CHARSET),
+ *DefaultCharset VALUE(NULL),
/* Default charset */
- RIPCache[32] VALUE("8m"),
+ *RIPCache VALUE(NULL),
/* Amount of memory for RIPs */
- TempDir[1024] VALUE(CUPS_REQUESTS "/tmp"),
+ *TempDir VALUE(NULL),
/* Temporary directory */
- Printcap[1024] VALUE(""),
+ *Printcap VALUE(NULL),
/* Printcap file */
- PrintcapGUI[1024] VALUE("/usr/bin/glpoptions"),
+ *PrintcapGUI VALUE(NULL),
/* GUI program to use for IRIX */
- FontPath[1024] VALUE(CUPS_FONTPATH),
+ *FontPath VALUE(NULL),
/* Font search path */
- RemoteRoot[32] VALUE("remroot"),
+ *RemoteRoot VALUE(NULL),
/* Remote root user */
- Classification[IPP_MAX_NAME] VALUE("");
+ *Classification VALUE(NULL);
/* Classification of system */
VAR int ClassifyOverride VALUE(0),
/* Allow overrides? */
/* Array of MIME types */
#ifdef HAVE_SSL
-VAR char ServerCertificate[1024] VALUE("ssl/server.crt"),
+VAR char *ServerCertificate VALUE(NULL),
/* Server certificate file */
- ServerKey[1024] VALUE("ssl/server.key");
+ *ServerKey VALUE(NULL);
/* Server key file */
#endif /* HAVE_SSL */
#ifdef HAVE_CDSASSL
/*
- * End of "$Id: conf.h,v 1.36.2.13 2003/01/24 19:19:46 mike Exp $".
+ * End of "$Id: conf.h,v 1.36.2.14 2003/01/29 20:08:21 mike Exp $".
*/
/*
- * "$Id: cupsd.h,v 1.28.2.12 2003/01/29 15:38:46 mike Exp $"
+ * "$Id: cupsd.h,v 1.28.2.13 2003/01/29 20:08:21 mike Exp $"
*
* Main header file for the Common UNIX Printing System (CUPS) scheduler.
*
VAR int NeedReload VALUE(TRUE);
/* Need to load configuration? */
-VAR char TZ[1024] VALUE("TZ=GMT");
+VAR char *TZ VALUE(NULL);
/* Timezone configuration */
VAR ipp_t *Devices VALUE(NULL),
*/
extern void CatchChildSignals(void);
+extern void ClearString(char **s);
extern void IgnoreChildSignals(void);
extern void LoadDevices(const char *d);
extern void LoadPPDs(const char *d);
+extern void SetString(char **s, const char *v);
+extern void SetStringf(char **s, const char *f, ...);
extern void StartServer(void);
extern void StopServer(void);
/*
- * End of "$Id: cupsd.h,v 1.28.2.12 2003/01/29 15:38:46 mike Exp $".
+ * End of "$Id: cupsd.h,v 1.28.2.13 2003/01/29 20:08:21 mike Exp $".
*/
/*
- * "$Id: dirsvc.c,v 1.73.2.22 2003/01/24 18:00:54 mike Exp $"
+ * "$Id: dirsvc.c,v 1.73.2.23 2003/01/29 20:08:21 mike Exp $"
*
* Directory services routines for the Common UNIX Printing System (CUPS).
*
{
if ((p = FindClass(resource + 9)) != NULL)
{
- if (strcasecmp(p->hostname, host) != 0 && p->hostname[0])
+ if (p->hostname && strcasecmp(p->hostname, host) != 0)
{
/*
* Nope, this isn't the same host; if the hostname isn't the local host,
p = NULL;
}
- else if (!p->hostname[0])
+ else if (!p->hostname)
{
- strlcpy(p->hostname, host, sizeof(p->hostname));
- strlcpy(p->uri, uri, sizeof(p->uri));
- strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+ SetString(&p->hostname, host);
+ SetString(&p->uri, uri);
+ SetString(&p->device_uri, uri);
update = 1;
}
}
else
strlcpy(name, resource + 9, sizeof(name));
}
- else if (p != NULL && !p->hostname[0])
+ else if (p != NULL && !p->hostname)
{
- strlcpy(p->hostname, host, sizeof(p->hostname));
- strlcpy(p->uri, uri, sizeof(p->uri));
- strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+ SetString(&p->hostname, host);
+ SetString(&p->uri, uri);
+ SetString(&p->device_uri, uri);
update = 1;
}
p->type = type;
p->accepting = 1;
- strlcpy(p->uri, uri, sizeof(p->uri));
- strlcpy(p->device_uri, uri, sizeof(p->device_uri));
- strlcpy(p->hostname, host, sizeof(p->hostname));
+ SetString(&p->uri, uri);
+ SetString(&p->device_uri, uri);
+ SetString(&p->hostname, host);
update = 1;
}
{
if ((p = FindPrinter(resource + 10)) != NULL)
{
- if (strcasecmp(p->hostname, host) != 0 && p->hostname[0])
+ if (p->hostname && strcasecmp(p->hostname, host) != 0)
{
/*
* Nope, this isn't the same host; if the hostname isn't the local host,
if (p->type & CUPS_PRINTER_REMOTE)
{
- strlcat(p->name, "@", sizeof(p->name));
- strlcat(p->name, p->hostname, sizeof(p->name));
+ SetStringf(&p->name, "%s@%s", p->name, p->hostname);
SetPrinterAttrs(p);
SortPrinters();
}
p = NULL;
}
- else if (!p->hostname[0])
+ else if (!p->hostname)
{
- strlcpy(p->hostname, host, sizeof(p->hostname));
- strlcpy(p->uri, uri, sizeof(p->uri));
- strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+ SetString(&p->hostname, host);
+ SetString(&p->uri, uri);
+ SetString(&p->device_uri, uri);
update = 1;
}
}
else
strlcpy(name, resource + 10, sizeof(name));
}
- else if (p != NULL && !p->hostname[0])
+ else if (p != NULL && !p->hostname)
{
- strlcpy(p->hostname, host, sizeof(p->hostname));
- strlcpy(p->uri, uri, sizeof(p->uri));
- strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+ SetString(&p->hostname, host);
+ SetString(&p->uri, uri);
+ SetString(&p->device_uri, uri);
update = 1;
}
p->type = type;
p->accepting = 1;
- strlcpy(p->hostname, host, sizeof(p->hostname));
- strlcpy(p->uri, uri, sizeof(p->uri));
- strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+ SetString(&p->hostname, host);
+ SetString(&p->uri, uri);
+ SetString(&p->device_uri, uri);
update = 1;
}
update = 1;
}
- if (strcmp(p->location, location))
+ if (!p->location || strcmp(p->location, location))
{
- strlcpy(p->location, location, sizeof(p->location));
+ SetString(&p->location, location);
update = 1;
}
- if (strcmp(p->info, info))
+ if (!p->info || strcmp(p->info, info))
{
- strlcpy(p->info, info, sizeof(p->info));
+ SetString(&p->info, info);
update = 1;
}
snprintf(local_make_model, sizeof(local_make_model),
"%s on %s", make_model, host);
- if (strcmp(p->make_model, local_make_model))
+ if (!p->make_model || strcmp(p->make_model, local_make_model))
{
- strlcpy(p->make_model, local_make_model, sizeof(p->make_model));
+ SetString(&p->make_model, local_make_model);
update = 1;
}
pclass->accepting = 1;
pclass->state = IPP_PRINTER_IDLE;
- strcpy(pclass->location, p->location);
- strcpy(pclass->info, p->info);
+ SetString(&pclass->location, p->location);
+ SetString(&pclass->info, p->info);
SetPrinterAttrs(pclass);
/*
- * End of "$Id: dirsvc.c,v 1.73.2.22 2003/01/24 18:00:54 mike Exp $".
+ * End of "$Id: dirsvc.c,v 1.73.2.23 2003/01/29 20:08:21 mike Exp $".
*/
/*
- * "$Id: ipp.c,v 1.127.2.38 2003/01/24 14:06:40 mike Exp $"
+ * "$Id: ipp.c,v 1.127.2.39 2003/01/29 20:08:22 mike Exp $"
*
* IPP routines for the Common UNIX Printing System (CUPS) scheduler.
*
*/
if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL)
- strlcpy(pclass->location, attr->values[0].string.text, sizeof(pclass->location));
+ SetString(&pclass->location, attr->values[0].string.text);
if ((attr = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT)) != NULL)
- strlcpy(pclass->info, attr->values[0].string.text, sizeof(pclass->info));
+ SetString(&pclass->info, attr->values[0].string.text);
if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL)
{
strlcpy(pclass->state_message, attr->values[0].string.text,
sizeof(pclass->state_message));
if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL &&
- !Classification[0])
+ !Classification)
{
- strlcpy(pclass->job_sheets[0], attr->values[0].string.text,
- sizeof(pclass->job_sheets[0]));
+ SetString(&pclass->job_sheets[0], attr->values[0].string.text);
if (attr->num_values > 1)
- strlcpy(pclass->job_sheets[1], attr->values[1].string.text,
- sizeof(pclass->job_sheets[1]));
+ SetString(&pclass->job_sheets[1], attr->values[1].string.text);
else
- strcpy(pclass->job_sheets[1], "none");
+ SetString(&pclass->job_sheets[1], "none");
}
if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed",
IPP_TAG_ZERO)) != NULL)
*/
if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL)
- strlcpy(printer->location, attr->values[0].string.text,
- sizeof(printer->location));
+ SetString(&printer->location, attr->values[0].string.text);
if ((attr = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT)) != NULL)
- strlcpy(printer->info, attr->values[0].string.text,
- sizeof(printer->info));
+ SetString(&printer->info, attr->values[0].string.text);
if ((attr = ippFindAttribute(con->request, "device-uri", IPP_TAG_URI)) != NULL)
{
LogMessage(L_INFO, "Setting %s device-uri to \"%s\" (was \"%s\".)",
printer->name, attr->values[0].string.text, printer->device_uri);
- strlcpy(printer->device_uri, attr->values[0].string.text,
- sizeof(printer->device_uri));
+ SetString(&printer->device_uri, attr->values[0].string.text);
}
if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL)
if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL &&
!Classification[0])
{
- strlcpy(printer->job_sheets[0], attr->values[0].string.text,
- sizeof(printer->job_sheets[0]));
+ SetString(&printer->job_sheets[0], attr->values[0].string.text);
if (attr->num_values > 1)
- strlcpy(printer->job_sheets[1], attr->values[1].string.text,
- sizeof(printer->job_sheets[1]));
+ SetString(&printer->job_sheets[1], attr->values[1].string.text);
else
- strcpy(printer->job_sheets[1], "none");
+ SetString(&printer->job_sheets[1], "none");
}
if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed",
IPP_TAG_ZERO)) != NULL)
* See if we have all required attributes...
*/
- if (printer->device_uri[0] == '\0')
- strcpy(printer->device_uri, "file:/dev/null");
+ if (!printer->device_uri)
+ SetString(&printer->device_uri, "file:/dev/null");
/*
* See if we have an interface script or PPD file attached to the request...
job->attrs = con->request;
con->request = NULL;
- strlcpy(job->title, title, sizeof(job->title));
+ SetString(&job->title, title);
attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
if (con->username[0])
- strlcpy(job->username, con->username, sizeof(job->username));
+ SetString(&job->username, con->username);
else if (attr != NULL)
{
LogMessage(L_DEBUG, "create_job: requesting-user-name = \'%s\'",
attr->values[0].string.text);
- strlcpy(job->username, attr->values[0].string.text,
- sizeof(job->username));
+ SetString(&job->username, attr->values[0].string.text);
}
else
- strcpy(job->username, "anonymous");
+ SetString(&job->username, "anonymous");
if (attr == NULL)
ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-originating-user-name",
else
{
attr->group_tag = IPP_TAG_JOB;
- free(attr->name);
- attr->name = strdup("job-originating-user-name");
+ SetString(&attr->name, "job-originating-user-name");
}
if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
job->state->values[0].integer = IPP_JOB_HELD;
- if (!(printer->type & CUPS_PRINTER_REMOTE) || Classification[0])
+ if (!(printer->type & CUPS_PRINTER_REMOTE) || Classification)
{
/*
* Add job sheets options...
* Enforce classification level if set...
*/
- if (Classification[0])
+ if (Classification)
{
if (ClassifyOverride)
{
* Force the leading banner to have the classification on it...
*/
- free(attr->values[0].string.text);
- attr->values[0].string.text = strdup(Classification);
+ SetString(&attr->values[0].string.text, Classification);
}
else if (attr->num_values == 2 &&
strcmp(attr->values[0].string.text, attr->values[1].string.text) != 0 &&
* Can't put two different security markings on the same document!
*/
- free(attr->values[1].string.text);
- attr->values[1].string.text = strdup(attr->values[0].string.text);
+ SetString(&attr->values[1].string.text, attr->values[0].string.text);
}
}
else if (strcmp(attr->values[0].string.text, Classification) != 0 &&
* Force the leading banner to have the classification on it...
*/
- free(attr->values[0].string.text);
- attr->values[0].string.text = strdup(Classification);
+ SetString(&attr->values[0].string.text, Classification);
}
}
{
/*
* Make a copy of the printer name...
- *
- * Note: name and printer->name are both IPP_MAX_NAME characters
- * in size, so strcpy() is safe...
*/
- strcpy(name, printer->name);
+ strlcpy(name, printer->name, sizeof(name));
if ((nameptr = strchr(name, '@')) != NULL)
{
* Copy the rest of the job info...
*/
- strlcpy(job->title, title, sizeof(job->title));
+ SetString(&job->title, title);
attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
if (con->username[0])
- strlcpy(job->username, con->username, sizeof(job->username));
+ SetString(&job->username, con->username);
else if (attr != NULL)
{
LogMessage(L_DEBUG, "print_job: requesting-user-name = \'%s\'",
attr->values[0].string.text);
- strlcpy(job->username, attr->values[0].string.text, sizeof(job->username));
+ SetString(&job->username, attr->values[0].string.text);
}
else
- strcpy(job->username, "anonymous");
+ SetString(&job->username, "anonymous");
if (attr == NULL)
ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-originating-user-name",
else
{
attr->group_tag = IPP_TAG_JOB;
- free(attr->name);
- attr->name = strdup("job-originating-user-name");
+ SetString(&attr->name, "job-originating-user-name");
}
/*
SetJobHoldUntil(job->id, attr->values[0].string.text);
}
- if (!(printer->type & CUPS_PRINTER_REMOTE) || Classification[0])
+ if (!(printer->type & CUPS_PRINTER_REMOTE) || Classification)
{
/*
* Add job sheets options...
* Enforce classification level if set...
*/
- if (Classification[0])
+ if (Classification)
{
if (ClassifyOverride)
{
* Force the leading banner to have the classification on it...
*/
- free(attr->values[0].string.text);
- attr->values[0].string.text = strdup(Classification);
+ SetString(&attr->values[0].string.text, Classification);
}
else if (attr->num_values == 2 &&
strcmp(attr->values[0].string.text, attr->values[1].string.text) != 0 &&
* Can't put two different security markings on the same document!
*/
- free(attr->values[1].string.text);
- attr->values[1].string.text = strdup(attr->values[0].string.text);
+ SetString(&attr->values[1].string.text, attr->values[0].string.text);
}
}
else if (strcmp(attr->values[0].string.text, Classification) != 0 &&
* Force the leading banner to have the classification on it...
*/
- free(attr->values[0].string.text);
- attr->values[0].string.text = strdup(Classification);
+ SetString(&attr->values[0].string.text, Classification);
}
}
*/
if (strcmp(attr->name, "job-name") == 0)
- strlcpy(job->title, attr->values[0].string.text, sizeof(job->title));
+ SetString(&job->title, attr->values[0].string.text);
else if (strcmp(attr->name, "job-hold-until") == 0)
{
SetJobHoldUntil(job->id, attr->values[0].string.text);
/*
- * End of "$Id: ipp.c,v 1.127.2.38 2003/01/24 14:06:40 mike Exp $".
+ * End of "$Id: ipp.c,v 1.127.2.39 2003/01/29 20:08:22 mike Exp $".
*/
/*
- * "$Id: job.c,v 1.124.2.43 2003/01/24 21:15:43 mike Exp $"
+ * "$Id: job.c,v 1.124.2.44 2003/01/29 20:08:25 mike Exp $"
*
* Job management routines for the Common UNIX Printing System (CUPS).
*
job->print_pipes[1] = -1;
job->status_pipe = -1;
- strlcpy(job->dest, dest, sizeof(job->dest));
+ SetString(&job->dest, dest);
NumJobs ++;
if (strncmp(resource, "/classes/", 9) == 0)
{
p = AddClass(resource + 9);
- strcpy(p->make_model, "Remote Class on unknown");
+ SetString(&p->make_model, "Remote Class on unknown");
}
else
{
p = AddPrinter(resource + 10);
- strcpy(p->make_model, "Remote Printer on unknown");
+ SetString(&p->make_model, "Remote Printer on unknown");
}
p->state = IPP_PRINTER_STOPPED;
p->type |= CUPS_PRINTER_REMOTE;
p->browse_time = 2147483647;
- strcpy(p->location, "Location Unknown");
- strcpy(p->info, "No Information Available");
+ SetString(&p->location, "Location Unknown");
+ SetString(&p->info, "No Information Available");
p->hostname[0] = '\0';
SetPrinterAttrs(p);
continue;
}
- strlcpy(job->dest, dest, sizeof(job->dest));
+ SetString(&job->dest, dest);
job->sheets = ippFindAttribute(job->attrs, "job-media-sheets-completed",
IPP_TAG_INTEGER);
job->priority = attr->values[0].integer;
attr = ippFindAttribute(job->attrs, "job-name", IPP_TAG_NAME);
- strlcpy(job->title, attr->values[0].string.text,
- sizeof(job->title));
+ SetString(&job->title, attr->values[0].string.text);
attr = ippFindAttribute(job->attrs, "job-originating-user-name", IPP_TAG_NAME);
- strlcpy(job->username, attr->values[0].string.text,
- sizeof(job->username));
+ SetString(&job->username, attr->values[0].string.text);
/*
* Insert the job into the array, sorting by job priority and ID...
if (current->state->values[0].integer >= IPP_JOB_PROCESSING)
break;
- strlcpy(current->dest, dest, sizeof(current->dest));
+ SetString(¤t->dest, dest);
current->dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE |
CUPS_PRINTER_IMPLICIT);
else
class_name[0] = '\0';
- if (Classification[0] && !banner_page)
+ if (Classification && !banner_page)
{
if ((attr = ippFindAttribute(current->attrs, "job-sheets",
IPP_TAG_NAME)) == NULL)
/*
- * End of "$Id: job.c,v 1.124.2.43 2003/01/24 21:15:43 mike Exp $".
+ * End of "$Id: job.c,v 1.124.2.44 2003/01/29 20:08:25 mike Exp $".
*/
/*
- * "$Id: job.h,v 1.25.2.6 2003/01/07 18:27:24 mike Exp $"
+ * "$Id: job.h,v 1.25.2.7 2003/01/29 20:08:26 mike Exp $"
*
* Print job definitions for the Common UNIX Printing System (CUPS) scheduler.
*
ipp_attribute_t *state; /* Job state */
ipp_attribute_t *sheets; /* job-media-sheets-completed */
time_t hold_until; /* Hold expiration date/time */
- char username[33]; /* Printing user */
- char dest[IPP_MAX_NAME]; /* Destination printer or class */
+ char *username; /* Printing user */
+ char *dest; /* Destination printer or class */
cups_ptype_t dtype; /* Destination type (class/remote bits) */
- char title[IPP_MAX_NAME]; /* Job name/title */
+ char *title; /* Job name/title */
ipp_attribute_t *job_sheets; /* Job sheets (NULL if none) */
int num_files; /* Number of files in job */
int current_file; /* Current file in job */
/*
- * End of "$Id: job.h,v 1.25.2.6 2003/01/07 18:27:24 mike Exp $".
+ * End of "$Id: job.h,v 1.25.2.7 2003/01/29 20:08:26 mike Exp $".
*/
/*
- * "$Id: main.c,v 1.57.2.28 2003/01/13 20:38:38 mike Exp $"
+ * "$Id: main.c,v 1.57.2.29 2003/01/29 20:08:26 mike Exp $"
*
* Scheduler main loop for the Common UNIX Printing System (CUPS).
*
* main() - Main entry for the CUPS scheduler.
* CatchChildSignals() - Catch SIGCHLD signals...
* IgnoreChildSignals() - Ignore SIGCHLD signals...
+ * SetString() - Set a string value.
+ * SetStringf() - Set a formatted string value.
* sigchld_handler() - Handle 'child' signals from old processes.
* sighup_handler() - Handle 'hangup' signals to reconfigure the scheduler.
* sigterm_handler() - Handle 'terminate' signals that stop the scheduler.
* Absolute directory...
*/
- strlcpy(ConfigurationFile, argv[i], sizeof(ConfigurationFile));
+ SetString(&ConfigurationFile, argv[i]);
}
else
{
* Relative directory...
*/
- getcwd(ConfigurationFile, sizeof(ConfigurationFile));
- strlcat(ConfigurationFile, "/", sizeof(ConfigurationFile));
- strlcat(ConfigurationFile, argv[i], sizeof(ConfigurationFile));
+ char current[1024]; /* Current directory */
+
+
+ getcwd(current, sizeof(current));
+ SetStringf(&ConfigurationFile, "%s/%s", current, argv[i]);
}
break;
*/
if (getenv("TZ") != NULL)
- snprintf(TZ, sizeof(TZ), "TZ=%s", getenv("TZ"));
+ SetStringf(&TZ, "TZ=%s", getenv("TZ"));
else
- TZ[0] = '\0';
+ SetString(&TZ, "");
tzset();
}
+/*
+ * 'ClearString()' - Clear a string.
+ */
+
+void
+ClearString(char **s) /* O - String value */
+{
+ if (s && *s)
+ {
+ free(*s);
+ *s = NULL;
+ }
+}
+
+
/*
* 'IgnoreChildSignals()' - Ignore SIGCHLD signals...
*/
}
+/*
+ * 'SetString()' - Set a string value.
+ */
+
+void
+SetString(char **s, /* O - New string */
+ const char *v) /* I - String value */
+{
+ if (!s)
+ return;
+
+ if (*s)
+ free(*s);
+
+ if (v)
+ *s = strdup(v);
+ else
+ *s = NULL;
+}
+
+
+/*
+ * 'SetStringf()' - Set a formatted string value.
+ */
+
+void
+SetStringf(char **s, /* O - New string */
+ const char *f, /* I - Printf-style format string */
+ ...) /* I - Additional args as needed */
+{
+ char v[1024]; /* Formatting string value */
+ va_list ap; /* Argument pointer */
+
+
+ if (!s)
+ return;
+
+ if (*s)
+ free(*s);
+
+ if (f)
+ {
+ va_start(ap, f);
+ vsnprintf(v, sizeof(v), f, ap);
+ va_end(ap);
+
+ *s = strdup(v);
+ }
+ else
+ *s = NULL;
+}
+
+
/*
* 'sigchld_handler()' - Handle 'child' signals from old processes.
*/
/*
- * End of "$Id: main.c,v 1.57.2.28 2003/01/13 20:38:38 mike Exp $".
+ * End of "$Id: main.c,v 1.57.2.29 2003/01/29 20:08:26 mike Exp $".
*/
/*
- * "$Id: printers.c,v 1.93.2.33 2003/01/24 18:00:55 mike Exp $"
+ * "$Id: printers.c,v 1.93.2.34 2003/01/29 20:08:27 mike Exp $"
*
* Printer routines for the Common UNIX Printing System (CUPS).
*
if ((p = calloc(1, sizeof(printer_t))) == NULL)
return (NULL);
- strlcpy(p->name, name, sizeof(p->name));
- strlcpy(p->info, name, sizeof(p->info));
- strlcpy(p->hostname, ServerName, sizeof(p->hostname));
+ SetString(&p->name, name);
+ SetString(&p->info, name);
+ SetString(&p->hostname, ServerName);
#ifdef AF_INET6
if (Listeners[0].address.addr.sa_family == AF_INET6)
- snprintf(p->uri, sizeof(p->uri), "ipp://%s:%d/printers/%s", ServerName,
- ntohs(Listeners[0].address.ipv6.sin6_port), name);
+ SetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName,
+ ntohs(Listeners[0].address.ipv6.sin6_port), name);
else
#endif /* AF_INET6 */
- snprintf(p->uri, sizeof(p->uri), "ipp://%s:%d/printers/%s", ServerName,
- ntohs(Listeners[0].address.ipv4.sin_port), name);
+ SetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName,
+ ntohs(Listeners[0].address.ipv4.sin_port), name);
p->state = IPP_PRINTER_STOPPED;
p->accepting = 0;
p->filetype = mimeAddType(MimeDatabase, "printer", name);
- strcpy(p->job_sheets[0], "none");
- strcpy(p->job_sheets[1], "none");
+ SetString(&p->job_sheets[0], "none");
+ SetString(&p->job_sheets[1], "none");
/*
* Insert the printer in the printer list alphabetically...
FreePrinterUsers(p);
FreeQuotas(p);
+ ClearString(&p->uri);
+ ClearString(&p->hostname);
+ ClearString(&p->name);
+ ClearString(&p->location);
+ ClearString(&p->make_model);
+ ClearString(&p->info);
+ ClearString(&p->job_sheets[0]);
+ ClearString(&p->job_sheets[1]);
+ ClearString(&p->device_uri);
+ ClearString(&p->backend);
+
free(p);
/*
return;
}
else if (strcmp(name, "Info") == 0)
- strlcpy(p->info, value, sizeof(p->info));
+ SetString(&p->info, value);
else if (strcmp(name, "Location") == 0)
- strlcpy(p->location, value, sizeof(p->location));
+ SetString(&p->location, value);
else if (strcmp(name, "DeviceURI") == 0)
- strlcpy(p->device_uri, value, sizeof(p->device_uri));
+ SetString(&p->device_uri, value);
else if (strcmp(name, "State") == 0)
{
/*
if (*valueptr)
*valueptr++ = '\0';
- strlcpy(p->job_sheets[0], value, sizeof(p->job_sheets[0]));
+ SetString(&p->job_sheets[0], value);
while (isspace(*valueptr))
valueptr ++;
if (*valueptr)
*valueptr++ = '\0';
- strlcpy(p->job_sheets[1], value, sizeof(p->job_sheets[1]));
+ SetString(&p->job_sheets[1], value);
}
}
else if (strcmp(name, "AllowUser") == 0)
else
fprintf(fp, "<Printer %s>\n", printer->name);
- if (printer->info[0])
+ if (printer->info)
fprintf(fp, "Info %s\n", printer->info);
- if (printer->location[0])
+ if (printer->location)
fprintf(fp, "Location %s\n", printer->location);
- if (printer->device_uri[0])
+ if (printer->device_uri)
fprintf(fp, "DeviceURI %s\n", printer->device_uri);
if (printer->state == IPP_PRINTER_STOPPED)
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL,
p->name);
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location",
- NULL, p->location);
+ NULL, p->location ? p->location : "");
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info",
- NULL, p->info);
+ NULL, p->info ? p->info : "");
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info",
NULL, p->uri);
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
* Setup the job-sheets-supported and job-sheets-default attributes...
*/
- if (Classification[0] && !ClassifyOverride)
+ if (Classification && !ClassifyOverride)
attr = ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
"job-sheets-supported", NULL, Classification);
else
LogMessage(L_EMERG, "SetPrinterAttrs: Unable to allocate memory for "
"job-sheets-supported attribute: %s!",
strerror(errno));
- else if (!Classification[0] || ClassifyOverride)
+ else if (!Classification || ClassifyOverride)
{
attr->values[0].string.text = strdup("none");
if (attr != NULL)
{
- attr->values[0].string.text = strdup(Classification[0] ?
+ attr->values[0].string.text = strdup(Classification ?
Classification : p->job_sheets[0]);
- attr->values[1].string.text = strdup(Classification[0] ?
+ attr->values[1].string.text = strdup(Classification ?
Classification : p->job_sheets[1]);
}
}
* URI so it doesn't have a username or password in it...
*/
- if (strstr(p->device_uri, "://") != NULL)
+ if (!p->device_uri)
+ strcpy(uri, "file:/dev/null");
+ else if (strstr(p->device_uri, "://") != NULL)
{
/*
* http://..., ipp://..., etc.
* file:..., serial:..., etc.
*/
- strcpy(uri, p->device_uri);
+ strlcpy(uri, p->device_uri, sizeof(uri));
}
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
"pages-per-minute", ppd->throughput);
if (ppd->nickname)
- strlcpy(p->make_model, ppd->nickname, sizeof(p->make_model));
+ SetString(&p->make_model, ppd->nickname);
else if (ppd->modelname)
- strlcpy(p->make_model, ppd->modelname, sizeof(p->make_model));
+ SetString(&p->make_model, ppd->modelname);
else
- strcpy(p->make_model, "Bad PPD File");
+ SetString(&p->make_model, "Bad PPD File");
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
"printer-make-and-model", NULL, p->make_model);
ServerRoot, p->name);
AddPrinterFilter(p, filename);
}
- else if (strncmp(p->device_uri, "ipp://", 6) == 0 &&
+ else if (p->device_uri &&
+ strncmp(p->device_uri, "ipp://", 6) == 0 &&
(strstr(p->device_uri, "/printers/") != NULL ||
strstr(p->device_uri, "/classes/") != NULL))
{
fprintf(fp, "%s:\\\n"
"\t:bsdaddr=%s,%s:\\\n"
"\t:description=%s:\n",
- p->name, ServerName, p->name, p->info);
+ p->name, ServerName, p->name, p->info ? p->info : "");
break;
}
{
fprintf(fp, "Printer Class | %s\n",
(p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");
- fprintf(fp, "Printer Model | %s\n", p->make_model);
- fprintf(fp, "Location Code | %s\n", p->location);
- fprintf(fp, "Physical Location | %s\n", p->info);
- fprintf(fp, "Port Path | %s\n", p->device_uri);
+ fprintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : "");
+ fprintf(fp, "Location Code | %s\n", p->location ? p->location : "");
+ fprintf(fp, "Physical Location | %s\n", p->info ? p->info : "");
+ fprintf(fp, "Port Path | %s\n", p->device_uri ? p->device_uri : "");
fprintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name);
fprintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
fputs("Status Update Wait | 10 seconds\n", fp);
(p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
"Faulted");
fprintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION);
- fprintf(fp, "Information | 02 00 00 | Device URI: %s\n", p->device_uri);
+ fprintf(fp, "Information | 02 00 00 | Device URI: %s\n",
+ p->device_uri ? p->device_uri : "");
fprintf(fp, "Information | 03 00 00 | %s jobs\n",
p->accepting ? "Accepting" : "Not accepting");
fprintf(fp, "Information | 04 00 00 | %s\n", p->state_message);
/*
- * End of "$Id: printers.c,v 1.93.2.33 2003/01/24 18:00:55 mike Exp $".
+ * End of "$Id: printers.c,v 1.93.2.34 2003/01/29 20:08:27 mike Exp $".
*/
/*
- * "$Id: printers.h,v 1.22.2.7 2003/01/24 18:00:56 mike Exp $"
+ * "$Id: printers.h,v 1.22.2.8 2003/01/29 20:08:28 mike Exp $"
*
* Printer definitions for the Common UNIX Printing System (CUPS) scheduler.
*
typedef struct printer_str
{
struct printer_str *next; /* Next printer in list */
- char uri[HTTP_MAX_URI], /* Printer URI */
- hostname[HTTP_MAX_HOST],/* Host printer resides on */
- name[IPP_MAX_NAME], /* Printer name */
- location[IPP_MAX_NAME], /* Location code */
- make_model[IPP_MAX_NAME],
- /* Make and model */
- info[IPP_MAX_NAME], /* Description */
- op_policy[IPP_MAX_NAME],/* Operation policy name */
- error_policy[IPP_MAX_NAME];
- /* Error policy */
+ char *uri, /* Printer URI */
+ *hostname, /* Host printer resides on */
+ *name, /* Printer name */
+ *location, /* Location code */
+ *make_model, /* Make and model */
+ *info, /* Description */
+ *op_policy, /* Operation policy name */
+ *error_policy; /* Error policy */
policy_t *op_policy_ptr; /* Pointer to operation policy */
int accepting; /* Accepting jobs? */
ipp_pstate_t state; /* Printer state */
char state_message[1024]; /* Printer state message */
ipp_attribute_t *state_reasons; /* Printer state reasons */
time_t state_time; /* Time at this state */
- char job_sheets[2][IPP_MAX_NAME];
- /* Banners/job sheets */
+ char *job_sheets[2]; /* Banners/job sheets */
cups_ptype_t type; /* Printer type (color, small, etc.) */
time_t browse_time; /* Last time update was sent/received */
- char device_uri[HTTP_MAX_URI],/* Device URI */
- backend[1024]; /* Backend to use */
+ char *device_uri, /* Device URI */
+ *backend; /* Backend to use */
int raw; /* Raw queue? */
mime_type_t *filetype; /* Pseudo-filetype for printer */
void *job; /* Current job in queue */
/*
- * End of "$Id: printers.h,v 1.22.2.7 2003/01/24 18:00:56 mike Exp $".
+ * End of "$Id: printers.h,v 1.22.2.8 2003/01/29 20:08:28 mike Exp $".
*/