2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-2000 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: amservice.c 11167 2008-05-06 11:53:54Z martineau $
29 * Take the REQ packet in stdin and output the REP packet in stdout
37 #include "server_util.h"
38 #include "amfeatures.h"
40 static time_t conf_ctimeout;
41 static am_feature_t *our_features = NULL;
42 static char *our_feature_string = NULL;
43 static int remote_errors = 0;
48 void client_protocol(char *hostname, char *auth, char *service, FILE *input_file);
49 int main(int argc, char **argv);
54 error(_("Usage: amservice%s [-o configoption]* [-f input_file] host auth service"),
64 config_overwrites_t *cfg_ovr;
74 * Configure program for internationalization:
75 * 1) Only set the message locale for now.
76 * 2) Set textdomain for all amanda related programs to "amanda"
77 * We don't want to be forced to support dozens of message catalogs.
79 setlocale(LC_MESSAGES, "C");
85 set_pname("amservice");
86 /* drop root privileges */
87 if (!set_root_privs(0)) {
88 error(_("amservice must be run setuid root"));
91 /* Don't die when child closes pipe */
92 signal(SIGPIPE, SIG_IGN);
94 dbopen(DBG_SUBDIR_SERVER);
96 erroutput_type = ERR_INTERACTIVE;
98 our_features = am_init_feature_set();
99 our_feature_string = am_feature_to_string(our_features);
101 /* process arguments */
103 cfg_ovr = new_config_overwrites(argc/2);
105 while((opt = getopt(argc, argv, "o:f:")) != EOF) {
107 case 'o': add_config_overwrite_opt(cfg_ovr, optarg);
109 case 'f': if (*optarg == '/') {
110 input_file = fopen(optarg, "r");
112 char *name = vstralloc(get_original_cwd(), "/",
114 input_file = fopen(name, "r");
118 g_critical("Cannot open output file '%s': %s",
119 optarg, strerror(errno));
124 argc -= optind, argv += optind;
125 if(argc < 3) usage();
127 /* set a default config */
128 config_init(CONFIG_INIT_CLIENT, NULL);
129 apply_config_overwrites(cfg_ovr);
130 dbrename(get_config_name(), DBG_SUBDIR_SERVER);
132 if (config_errors(NULL) >= CFGERR_WARNINGS) {
133 config_print_errors();
134 if (config_errors(NULL) >= CFGERR_ERRORS) {
135 g_critical(_("errors processing config file"));
139 conf_ctimeout = (time_t)getconf_int(CNF_CTIMEOUT);
145 /* start client side checks */
147 client_protocol(hostname, auth, service, input_file);
149 amfree(our_feature_string);
150 am_release_feature_set(our_features);
154 return(remote_errors != 0);
157 /* --------------------------------------------------- */
159 static void handle_result(void *, pkt_t *, security_handle_t *);
160 void start_host(char *hostname, char *auth, char *req);
168 const security_driver_t *secdrv;
169 secdrv = security_getdriver(auth);
170 if (secdrv == NULL) {
171 fprintf(stderr, _("Could not find security driver \"%s\".\n"), auth);
173 protocol_sendreq(hostname, secdrv, amhost_get_security_conf,
174 req, conf_ctimeout, handle_result, NULL);
188 req = g_strdup_printf("SERVICE %s\nOPTIONS features=%s\n",
189 service, our_feature_string);
191 while(fgets(req1, 1024, input_file) != NULL) {
192 vstrextend(&req, req1, NULL);
196 start_host(hostname, auth, req);
202 amfree(our_feature_string);
209 G_GNUC_UNUSED void *datap,
211 security_handle_t * sech)
219 _("Request failed: %s\n"), security_geterror(sech));
228 skip_quoted_line(s, ch);
233 fprintf(stdout, "%s\n", line);
235 fprintf(stdout, "\n");