1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/*
* "$Id: cupsctl.c 10431 2012-04-23 19:19:19Z mike $"
*
* Scheduler control program for CUPS.
*
* Copyright 2007-2012 by Apple Inc.
* Copyright 2006-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* property of Apple Inc. and are protected by Federal copyright
* law. Distribution and use rights are outlined in the file "LICENSE.txt"
* which should have been included with this file. If this file is
* file is missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*
* Contents:
*
* main() - Get/set server settings.
* usage() - Show program usage.
*/
/*
* Include necessary headers...
*/
#include <cups/cups-private.h>
#include <cups/adminutil.h>
/*
* Local functions...
*/
static void usage(const char *opt) __attribute__((noreturn));
/*
* 'main()' - Get/set server settings.
*/
int /* O - Exit status */
main(int argc, /* I - Number of command-line args */
char *argv[]) /* I - Command-line arguments */
{
int i, /* Looping var */
num_settings; /* Number of settings */
cups_option_t *settings; /* Settings */
const char *opt; /* Current option character */
http_t *http; /* Connection to server */
/*
* Process the command-line...
*/
_cupsSetLocale(argv);
num_settings = 0;
settings = NULL;
for (i = 1; i < argc; i ++)
{
if (argv[i][0] == '-')
{
if (argv[i][1] == '-')
{
if (!strcmp(argv[i], "--debug-logging"))
num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING, "1",
num_settings, &settings);
else if (!strcmp(argv[i], "--no-debug-logging"))
num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING, "0",
num_settings, &settings);
else if (!strcmp(argv[i], "--remote-admin"))
num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN, "1",
num_settings, &settings);
else if (!strcmp(argv[i], "--no-remote-admin"))
num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN, "0",
num_settings, &settings);
else if (!strcmp(argv[i], "--remote-any"))
num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY, "1",
num_settings, &settings);
else if (!strcmp(argv[i], "--no-remote-any"))
num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY, "0",
num_settings, &settings);
else if (!strcmp(argv[i], "--share-printers"))
num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "1",
num_settings, &settings);
else if (!strcmp(argv[i], "--no-share-printers"))
num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "0",
num_settings, &settings);
else if (!strcmp(argv[i], "--user-cancel-any"))
num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "1",
num_settings, &settings);
else if (!strcmp(argv[i], "--no-user-cancel-any"))
num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "0",
num_settings, &settings);
else
usage(argv[i]);
}
else
{
for (opt = argv[i] + 1; *opt; opt ++)
switch (*opt)
{
case 'E' :
cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
break;
case 'U' :
i ++;
if (i >= argc)
usage(NULL);
cupsSetUser(argv[i]);
break;
case 'h' :
i ++;
if (i >= argc)
usage(NULL);
cupsSetServer(argv[i]);
break;
default :
usage(opt);
break;
}
}
}
else if (strchr(argv[i], '='))
num_settings = cupsParseOptions(argv[i], num_settings, &settings);
else
usage(argv[i]);
}
if (cupsGetOption("Listen", num_settings, settings) ||
cupsGetOption("Port", num_settings, settings))
{
_cupsLangPuts(stderr, _("cupsctl: Cannot set Listen or Port directly."));
return (1);
}
/*
* Connect to the server using the defaults...
*/
if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
cupsEncryption())) == NULL)
{
_cupsLangPrintf(stderr, _("cupsctl: Unable to connect to server: %s"),
strerror(errno));
return (1);
}
/*
* Set the current configuration if we have anything on the command-line...
*/
if (num_settings > 0)
{
if (!cupsAdminSetServerSettings(http, num_settings, settings))
{
_cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
return (1);
}
}
else if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
{
_cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
return (1);
}
else
{
for (i = 0; i < num_settings; i ++)
_cupsLangPrintf(stdout, "%s=%s", settings[i].name, settings[i].value);
}
cupsFreeOptions(num_settings, settings);
return (0);
}
/*
* 'usage()' - Show program usage.
*/
static void
usage(const char *opt) /* I - Option character/string */
{
if (opt)
{
if (*opt == '-')
_cupsLangPrintf(stderr, _("cupsctl: Unknown option \"%s\""), opt);
else
_cupsLangPrintf(stderr, _("cupsctl: Unknown option \"-%c\""), *opt);
}
_cupsLangPuts(stdout, _("Usage: cupsctl [options] [param=value ... "
"paramN=valueN]"));
_cupsLangPuts(stdout, "");
_cupsLangPuts(stdout, _("Options:"));
_cupsLangPuts(stdout, "");
_cupsLangPuts(stdout, _(" -E Encrypt the connection."));
_cupsLangPuts(stdout, _(" -U username Specify username."));
_cupsLangPuts(stdout, _(" -h server[:port] Specify server "
"address."));
_cupsLangPuts(stdout, "");
_cupsLangPuts(stdout, _(" --[no-]debug-logging Turn debug logging "
"on/off."));
_cupsLangPuts(stdout, _(" --[no-]remote-admin Turn remote "
"administration on/off."));
_cupsLangPuts(stdout, _(" --[no-]remote-any Allow/prevent access "
"from the Internet."));
_cupsLangPuts(stdout, _(" --[no-]share-printers Turn printer sharing "
"on/off."));
_cupsLangPuts(stdout, _(" --[no-]user-cancel-any Allow/prevent users to "
"cancel any job."));
exit(1);
}
/*
* End of "$Id: cupsctl.c 10431 2012-04-23 19:19:19Z mike $".
*/
|