2 * Scheduler control program for CUPS.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 2006-2007 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
15 #include <cups/cups-private.h>
16 #include <cups/adminutil.h>
23 static void usage(const char *opt
) _CUPS_NORETURN
;
27 * 'main()' - Get/set server settings.
30 int /* O - Exit status */
31 main(int argc
, /* I - Number of command-line args */
32 char *argv
[]) /* I - Command-line arguments */
34 int i
, /* Looping var */
35 num_settings
; /* Number of settings */
36 cups_option_t
*settings
; /* Settings */
37 const char *opt
; /* Current option character */
38 http_t
*http
; /* Connection to server */
42 * Process the command-line...
50 for (i
= 1; i
< argc
; i
++)
52 if (!strcmp(argv
[i
], "--help"))
54 else if (argv
[i
][0] == '-')
56 if (argv
[i
][1] == '-')
58 if (!strcmp(argv
[i
], "--debug-logging"))
59 num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
, "1",
60 num_settings
, &settings
);
61 else if (!strcmp(argv
[i
], "--no-debug-logging"))
62 num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
, "0",
63 num_settings
, &settings
);
64 else if (!strcmp(argv
[i
], "--remote-admin"))
65 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
, "1",
66 num_settings
, &settings
);
67 else if (!strcmp(argv
[i
], "--no-remote-admin"))
68 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
, "0",
69 num_settings
, &settings
);
70 else if (!strcmp(argv
[i
], "--remote-any"))
71 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ANY
, "1",
72 num_settings
, &settings
);
73 else if (!strcmp(argv
[i
], "--no-remote-any"))
74 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ANY
, "0",
75 num_settings
, &settings
);
76 else if (!strcmp(argv
[i
], "--share-printers"))
77 num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
, "1",
78 num_settings
, &settings
);
79 else if (!strcmp(argv
[i
], "--no-share-printers"))
80 num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
, "0",
81 num_settings
, &settings
);
82 else if (!strcmp(argv
[i
], "--user-cancel-any"))
83 num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
, "1",
84 num_settings
, &settings
);
85 else if (!strcmp(argv
[i
], "--no-user-cancel-any"))
86 num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
, "0",
87 num_settings
, &settings
);
93 for (opt
= argv
[i
] + 1; *opt
; opt
++)
97 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
105 cupsSetUser(argv
[i
]);
113 cupsSetServer(argv
[i
]);
122 else if (strchr(argv
[i
], '='))
123 num_settings
= cupsParseOptions(argv
[i
], num_settings
, &settings
);
128 if (cupsGetOption("Listen", num_settings
, settings
) ||
129 cupsGetOption("Port", num_settings
, settings
))
131 _cupsLangPuts(stderr
, _("cupsctl: Cannot set Listen or Port directly."));
136 * Connect to the server using the defaults...
139 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
140 cupsEncryption())) == NULL
)
142 _cupsLangPrintf(stderr
, _("cupsctl: Unable to connect to server: %s"),
148 * Set the current configuration if we have anything on the command-line...
151 if (num_settings
> 0)
153 if (!cupsAdminSetServerSettings(http
, num_settings
, settings
))
155 _cupsLangPrintf(stderr
, "cupsctl: %s", cupsLastErrorString());
159 else if (!cupsAdminGetServerSettings(http
, &num_settings
, &settings
))
161 _cupsLangPrintf(stderr
, "cupsctl: %s", cupsLastErrorString());
166 for (i
= 0; i
< num_settings
; i
++)
167 _cupsLangPrintf(stdout
, "%s=%s", settings
[i
].name
, settings
[i
].value
);
170 cupsFreeOptions(num_settings
, settings
);
176 * 'usage()' - Show program usage.
180 usage(const char *opt
) /* I - Option character/string */
185 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"%s\""), opt
);
187 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"-%c\""), *opt
);
190 _cupsLangPuts(stdout
, _("Usage: cupsctl [options] [param=value ... paramN=valueN]"));
191 _cupsLangPuts(stdout
, _("Options:"));
192 _cupsLangPuts(stdout
, _("-E Encrypt the connection to the server"));
193 _cupsLangPuts(stdout
, _("-h server[:port] Connect to the named server and port"));
194 _cupsLangPuts(stdout
, _("-U username Specify username to use for authentication"));
195 _cupsLangPuts(stdout
, _("--[no-]debug-logging Turn debug logging on/off"));
196 _cupsLangPuts(stdout
, _("--[no-]remote-admin Turn remote administration on/off"));
197 _cupsLangPuts(stdout
, _("--[no-]remote-any Allow/prevent access from the Internet"));
198 _cupsLangPuts(stdout
, _("--[no-]share-printers Turn printer sharing on/off"));
199 _cupsLangPuts(stdout
, _("--[no-]user-cancel-any Allow/prevent users to cancel any job"));