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
36 #include "server_util.h"
37 #include "amfeatures.h"
39 static time_t conf_ctimeout;
40 static am_feature_t *our_features = NULL;
41 static char *our_feature_string = NULL;
42 static int remote_errors = 0;
47 void client_protocol(char *hostname, char *auth, char *service, FILE *input_file);
48 int main(int argc, char **argv);
53 error(_("Usage: amservice [-o configoption]* [-f input_file] host auth service"));
62 config_overrides_t *cfg_ovr;
72 * Configure program for internationalization:
73 * 1) Only set the message locale for now.
74 * 2) Set textdomain for all amanda related programs to "amanda"
75 * We don't want to be forced to support dozens of message catalogs.
77 setlocale(LC_MESSAGES, "C");
83 set_pname("amservice");
84 /* drop root privileges */
85 if (!set_root_privs(0)) {
86 error(_("amservice must be run setuid root"));
89 /* Don't die when child closes pipe */
90 signal(SIGPIPE, SIG_IGN);
92 dbopen(DBG_SUBDIR_SERVER);
94 add_amanda_log_handler(amanda_log_stderr);
96 our_features = am_init_feature_set();
97 our_feature_string = am_feature_to_string(our_features);
99 /* process arguments */
101 cfg_ovr = new_config_overrides(argc/2);
103 while((opt = getopt(argc, argv, "o:f:")) != EOF) {
105 case 'o': add_config_override_opt(cfg_ovr, optarg);
107 case 'f': if (*optarg == '/') {
108 input_file = fopen(optarg, "r");
110 char *name = vstralloc(get_original_cwd(), "/",
112 input_file = fopen(name, "r");
116 g_critical("Cannot open output file '%s': %s",
117 optarg, strerror(errno));
122 argc -= optind, argv += optind;
123 if(argc < 3) usage();
125 /* set a default config */
126 set_config_overrides(cfg_ovr);
127 config_init(CONFIG_INIT_CLIENT, NULL);
128 dbrename(get_config_name(), DBG_SUBDIR_SERVER);
130 if (config_errors(NULL) >= CFGERR_WARNINGS) {
131 config_print_errors();
132 if (config_errors(NULL) >= CFGERR_ERRORS) {
133 g_critical(_("errors processing config file"));
137 conf_ctimeout = (time_t)getconf_int(CNF_CTIMEOUT);
143 /* start client side checks */
145 client_protocol(hostname, auth, service, input_file);
147 amfree(our_feature_string);
148 am_release_feature_set(our_features);
152 return(remote_errors != 0);
155 /* --------------------------------------------------- */
157 static void handle_result(void *, pkt_t *, security_handle_t *);
158 void start_host(char *hostname, char *auth, char *req);
166 const security_driver_t *secdrv;
167 secdrv = security_getdriver(auth);
168 if (secdrv == NULL) {
169 fprintf(stderr, _("Could not find security driver \"%s\".\n"), auth);
171 protocol_sendreq(hostname, secdrv, amhost_get_security_conf,
172 req, conf_ctimeout, handle_result, NULL);
186 req = g_strdup_printf("SERVICE %s\nOPTIONS features=%s\n",
187 service, our_feature_string);
189 while(fgets(req1, 1024, input_file) != NULL) {
190 vstrextend(&req, req1, NULL);
194 start_host(hostname, auth, req);
200 amfree(our_feature_string);
207 G_GNUC_UNUSED void *datap,
209 security_handle_t * sech)
217 _("Request failed: %s\n"), security_geterror(sech));
226 skip_quoted_line(s, ch);
231 fprintf(stdout, "%s\n", line);
233 fprintf(stdout, "\n");