]> git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupsctl.c
Greatly simplify the man page handling.
[thirdparty/cups.git] / systemv / cupsctl.c
1 /*
2 * Scheduler control program for CUPS.
3 *
4 * Copyright © 2007-2018 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, /* Looping var */
35 num_settings; /* Number of settings */
36 cups_option_t *settings; /* Settings */
37 const char *opt; /* Current option character */
38 http_t *http; /* Connection to server */
39
40
41 /*
42 * Process the command-line...
43 */
44
45 _cupsSetLocale(argv);
46
47 num_settings = 0;
48 settings = NULL;
49
50 for (i = 1; i < argc; i ++)
51 {
52 if (!strcmp(argv[i], "--help"))
53 usage(NULL);
54 else if (argv[i][0] == '-')
55 {
56 if (argv[i][1] == '-')
57 {
58 if (!strcmp(argv[i], "--debug-logging"))
59 num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING, "1",
60 num_settings, &settings);
61 else if (!strcmp(argv[i], "--no-debug-logging"))
62 num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING, "0",
63 num_settings, &settings);
64 else if (!strcmp(argv[i], "--remote-admin"))
65 num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN, "1",
66 num_settings, &settings);
67 else if (!strcmp(argv[i], "--no-remote-admin"))
68 num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN, "0",
69 num_settings, &settings);
70 else if (!strcmp(argv[i], "--remote-any"))
71 num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY, "1",
72 num_settings, &settings);
73 else if (!strcmp(argv[i], "--no-remote-any"))
74 num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY, "0",
75 num_settings, &settings);
76 else if (!strcmp(argv[i], "--share-printers"))
77 num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "1",
78 num_settings, &settings);
79 else if (!strcmp(argv[i], "--no-share-printers"))
80 num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "0",
81 num_settings, &settings);
82 else if (!strcmp(argv[i], "--user-cancel-any"))
83 num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "1",
84 num_settings, &settings);
85 else if (!strcmp(argv[i], "--no-user-cancel-any"))
86 num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "0",
87 num_settings, &settings);
88 else
89 usage(argv[i]);
90 }
91 else
92 {
93 for (opt = argv[i] + 1; *opt; opt ++)
94 switch (*opt)
95 {
96 case 'E' :
97 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
98 break;
99
100 case 'U' :
101 i ++;
102 if (i >= argc)
103 usage(NULL);
104
105 cupsSetUser(argv[i]);
106 break;
107
108 case 'h' :
109 i ++;
110 if (i >= argc)
111 usage(NULL);
112
113 cupsSetServer(argv[i]);
114 break;
115
116 default :
117 usage(opt);
118 break;
119 }
120 }
121 }
122 else if (strchr(argv[i], '='))
123 num_settings = cupsParseOptions(argv[i], num_settings, &settings);
124 else
125 usage(argv[i]);
126 }
127
128 if (cupsGetOption("Listen", num_settings, settings) ||
129 cupsGetOption("Port", num_settings, settings))
130 {
131 _cupsLangPuts(stderr, _("cupsctl: Cannot set Listen or Port directly."));
132 return (1);
133 }
134
135 /*
136 * Connect to the server using the defaults...
137 */
138
139 if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
140 cupsEncryption())) == NULL)
141 {
142 _cupsLangPrintf(stderr, _("cupsctl: Unable to connect to server: %s"),
143 strerror(errno));
144 return (1);
145 }
146
147 /*
148 * Set the current configuration if we have anything on the command-line...
149 */
150
151 if (num_settings > 0)
152 {
153 if (!cupsAdminSetServerSettings(http, num_settings, settings))
154 {
155 _cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
156 return (1);
157 }
158 }
159 else if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
160 {
161 _cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
162 return (1);
163 }
164 else
165 {
166 for (i = 0; i < num_settings; i ++)
167 _cupsLangPrintf(stdout, "%s=%s", settings[i].name, settings[i].value);
168 }
169
170 cupsFreeOptions(num_settings, settings);
171 return (0);
172 }
173
174
175 /*
176 * 'usage()' - Show program usage.
177 */
178
179 static void
180 usage(const char *opt) /* I - Option character/string */
181 {
182 if (opt)
183 {
184 if (*opt == '-')
185 _cupsLangPrintf(stderr, _("cupsctl: Unknown option \"%s\""), opt);
186 else
187 _cupsLangPrintf(stderr, _("cupsctl: Unknown option \"-%c\""), *opt);
188 }
189
190 _cupsLangPuts(stdout, _("Usage: cupsctl [options] [param=value ... paramN=valueN]"));
191 _cupsLangPuts(stdout, _("Options:"));
192 _cupsLangPuts(stdout, _("-E Encrypt the connection to the server"));
193 _cupsLangPuts(stdout, _("-h server[:port] Connect to the named server and port"));
194 _cupsLangPuts(stdout, _("-U username Specify username to use for authentication"));
195 _cupsLangPuts(stdout, _("--[no-]debug-logging Turn debug logging on/off"));
196 _cupsLangPuts(stdout, _("--[no-]remote-admin Turn remote administration on/off"));
197 _cupsLangPuts(stdout, _("--[no-]remote-any Allow/prevent access from the Internet"));
198 _cupsLangPuts(stdout, _("--[no-]share-printers Turn printer sharing on/off"));
199 _cupsLangPuts(stdout, _("--[no-]user-cancel-any Allow/prevent users to cancel any job"));
200
201 exit(1);
202 }