X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=cups%2Fadminutil.c;h=580511b8fe54f90638879f395d10fa13de13a82f;hb=61515785f7de12d8b2a29090020e684988f89977;hp=87ff36fd791745302a6764a812dee17f67950bd3;hpb=1f0275e3cc0bc5fbe11e3bffd54581aa05c9c764;p=thirdparty%2Fcups.git diff --git a/cups/adminutil.c b/cups/adminutil.c index 87ff36fd7..580511b8f 100644 --- a/cups/adminutil.c +++ b/cups/adminutil.c @@ -1,10 +1,9 @@ /* - * "$Id: adminutil.c 7576 2008-05-15 21:05:14Z mike $" + * "$Id: adminutil.c 10996 2013-05-29 11:51:34Z msweet $" * - * Administration utility API definitions for the Common UNIX Printing - * System (CUPS). + * Administration utility API definitions for CUPS. * - * Copyright 2007-2008 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 2001-2007 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -17,26 +16,22 @@ * * Contents: * - * cupsAdminCreateWindowsPPD() - Create the Windows PPD file for a printer. - * cupsAdminExportSamba() - Export a printer to Samba. - * cupsAdminGetServerSettings() - Get settings from the server. - * _cupsAdminGetServerSettings() - Get settings from the server (private). - * cupsAdminSetServerSettings() - Set settings on the server. - * _cupsAdminSetServerSettings() - Set settings on the server (private). - * do_samba_command() - Do a SAMBA command. - * get_cupsd_conf() - Get the current cupsd.conf file. - * invalidate_cupsd_cache() - Invalidate the cached cupsd.conf settings. - * write_option() - Write a CUPS option to a PPD file. + * cupsAdminCreateWindowsPPD() - Create the Windows PPD file for a printer. + * cupsAdminExportSamba() - Export a printer to Samba. + * cupsAdminGetServerSettings() - Get settings from the server. + * cupsAdminSetServerSettings() - Set settings on the server. + * do_samba_command() - Do a SAMBA command. + * get_cupsd_conf() - Get the current cupsd.conf file. + * invalidate_cupsd_cache() - Invalidate the cached cupsd.conf settings. + * write_option() - Write a CUPS option to a PPD file. */ /* * Include necessary headers... */ +#include "cups-private.h" #include "adminutil.h" -#include "globals.h" -#include "debug.h" -#include #include #include #ifdef WIN32 @@ -50,12 +45,6 @@ * Local functions... */ -extern int _cupsAdminGetServerSettings(http_t *http, - int *num_settings, - cups_option_t **settings); -extern int _cupsAdminSetServerSettings(http_t *http, - int num_settings, - cups_option_t *settings); static int do_samba_command(const char *command, const char *address, const char *subcommand, @@ -75,6 +64,8 @@ static void write_option(cups_file_t *dstfp, int order, /* * 'cupsAdminCreateWindowsPPD()' - Create the Windows PPD file for a printer. + * + * @deprecated@ */ char * /* O - PPD file or NULL */ @@ -138,7 +129,7 @@ cupsAdminCreateWindowsPPD( * Get the supported banner pages, etc. for the printer... */ - request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES); + request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES); httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/printers/%s", dest); @@ -154,7 +145,7 @@ cupsAdminCreateWindowsPPD( */ response = cupsDoRequest(http, request, "/"); - if (!response || cupsLastError() > IPP_OK_CONFLICT) + if (!response || cupsLastError() > IPP_STATUS_OK_CONFLICTING) { unlink(src); return (NULL); @@ -241,7 +232,7 @@ cupsAdminCreateWindowsPPD( } else if (jcloption && !strncmp(line, "*OrderDependency:", 17)) { - for (ptr = line + 17; *ptr && isspace(*ptr & 255); ptr ++); + for (ptr = line + 17; _cups_isspace(*ptr); ptr ++); ptr = strchr(ptr, ' '); @@ -260,9 +251,9 @@ cupsAdminCreateWindowsPPD( if ((ptr = strchr(line, ':')) == NULL) { snprintf(line, sizeof(line), - _cupsLangString(language, _("Missing value on line %d!")), - linenum); - _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line); + _cupsLangString(language, _("Missing value on line %d.")), + linenum); + _cupsSetError(IPP_STATUS_ERROR_DOCUMENT_FORMAT_ERROR, line, 0); cupsFileClose(srcfp); cupsFileClose(dstfp); @@ -279,9 +270,9 @@ cupsAdminCreateWindowsPPD( { snprintf(line, sizeof(line), _cupsLangString(language, - _("Missing double quote on line %d!")), + _("Missing double quote on line %d.")), linenum); - _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line); + _cupsSetError(IPP_STATUS_ERROR_DOCUMENT_FORMAT_ERROR, line, 0); cupsFileClose(srcfp); cupsFileClose(dstfp); @@ -298,9 +289,9 @@ cupsAdminCreateWindowsPPD( { snprintf(line, sizeof(line), _cupsLangString(language, - _("Bad option + choice on line %d!")), + _("Bad option + choice on line %d.")), linenum); - _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line); + _cupsSetError(IPP_STATUS_ERROR_DOCUMENT_FORMAT_ERROR, line, 0); cupsFileClose(srcfp); cupsFileClose(dstfp); @@ -343,10 +334,7 @@ cupsAdminCreateWindowsPPD( if (linenum == 0) { - snprintf(line, sizeof(line), - _cupsLangString(language, _("Empty PPD file!")), - linenum); - _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line); + _cupsSetError(IPP_STATUS_ERROR_DOCUMENT_FORMAT_ERROR, _("Empty PPD file."), 1); cupsFileClose(dstfp); unlink(buffer); @@ -404,6 +392,8 @@ cupsAdminCreateWindowsPPD( /* * 'cupsAdminExportSamba()' - Export a printer to Samba. + * + * @deprecated@ */ int /* O - 1 on success, 0 on failure */ @@ -434,7 +424,7 @@ cupsAdminExportSamba( if (!dest || !ppd || !samba_server || !samba_user || !samba_password) { - _cupsSetError(IPP_INTERNAL_ERROR, NULL); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); return (0); } @@ -444,7 +434,7 @@ cupsAdminExportSamba( if ((fp = cupsTempFile2(authfile, sizeof(authfile))) == NULL) { - _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno)); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0); return (0); } @@ -495,12 +485,12 @@ cupsAdminExportSamba( snprintf(message, sizeof(message), _cupsLangString(language, _("Unable to copy Windows 2000 printer " - "driver files (%d)!")), status); + "driver files (%d).")), status); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); if (logfile) - _cupsLangPrintf(logfile, "%s\n", message); + _cupsLangPuts(logfile, message); unlink(authfile); @@ -530,18 +520,18 @@ cupsAdminExportSamba( snprintf(message, sizeof(message), _cupsLangString(language, _("Unable to copy CUPS printer driver " - "files (%d)!")), status); + "files (%d).")), status); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); if (logfile) - _cupsLangPrintf(logfile, "%s\n", message); + _cupsLangPuts(logfile, message); unlink(authfile); return (0); } - + /* * Do the rpcclient command needed for the CUPS drivers... */ @@ -573,12 +563,12 @@ cupsAdminExportSamba( snprintf(message, sizeof(message), _cupsLangString(language, _("Unable to install Windows 2000 printer " - "driver files (%d)!")), status); + "driver files (%d).")), status); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); if (logfile) - _cupsLangPrintf(logfile, "%s\n", message); + _cupsLangPuts(logfile, message); unlink(authfile); @@ -618,12 +608,12 @@ cupsAdminExportSamba( snprintf(message, sizeof(message), _cupsLangString(language, _("Unable to copy Windows 9x printer " - "driver files (%d)!")), status); + "driver files (%d).")), status); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); if (logfile) - _cupsLangPrintf(logfile, "%s\n", message); + _cupsLangPuts(logfile, message); unlink(authfile); @@ -647,12 +637,12 @@ cupsAdminExportSamba( snprintf(message, sizeof(message), _cupsLangString(language, _("Unable to install Windows 9x printer " - "driver files (%d)!")), status); + "driver files (%d).")), status); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); if (logfile) - _cupsLangPrintf(logfile, "%s\n", message); + _cupsLangPuts(logfile, message); unlink(authfile); @@ -699,12 +689,12 @@ cupsAdminExportSamba( snprintf(message, sizeof(message), _cupsLangString(language, _("Unable to copy 64-bit Windows printer " - "driver files (%d)!")), status); + "driver files (%d).")), status); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); if (logfile) - _cupsLangPrintf(logfile, "%s\n", message); + _cupsLangPuts(logfile, message); unlink(authfile); @@ -734,18 +724,18 @@ cupsAdminExportSamba( snprintf(message, sizeof(message), _cupsLangString(language, _("Unable to copy 64-bit CUPS printer driver " - "files (%d)!")), status); + "files (%d).")), status); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); if (logfile) - _cupsLangPrintf(logfile, "%s\n", message); + _cupsLangPuts(logfile, message); unlink(authfile); return (0); } - + /* * Do the rpcclient command needed for the CUPS drivers... */ @@ -777,12 +767,12 @@ cupsAdminExportSamba( snprintf(message, sizeof(message), _cupsLangString(language, _("Unable to install Windows 2000 printer " - "driver files (%d)!")), status); + "driver files (%d).")), status); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); if (logfile) - _cupsLangPrintf(logfile, "%s\n", message); + _cupsLangPuts(logfile, message); unlink(authfile); @@ -795,22 +785,22 @@ cupsAdminExportSamba( if (!have_drivers) strlcpy(message, _cupsLangString(language, - _("No Windows printer drivers are installed!")), + _("No Windows printer drivers are installed.")), sizeof(message)); else strlcpy(message, _cupsLangString(language, _("Warning, no Windows 2000 printer drivers " - "are installed!")), + "are installed.")), sizeof(message)); - _cupsSetError(IPP_NOT_FOUND, message); - _cupsLangPrintf(logfile, "%s\n", message); + _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, message, 0); + _cupsLangPuts(logfile, message); } if (have_drivers == 0) { - _cupsSetError(IPP_NOT_FOUND, message); + _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, message, 0); unlink(authfile); @@ -828,13 +818,13 @@ cupsAdminExportSamba( { snprintf(message, sizeof(message), _cupsLangString(language, - _("Unable to set Windows printer driver (%d)!")), + _("Unable to set Windows printer driver (%d).")), status); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); if (logfile) - _cupsLangPrintf(logfile, "%s\n", message); + _cupsLangPuts(logfile, message); unlink(authfile); @@ -853,7 +843,7 @@ cupsAdminExportSamba( * The returned settings should be freed with cupsFreeOptions() when * you are done with them. * - * @since CUPS 1.3@ + * @since CUPS 1.3/OS X 10.5@ */ int /* O - 1 on success, 0 on failure */ @@ -861,25 +851,6 @@ cupsAdminGetServerSettings( http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ int *num_settings, /* O - Number of settings */ cups_option_t **settings) /* O - Settings */ -{ - return (_cupsAdminGetServerSettings(http, num_settings, settings)); -} - - -/* - * '_cupsAdminGetServerSettings()' - Get settings from the server. - * - * The returned settings should be freed with cupsFreeOptions() when - * you are done with them. - * - * @since CUPS 1.2@ - */ - -int /* O - 1 on success, 0 on failure */ -_cupsAdminGetServerSettings( - http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ - int *num_settings, /* O - Number of settings */ - cups_option_t **settings) /* O - Settings */ { int i; /* Looping var */ cups_file_t *cupsd; /* cupsd.conf file */ @@ -897,11 +868,64 @@ _cupsAdminGetServerSettings( */ if (!http) - http = _cupsConnect(); + { + /* + * See if we are connected to the same server... + */ + + if (cg->http) + { + /* + * Compare the connection hostname, port, and encryption settings to + * the cached defaults; these were initialized the first time we + * connected... + */ + + if (strcmp(cg->http->hostname, cg->server) || + cg->ipp_port != httpAddrPort(cg->http->hostaddr) || + (cg->http->encryption != cg->encryption && + cg->http->encryption == HTTP_ENCRYPTION_NEVER)) + { + /* + * Need to close the current connection because something has changed... + */ + + httpClose(cg->http); + cg->http = NULL; + } + } + + /* + * (Re)connect as needed... + */ + + if (!cg->http) + { + if ((cg->http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, + cupsEncryption(), 1, 0, NULL)) == NULL) + { + if (errno) + _cupsSetError(IPP_STATUS_ERROR_SERVICE_UNAVAILABLE, NULL, 0); + else + _cupsSetError(IPP_STATUS_ERROR_SERVICE_UNAVAILABLE, + _("Unable to connect to host."), 1); + + if (num_settings) + *num_settings = 0; + + if (settings) + *settings = NULL; + + return (0); + } + } + + http = cg->http; + } if (!http || !num_settings || !settings) { - _cupsSetError(IPP_INTERNAL_ERROR, NULL); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); if (num_settings) *num_settings = 0; @@ -920,7 +944,7 @@ _cupsAdminGetServerSettings( */ if ((status = get_cupsd_conf(http, cg, cg->cupsd_update, cupsdconf, - sizeof(cupsdconf), &remote)) == HTTP_OK) + sizeof(cupsdconf), &remote)) == HTTP_STATUS_OK) { if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL) { @@ -928,9 +952,9 @@ _cupsAdminGetServerSettings( snprintf(message, sizeof(message), - _cupsLangString(cupsLangDefault(), _("open of %s failed: %s")), + _cupsLangString(cupsLangDefault(), _("Open of %s failed: %s")), cupsdconf, strerror(errno)); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); } } else @@ -946,8 +970,6 @@ _cupsAdminGetServerSettings( remote_admin = 0, /* Remote administration allowed? */ remote_any = 0, /* Remote access from anywhere allowed? */ browsing = 1, /* Browsing enabled? */ - browse_allow = 1, /* Browse address set? */ - browse_address = 0, /* Browse address set? */ cancel_policy = 1, /* Cancel-job policy set? */ debug_logging = 0; /* LogLevel debug set? */ int linenum = 0, /* Line number in file */ @@ -967,7 +989,7 @@ _cupsAdminGetServerSettings( if (!value && strncmp(line, "")) + else if (!_cups_strcasecmp(line, "")) { in_policy = 0; } - else if (!strcasecmp(line, "")) + else if (!_cups_strcasecmp(line, "")) { in_cancel_job = 0; } - else if (!strcasecmp(line, "Require") && in_cancel_job) + else if (!_cups_strcasecmp(line, "Require") && in_cancel_job) { cancel_policy = 0; } - else if (!strcasecmp(line, "")) + else if (!_cups_strcasecmp(line, "")) { in_admin_location = 0; in_location = 0; } - else if (!strcasecmp(line, "Allow") && value && - strcasecmp(value, "localhost") && strcasecmp(value, "127.0.0.1") + else if (!_cups_strcasecmp(line, "Allow") && value && + _cups_strcasecmp(value, "localhost") && + _cups_strcasecmp(value, "127.0.0.1") #ifdef AF_LOCAL && *value != '/' #endif /* AF_LOCAL */ @@ -1078,10 +1092,16 @@ _cupsAdminGetServerSettings( { if (in_admin_location) remote_admin = 1; - else if (!strcasecmp(value, "all")) + else if (!_cups_strcasecmp(value, "all")) remote_any = 1; } - else if (line[0] != '<' && !in_location && !in_policy) + else if (line[0] != '<' && !in_location && !in_policy && + _cups_strcasecmp(line, "Allow") && + _cups_strcasecmp(line, "AuthType") && + _cups_strcasecmp(line, "Deny") && + _cups_strcasecmp(line, "Order") && + _cups_strcasecmp(line, "Require") && + _cups_strcasecmp(line, "Satisfy")) cg->cupsd_num_settings = cupsAddOption(line, value, cg->cupsd_num_settings, &(cg->cupsd_settings)); @@ -1105,15 +1125,9 @@ _cupsAdminGetServerSettings( cg->cupsd_num_settings, &(cg->cupsd_settings)); - cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS, - (browsing && browse_allow) ? - "1" : "0", - cg->cupsd_num_settings, - &(cg->cupsd_settings)); - cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, - (remote_access && browsing && - browse_address) ? "1" : "0", + (remote_access && browsing) ? "1" : + "0", cg->cupsd_num_settings, &(cg->cupsd_settings)); @@ -1122,7 +1136,7 @@ _cupsAdminGetServerSettings( cg->cupsd_num_settings, &(cg->cupsd_settings)); } - else if (status != HTTP_NOT_MODIFIED) + else if (status != HTTP_STATUS_NOT_MODIFIED) invalidate_cupsd_cache(cg); /* @@ -1145,7 +1159,7 @@ _cupsAdminGetServerSettings( /* * 'cupsAdminSetServerSettings()' - Set settings on the server. * - * @since CUPS 1.3@ + * @since CUPS 1.3/OS X 10.5@ */ int /* O - 1 on success, 0 on failure */ @@ -1153,22 +1167,6 @@ cupsAdminSetServerSettings( http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ int num_settings, /* I - Number of settings */ cups_option_t *settings) /* I - Settings */ -{ - return (_cupsAdminSetServerSettings(http, num_settings, settings)); -} - - -/* - * '_cupsAdminSetServerSettings()' - Set settings on the server. - * - * @since CUPS 1.2@ - */ - -int /* O - 1 on success, 0 on failure */ -_cupsAdminSetServerSettings( - http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ - int num_settings, /* I - Number of settings */ - cups_option_t *settings) /* I - Settings */ { int i; /* Looping var */ http_status_t status; /* GET/PUT status */ @@ -1190,8 +1188,7 @@ _cupsAdminSetServerSettings( in_conf_location, /* In the /admin/conf location? */ in_root_location; /* In the / location? */ const char *val; /* Setting value */ - int remote_printers, /* Show remote printers */ - share_printers, /* Share local printers */ + int share_printers, /* Share local printers */ remote_admin, /* Remote administration allowed? */ remote_any, /* Remote access from anywhere? */ user_cancel_any, /* Cancel-job policy set? */ @@ -1205,8 +1202,7 @@ _cupsAdminSetServerSettings( wrote_root_location; /* Wrote the / location? */ int indent; /* Indentation */ int cupsd_num_settings; /* New number of settings */ - int old_remote_printers, /* Show remote printers */ - old_share_printers, /* Share local printers */ + int old_share_printers, /* Share local printers */ old_remote_admin, /* Remote administration allowed? */ old_user_cancel_any, /* Cancel-job policy set? */ old_debug_logging; /* LogLevel debug set? */ @@ -1224,7 +1220,7 @@ _cupsAdminSetServerSettings( if (!http || !num_settings || !settings) { - _cupsSetError(IPP_INTERNAL_ERROR, NULL); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); return (0); } @@ -1234,11 +1230,11 @@ _cupsAdminSetServerSettings( */ if (get_cupsd_conf(http, cg, 0, cupsdconf, sizeof(cupsdconf), - &remote) == HTTP_OK) + &remote) == HTTP_STATUS_OK) { if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL) { - _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno)); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0); return (0); } } @@ -1249,8 +1245,8 @@ _cupsAdminSetServerSettings( * Get current settings... */ - if (!_cupsAdminGetServerSettings(http, &cupsd_num_settings, - &cupsd_settings)) + if (!cupsAdminGetServerSettings(http, &cupsd_num_settings, + &cupsd_settings)) return (0); if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, cupsd_num_settings, @@ -1259,23 +1255,26 @@ _cupsAdminSetServerSettings( else old_debug_logging = 0; + DEBUG_printf(("1cupsAdminSetServerSettings: old debug_logging=%d", + old_debug_logging)); + if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, cupsd_num_settings, cupsd_settings)) != NULL) old_remote_admin = atoi(val); else old_remote_admin = 0; + DEBUG_printf(("1cupsAdminSetServerSettings: old remote_admin=%d", + old_remote_admin)); + if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, cupsd_num_settings, cupsd_settings)) != NULL) remote_any = atoi(val); else remote_any = 0; - if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, cupsd_num_settings, - cupsd_settings)) != NULL) - old_remote_printers = atoi(val); - else - old_remote_printers = 1; + DEBUG_printf(("1cupsAdminSetServerSettings: old remote_any=%d", + remote_any)); if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, cupsd_num_settings, cupsd_settings)) != NULL) @@ -1283,12 +1282,18 @@ _cupsAdminSetServerSettings( else old_share_printers = 0; + DEBUG_printf(("1cupsAdminSetServerSettings: old share_printers=%d", + old_share_printers)); + if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, cupsd_num_settings, cupsd_settings)) != NULL) old_user_cancel_any = atoi(val); else old_user_cancel_any = 0; + DEBUG_printf(("1cupsAdminSetServerSettings: old user_cancel_any=%d", + old_user_cancel_any)); + cupsFreeOptions(cupsd_num_settings, cupsd_settings); /* @@ -1312,16 +1317,22 @@ _cupsAdminSetServerSettings( else debug_logging = -1; + DEBUG_printf(("1cupsAdminSetServerSettings: debug_logging=%d", + debug_logging)); + if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, num_settings, settings)) != NULL) remote_any = atoi(val); + DEBUG_printf(("1cupsAdminSetServerSettings: remote_any=%d", + remote_any)); + if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, num_settings, settings)) != NULL) { remote_admin = atoi(val); - if (remote_admin == old_remote_admin && remote_any < 0) + if (remote_admin == old_remote_admin) { /* * No change to this setting... @@ -1333,29 +1344,15 @@ _cupsAdminSetServerSettings( else remote_admin = -1; - if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, num_settings, - settings)) != NULL) - { - remote_printers = atoi(val); - - if (remote_printers == old_remote_printers) - { - /* - * No change to this setting... - */ - - remote_printers = -1; - } - } - else - remote_printers = -1; + DEBUG_printf(("1cupsAdminSetServerSettings: remote_admin=%d", + remote_admin)); if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, num_settings, settings)) != NULL) { share_printers = atoi(val); - if (share_printers == old_share_printers && remote_any < 0) + if (share_printers == old_share_printers) { /* * No change to this setting... @@ -1367,6 +1364,9 @@ _cupsAdminSetServerSettings( else share_printers = -1; + DEBUG_printf(("1cupsAdminSetServerSettings: share_printers=%d", + share_printers)); + if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, num_settings, settings)) != NULL) { @@ -1384,6 +1384,9 @@ _cupsAdminSetServerSettings( else user_cancel_any = -1; + DEBUG_printf(("1cupsAdminSetServerSettings: user_cancel_any=%d", + user_cancel_any)); + /* * Create a temporary file for the new cupsd.conf file... */ @@ -1395,7 +1398,7 @@ _cupsAdminSetServerSettings( if (remote) unlink(cupsdconf); - _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno)); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0); return (0); } @@ -1434,14 +1437,14 @@ _cupsAdminSetServerSettings( while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum)) { - if ((!strcasecmp(line, "Port") || !strcasecmp(line, "Listen")) && - (share_printers >= 0 || remote_admin >= 0)) + if ((!_cups_strcasecmp(line, "Port") || !_cups_strcasecmp(line, "Listen")) && + (remote_admin >= 0 || remote_any > 0 || share_printers >= 0)) { if (!wrote_port_listen) { wrote_port_listen = 1; - if (share_printers > 0 || remote_admin > 0) + if (remote_admin > 0 || remote_any > 0 || share_printers > 0) { cupsFilePuts(temp, "# Allow remote access\n"); cupsFilePrintf(temp, "Port %d\n", server_port); @@ -1466,89 +1469,47 @@ _cupsAdminSetServerSettings( ) cupsFilePrintf(temp, "Listen %s\n", value); } - else if ((!strcasecmp(line, "Browsing") || - !strcasecmp(line, "BrowseAddress") || - !strcasecmp(line, "BrowseAllow") || - !strcasecmp(line, "BrowseDeny") || - !strcasecmp(line, "BrowseLocalProtocols") || - !strcasecmp(line, "BrowseRemoteProtocols") || - !strcasecmp(line, "BrowseOrder")) && - (remote_printers >= 0 || share_printers >= 0)) + else if ((!_cups_strcasecmp(line, "Browsing") || + !_cups_strcasecmp(line, "BrowseLocalProtocols")) && + share_printers >= 0) { if (!wrote_browsing) { - int new_remote_printers = (remote_printers > 0 || - (remote_printers == -1 && - old_remote_printers > 0)); int new_share_printers = (share_printers > 0 || (share_printers == -1 && old_share_printers > 0)); wrote_browsing = 1; - if (new_remote_printers || new_share_printers) + if (new_share_printers) { const char *localp = cupsGetOption("BrowseLocalProtocols", num_settings, settings); - const char *remotep = cupsGetOption("BrowseRemoteProtocols", - num_settings, settings); - if (!localp) + if (!localp || !localp[0]) localp = cupsGetOption("BrowseLocalProtocols", cupsd_num_settings, cupsd_settings); - if (!remotep) - remotep = cupsGetOption("BrowseRemoteProtocols", cupsd_num_settings, - cupsd_settings); - - if (new_remote_printers && new_share_printers) - cupsFilePuts(temp, - "# Enable printer sharing and shared printers.\n"); - else if (new_remote_printers) - cupsFilePuts(temp, - "# Show shared printers on the local network.\n"); - else - cupsFilePuts(temp, - "# Share local printers on the local network.\n"); - + cupsFilePuts(temp, "# Share local printers on the local network.\n"); cupsFilePuts(temp, "Browsing On\n"); - cupsFilePuts(temp, "BrowseOrder allow,deny\n"); - if (new_remote_printers) - { - cupsFilePuts(temp, "BrowseAllow all\n"); - - if (!remotep || !*remotep) - cupsFilePuts(temp, "BrowseRemoteProtocols " - CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS "\n"); - else if (remotep) - cupsFilePrintf(temp, "BrowseRemoteProtocols %s\n", remotep); - } - else - cupsFilePuts(temp, "BrowseRemoteProtocols\n"); - - if (new_share_printers) - { - cupsFilePuts(temp, "BrowseAddress @LOCAL\n"); + if (!localp) + localp = CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS; - if (!localp || !*localp) - cupsFilePuts(temp, "BrowseLocalProtocols " - CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS "\n"); - else if (localp) - cupsFilePrintf(temp, "BrowseLocalProtocols %s\n", localp); - } - else - cupsFilePuts(temp, "BrowseLocalProtocols\n"); + cupsFilePrintf(temp, "BrowseLocalProtocols %s\n", localp); + + cupsd_num_settings = cupsAddOption("BrowseLocalProtocols", localp, + cupsd_num_settings, + &cupsd_settings); } else { - cupsFilePuts(temp, - "# Disable printer sharing and shared printers.\n"); + cupsFilePuts(temp, "# Disable printer sharing.\n"); cupsFilePuts(temp, "Browsing Off\n"); } } } - else if (!strcasecmp(line, "LogLevel") && debug_logging >= 0) + else if (!_cups_strcasecmp(line, "LogLevel") && debug_logging >= 0) { wrote_loglevel = 1; @@ -1564,15 +1525,15 @@ _cupsAdminSetServerSettings( cupsFilePuts(temp, "LogLevel " CUPS_DEFAULT_LOG_LEVEL "\n"); } } - else if (!strcasecmp(line, "\n", line, value); indent += 2; } - else if (!strcasecmp(line, "")) + else if (!_cups_strcasecmp(line, "")) { indent -= 2; if (!wrote_policy && in_default_policy) @@ -1585,7 +1546,7 @@ _cupsAdminSetServerSettings( " \n" " Order deny,allow\n" " Require user @OWNER " - CUPS_DEFAULT_PRINTADMIN_AUTH "\n" + CUPS_DEFAULT_PRINTOPERATOR_AUTH "\n" " \n"); } @@ -1594,7 +1555,7 @@ _cupsAdminSetServerSettings( cupsFilePuts(temp, "\n"); } - else if (!strcasecmp(line, "\n", line, value); } - else if (!strcasecmp(line, "")) + else if (!_cups_strcasecmp(line, "")) { in_location = 0; indent -= 2; @@ -1643,7 +1604,8 @@ _cupsAdminSetServerSettings( cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); } - else if (in_root_location && (remote_admin >= 0 || share_printers >= 0)) + else if (in_root_location && + (remote_admin >= 0 || remote_any > 0 || share_printers >= 0)) { wrote_root_location = 1; @@ -1654,12 +1616,14 @@ _cupsAdminSetServerSettings( cupsFilePuts(temp, " # Allow remote administration...\n"); else if (share_printers > 0) cupsFilePuts(temp, " # Allow shared printing...\n"); + else if (remote_any > 0) + cupsFilePuts(temp, " # Allow remote access...\n"); else cupsFilePuts(temp, " # Restrict access to the server...\n"); cupsFilePuts(temp, " Order allow,deny\n"); - if (remote_admin > 0 || share_printers > 0) + if (remote_admin > 0 || remote_any > 0 || share_printers > 0) cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); } @@ -1670,84 +1634,86 @@ _cupsAdminSetServerSettings( cupsFilePuts(temp, "\n"); } - else if (!strcasecmp(line, "= 0) + if (in_default_policy) { /* - * Don't write anything for this limit section... + * See if the policy limit is for the Cancel-Job operation... */ - in_cancel_job = 2; - } - else - { - cupsFilePrintf(temp, " %s", line); + char *valptr; /* Pointer into value */ - while (*value) + + if (!_cups_strcasecmp(value, "cancel-job") && user_cancel_any >= 0) { - for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++); + /* + * Don't write anything for this limit section... + */ - if (*valptr) - *valptr++ = '\0'; + in_cancel_job = 2; + } + else + { + cupsFilePrintf(temp, "%*s%s", indent, "", line); - if (!strcasecmp(value, "cancel-job") && user_cancel_any >= 0) + while (*value) { - /* - * Write everything except for this definition... - */ + for (valptr = value; *valptr && !_cups_isspace(*valptr); valptr ++); - in_cancel_job = 1; + if (*valptr) + *valptr++ = '\0'; + + if (!_cups_strcasecmp(value, "cancel-job") && user_cancel_any >= 0) + { + /* + * Write everything except for this definition... + */ + + in_cancel_job = 1; + } + else + cupsFilePrintf(temp, " %s", value); + + for (value = valptr; _cups_isspace(*value); value ++); } - else - cupsFilePrintf(temp, " %s", value); - for (value = valptr; isspace(*value & 255); value ++); + cupsFilePuts(temp, ">\n"); } - - cupsFilePuts(temp, ">\n"); } + else + cupsFilePrintf(temp, "%*s%s %s>\n", indent, "", line, value); + + indent += 2; } - else if (!strcasecmp(line, "") && in_cancel_job) + else if (!_cups_strcasecmp(line, "") && in_cancel_job) { indent -= 2; if (in_cancel_job == 1) - cupsFilePuts(temp, " \n"); + cupsFilePuts(temp, " \n"); wrote_policy = 1; if (!user_cancel_any) cupsFilePuts(temp, " # Only the owner or an administrator can cancel " - "a job...\n" - " \n" - " Order deny,allow\n" - " Require user @OWNER " - CUPS_DEFAULT_PRINTADMIN_AUTH "\n" + "a job...\n" + " \n" + " Order deny,allow\n" + " Require user @OWNER " + CUPS_DEFAULT_PRINTOPERATOR_AUTH "\n" " \n"); in_cancel_job = 0; } else if ((((in_admin_location || in_conf_location || in_root_location) && - remote_admin >= 0) || + (remote_admin >= 0 || remote_any > 0)) || (in_root_location && share_printers >= 0)) && - (((!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny")) && - !strcasecmp(value, "@LOCAL")) || - !strcasecmp(line, "Order"))) + (!_cups_strcasecmp(line, "Allow") || !_cups_strcasecmp(line, "Deny") || + !_cups_strcasecmp(line, "Order"))) continue; else if (in_cancel_job == 2) continue; - else if (!strcasecmp(line, "\n", line, value); else if (line[0] == '<') { if (value) @@ -1787,7 +1753,7 @@ _cupsAdminSetServerSettings( /* * Record the non-policy, non-location directives that we find * in the server settings, since we cache this info and record it - * in _cupsAdminGetServerSettings()... + * in cupsAdminGetServerSettings()... */ cupsd_num_settings = cupsAddOption(line, value, cupsd_num_settings, @@ -1804,25 +1770,12 @@ _cupsAdminSetServerSettings( * Write any missing info... */ - if (!wrote_browsing && (remote_printers >= 0 || share_printers >= 0)) + if (!wrote_browsing && share_printers >= 0) { - if (remote_printers > 0 || share_printers > 0) + if (share_printers > 0) { - if (remote_printers > 0 && share_printers > 0) - cupsFilePuts(temp, "# Enable printer sharing and shared printers.\n"); - else if (remote_printers > 0) - cupsFilePuts(temp, "# Show shared printers on the local network.\n"); - else - cupsFilePuts(temp, "# Share local printers on the local network.\n"); - + cupsFilePuts(temp, "# Share local printers on the local network.\n"); cupsFilePuts(temp, "Browsing On\n"); - cupsFilePuts(temp, "BrowseOrder allow,deny\n"); - - if (remote_printers > 0) - cupsFilePuts(temp, "BrowseAllow all\n"); - - if (share_printers > 0) - cupsFilePuts(temp, "BrowseAddress @LOCAL\n"); } else { @@ -1845,9 +1798,10 @@ _cupsAdminSetServerSettings( } } - if (!wrote_port_listen && (share_printers >= 0 || remote_admin >= 0)) + if (!wrote_port_listen && + (remote_admin >= 0 || remote_any > 0 || share_printers >= 0)) { - if (share_printers > 0 || remote_admin > 0) + if (remote_admin > 0 || remote_any > 0 || share_printers > 0) { cupsFilePuts(temp, "# Allow remote access\n"); cupsFilePrintf(temp, "Port %d\n", ippPort()); @@ -1865,7 +1819,8 @@ _cupsAdminSetServerSettings( #endif /* CUPS_DEFAULT_DOMAINSOCKET */ } - if (!wrote_root_location && (remote_admin >= 0 || share_printers >= 0)) + if (!wrote_root_location && + (remote_admin >= 0 || remote_any > 0 || share_printers >= 0)) { if (remote_admin > 0 && share_printers > 0) cupsFilePuts(temp, @@ -1874,13 +1829,15 @@ _cupsAdminSetServerSettings( cupsFilePuts(temp, "# Allow remote administration...\n"); else if (share_printers > 0) cupsFilePuts(temp, "# Allow shared printing...\n"); + else if (remote_any > 0) + cupsFilePuts(temp, "# Allow remote access...\n"); else cupsFilePuts(temp, "# Restrict access to the server...\n"); cupsFilePuts(temp, "\n" " Order allow,deny\n"); - if (remote_admin > 0 || share_printers > 0) + if (remote_admin > 0 || remote_any > 0 || share_printers > 0) cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); cupsFilePuts(temp, "\n"); @@ -1958,7 +1915,7 @@ _cupsAdminSetServerSettings( " \n" " Order deny,allow\n" " Require user @OWNER " - CUPS_DEFAULT_PRINTADMIN_AUTH "\n" + CUPS_DEFAULT_PRINTOPERATOR_AUTH "\n" " \n"); cupsFilePuts(temp, " \n" @@ -1969,6 +1926,8 @@ _cupsAdminSetServerSettings( for (i = num_settings, setting = settings; i > 0; i --, setting ++) if (setting->name[0] != '_' && + _cups_strcasecmp(setting->name, "Listen") && + _cups_strcasecmp(setting->name, "Port") && !cupsGetOption(setting->name, cupsd_num_settings, cupsd_settings)) { /* @@ -1995,7 +1954,7 @@ _cupsAdminSetServerSettings( status = cupsPutFile(http, "/admin/conf/cupsd.conf", tempfile); - if (status == HTTP_CREATED) + if (status == HTTP_STATUS_CREATED) { /* * Updated OK, add the basic settings... @@ -2023,15 +1982,6 @@ _cupsAdminSetServerSettings( remote_any ? "1" : "0", cupsd_num_settings, &cupsd_settings); - if (remote_printers >= 0) - cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS, - remote_printers ? "1" : "0", - cupsd_num_settings, &cupsd_settings); - else - cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS, - old_remote_printers ? "1" : "0", - cupsd_num_settings, &cupsd_settings); - if (share_printers >= 0) cupsd_num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, share_printers ? "1" : "0", @@ -2074,7 +2024,7 @@ _cupsAdminSetServerSettings( unlink(tempfile); - return (status == HTTP_CREATED); + return (status == HTTP_STATUS_CREATED); } @@ -2099,7 +2049,7 @@ do_samba_command(const char *command, /* I - Command to run */ if (logfile) _cupsLangPrintf(logfile, - _("Running command: %s %s -N -A %s -c \'%s\'\n"), + _("Running command: %s %s -N -A %s -c \'%s\'"), command, address, authfile, subcmd); if ((pid = fork()) == 0) @@ -2108,18 +2058,23 @@ do_samba_command(const char *command, /* I - Command to run */ * Child goes here, redirect stdin/out/err and execute the command... */ - close(0); - open("/dev/null", O_RDONLY); + int fd = open("/dev/null", O_RDONLY); - close(1); + if (fd > 0) + { + dup2(fd, 0); + close(fd); + } if (logfile) - dup(fileno(logfile)); - else - open("/dev/null", O_WRONLY); + dup2(fileno(logfile), 1); + else if ((fd = open("/dev/null", O_WRONLY)) > 1) + { + dup2(fd, 1); + close(fd); + } - close(2); - dup(1); + dup2(1, 2); execlp(command, command, address, "-N", "-A", authfile, "-c", subcmd, (char *)0); @@ -2130,7 +2085,7 @@ do_samba_command(const char *command, /* I - Command to run */ status = -1; if (logfile) - _cupsLangPrintf(logfile, _("Unable to run \"%s\": %s\n"), + _cupsLangPrintf(logfile, _("Unable to run \"%s\": %s"), command, strerror(errno)); } else @@ -2143,9 +2098,9 @@ do_samba_command(const char *command, /* I - Command to run */ } if (logfile) - _cupsLangPuts(logfile, "\n"); + _cupsLangPuts(logfile, ""); - DEBUG_printf(("status=%d\n", status)); + DEBUG_printf(("9do_samba_command: status=%d", status)); if (WIFEXITED(status)) return (WEXITSTATUS(status)); @@ -2182,14 +2137,14 @@ get_cupsd_conf( httpGetHostname(http, host, sizeof(host)); - if (strcasecmp(cg->cupsd_hostname, host)) + if (_cups_strcasecmp(cg->cupsd_hostname, host)) invalidate_cupsd_cache(cg); snprintf(name, namesize, "%s/cupsd.conf", cg->cups_serverroot); *remote = 0; #ifndef WIN32 - if (!strcasecmp(host, "localhost") && !access(name, R_OK)) + if (!_cups_strcasecmp(host, "localhost") && !access(name, R_OK)) { /* * Read the local file rather than using HTTP... @@ -2203,16 +2158,16 @@ get_cupsd_conf( snprintf(message, sizeof(message), _cupsLangString(cupsLangDefault(), _("stat of %s failed: %s")), name, strerror(errno)); - _cupsSetError(IPP_INTERNAL_ERROR, message); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0); *name = '\0'; - return (HTTP_SERVER_ERROR); + return (HTTP_STATUS_SERVER_ERROR); } else if (last_update && info.st_mtime <= last_update) - status = HTTP_NOT_MODIFIED; + status = HTTP_STATUS_NOT_MODIFIED; else - status = HTTP_OK; + status = HTTP_STATUS_OK; } else #endif /* !WIN32 */ @@ -2225,11 +2180,11 @@ get_cupsd_conf( { *name = '\0'; - _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno)); + _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0); invalidate_cupsd_cache(cg); - return (HTTP_SERVER_ERROR); + return (HTTP_STATUS_SERVER_ERROR); } *remote = 1; @@ -2244,7 +2199,7 @@ get_cupsd_conf( close(fd); - if (status != HTTP_OK) + if (status != HTTP_STATUS_OK) { unlink(name); *name = '\0'; @@ -2382,5 +2337,5 @@ write_option(cups_file_t *dstfp, /* I - PPD file */ /* - * End of "$Id: adminutil.c 7576 2008-05-15 21:05:14Z mike $". + * End of "$Id: adminutil.c 10996 2013-05-29 11:51:34Z msweet $". */