diff --git a/cups/adminutil.c b/cups/adminutil.c index d66918cb75..161d118529 100644 --- a/cups/adminutil.c +++ b/cups/adminutil.c @@ -441,10 +441,7 @@ cupsAdminSetServerSettings( remote_any, /* Remote access from anywhere? */ user_cancel_any, /* Cancel-job policy set? */ debug_logging; /* LogLevel debug set? */ - int wrote_port_listen, /* Wrote the port/listen lines? */ - wrote_browsing, /* Wrote the browsing lines? */ - wrote_policy, /* Wrote the policy? */ - wrote_loglevel, /* Wrote the LogLevel line? */ + int wrote_policy, /* Wrote the policy? */ wrote_admin_location, /* Wrote the /admin location? */ wrote_conf_location, /* Wrote the /admin/conf location? */ wrote_log_location, /* Wrote the /admin/log location? */ @@ -550,100 +547,50 @@ cupsAdminSetServerSettings( * Get basic settings... */ + debug_logging = old_debug_logging; if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, num_settings, settings)) != NULL) { debug_logging = atoi(val); - - if (debug_logging == old_debug_logging) - { - /* - * No change to this setting... - */ - - debug_logging = -1; - } } - else - debug_logging = -1; DEBUG_printf(("1cupsAdminSetServerSettings: debug_logging=%d", debug_logging)); + remote_any = old_remote_any; if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, num_settings, settings)) != NULL) { remote_any = atoi(val); - - if (remote_any == old_remote_any) - { - /* - * No change to this setting... - */ - - remote_any = -1; - } } - else - remote_any = -1; DEBUG_printf(("1cupsAdminSetServerSettings: remote_any=%d", remote_any)); + remote_admin = old_remote_admin; if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, num_settings, settings)) != NULL) { remote_admin = atoi(val); - - if (remote_admin == old_remote_admin) - { - /* - * No change to this setting... - */ - - remote_admin = -1; - } } - else - remote_admin = -1; DEBUG_printf(("1cupsAdminSetServerSettings: remote_admin=%d", remote_admin)); + share_printers = old_share_printers; if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, num_settings, settings)) != NULL) { share_printers = atoi(val); - - if (share_printers == old_share_printers) - { - /* - * No change to this setting... - */ - - share_printers = -1; - } } - else - share_printers = -1; DEBUG_printf(("1cupsAdminSetServerSettings: share_printers=%d", share_printers)); + user_cancel_any = old_user_cancel_any; if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, num_settings, settings)) != NULL) { user_cancel_any = atoi(val); - - if (user_cancel_any == old_user_cancel_any) - { - /* - * No change to this setting... - */ - - user_cancel_any = -1; - } } - else - user_cancel_any = -1; DEBUG_printf(("1cupsAdminSetServerSettings: user_cancel_any=%d", user_cancel_any)); @@ -678,12 +625,9 @@ cupsAdminSetServerSettings( in_root_location = 0; linenum = 0; wrote_admin_location = 0; - wrote_browsing = 0; wrote_conf_location = 0; wrote_log_location = 0; - wrote_loglevel = 0; wrote_policy = 0; - wrote_port_listen = 0; wrote_root_location = 0; indent = 0; @@ -698,34 +642,70 @@ cupsAdminSetServerSettings( if (server_port <= 0) server_port = IPP_PORT; - while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum)) + /* + * Write basic settings anyway + */ + if (share_printers > 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; + const char *localp = cupsGetOption("BrowseLocalProtocols", + num_settings, settings); - if (remote_admin > 0 || remote_any > 0 || share_printers > 0) - { - cupsFilePuts(temp, "# Allow remote access\n"); - cupsFilePrintf(temp, "Port %d\n", server_port); - } - else - { - cupsFilePuts(temp, "# Only listen for connections from the local " - "machine.\n"); - cupsFilePrintf(temp, "Listen localhost:%d\n", server_port); - } + if (!localp || !localp[0]) + localp = cupsGetOption("BrowseLocalProtocols", cupsd_num_settings, + cupsd_settings); + + cupsFilePuts(temp, "# Share local printers on the local network.\n"); + cupsFilePuts(temp, "Browsing On\n"); + + if (!localp) + localp = CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS; + + 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, "Browsing Off\n"); + } + + if (debug_logging) + { + cupsFilePuts(temp, "# Show troubleshooting information in error_log.\n"); + cupsFilePuts(temp, "LogLevel debug\n"); + } + else + { + cupsFilePuts(temp, "# Show general information in error_log.\n"); + cupsFilePuts(temp, "LogLevel " CUPS_DEFAULT_LOG_LEVEL "\n"); + } + + /* Allow remote access only make sense when remote_admin or share_printers turns on */ + if ((remote_admin > 0 || share_printers > 0) && remote_any) + { + cupsFilePuts(temp, "# Allow remote access\n"); + cupsFilePrintf(temp, "Port %d\n", ippPort()); + } + else + { + cupsFilePuts(temp, + "# Only listen for connections from the local machine.\n"); + cupsFilePrintf(temp, "Listen localhost:%d\n", ippPort()); + } #ifdef CUPS_DEFAULT_DOMAINSOCKET - if ((!value || strcmp(CUPS_DEFAULT_DOMAINSOCKET, value)) && - !access(CUPS_DEFAULT_DOMAINSOCKET, 0)) - cupsFilePuts(temp, "Listen " CUPS_DEFAULT_DOMAINSOCKET "\n"); + if (!access(CUPS_DEFAULT_DOMAINSOCKET, 0)) + cupsFilePuts(temp, "Listen " CUPS_DEFAULT_DOMAINSOCKET "\n"); #endif /* CUPS_DEFAULT_DOMAINSOCKET */ - } - else if (value && value[0] == '/' + + while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum)) + { + if ((!_cups_strcasecmp(line, "Port") || !_cups_strcasecmp(line, "Listen"))) + { + /* Keep non-default Listen option untouched */ + if (value && value[0] == '/' #ifdef CUPS_DEFAULT_DOMAINSOCKET && strcmp(CUPS_DEFAULT_DOMAINSOCKET, value) #endif /* CUPS_DEFAULT_DOMAINSOCKET */ @@ -733,57 +713,10 @@ cupsAdminSetServerSettings( cupsFilePrintf(temp, "Listen %s\n", value); } else if ((!_cups_strcasecmp(line, "Browsing") || - !_cups_strcasecmp(line, "BrowseLocalProtocols")) && - share_printers >= 0) - { - if (!wrote_browsing) - { - wrote_browsing = 1; - - if (share_printers) - { - const char *localp = cupsGetOption("BrowseLocalProtocols", - num_settings, settings); - - if (!localp || !localp[0]) - localp = cupsGetOption("BrowseLocalProtocols", cupsd_num_settings, - cupsd_settings); - - cupsFilePuts(temp, "# Share local printers on the local network.\n"); - cupsFilePuts(temp, "Browsing On\n"); - - if (!localp) - localp = CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS; - - cupsFilePrintf(temp, "BrowseLocalProtocols %s\n", localp); - - cupsd_num_settings = cupsAddOption("BrowseLocalProtocols", localp, - cupsd_num_settings, - &cupsd_settings); - } - else - { - cupsFilePuts(temp, "# Disable printer sharing.\n"); - cupsFilePuts(temp, "Browsing Off\n"); - } - } - } - else if (!_cups_strcasecmp(line, "LogLevel") && debug_logging >= 0) - { - wrote_loglevel = 1; - - if (debug_logging) - { - cupsFilePuts(temp, - "# Show troubleshooting information in error_log.\n"); - cupsFilePuts(temp, "LogLevel debug\n"); - } - else - { - cupsFilePuts(temp, "# Show general information in error_log.\n"); - cupsFilePuts(temp, "LogLevel " CUPS_DEFAULT_LOG_LEVEL "\n"); - } - } + !_cups_strcasecmp(line, "BrowseLocalProtocols"))) + continue; + else if (!_cups_strcasecmp(line, "LogLevel")) + continue; else if (!_cups_strcasecmp(line, "= 0) + if (in_admin_location) { wrote_admin_location = 1; if (remote_admin) cupsFilePuts(temp, " # Allow remote administration...\n"); - else if (remote_admin == 0) + else cupsFilePuts(temp, " # Restrict access to the admin pages...\n"); cupsFilePuts(temp, " Order allow,deny\n"); if (remote_admin) - { - if (remote_any >= 0) - cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); - else - cupsFilePrintf(temp, " Allow %s\n", old_remote_any > 0 ? "all" : "@LOCAL"); - } + cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); } - else if (in_conf_location && remote_admin >= 0) + else if (in_conf_location) { wrote_conf_location = 1; @@ -866,14 +794,9 @@ cupsAdminSetServerSettings( cupsFilePuts(temp, " Order allow,deny\n"); if (remote_admin) - { - if (remote_any >= 0) - cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); - else - cupsFilePrintf(temp, " Allow %s\n", old_remote_any > 0 ? "all" : "@LOCAL"); - } + cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); } - else if (in_log_location && remote_admin >= 0) + else if (in_log_location) { wrote_log_location = 1; @@ -887,15 +810,9 @@ cupsAdminSetServerSettings( cupsFilePuts(temp, " Order allow,deny\n"); if (remote_admin) - { - if (remote_any >= 0) - cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); - else - cupsFilePrintf(temp, " Allow %s\n", old_remote_any > 0 ? "all" : "@LOCAL"); - } + cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); } - else if (in_root_location && - (remote_admin >= 0 || remote_any >= 0 || share_printers >= 0)) + else if (in_root_location) { wrote_root_location = 1; @@ -906,20 +823,13 @@ 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 || remote_any > 0 || share_printers > 0) - { - if (remote_any >= 0) - cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); - else - cupsFilePrintf(temp, " Allow %s\n", old_remote_any > 0 ? "all" : "@LOCAL"); - } + if (remote_admin > 0 || share_printers > 0) + cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); } in_admin_location = 0; @@ -940,7 +850,7 @@ cupsAdminSetServerSettings( char *valptr; /* Pointer into value */ - if (!_cups_strcasecmp(value, "cancel-job") && user_cancel_any >= 0) + if (!_cups_strcasecmp(value, "cancel-job")) { /* * Don't write anything for this limit section... @@ -959,7 +869,7 @@ cupsAdminSetServerSettings( if (*valptr) *valptr++ = '\0'; - if (!_cups_strcasecmp(value, "cancel-job") && user_cancel_any >= 0) + if (!_cups_strcasecmp(value, "cancel-job")) { /* * Write everything except for this definition... @@ -1001,9 +911,9 @@ cupsAdminSetServerSettings( in_cancel_job = 0; } - else if ((((in_admin_location || in_conf_location || in_root_location || in_log_location) && - (remote_admin >= 0 || remote_any >= 0)) || - (in_root_location && share_printers >= 0)) && + /* Write Allow, Deny, Order in location later */ + else if ((in_admin_location || in_conf_location || in_root_location || in_log_location || + in_root_location) && (!_cups_strcasecmp(line, "Allow") || !_cups_strcasecmp(line, "Deny") || !_cups_strcasecmp(line, "Order"))) continue; @@ -1065,57 +975,7 @@ cupsAdminSetServerSettings( * Write any missing info... */ - if (!wrote_browsing && share_printers >= 0) - { - if (share_printers > 0) - { - cupsFilePuts(temp, "# Share local printers on the local network.\n"); - cupsFilePuts(temp, "Browsing On\n"); - } - else - { - cupsFilePuts(temp, "# Disable printer sharing and shared printers.\n"); - cupsFilePuts(temp, "Browsing Off\n"); - } - } - - if (!wrote_loglevel && debug_logging >= 0) - { - if (debug_logging) - { - cupsFilePuts(temp, "# Show troubleshooting information in error_log.\n"); - cupsFilePuts(temp, "LogLevel debug\n"); - } - else - { - cupsFilePuts(temp, "# Show general information in error_log.\n"); - cupsFilePuts(temp, "LogLevel " CUPS_DEFAULT_LOG_LEVEL "\n"); - } - } - - if (!wrote_port_listen && - (remote_admin >= 0 || remote_any >= 0 || share_printers >= 0)) - { - if (remote_admin > 0 || remote_any > 0 || share_printers > 0) - { - cupsFilePuts(temp, "# Allow remote access\n"); - cupsFilePrintf(temp, "Port %d\n", ippPort()); - } - else - { - cupsFilePuts(temp, - "# Only listen for connections from the local machine.\n"); - cupsFilePrintf(temp, "Listen localhost:%d\n", ippPort()); - } - -#ifdef CUPS_DEFAULT_DOMAINSOCKET - if (!access(CUPS_DEFAULT_DOMAINSOCKET, 0)) - cupsFilePuts(temp, "Listen " CUPS_DEFAULT_DOMAINSOCKET "\n"); -#endif /* CUPS_DEFAULT_DOMAINSOCKET */ - } - - if (!wrote_root_location && - (remote_admin >= 0 || remote_any >= 0 || share_printers >= 0)) + if (!wrote_root_location) { if (remote_admin > 0 && share_printers > 0) cupsFilePuts(temp, @@ -1124,21 +984,19 @@ 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 || remote_any > 0 || share_printers > 0) + if (remote_admin > 0 || share_printers > 0) cupsFilePrintf(temp, " Allow %s\n", remote_any > 0 ? "all" : "@LOCAL"); cupsFilePuts(temp, "\n"); } - if (!wrote_admin_location && remote_admin >= 0) + if (!wrote_admin_location) { if (remote_admin) cupsFilePuts(temp, "# Allow remote administration...\n"); @@ -1154,7 +1012,7 @@ cupsAdminSetServerSettings( cupsFilePuts(temp, "\n"); } - if (!wrote_conf_location && remote_admin >= 0) + if (!wrote_conf_location) { if (remote_admin) cupsFilePuts(temp, @@ -1173,7 +1031,7 @@ cupsAdminSetServerSettings( cupsFilePuts(temp, "\n"); } - if (!wrote_log_location && remote_admin >= 0) + if (!wrote_log_location) { if (remote_admin) cupsFilePuts(temp, @@ -1192,7 +1050,7 @@ cupsAdminSetServerSettings( cupsFilePuts(temp, "\n"); } - if (!wrote_policy && user_cancel_any >= 0) + if (!wrote_policy) { cupsFilePuts(temp, "\n" " # Job-related operations must be done by the owner "