## Overview

The administrative APIs provide convenience functions to perform certain administrative functions with the CUPS scheduler.

> Note:

> Administrative functions normally require administrative privileges to execute and must not be used in ordinary user applications!

### Scheduler Settings

The `cupsAdminGetServerSettings` and `cupsAdminSetServerSettings` functions allow you to get and set simple directives and their values, respectively, in the cupsd.conf file for the CUPS scheduler. Settings are stored in CUPS option arrays which provide a simple list of string name/value pairs. While any simple cupsd.conf directive name can be specified, the following convenience names are also defined to control common complex directives:

- `CUPS_SERVER_DEBUG_LOGGING`
: For `cupsAdminGetServerSettings`, a value of "1" means that the `LogLevel` directive is set to `debug` or `debug2` while a value of "0" means it is set to any other value. For `cupsAdminSetServerSettings` a value of "1" sets the `LogLeveL` to `debug` while a value of "0" sets it to `warn`.
- `CUPS_SERVER_REMOTE_ADMIN`
: A value of "1" specifies that administrative requests are accepted from remote addresses while "0" specifies that requests are only accepted from local addresses (loopback interface and domain sockets).
- `CUPS_SERVER_REMOTE_ANY`
: A value of "1" specifies that requests are accepts from any address while "0" specifies that requests are only accepted from the local subnet (when sharing is enabled) or local addresses (loopback interface and domain sockets).
- `CUPS_SERVER_SHARE_PRINTERS`
: A value of "1" specifies that printer sharing is enabled for selected printers and remote requests are accepted while a value of "0" specifies that printer sharing is disables and remote requests are not accepted.
- `CUPS_SERVER_USER_CANCEL_ANY`
: A value of "1" specifies that the default security policy allows any user to cancel any print job, regardless of the owner. A value of "0" specifies that only administrative users can cancel other user's jobs.

> Note:

> Changing settings will restart the CUPS scheduler.

> When printer sharing or the web interface are enabled, the scheduler's launch-on-demand functionality is effectively disabled. This can affect power usage, system performance, and the security profile of a system.

The recommended way to make changes to the cupsd.conf is to first call `cupsAdminGetServerSettings`, make any changes to the returned option array, and then call `cupsAdminSetServerSettings` to save those settings. For example, to enable the web interface:

    #include <cups/cups.h>
    #include <cups/adminutil.h>

    void
    enable_web_interface(void)
    {
      int num_settings = 0;           /* Number of settings */
      cups_option_t *settings = NULL; /* Settings */

      if (!cupsAdminGetServerSettings(CUPS_HTTP_DEFAULT, &num_settings, &settings))
      {
        fprintf(stderr, "ERROR: Unable to get server settings: %s\n", cupsLastErrorString());
        return;
      }

      num_settings = cupsAddOption("WebInterface", "Yes", num_settings, &settings);

      if (!cupsAdminSetServerSettings(CUPS_HTTP_DEFAULT, num_settings, settings))
      {
        fprintf(stderr, "ERROR: Unable to set server settings: %s\n", cupsLastErrorString());
      }

      cupsFreeOptions(num_settings, settings);
    }

### Devices

Printers can be discovered through the CUPS scheduler using the `cupsGetDevices` API. Typically this API is used to locate printers to add the the system. Each device that is found will cause a supplied callback function to be executed. For example, to list the available printer devices that can be found within 30 seconds:

    #include <cups/cups.h>
    #include <cups/adminutil.h>

    void
    get_devices_cb(
        const char *device_class,           /* I - Class */
        const char *device_id,              /* I - 1284 device ID */
        const char *device_info,            /* I - Description */
        const char *device_make_and_model,  /* I - Make and model */
        const char *device_uri,             /* I - Device URI */
        const char *device_location,        /* I - Location */
        void       *user_data)              /* I - User data */
    {
      puts(device_uri);
    }

    void
    show_devices(void)
    {
      cupsGetDevices(CUPS_HTTP_DEFAULT, 30, NULL, NULL, get_devices_cb, NULL);
    }