4 * Scheduler control program for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 2006-2007 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Get/set server settings.
20 * usage() - Show program usage.
24 * Include necessary headers...
27 #include <cups/cups-private.h>
28 #include <cups/adminutil.h>
35 static void usage(const char *opt
) __attribute__((noreturn
));
39 * 'main()' - Get/set server settings.
42 int /* O - Exit status */
43 main(int argc
, /* I - Number of command-line args */
44 char *argv
[]) /* I - Command-line arguments */
46 int i
, /* Looping var */
47 num_settings
; /* Number of settings */
48 cups_option_t
*settings
; /* Settings */
49 const char *opt
; /* Current option character */
50 http_t
*http
; /* Connection to server */
54 * Process the command-line...
62 for (i
= 1; i
< argc
; i
++)
64 if (argv
[i
][0] == '-')
66 if (argv
[i
][1] == '-')
68 if (!strcmp(argv
[i
], "--debug-logging"))
69 num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
, "1",
70 num_settings
, &settings
);
71 else if (!strcmp(argv
[i
], "--no-debug-logging"))
72 num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
, "0",
73 num_settings
, &settings
);
74 else if (!strcmp(argv
[i
], "--remote-admin"))
75 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
, "1",
76 num_settings
, &settings
);
77 else if (!strcmp(argv
[i
], "--no-remote-admin"))
78 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
, "0",
79 num_settings
, &settings
);
80 else if (!strcmp(argv
[i
], "--remote-any"))
81 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ANY
, "1",
82 num_settings
, &settings
);
83 else if (!strcmp(argv
[i
], "--no-remote-any"))
84 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ANY
, "0",
85 num_settings
, &settings
);
86 else if (!strcmp(argv
[i
], "--share-printers"))
87 num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
, "1",
88 num_settings
, &settings
);
89 else if (!strcmp(argv
[i
], "--no-share-printers"))
90 num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
, "0",
91 num_settings
, &settings
);
92 else if (!strcmp(argv
[i
], "--user-cancel-any"))
93 num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
, "1",
94 num_settings
, &settings
);
95 else if (!strcmp(argv
[i
], "--no-user-cancel-any"))
96 num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
, "0",
97 num_settings
, &settings
);
103 for (opt
= argv
[i
] + 1; *opt
; opt
++)
107 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
115 cupsSetUser(argv
[i
]);
123 cupsSetServer(argv
[i
]);
132 else if (strchr(argv
[i
], '='))
133 num_settings
= cupsParseOptions(argv
[i
], num_settings
, &settings
);
138 if (cupsGetOption("Listen", num_settings
, settings
) ||
139 cupsGetOption("Port", num_settings
, settings
))
141 _cupsLangPuts(stderr
, _("cupsctl: Cannot set Listen or Port directly."));
146 * Connect to the server using the defaults...
149 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
150 cupsEncryption())) == NULL
)
152 _cupsLangPrintf(stderr
, _("cupsctl: Unable to connect to server: %s"),
158 * Set the current configuration if we have anything on the command-line...
161 if (num_settings
> 0)
163 if (!cupsAdminSetServerSettings(http
, num_settings
, settings
))
165 _cupsLangPrintf(stderr
, "cupsctl: %s", cupsLastErrorString());
169 else if (!cupsAdminGetServerSettings(http
, &num_settings
, &settings
))
171 _cupsLangPrintf(stderr
, "cupsctl: %s", cupsLastErrorString());
176 for (i
= 0; i
< num_settings
; i
++)
177 _cupsLangPrintf(stdout
, "%s=%s", settings
[i
].name
, settings
[i
].value
);
180 cupsFreeOptions(num_settings
, settings
);
186 * 'usage()' - Show program usage.
190 usage(const char *opt
) /* I - Option character/string */
195 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"%s\""), opt
);
197 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"-%c\""), *opt
);
200 _cupsLangPuts(stdout
, _("Usage: cupsctl [options] [param=value ... "
202 _cupsLangPuts(stdout
, "");
203 _cupsLangPuts(stdout
, _("Options:"));
204 _cupsLangPuts(stdout
, "");
205 _cupsLangPuts(stdout
, _(" -E Enable encryption."));
206 _cupsLangPuts(stdout
, _(" -U username Specify username."));
207 _cupsLangPuts(stdout
, _(" -h server[:port] Specify server "
209 _cupsLangPuts(stdout
, "");
210 _cupsLangPuts(stdout
, _(" --[no-]debug-logging Turn debug logging "
212 _cupsLangPuts(stdout
, _(" --[no-]remote-admin Turn remote "
213 "administration on/off."));
214 _cupsLangPuts(stdout
, _(" --[no-]remote-any Allow/prevent access "
215 "from the Internet."));
216 _cupsLangPuts(stdout
, _(" --[no-]share-printers Turn printer sharing "
218 _cupsLangPuts(stdout
, _(" --[no-]user-cancel-any Allow/prevent users to "