2 * Scheduler control program for CUPS.
4 * Copyright 2007-2012 by Apple Inc.
5 * Copyright 2006-2007 by Easy Software Products.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers...
20 #include <cups/cups-private.h>
21 #include <cups/adminutil.h>
28 static void usage(const char *opt
) __attribute__((noreturn
));
32 * 'main()' - Get/set server settings.
35 int /* O - Exit status */
36 main(int argc
, /* I - Number of command-line args */
37 char *argv
[]) /* I - Command-line arguments */
39 int i
, /* Looping var */
40 num_settings
; /* Number of settings */
41 cups_option_t
*settings
; /* Settings */
42 const char *opt
; /* Current option character */
43 http_t
*http
; /* Connection to server */
47 * Process the command-line...
55 for (i
= 1; i
< argc
; i
++)
57 if (argv
[i
][0] == '-')
59 if (argv
[i
][1] == '-')
61 if (!strcmp(argv
[i
], "--debug-logging"))
62 num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
, "1",
63 num_settings
, &settings
);
64 else if (!strcmp(argv
[i
], "--no-debug-logging"))
65 num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
, "0",
66 num_settings
, &settings
);
67 else if (!strcmp(argv
[i
], "--remote-admin"))
68 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
, "1",
69 num_settings
, &settings
);
70 else if (!strcmp(argv
[i
], "--no-remote-admin"))
71 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
, "0",
72 num_settings
, &settings
);
73 else if (!strcmp(argv
[i
], "--remote-any"))
74 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ANY
, "1",
75 num_settings
, &settings
);
76 else if (!strcmp(argv
[i
], "--no-remote-any"))
77 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ANY
, "0",
78 num_settings
, &settings
);
79 else if (!strcmp(argv
[i
], "--share-printers"))
80 num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
, "1",
81 num_settings
, &settings
);
82 else if (!strcmp(argv
[i
], "--no-share-printers"))
83 num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
, "0",
84 num_settings
, &settings
);
85 else if (!strcmp(argv
[i
], "--user-cancel-any"))
86 num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
, "1",
87 num_settings
, &settings
);
88 else if (!strcmp(argv
[i
], "--no-user-cancel-any"))
89 num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
, "0",
90 num_settings
, &settings
);
96 for (opt
= argv
[i
] + 1; *opt
; opt
++)
100 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
108 cupsSetUser(argv
[i
]);
116 cupsSetServer(argv
[i
]);
125 else if (strchr(argv
[i
], '='))
126 num_settings
= cupsParseOptions(argv
[i
], num_settings
, &settings
);
131 if (cupsGetOption("Listen", num_settings
, settings
) ||
132 cupsGetOption("Port", num_settings
, settings
))
134 _cupsLangPuts(stderr
, _("cupsctl: Cannot set Listen or Port directly."));
139 * Connect to the server using the defaults...
142 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
143 cupsEncryption())) == NULL
)
145 _cupsLangPrintf(stderr
, _("cupsctl: Unable to connect to server: %s"),
151 * Set the current configuration if we have anything on the command-line...
154 if (num_settings
> 0)
156 if (!cupsAdminSetServerSettings(http
, num_settings
, settings
))
158 _cupsLangPrintf(stderr
, "cupsctl: %s", cupsLastErrorString());
162 else if (!cupsAdminGetServerSettings(http
, &num_settings
, &settings
))
164 _cupsLangPrintf(stderr
, "cupsctl: %s", cupsLastErrorString());
169 for (i
= 0; i
< num_settings
; i
++)
170 _cupsLangPrintf(stdout
, "%s=%s", settings
[i
].name
, settings
[i
].value
);
173 cupsFreeOptions(num_settings
, settings
);
179 * 'usage()' - Show program usage.
183 usage(const char *opt
) /* I - Option character/string */
188 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"%s\""), opt
);
190 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"-%c\""), *opt
);
193 _cupsLangPuts(stdout
, _("Usage: cupsctl [options] [param=value ... "
195 _cupsLangPuts(stdout
, "");
196 _cupsLangPuts(stdout
, _("Options:"));
197 _cupsLangPuts(stdout
, "");
198 _cupsLangPuts(stdout
, _(" -E Encrypt the connection."));
199 _cupsLangPuts(stdout
, _(" -U username Specify username."));
200 _cupsLangPuts(stdout
, _(" -h server[:port] Specify server "
202 _cupsLangPuts(stdout
, "");
203 _cupsLangPuts(stdout
, _(" --[no-]debug-logging Turn debug logging "
205 _cupsLangPuts(stdout
, _(" --[no-]remote-admin Turn remote "
206 "administration on/off."));
207 _cupsLangPuts(stdout
, _(" --[no-]remote-any Allow/prevent access "
208 "from the Internet."));
209 _cupsLangPuts(stdout
, _(" --[no-]share-printers Turn printer sharing "
211 _cupsLangPuts(stdout
, _(" --[no-]user-cancel-any Allow/prevent users to "