Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
srohatgi01
GitHub Repository: srohatgi01/cups
Path: blob/master/systemv/cupsctl.c
1090 views
1
/*
2
* Scheduler control program for CUPS.
3
*
4
* Copyright © 2007-2019 by Apple Inc.
5
* Copyright © 2006-2007 by Easy Software Products.
6
*
7
* Licensed under Apache License v2.0. See the file "LICENSE" for more
8
* information.
9
*/
10
11
/*
12
* Include necessary headers...
13
*/
14
15
#include <cups/cups-private.h>
16
#include <cups/adminutil.h>
17
18
19
/*
20
* Local functions...
21
*/
22
23
static void usage(const char *opt) _CUPS_NORETURN;
24
25
26
/*
27
* 'main()' - Get/set server settings.
28
*/
29
30
int /* O - Exit status */
31
main(int argc, /* I - Number of command-line args */
32
char *argv[]) /* I - Command-line arguments */
33
{
34
int i, j, /* Looping vars */
35
num_settings; /* Number of settings */
36
cups_option_t *settings, /* Settings */
37
*setting; /* Current setting */
38
const char *opt; /* Current option character */
39
http_t *http; /* Connection to server */
40
static const char * const disallowed[] =
41
{ /* List of disallowed directives for cupsd.conf */
42
"AccessLog",
43
"CacheDir",
44
"ConfigFilePerm",
45
"DataDir",
46
"DocumentRoot",
47
"ErrorLog",
48
"FatalErrors",
49
"FileDevice",
50
"Group",
51
"Listen",
52
"LogFilePerm",
53
"PageLog",
54
"PassEnv",
55
"Port",
56
"Printcap",
57
"PrintcapFormat",
58
"RemoteRoot",
59
"RequestRoot",
60
"ServerBin",
61
"ServerCertificate",
62
"ServerKey",
63
"ServerKeychain",
64
"ServerRoot",
65
"SetEnv",
66
"StateDir",
67
"SystemGroup",
68
"SystemGroupAuthKey",
69
"TempDir",
70
"User"
71
};
72
73
74
/*
75
* Process the command-line...
76
*/
77
78
_cupsSetLocale(argv);
79
80
num_settings = 0;
81
settings = NULL;
82
83
for (i = 1; i < argc; i ++)
84
{
85
if (!strcmp(argv[i], "--help"))
86
usage(NULL);
87
else if (argv[i][0] == '-')
88
{
89
if (argv[i][1] == '-')
90
{
91
if (!strcmp(argv[i], "--debug-logging"))
92
num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING, "1",
93
num_settings, &settings);
94
else if (!strcmp(argv[i], "--no-debug-logging"))
95
num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING, "0",
96
num_settings, &settings);
97
else if (!strcmp(argv[i], "--remote-admin"))
98
num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN, "1",
99
num_settings, &settings);
100
else if (!strcmp(argv[i], "--no-remote-admin"))
101
num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN, "0",
102
num_settings, &settings);
103
else if (!strcmp(argv[i], "--remote-any"))
104
num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY, "1",
105
num_settings, &settings);
106
else if (!strcmp(argv[i], "--no-remote-any"))
107
num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY, "0",
108
num_settings, &settings);
109
else if (!strcmp(argv[i], "--share-printers"))
110
num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "1",
111
num_settings, &settings);
112
else if (!strcmp(argv[i], "--no-share-printers"))
113
num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "0",
114
num_settings, &settings);
115
else if (!strcmp(argv[i], "--user-cancel-any"))
116
num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "1",
117
num_settings, &settings);
118
else if (!strcmp(argv[i], "--no-user-cancel-any"))
119
num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "0",
120
num_settings, &settings);
121
else
122
usage(argv[i]);
123
}
124
else
125
{
126
for (opt = argv[i] + 1; *opt; opt ++)
127
switch (*opt)
128
{
129
case 'E' :
130
cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
131
break;
132
133
case 'U' :
134
i ++;
135
if (i >= argc)
136
usage(NULL);
137
138
cupsSetUser(argv[i]);
139
break;
140
141
case 'h' :
142
i ++;
143
if (i >= argc)
144
usage(NULL);
145
146
cupsSetServer(argv[i]);
147
break;
148
149
default :
150
usage(opt);
151
}
152
}
153
}
154
else if (strchr(argv[i], '='))
155
num_settings = cupsParseOptions(argv[i], num_settings, &settings);
156
else
157
usage(argv[i]);
158
}
159
160
for (i = num_settings, setting = settings; i > 0; i --, setting ++)
161
{
162
for (j = 0; j < (int)(sizeof(disallowed) / sizeof(disallowed[0])); j ++)
163
{
164
if (!_cups_strcasecmp(setting->name, disallowed[j]))
165
{
166
_cupsLangPrintf(stderr, _("cupsctl: Cannot set %s directly."), disallowed[j]);
167
return (1);
168
}
169
}
170
}
171
172
/*
173
* Connect to the server using the defaults...
174
*/
175
176
if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
177
cupsEncryption())) == NULL)
178
{
179
_cupsLangPrintf(stderr, _("cupsctl: Unable to connect to server: %s"),
180
strerror(errno));
181
return (1);
182
}
183
184
/*
185
* Set the current configuration if we have anything on the command-line...
186
*/
187
188
if (num_settings > 0)
189
{
190
if (!cupsAdminSetServerSettings(http, num_settings, settings))
191
{
192
_cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
193
return (1);
194
}
195
}
196
else if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
197
{
198
_cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
199
return (1);
200
}
201
else
202
{
203
for (i = 0; i < num_settings; i ++)
204
_cupsLangPrintf(stdout, "%s=%s", settings[i].name, settings[i].value);
205
}
206
207
cupsFreeOptions(num_settings, settings);
208
return (0);
209
}
210
211
212
/*
213
* 'usage()' - Show program usage.
214
*/
215
216
static void
217
usage(const char *opt) /* I - Option character/string */
218
{
219
if (opt)
220
{
221
if (*opt == '-')
222
_cupsLangPrintf(stderr, _("cupsctl: Unknown option \"%s\""), opt);
223
else
224
_cupsLangPrintf(stderr, _("cupsctl: Unknown option \"-%c\""), *opt);
225
}
226
227
_cupsLangPuts(stdout, _("Usage: cupsctl [options] [param=value ... paramN=valueN]"));
228
_cupsLangPuts(stdout, _("Options:"));
229
_cupsLangPuts(stdout, _("-E Encrypt the connection to the server"));
230
_cupsLangPuts(stdout, _("-h server[:port] Connect to the named server and port"));
231
_cupsLangPuts(stdout, _("-U username Specify username to use for authentication"));
232
_cupsLangPuts(stdout, _("--[no-]debug-logging Turn debug logging on/off"));
233
_cupsLangPuts(stdout, _("--[no-]remote-admin Turn remote administration on/off"));
234
_cupsLangPuts(stdout, _("--[no-]remote-any Allow/prevent access from the Internet"));
235
_cupsLangPuts(stdout, _("--[no-]share-printers Turn printer sharing on/off"));
236
_cupsLangPuts(stdout, _("--[no-]user-cancel-any Allow/prevent users to cancel any job"));
237
238
exit(1);
239
}
240
241