From 3ac260e3a39487ade6b36a506f4d3696a4fa731e Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 16 Apr 2024 08:51:38 -0400 Subject: [PATCH] Update cups-files.conf man page. Move writing of strings files to cupsdCleanDirty, and add new CUPSD_DIRTY_STRINGS bit. Update PPD cache version and check modification time of cups-files.conf to trigger re-load of strings. Make sure "strings" subdirectory is created as necessary. --- cups/ppd-private.h | 2 +- cups/string-private.h | 8 ++++---- doc/help/man-cups-files.conf.html | 4 ++++ man/cups-files.conf.5 | 7 ++++++- scheduler/conf.c | 8 +++++++- scheduler/cupsd.h | 9 --------- scheduler/printers.c | 19 ++++++------------- scheduler/printers.h | 1 - scheduler/sysman.c | 3 +++ scheduler/sysman.h | 1 + 10 files changed, 32 insertions(+), 30 deletions(-) diff --git a/cups/ppd-private.h b/cups/ppd-private.h index fbeac2d559..3f88fb46fd 100644 --- a/cups/ppd-private.h +++ b/cups/ppd-private.h @@ -25,7 +25,7 @@ extern "C" { * Constants... */ -# define _PPD_CACHE_VERSION 12 /* Version number in cache file */ +# define _PPD_CACHE_VERSION 13 /* Version number in cache file */ /* diff --git a/cups/string-private.h b/cups/string-private.h index 6f9d35dbe3..966382238c 100644 --- a/cups/string-private.h +++ b/cups/string-private.h @@ -129,10 +129,10 @@ extern void _cups_strcpy(char *dst, const char *src) _CUPS_PRIVATE; extern int _cups_strcasecmp(const char *, const char *) _CUPS_PRIVATE; extern int _cups_strncasecmp(const char *, const char *, size_t n) _CUPS_PRIVATE; -extern int _cupsArrayStrcasecmp(const char *s, const char *t, void *data) _CUPS_PRIVATE; -extern int _cupsArrayStrcmp(const char *s1, const char *s2, void *data) _CUPS_PRIVATE; -extern char *_cupsArrayStrdup(const char *element, void *data) _CUPS_PRIVATE; -extern void _cupsArrayFree(void *element, void *data) _CUPS_PRIVATE; +extern int _cupsArrayStrcasecmp(const char *s, const char *t, void *data) _CUPS_PRIVATE; +extern int _cupsArrayStrcmp(const char *s1, const char *s2, void *data) _CUPS_PRIVATE; +extern char *_cupsArrayStrdup(const char *element, void *data) _CUPS_PRIVATE; +extern void _cupsArrayFree(void *element, void *data) _CUPS_PRIVATE; extern char *_cupsStrAlloc(const char *s) _CUPS_PRIVATE; extern char *_cupsStrDate(char *buf, size_t bufsize, time_t timeval) _CUPS_PRIVATE; diff --git a/doc/help/man-cups-files.conf.html b/doc/help/man-cups-files.conf.html index 9168af6a40..a4af17b927 100644 --- a/doc/help/man-cups-files.conf.html +++ b/doc/help/man-cups-files.conf.html @@ -124,6 +124,10 @@ Bad startup file permissions are fatal, for example shared TLS certificate and k

Group group-name-or-number
Specifies the group name or ID that will be used when executing external programs. The default group is operating system specific but is usually "lp" or "nobody". +

+

Languages LOCALE ... LOCALE
+Lists the language locales that should be supported by the server. +The default is English ("en") and the current system locale (if not English).

LogFileGroup group-name-or-number
Specifies the group name or ID that will be used for log files. diff --git a/man/cups-files.conf.5 b/man/cups-files.conf.5 index cbc7b1841a..1c43626e17 100644 --- a/man/cups-files.conf.5 +++ b/man/cups-files.conf.5 @@ -8,7 +8,7 @@ .\" Licensed under Apache License v2.0. See the file "LICENSE" for more .\" information. .\" -.TH cups-files.conf 5 "CUPS" "2021-03-06" "OpenPrinting" +.TH cups-files.conf 5 "CUPS" "2024-04-16" "OpenPrinting" .SH NAME cups\-files.conf \- file and directory configuration file for cups .SH DESCRIPTION @@ -132,6 +132,11 @@ Bad startup file permissions are fatal, for example shared TLS certificate and k \fBGroup \fIgroup-name-or-number\fR Specifies the group name or ID that will be used when executing external programs. The default group is operating system specific but is usually "lp" or "nobody". +.\"#Languages +.TP 5 +\fBLanguages \fILOCALE ... LOCALE\fR +Lists the language locales that should be supported by the server. +The default is English ("en") and the current system locale (if not English). .\"#LogFileGroup .TP 5 \fBLogFileGroup \fIgroup-name-or-number\fR diff --git a/scheduler/conf.c b/scheduler/conf.c index 6846f47bc7..95abf82925 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -1737,11 +1737,17 @@ cupsdWriteStrings(void) char strings_file[1024]; // Strings file + // Make sure the strings directory is there... + if (cupsdCheckPermissions(ServerRoot, "strings", 0755, RunUser, Group, /*is_dir*/1, /*create_dir*/1) < 0) + return; + // Save each language... for (lang = Languages; lang; lang = lang->next) { snprintf(strings_file, sizeof(strings_file), "%s/strings/%s.strings", ServerRoot, lang->language); - _cupsMessageSave(strings_file, _CUPS_MESSAGE_STRINGS, lang->strings); + + if (_cupsMessageSave(strings_file, _CUPS_MESSAGE_STRINGS, lang->strings)) + cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to save '%s': %s", strings_file, strerror(errno)); } } diff --git a/scheduler/cupsd.h b/scheduler/cupsd.h index cf2023fc6f..689b88b49b 100644 --- a/scheduler/cupsd.h +++ b/scheduler/cupsd.h @@ -9,11 +9,6 @@ * information. */ - -/* - * Include necessary headers. - */ - #include #include #include @@ -230,7 +225,3 @@ extern void cupsdStopSelect(void); /* server.c */ extern void cupsdStartServer(void); extern void cupsdStopServer(void); - -extern int _cupsArrayStrcmp(const char *s1, const char *s2, void *data); -extern char *_cupsArrayStrdup(const char *element, void *data); -extern void _cupsArrayFree(void *element, void *data); diff --git a/scheduler/printers.c b/scheduler/printers.c index 24353f20b5..e67d32b41d 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -735,7 +735,6 @@ cupsdDeletePrinter( cupsdClearString(&p->port_monitor); cupsdClearString(&p->op_policy); cupsdClearString(&p->error_policy); - cupsdClearString(&p->strings); cupsdClearString(&p->alert); cupsdClearString(&p->alert_description); @@ -3756,6 +3755,7 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ char cache_name[1024]; /* Cache filename */ struct stat cache_info; /* Cache file info */ struct stat conf_info; /* cupsd.conf file info */ + struct stat files_info; /* cups-files.conf file info */ ppd_file_t *ppd; /* PPD file */ char ppd_name[1024]; /* PPD filename */ struct stat ppd_info; /* PPD file info */ @@ -3888,6 +3888,9 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ if (stat(ConfigurationFile, &conf_info)) conf_info.st_mtime = 0; + if (stat(CupsFilesFile, &files_info)) + files_info.st_mtime = 0; + snprintf(cache_name, sizeof(cache_name), "%s/%s.data", CacheDir, p->name); if (stat(cache_name, &cache_info)) cache_info.st_mtime = 0; @@ -3904,7 +3907,7 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ _ppdCacheDestroy(p->pc); p->pc = NULL; - if (cache_info.st_mtime >= ppd_info.st_mtime && cache_info.st_mtime >= conf_info.st_mtime) + if (cache_info.st_mtime >= ppd_info.st_mtime && cache_info.st_mtime >= conf_info.st_mtime && cache_info.st_mtime >= files_info.st_mtime) { cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", cache_name); @@ -3915,16 +3918,6 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ * Loaded successfully! */ - /* - * Set `strings` (source for printer-strings-uri IPP attribute) - * if printer's .strings file with localization exists. - */ - - if (!access(strings_name, R_OK)) - cupsdSetString(&p->strings, strings_name); - else - cupsdClearString(&p->strings); - return; } } @@ -4029,7 +4022,7 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ if (!p->pc) cupsdLogMessage(CUPSD_LOG_WARN, "Unable to create cache of \"%s\": %s", ppd_name, cupsGetErrorString()); - cupsdWriteStrings(); + cupsdMarkDirty(CUPSD_DIRTY_STRINGS); ppdMarkDefaults(ppd); diff --git a/scheduler/printers.h b/scheduler/printers.h index 48d8aacf57..3c1b12de41 100644 --- a/scheduler/printers.h +++ b/scheduler/printers.h @@ -64,7 +64,6 @@ struct cupsd_printer_s *info, /* Description */ *organization, /* Organization name */ *organizational_unit, /* Organizational unit (department, etc.) */ - *strings, /* Strings file, if any */ *op_policy, /* Operation policy name */ *error_policy; /* Error policy */ cupsd_policy_t *op_policy_ptr; /* Pointer to operation policy */ diff --git a/scheduler/sysman.c b/scheduler/sysman.c index 13ca84c20c..cce3fa986c 100644 --- a/scheduler/sysman.c +++ b/scheduler/sysman.c @@ -69,6 +69,9 @@ cupsdCleanDirty(void) if (DirtyFiles & CUPSD_DIRTY_SUBSCRIPTIONS) cupsdSaveAllSubscriptions(); + if (DirtyFiles & CUPSD_DIRTY_STRINGS) + cupsdWriteStrings(); + DirtyFiles = CUPSD_DIRTY_NONE; DirtyCleanTime = 0; diff --git a/scheduler/sysman.h b/scheduler/sysman.h index e9091bac4c..e155705cb9 100644 --- a/scheduler/sysman.h +++ b/scheduler/sysman.h @@ -18,6 +18,7 @@ #define CUPSD_DIRTY_PRINTCAP 4 /* printcap is dirty */ #define CUPSD_DIRTY_JOBS 8 /* jobs.cache or "c" file(s) are dirty */ #define CUPSD_DIRTY_SUBSCRIPTIONS 16 /* subscriptions.conf is dirty */ +#define CUPSD_DIRTY_STRINGS 32 /* The .strings files are dirty */ /* -- 2.47.2