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