* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: amrecover.c,v 1.29.4.7.4.6.2.7 2003/01/04 04:33:32 martinea Exp $
+ * $Id: amrecover.c,v 1.52 2006/01/14 04:37:19 paddy_s Exp $
*
* an interactive program for recovering backed-up files
*/
#include "amrecover.h"
#include "getfsent.h"
#include "dgram.h"
-
-#if defined(KRB4_SECURITY)
-#include "krb4-security.h"
-#endif
#include "util.h"
#ifdef HAVE_LIBREADLINE
int tape_server_socket;
char *tape_device_name = NULL;
am_feature_t *our_features = NULL;
-am_feature_t *their_features = NULL;
+am_feature_t *indexsrv_features = NULL;
+am_feature_t *tapesrv_features = NULL;
#ifndef HAVE_LIBREADLINE
int send_command(cmd)
char *cmd;
{
- size_t l, n;
- ssize_t s;
- char *end;
-
/*
* NOTE: this routine is called from sigint_handler, so we must be
* **very** careful about what we do since there is no way to know
* our state at the time the interrupt happened. For instance,
- * do not use any stdio routines here.
+ * do not use any stdio or malloc routines here.
*/
- for (l = 0, n = strlen(cmd); l < n; l += s)
- if ((s = write(server_socket, cmd + l, n - l)) < 0) {
- perror("amrecover: Error writing to server");
- return -1;
- }
- end = "\r\n";
- for (l = 0, n = strlen(end); l < n; l += s)
- if ((s = write(server_socket, end + l, n - l)) < 0) {
- perror("amrecover: Error writing to server");
- return -1;
- }
- return 0;
+ struct iovec msg[2];
+ ssize_t bytes;
+
+ msg[0].iov_base = cmd;
+ msg[0].iov_len = strlen(msg[0].iov_base);
+ msg[1].iov_base = "\r\n";
+ msg[1].iov_len = strlen(msg[1].iov_base);
+ bytes = msg[0].iov_len + msg[1].iov_len;
+
+ if (writev(server_socket, msg, 2) < bytes) {
+ return -1;
+ }
+ return (0);
}
char cwd[STR_SIZE], *dn_guess = NULL, *mpt_guess = NULL;
char *service_name;
char *line = NULL;
- int fd;
- for(fd = 3; fd < FD_SETSIZE; fd++) {
- /*
- * Make sure nobody spoofs us with a lot of extra open files
- * that would cause an open we do to get a very high file
- * descriptor, which in turn might be used as an index into
- * an array (e.g. an fd_set).
- */
- close(fd);
- }
+ safe_fd(-1, 0);
set_pname("amrecover");
+
+ /* Don't die when child closes pipe */
+ signal(SIGPIPE, SIG_IGN);
+
dbopen();
#ifndef IGNORE_UID_CHECK
amfree(disk_path);
dump_date[0] = '\0';
+ /* Don't die when child closes pipe */
+ signal(SIGPIPE, SIG_IGN);
+
/* set up signal handler */
act.sa_handler = sigint_handler;
sigemptyset(&act.sa_mask);
ntohs(sp->s_port),
-1,
-1,
- &my_port);
+ &my_port,
+ 0);
if (server_socket < 0)
{
error("cannot connect to %s: %s", server_name, strerror(errno));
}
/* do the security thing */
-#if defined(KRB4_SECURITY)
-#if 0 /* not yet implemented */
- if(krb4_auth)
- {
- line = get_krb_security();
- } else
-#endif /* 0 */
-#endif
- {
- line = get_bsd_security();
- }
+ line = get_security();
if (converse(line) == -1)
exit(1);
if (!server_happy())
memset(line, '\0', strlen(line));
amfree(line);
- /* try to get the features form the server */
+ /* try to get the features from the server */
{
char *our_feature_string = NULL;
char *their_feature_string = NULL;
line = stralloc2("FEATURES ", our_feature_string);
if(exchange(line) == 0) {
their_feature_string = stralloc(server_line+13);
- their_features = am_string_to_feature(their_feature_string);
+ indexsrv_features = am_string_to_feature(their_feature_string);
}
else {
- their_features = am_set_default_feature_set();
+ indexsrv_features = am_set_default_feature_set();
}
amfree(our_feature_string);
amfree(their_feature_string);
aclose(server_socket);
return 0;
}
+
+char *
+get_security()
+{
+ struct passwd *pwptr;
+
+ if((pwptr = getpwuid(getuid())) == NULL)
+ error("can't get login name for my uid %ld", (long)getuid());
+ return stralloc2("SECURITY USER ", pwptr->pw_name);
+}