2 * Scheduler control program for CUPS.
4 * Copyright 2007-2012 by Apple Inc.
5 * Copyright 2006-2007 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include <cups/cups-private.h>
15 #include <cups/adminutil.h>
22 static void usage(const char *opt
) __attribute__((noreturn
));
26 * 'main()' - Get/set server settings.
29 int /* O - Exit status */
30 main(int argc
, /* I - Number of command-line args */
31 char *argv
[]) /* I - Command-line arguments */
33 int i
, /* Looping var */
34 num_settings
; /* Number of settings */
35 cups_option_t
*settings
; /* Settings */
36 const char *opt
; /* Current option character */
37 http_t
*http
; /* Connection to server */
41 * Process the command-line...
49 for (i
= 1; i
< argc
; i
++)
51 if (argv
[i
][0] == '-')
53 if (argv
[i
][1] == '-')
55 if (!strcmp(argv
[i
], "--debug-logging"))
56 num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
, "1",
57 num_settings
, &settings
);
58 else if (!strcmp(argv
[i
], "--no-debug-logging"))
59 num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
, "0",
60 num_settings
, &settings
);
61 else if (!strcmp(argv
[i
], "--remote-admin"))
62 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
, "1",
63 num_settings
, &settings
);
64 else if (!strcmp(argv
[i
], "--no-remote-admin"))
65 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
, "0",
66 num_settings
, &settings
);
67 else if (!strcmp(argv
[i
], "--remote-any"))
68 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ANY
, "1",
69 num_settings
, &settings
);
70 else if (!strcmp(argv
[i
], "--no-remote-any"))
71 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ANY
, "0",
72 num_settings
, &settings
);
73 else if (!strcmp(argv
[i
], "--share-printers"))
74 num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
, "1",
75 num_settings
, &settings
);
76 else if (!strcmp(argv
[i
], "--no-share-printers"))
77 num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
, "0",
78 num_settings
, &settings
);
79 else if (!strcmp(argv
[i
], "--user-cancel-any"))
80 num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
, "1",
81 num_settings
, &settings
);
82 else if (!strcmp(argv
[i
], "--no-user-cancel-any"))
83 num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
, "0",
84 num_settings
, &settings
);
90 for (opt
= argv
[i
] + 1; *opt
; opt
++)
94 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
102 cupsSetUser(argv
[i
]);
110 cupsSetServer(argv
[i
]);
119 else if (strchr(argv
[i
], '='))
120 num_settings
= cupsParseOptions(argv
[i
], num_settings
, &settings
);
125 if (cupsGetOption("Listen", num_settings
, settings
) ||
126 cupsGetOption("Port", num_settings
, settings
))
128 _cupsLangPuts(stderr
, _("cupsctl: Cannot set Listen or Port directly."));
133 * Connect to the server using the defaults...
136 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
137 cupsEncryption())) == NULL
)
139 _cupsLangPrintf(stderr
, _("cupsctl: Unable to connect to server: %s"),
145 * Set the current configuration if we have anything on the command-line...
148 if (num_settings
> 0)
150 if (!cupsAdminSetServerSettings(http
, num_settings
, settings
))
152 _cupsLangPrintf(stderr
, "cupsctl: %s", cupsLastErrorString());
156 else if (!cupsAdminGetServerSettings(http
, &num_settings
, &settings
))
158 _cupsLangPrintf(stderr
, "cupsctl: %s", cupsLastErrorString());
163 for (i
= 0; i
< num_settings
; i
++)
164 _cupsLangPrintf(stdout
, "%s=%s", settings
[i
].name
, settings
[i
].value
);
167 cupsFreeOptions(num_settings
, settings
);
173 * 'usage()' - Show program usage.
177 usage(const char *opt
) /* I - Option character/string */
182 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"%s\""), opt
);
184 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"-%c\""), *opt
);
187 _cupsLangPuts(stdout
, _("Usage: cupsctl [options] [param=value ... "
189 _cupsLangPuts(stdout
, "");
190 _cupsLangPuts(stdout
, _("Options:"));
191 _cupsLangPuts(stdout
, "");
192 _cupsLangPuts(stdout
, _(" -E Encrypt the connection."));
193 _cupsLangPuts(stdout
, _(" -U username Specify username."));
194 _cupsLangPuts(stdout
, _(" -h server[:port] Specify server "
196 _cupsLangPuts(stdout
, "");
197 _cupsLangPuts(stdout
, _(" --[no-]debug-logging Turn debug logging "
199 _cupsLangPuts(stdout
, _(" --[no-]remote-admin Turn remote "
200 "administration on/off."));
201 _cupsLangPuts(stdout
, _(" --[no-]remote-any Allow/prevent access "
202 "from the Internet."));
203 _cupsLangPuts(stdout
, _(" --[no-]share-printers Turn printer sharing "
205 _cupsLangPuts(stdout
, _(" --[no-]user-cancel-any Allow/prevent users to "