]> git.ipfire.org Git - thirdparty/cups.git/blame - systemv/cupsctl.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / systemv / cupsctl.c
CommitLineData
bc44d920 1/*
503b54c9 2 * Scheduler control program for CUPS.
bc44d920 3 *
503b54c9
MS
4 * Copyright 2007-2012 by Apple Inc.
5 * Copyright 2006-2007 by Easy Software Products.
bc44d920 6 *
e3101897 7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
bc44d920 8 */
9
10/*
11 * Include necessary headers...
12 */
13
71e16022 14#include <cups/cups-private.h>
bc44d920 15#include <cups/adminutil.h>
bc44d920 16
17
18/*
19 * Local functions...
20 */
21
85dda01c 22static void usage(const char *opt) __attribute__((noreturn));
bc44d920 23
24
25/*
26 * 'main()' - Get/set server settings.
27 */
28
29int /* O - Exit status */
30main(int argc, /* I - Number of command-line args */
31 char *argv[]) /* I - Command-line arguments */
32{
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 */
38
39
40 /*
41 * Process the command-line...
42 */
43
44 _cupsSetLocale(argv);
45
46 num_settings = 0;
47 settings = NULL;
48
49 for (i = 1; i < argc; i ++)
50 {
51 if (argv[i][0] == '-')
52 {
53 if (argv[i][1] == '-')
54 {
355e94dc 55 if (!strcmp(argv[i], "--debug-logging"))
bc44d920 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);
bc44d920 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);
85 else
86 usage(argv[i]);
87 }
88 else
89 {
90 for (opt = argv[i] + 1; *opt; opt ++)
91 switch (*opt)
92 {
93 case 'E' :
94 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
95 break;
96
97 case 'U' :
98 i ++;
99 if (i >= argc)
100 usage(NULL);
101
102 cupsSetUser(argv[i]);
103 break;
104
105 case 'h' :
106 i ++;
107 if (i >= argc)
108 usage(NULL);
109
110 cupsSetServer(argv[i]);
111 break;
112
113 default :
114 usage(opt);
115 break;
116 }
117 }
118 }
119 else if (strchr(argv[i], '='))
120 num_settings = cupsParseOptions(argv[i], num_settings, &settings);
121 else
122 usage(argv[i]);
123 }
124
0268488e
MS
125 if (cupsGetOption("Listen", num_settings, settings) ||
126 cupsGetOption("Port", num_settings, settings))
127 {
82f97232 128 _cupsLangPuts(stderr, _("cupsctl: Cannot set Listen or Port directly."));
0268488e
MS
129 return (1);
130 }
131
bc44d920 132 /*
133 * Connect to the server using the defaults...
134 */
135
db0bd74a
MS
136 if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
137 cupsEncryption())) == NULL)
138 {
0837b7e8 139 _cupsLangPrintf(stderr, _("cupsctl: Unable to connect to server: %s"),
db0bd74a
MS
140 strerror(errno));
141 return (1);
142 }
bc44d920 143
144 /*
145 * Set the current configuration if we have anything on the command-line...
146 */
147
148 if (num_settings > 0)
149 {
150 if (!cupsAdminSetServerSettings(http, num_settings, settings))
151 {
0837b7e8 152 _cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
bc44d920 153 return (1);
154 }
155 }
156 else if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
157 {
0837b7e8 158 _cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
bc44d920 159 return (1);
160 }
161 else
162 {
163 for (i = 0; i < num_settings; i ++)
0837b7e8 164 _cupsLangPrintf(stdout, "%s=%s", settings[i].name, settings[i].value);
bc44d920 165 }
166
167 cupsFreeOptions(num_settings, settings);
168 return (0);
169}
170
171
172/*
173 * 'usage()' - Show program usage.
174 */
175
176static void
177usage(const char *opt) /* I - Option character/string */
178{
179 if (opt)
180 {
181 if (*opt == '-')
0837b7e8 182 _cupsLangPrintf(stderr, _("cupsctl: Unknown option \"%s\""), opt);
bc44d920 183 else
0837b7e8 184 _cupsLangPrintf(stderr, _("cupsctl: Unknown option \"-%c\""), *opt);
bc44d920 185 }
186
0837b7e8
MS
187 _cupsLangPuts(stdout, _("Usage: cupsctl [options] [param=value ... "
188 "paramN=valueN]"));
189 _cupsLangPuts(stdout, "");
190 _cupsLangPuts(stdout, _("Options:"));
191 _cupsLangPuts(stdout, "");
f3c17241 192 _cupsLangPuts(stdout, _(" -E Encrypt the connection."));
84315f46
MS
193 _cupsLangPuts(stdout, _(" -U username Specify username."));
194 _cupsLangPuts(stdout, _(" -h server[:port] Specify server "
0837b7e8
MS
195 "address."));
196 _cupsLangPuts(stdout, "");
84315f46 197 _cupsLangPuts(stdout, _(" --[no-]debug-logging Turn debug logging "
0837b7e8 198 "on/off."));
84315f46 199 _cupsLangPuts(stdout, _(" --[no-]remote-admin Turn remote "
0837b7e8 200 "administration on/off."));
84315f46 201 _cupsLangPuts(stdout, _(" --[no-]remote-any Allow/prevent access "
0837b7e8 202 "from the Internet."));
84315f46 203 _cupsLangPuts(stdout, _(" --[no-]share-printers Turn printer sharing "
0837b7e8 204 "on/off."));
84315f46 205 _cupsLangPuts(stdout, _(" --[no-]user-cancel-any Allow/prevent users to "
0837b7e8 206 "cancel any job."));
bc44d920 207
208 exit(1);
209}