- socklen = sizeof (addr);
- if (getpeername(0, (struct sockaddr *)&addr, &socklen) == -1)
- error("getpeername: %s", strerror(errno));
- if (addr.sin_family != AF_INET || ntohs(addr.sin_port) == 20) {
- error("connection rejected from %s family %d port %d",
- inet_ntoa(addr.sin_addr), addr.sin_family, htons(addr.sin_port));
+ if(from_amandad == 0) {
+ socklen = SIZEOF(addr);
+ if (getpeername(0, (struct sockaddr *)&addr, &socklen) == -1) {
+ error(_("getpeername: %s"), strerror(errno));
+ /*NOTREACHED*/
+ }
+ if ((addr.sin_family != (sa_family_t)AF_INET)
+ || (ntohs(addr.sin_port) == 20)) {
+ error(_("connection rejected from %s family %d port %d"),
+ inet_ntoa(addr.sin_addr), addr.sin_family,
+ htons(addr.sin_port));
+ /*NOTREACHED*/
+ }
+
+ /* do the security thing */
+ amfree(buf);
+ fflush(stdout);
+ cmdout = stdout;
+ cmdin = stdin;
+ buf = stralloc(get_client_line(cmdin));
+ check_security_buffer(buf);
+ }
+ else {
+ ctlfdout = DATA_FD_OFFSET + 0;
+ ctlfdin = DATA_FD_OFFSET + 1;
+ datafdout = DATA_FD_OFFSET + 2;
+ close(DATA_FD_OFFSET +3);
+
+ /* read the REQ packet */
+ for(; (line = agets(stdin)) != NULL; free(line)) {
+ if(strncmp_const(line, "OPTIONS ") == 0) {
+ if (g_options)
+ error(_("ERROR recover program sent multiple OPTIONS"));
+ g_options = parse_g_options(line+8, 1);
+ if(!g_options->hostname) {
+ g_options->hostname = alloc(MAX_HOSTNAME_LENGTH+1);
+ gethostname(g_options->hostname, MAX_HOSTNAME_LENGTH);
+ g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0';
+ }
+ }
+ }
+ amfree(line);
+
+ if(amandad_auth && g_options->auth) {
+ if(strcasecmp(amandad_auth, g_options->auth) != 0) {
+ g_printf(_("ERROR recover program ask for auth=%s while amidxtaped is configured for '%s'\n"),
+ g_options->auth, amandad_auth);
+ error(_("ERROR recover program ask for auth=%s while amidxtaped is configured for '%s'"),
+ g_options->auth, amandad_auth);
+ /*NOTREACHED*/
+ }
+ }
+ /* send the REP packet */
+ g_printf("CONNECT CTL %d DATA %d\n", DATA_FD_OFFSET, DATA_FD_OFFSET+1);
+ g_printf("\n");
+ fflush(stdout);
+ fclose(stdin);
+ fclose(stdout);
+ cmdout = fdopen(ctlfdout, "a");
+ if (!cmdout) {
+ error(_("amidxtaped: Can't fdopen(ctlfdout): %s"), strerror(errno));
+ /*NOTREACHED*/
+ }
+ cmdin = fdopen(ctlfdin, "r");
+ if (!cmdin) {
+ error(_("amidxtaped: Can't fdopen(ctlfdin): %s"), strerror(errno));
+ /*NOTREACHED*/
+ }