diff options
author | Michael R Sweet <michaelrsweet@gmail.com> | 2017-12-19 14:53:00 -0500 |
---|---|---|
committer | Michael R Sweet <michaelrsweet@gmail.com> | 2017-12-19 14:53:00 -0500 |
commit | 2fa1ba3cc0e02799b739ef0e06efc940a8c5a33e (patch) | |
tree | 3d9da027144be82db3acea277a4c7dcd58d0f40f /scheduler/client.c | |
parent | 3d90ace3170087acd66d189fcf2362242815f88d (diff) | |
download | cups-2fa1ba3cc0e02799b739ef0e06efc940a8c5a33e.tar.gz |
Generate strings files for localizing PPD options (Issue #5194)
cups/language-private.h:
- New _cupsMessageAdd and _cupsMessageSave private APIs.
cups/language.c:
- Implement new _cupsMessageAdd and _cupsMessageSave private APIs.
cups/ppd-cache.c:
- Generate strings array when loading cache from PPD.
- Remove strings_uri (just pulling strings from PPD now).
cups/ppd-private.h:
- Remove strings_uri and add strings array to cache.
scheduler/client.c:
- Add support for /strings/NAME.strings
- Cleanup implementation of GET/HEAD/POST to files.
scheduler/ipp.c:
- Return local strings file URI.
- Clean up copy_printer_attrs implementation.
scheduler/printers.c:
- Save strings array to cache file, drop support for strings_uri.
scheduler/printers.h:
- Add strings filename to cupsd_printer_t structure.
Diffstat (limited to 'scheduler/client.c')
-rw-r--r-- | scheduler/client.c | 552 |
1 files changed, 175 insertions, 377 deletions
diff --git a/scheduler/client.c b/scheduler/client.c index 775265a89..f388499dc 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -556,7 +556,6 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ char buf[1024]; /* Buffer for real filename */ struct stat filestats; /* File information */ mime_type_t *type; /* MIME type of file */ - cupsd_printer_t *p; /* Printer */ static unsigned request_id = 0; /* Request ID for temp files */ @@ -1039,130 +1038,57 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ case HTTP_STATE_GET_SEND : cupsdLogClient(con, CUPSD_LOG_DEBUG, "Processing GET %s", con->uri); - if ((!strncmp(con->uri, "/ppd/", 5) || - !strncmp(con->uri, "/printers/", 10) || - !strncmp(con->uri, "/classes/", 9)) && - !strcmp(con->uri + strlen(con->uri) - 4, ".ppd")) - { - /* - * Send PPD file - get the real printer name since printer - * names are not case sensitive but filenames can be... - */ + if ((filename = get_file(con, &filestats, buf, sizeof(buf))) != NULL) + { + type = mimeFileType(MimeDatabase, filename, NULL, NULL); - con->uri[strlen(con->uri) - 4] = '\0'; /* Drop ".ppd" */ + cupsdLogClient(con, CUPSD_LOG_DEBUG, "filename=\"%s\", type=%s/%s", filename, type ? type->super : "", type ? type->type : ""); - if (!strncmp(con->uri, "/ppd/", 5)) - p = cupsdFindPrinter(con->uri + 5); - else if (!strncmp(con->uri, "/printers/", 10)) - p = cupsdFindPrinter(con->uri + 10); - else + if (is_cgi(con, filename, &filestats, type)) { - p = cupsdFindClass(con->uri + 9); + /* + * Note: con->command and con->options were set by is_cgi()... + */ - if (p) + if (!cupsdSendCommand(con, con->command, con->options, 0)) { - int i; /* Looping var */ - - for (i = 0; i < p->num_printers; i ++) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { - if (!(p->printers[i]->type & CUPS_PRINTER_CLASS)) - { - char ppdname[1024];/* PPD filename */ - - snprintf(ppdname, sizeof(ppdname), "%s/ppd/%s.ppd", - ServerRoot, p->printers[i]->name); - if (!access(ppdname, 0)) - { - p = p->printers[i]; - break; - } - } + cupsdCloseClient(con); + return; } + } + else + cupsdLogRequest(con, HTTP_STATUS_OK); - if (i >= p->num_printers) - p = NULL; - } + if (httpGetVersion(con->http) <= HTTP_VERSION_1_0) + httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); + break; } - if (p) - { - snprintf(con->uri, sizeof(con->uri), "/ppd/%s.ppd", p->name); - } - else - { - if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!check_if_modified(con, &filestats)) + { + if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } - - break; } - } - else if ((!strncmp(con->uri, "/icons/", 7) || - !strncmp(con->uri, "/printers/", 10) || - !strncmp(con->uri, "/classes/", 9)) && - !strcmp(con->uri + strlen(con->uri) - 4, ".png")) - { - /* - * Send icon file - get the real queue name since queue names are - * not case sensitive but filenames can be... - */ - - con->uri[strlen(con->uri) - 4] = '\0'; /* Drop ".png" */ - - if (!strncmp(con->uri, "/icons/", 7)) - p = cupsdFindPrinter(con->uri + 7); - else if (!strncmp(con->uri, "/printers/", 10)) - p = cupsdFindPrinter(con->uri + 10); - else + else { - p = cupsdFindClass(con->uri + 9); - - if (p) - { - int i; /* Looping var */ - - for (i = 0; i < p->num_printers; i ++) - { - if (!(p->printers[i]->type & CUPS_PRINTER_CLASS)) - { - char ppdname[1024];/* PPD filename */ - - snprintf(ppdname, sizeof(ppdname), "%s/ppd/%s.ppd", - ServerRoot, p->printers[i]->name); - if (!access(ppdname, 0)) - { - p = p->printers[i]; - break; - } - } - } - - if (i >= p->num_printers) - p = NULL; - } - } + if (type == NULL) + strlcpy(line, "text/plain", sizeof(line)); + else + snprintf(line, sizeof(line), "%s/%s", type->super, type->type); - if (p) - snprintf(con->uri, sizeof(con->uri), "/icons/%s.png", p->name); - else - { - if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!write_file(con, HTTP_STATUS_OK, filename, line, &filestats)) { cupsdCloseClient(con); return; } - - break; } - } - - if ((!strncmp(con->uri, "/admin", 6) && strcmp(con->uri, "/admin/conf/cupsd.conf") && strncmp(con->uri, "/admin/log/", 11)) || - !strncmp(con->uri, "/printers", 9) || - !strncmp(con->uri, "/classes", 8) || - !strncmp(con->uri, "/help", 5) || - !strncmp(con->uri, "/jobs", 5)) + } + else if (!strncmp(con->uri, "/admin", 6) || !strncmp(con->uri, "/printers", 9) || !strncmp(con->uri, "/classes", 8) || !strncmp(con->uri, "/help", 5) || !strncmp(con->uri, "/jobs", 5)) { if (!WebInterface) { @@ -1185,16 +1111,12 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (!strncmp(con->uri, "/admin", 6)) { - cupsdSetStringf(&con->command, "%s/cgi-bin/admin.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/admin.cgi", ServerBin); cupsdSetString(&con->options, strchr(con->uri + 6, '?')); } else if (!strncmp(con->uri, "/printers", 9)) { - cupsdSetStringf(&con->command, "%s/cgi-bin/printers.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/printers.cgi", ServerBin); if (con->uri[9] && con->uri[10]) cupsdSetString(&con->options, con->uri + 9); else @@ -1202,9 +1124,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else if (!strncmp(con->uri, "/classes", 8)) { - cupsdSetStringf(&con->command, "%s/cgi-bin/classes.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/classes.cgi", ServerBin); if (con->uri[8] && con->uri[9]) cupsdSetString(&con->options, con->uri + 8); else @@ -1212,9 +1132,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else if (!strncmp(con->uri, "/jobs", 5)) { - cupsdSetStringf(&con->command, "%s/cgi-bin/jobs.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/jobs.cgi", ServerBin); if (con->uri[5] && con->uri[6]) cupsdSetString(&con->options, con->uri + 5); else @@ -1222,9 +1140,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else { - cupsdSetStringf(&con->command, "%s/cgi-bin/help.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/help.cgi", ServerBin); if (con->uri[5] && con->uri[6]) cupsdSetString(&con->options, con->uri + 5); else @@ -1245,89 +1161,13 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (httpGetVersion(con->http) <= HTTP_VERSION_1_0) httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); } - else if (!strncmp(con->uri, "/admin/log/", 11) && (strchr(con->uri + 11, '/') || strlen(con->uri) == 11)) + else { - /* - * GET can only be done to configuration files directly under - * /admin/conf... - */ - - cupsdLogClient(con, CUPSD_LOG_ERROR, "Request for subdirectory \"%s\".", con->uri); - - if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } - - break; - } - else - { - /* - * Serve a file... - */ - - if ((filename = get_file(con, &filestats, buf, - sizeof(buf))) == NULL) - { - if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) - { - cupsdCloseClient(con); - return; - } - - break; - } - - type = mimeFileType(MimeDatabase, filename, NULL, NULL); - - cupsdLogClient(con, CUPSD_LOG_DEBUG, "filename=\"%s\", type=%s/%s", filename, type ? type->super : "", type ? type->type : ""); - - if (is_cgi(con, filename, &filestats, type)) - { - /* - * Note: con->command and con->options were set by - * is_cgi()... - */ - - if (!cupsdSendCommand(con, con->command, con->options, 0)) - { - if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) - { - cupsdCloseClient(con); - return; - } - } - else - cupsdLogRequest(con, HTTP_STATUS_OK); - - if (httpGetVersion(con->http) <= HTTP_VERSION_1_0) - httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF); - break; - } - - if (!check_if_modified(con, &filestats)) - { - if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE)) - { - cupsdCloseClient(con); - return; - } - } - else - { - if (type == NULL) - strlcpy(line, "text/plain", sizeof(line)); - else - snprintf(line, sizeof(line), "%s/%s", type->super, type->type); - - if (!write_file(con, HTTP_STATUS_OK, filename, line, &filestats)) - { - cupsdCloseClient(con); - return; - } - } } break; @@ -1337,9 +1177,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * so check the length against any limits that are set... */ - if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] && - MaxRequestSize > 0 && - httpGetLength2(con->http) > MaxRequestSize) + if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] && MaxRequestSize > 0 && httpGetLength2(con->http) > MaxRequestSize) { /* * Request too large... @@ -1373,9 +1211,11 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * content-type field will be "application/ipp"... */ - if (!strcmp(httpGetField(con->http, HTTP_FIELD_CONTENT_TYPE), - "application/ipp")) + if (!strcmp(httpGetField(con->http, HTTP_FIELD_CONTENT_TYPE), "application/ipp")) + { con->request = ippNew(); + break; + } else if (!WebInterface) { /* @@ -1390,11 +1230,29 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ break; } - else if ((!strncmp(con->uri, "/admin", 6) && strncmp(con->uri, "/admin/log/", 11)) || - !strncmp(con->uri, "/printers", 9) || - !strncmp(con->uri, "/classes", 8) || - !strncmp(con->uri, "/help", 5) || - !strncmp(con->uri, "/jobs", 5)) + + if ((filename = get_file(con, &filestats, buf, sizeof(buf))) != NULL) + { + /* + * POST to a file... + */ + + type = mimeFileType(MimeDatabase, filename, NULL, NULL); + + if (!is_cgi(con, filename, &filestats, type)) + { + /* + * Only POST to CGI's... + */ + + if (!cupsdSendError(con, HTTP_STATUS_UNAUTHORIZED, CUPSD_AUTH_NONE)) + { + cupsdCloseClient(con); + return; + } + } + } + else if (!strncmp(con->uri, "/admin", 6) || !strncmp(con->uri, "/printers", 9) || !strncmp(con->uri, "/classes", 8) || !strncmp(con->uri, "/help", 5) || !strncmp(con->uri, "/jobs", 5)) { /* * CGI request... @@ -1402,16 +1260,12 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (!strncmp(con->uri, "/admin", 6)) { - cupsdSetStringf(&con->command, "%s/cgi-bin/admin.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/admin.cgi", ServerBin); cupsdSetString(&con->options, strchr(con->uri + 6, '?')); } else if (!strncmp(con->uri, "/printers", 9)) { - cupsdSetStringf(&con->command, "%s/cgi-bin/printers.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/printers.cgi", ServerBin); if (con->uri[9] && con->uri[10]) cupsdSetString(&con->options, con->uri + 9); else @@ -1419,9 +1273,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else if (!strncmp(con->uri, "/classes", 8)) { - cupsdSetStringf(&con->command, "%s/cgi-bin/classes.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/classes.cgi", ServerBin); if (con->uri[8] && con->uri[9]) cupsdSetString(&con->options, con->uri + 8); else @@ -1429,9 +1281,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else if (!strncmp(con->uri, "/jobs", 5)) { - cupsdSetStringf(&con->command, "%s/cgi-bin/jobs.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/jobs.cgi", ServerBin); if (con->uri[5] && con->uri[6]) cupsdSetString(&con->options, con->uri + 5); else @@ -1439,9 +1289,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else { - cupsdSetStringf(&con->command, "%s/cgi-bin/help.cgi", - ServerBin); - + cupsdSetStringf(&con->command, "%s/cgi-bin/help.cgi", ServerBin); if (con->uri[5] && con->uri[6]) cupsdSetString(&con->options, con->uri + 5); else @@ -1453,35 +1301,10 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ } else { - /* - * POST to a file... - */ - - if ((filename = get_file(con, &filestats, buf, - sizeof(buf))) == NULL) - { - if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) - { - cupsdCloseClient(con); - return; - } - - break; - } - - type = mimeFileType(MimeDatabase, filename, NULL, NULL); - - if (!is_cgi(con, filename, &filestats, type)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) { - /* - * Only POST to CGI's... - */ - - if (!cupsdSendError(con, HTTP_STATUS_UNAUTHORIZED, CUPSD_AUTH_NONE)) - { - cupsdCloseClient(con); - return; - } + cupsdCloseClient(con); + return; } } break; @@ -1497,8 +1320,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * PUT can only be done to the cupsd.conf file... */ - cupsdLogClient(con, CUPSD_LOG_ERROR, - "Disallowed PUT request for \"%s\".", con->uri); + cupsdLogClient(con, CUPSD_LOG_ERROR, "Disallowed PUT request for \"%s\".", con->uri); if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE)) { @@ -1514,9 +1336,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * so check the length against any limits that are set... */ - if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] && - MaxRequestSize > 0 && - httpGetLength2(con->http) > MaxRequestSize) + if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] && MaxRequestSize > 0 && httpGetLength2(con->http) > MaxRequestSize) { /* * Request too large... @@ -1549,15 +1369,12 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Open a temporary file to hold the request... */ - cupsdSetStringf(&con->filename, "%s/%08x", RequestRoot, - request_id ++); + cupsdSetStringf(&con->filename, "%s/%08x", RequestRoot, request_id ++); con->file = open(con->filename, O_WRONLY | O_CREAT | O_TRUNC, 0640); if (con->file < 0) { - cupsdLogClient(con, CUPSD_LOG_ERROR, - "Unable to create request file \"%s\": %s", - con->filename, strerror(errno)); + cupsdLogClient(con, CUPSD_LOG_ERROR, "Unable to create request file \"%s\": %s", con->filename, strerror(errno)); if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE)) { @@ -1578,54 +1395,44 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ return; case HTTP_STATE_HEAD : - if (!strncmp(con->uri, "/printers/", 10) && - !strcmp(con->uri + strlen(con->uri) - 4, ".ppd")) - { - /* - * Send PPD file - get the real printer name since printer - * names are not case sensitive but filenames can be... - */ - - con->uri[strlen(con->uri) - 4] = '\0'; /* Drop ".ppd" */ - - if ((p = cupsdFindPrinter(con->uri + 10)) != NULL) - snprintf(con->uri, sizeof(con->uri), "/ppd/%s.ppd", p->name); - else + if ((filename = get_file(con, &filestats, buf, sizeof(buf))) != NULL) + { + if (!check_if_modified(con, &filestats)) { - if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) + if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } - cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND); - break; + cupsdLogRequest(con, HTTP_STATUS_NOT_MODIFIED); } - } - else if (!strncmp(con->uri, "/printers/", 10) && - !strcmp(con->uri + strlen(con->uri) - 4, ".png")) - { - /* - * Send PNG file - get the real printer name since printer - * names are not case sensitive but filenames can be... - */ - - con->uri[strlen(con->uri) - 4] = '\0'; /* Drop ".ppd" */ - - if ((p = cupsdFindPrinter(con->uri + 10)) != NULL) - snprintf(con->uri, sizeof(con->uri), "/icons/%s.png", p->name); else { - if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE)) + /* + * Serve a file... + */ + + type = mimeFileType(MimeDatabase, filename, NULL, NULL); + if (type == NULL) + strlcpy(line, "text/plain", sizeof(line)); + else + snprintf(line, sizeof(line), "%s/%s", type->super, type->type); + + httpClearFields(con->http); + + httpSetField(con->http, HTTP_FIELD_LAST_MODIFIED, httpGetDateString(filestats.st_mtime)); + httpSetLength(con->http, (size_t)filestats.st_size); + + if (!cupsdSendHeader(con, HTTP_STATUS_OK, line, CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } - cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND); - break; + cupsdLogRequest(con, HTTP_STATUS_OK); } - } + } else if (!WebInterface) { httpClearFields(con->http); @@ -1640,11 +1447,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ break; } - if ((!strncmp(con->uri, "/admin", 6) && strcmp(con->uri, "/admin/conf/cupsd.conf") && strncmp(con->uri, "/admin/log/", 11)) || - !strncmp(con->uri, "/printers", 9) || - !strncmp(con->uri, "/classes", 8) || - !strncmp(con->uri, "/help", 5) || - !strncmp(con->uri, "/jobs", 5)) + if (!strncmp(con->uri, "/admin", 6) || !strncmp(con->uri, "/printers", 9) || !strncmp(con->uri, "/classes", 8) || !strncmp(con->uri, "/help", 5) || !strncmp(con->uri, "/jobs", 5)) { /* * CGI output... @@ -1660,74 +1463,17 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ cupsdLogRequest(con, HTTP_STATUS_OK); } - else if (!strncmp(con->uri, "/admin/log/", 11) && (strchr(con->uri + 11, '/') || strlen(con->uri) == 11)) - { - /* - * HEAD can only be done to configuration files under - * /admin/conf... - */ - - cupsdLogClient(con, CUPSD_LOG_ERROR, - "Request for subdirectory \"%s\".", con->uri); - - if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE)) - { - cupsdCloseClient(con); - return; - } - - cupsdLogRequest(con, HTTP_STATUS_FORBIDDEN); - break; - } - else if ((filename = get_file(con, &filestats, buf, - sizeof(buf))) == NULL) - { - httpClearFields(con->http); - - if (!cupsdSendHeader(con, HTTP_STATUS_NOT_FOUND, "text/html", - CUPSD_AUTH_NONE)) - { - cupsdCloseClient(con); - return; - } - - cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND); - } - else if (!check_if_modified(con, &filestats)) - { - if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE)) - { - cupsdCloseClient(con); - return; - } - - cupsdLogRequest(con, HTTP_STATUS_NOT_MODIFIED); - } else { - /* - * Serve a file... - */ - - type = mimeFileType(MimeDatabase, filename, NULL, NULL); - if (type == NULL) - strlcpy(line, "text/plain", sizeof(line)); - else - snprintf(line, sizeof(line), "%s/%s", type->super, type->type); - httpClearFields(con->http); - httpSetField(con->http, HTTP_FIELD_LAST_MODIFIED, - httpGetDateString(filestats.st_mtime)); - httpSetLength(con->http, (size_t)filestats.st_size); - - if (!cupsdSendHeader(con, HTTP_STATUS_OK, line, CUPSD_AUTH_NONE)) + if (!cupsdSendHeader(con, HTTP_STATUS_NOT_FOUND, "text/html", CUPSD_AUTH_NONE)) { cupsdCloseClient(con); return; } - cupsdLogRequest(con, HTTP_STATUS_OK); + cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND); } break; @@ -2936,6 +2682,7 @@ get_file(cupsd_client_t *con, /* I - Client connection */ char language[7], /* Language subdirectory, if any */ dest[1024]; /* Destination name */ int perm_check = 1; /* Do permissions check? */ + cupsd_printer_t *p; /* Printer */ /* @@ -2944,47 +2691,76 @@ get_file(cupsd_client_t *con, /* I - Client connection */ language[0] = '\0'; - if (!strncmp(con->uri, "/ppd/", 5) && !strchr(con->uri + 5, '/')) + if ((!strncmp(con->uri, "/ppd/", 5) || !strncmp(con->uri, "/printers/", 10) || !strncmp(con->uri, "/classes/", 9)) && !strcmp(con->uri + strlen(con->uri) - 4, ".ppd")) { - strlcpy(dest, con->uri + 5, sizeof(dest)); - ptr = dest + strlen(dest) - 4; + strlcpy(dest, strchr(con->uri + 1, '/') + 1, sizeof(dest)); + dest[strlen(dest) - 4] = '\0'; /* Strip .ppd */ - if (ptr <= dest || strcmp(ptr, ".ppd")) + if ((p = cupsdFindDest(dest)) == NULL) { - cupsdLogClient(con, CUPSD_LOG_INFO, "Disallowed path \"%s\".", con->uri); + cupsdLogClient(con, CUPSD_LOG_INFO, "No destination \"%s\" found.", dest); return (NULL); } - *ptr = '\0'; - if (!cupsdFindPrinter(dest)) + if (p->type & CUPS_PRINTER_CLASS) { - cupsdLogClient(con, CUPSD_LOG_INFO, "No printer \"%s\" found.", dest); - return (NULL); - } + int i; /* Looping var */ - snprintf(filename, len, "%s%s", ServerRoot, con->uri); + for (i = 0; i < p->num_printers; i ++) + { + if (!(p->printers[i]->type & CUPS_PRINTER_CLASS)) + { + snprintf(filename, len, "%s/ppd/%s.ppd", ServerRoot, p->printers[i]->name); + if (!access(filename, 0)) + { + p = p->printers[i]; + break; + } + } + } + + if (i >= p->num_printers) + p = NULL; + } + else + snprintf(filename, len, "%s/ppd/%s.ppd", ServerRoot, p->name); perm_check = 0; } - else if (!strncmp(con->uri, "/icons/", 7) && !strchr(con->uri + 7, '/')) + else if ((!strncmp(con->uri, "/icons/", 7) || !strncmp(con->uri, "/printers/", 10) || !strncmp(con->uri, "/classes/", 9)) && !strcmp(con->uri + strlen(con->uri) - 4, ".png")) { - strlcpy(dest, con->uri + 7, sizeof(dest)); - ptr = dest + strlen(dest) - 4; + strlcpy(dest, strchr(con->uri + 1, '/') + 1, sizeof(dest)); + dest[strlen(dest) - 4] = '\0'; /* Strip .png */ - if (ptr <= dest || strcmp(ptr, ".png")) + if ((p = cupsdFindDest(dest)) == NULL) { - cupsdLogClient(con, CUPSD_LOG_INFO, "Disallowed path \"%s\".", con->uri); + cupsdLogClient(con, CUPSD_LOG_INFO, "No destination \"%s\" found.", dest); return (NULL); } - *ptr = '\0'; - if (!cupsdFindDest(dest)) + if (p->type & CUPS_PRINTER_CLASS) { - cupsdLogClient(con, CUPSD_LOG_INFO, "No printer \"%s\" found.", dest); - return (NULL); + int i; /* Looping var */ + + for (i = 0; i < p->num_printers; i ++) + { + if (!(p->printers[i]->type & CUPS_PRINTER_CLASS)) + { + snprintf(filename, len, "%s/images/%s.png", CacheDir, p->printers[i]->name); + if (!access(filename, 0)) + { + p = p->printers[i]; + break; + } + } + } + + if (i >= p->num_printers) + p = NULL; } + else + snprintf(filename, len, "%s/images/%s.png", CacheDir, p->name); - snprintf(filename, len, "%s/%s.png", CacheDir, dest); if (access(filename, F_OK) < 0) snprintf(filename, len, "%s/images/generic.png", DocumentRoot); @@ -2992,6 +2768,27 @@ get_file(cupsd_client_t *con, /* I - Client connection */ } else if (!strncmp(con->uri, "/rss/", 5) && !strchr(con->uri + 5, '/')) snprintf(filename, len, "%s/rss/%s", CacheDir, con->uri + 5); + else if (!strncmp(con->uri, "/strings/", 9) && !strcmp(con->uri + strlen(con->uri) - 8, ".strings")) + { + strlcpy(dest, con->uri + 9, sizeof(dest)); + dest[strlen(dest) - 8] = '\0'; + + if ((p = cupsdFindDest(dest)) == NULL) + { + cupsdLogClient(con, CUPSD_LOG_INFO, "No destination \"%s\" found.", dest); + return (NULL); + } + + if (!p->strings) + { + cupsdLogClient(con, CUPSD_LOG_INFO, "No strings files for \"%s\".", dest); + return (NULL); + } + + strlcpy(filename, p->strings, len); + + perm_check = 0; + } else if (!strcmp(con->uri, "/admin/conf/cupsd.conf")) { strlcpy(filename, ConfigurationFile, len); @@ -3031,6 +2828,7 @@ get_file(cupsd_client_t *con, /* I - Client connection */ strncmp(con->uri, "/icons/", 7) && strncmp(con->uri, "/ppd/", 5) && strncmp(con->uri, "/rss/", 5) && + strncmp(con->uri, "/strings/", 9) && strncmp(con->uri, "/admin/conf/", 12) && strncmp(con->uri, "/admin/log/", 11)) { |