Imported Upstream version 2.6.0
[debian/amanda] / common-src / rsh-security.c
index 9761f81b4bbaa6fa6c6d3f985fb40ae801a55109..26914c6845f1433b0a2445df54fe2a03155a969f 100644 (file)
 #include "stream.h"
 #include "version.h"
 
-#ifdef RSH_SECURITY
-
-/*#define      RSH_DEBUG*/
-
-#ifdef RSH_DEBUG
-#define        rshprintf(x)    dbprintf(x)
-#else
-#define        rshprintf(x)
-#endif
-
 /*
  * Path to the rsh binary.  This should be configurable.
  */
@@ -103,6 +93,8 @@ const security_driver_t rsh_security_driver = {
     tcpm_stream_read_sync,
     tcpm_stream_read_cancel,
     tcpm_close_connection,
+    NULL,
+    NULL
 };
 
 static int newhandle = 1;
@@ -126,28 +118,27 @@ rsh_connect(
     void *             datap)
 {
     struct sec_handle *rh;
-    struct hostent *he;
     char *amandad_path=NULL, *client_username=NULL;
 
     assert(fn != NULL);
     assert(hostname != NULL);
 
-    rshprintf(("%s: rsh: rsh_connect: %s\n", debug_prefix_time(NULL),
-              hostname));
+    auth_debug(1, _("rsh: rsh_connect: %s\n"), hostname);
 
     rh = alloc(SIZEOF(*rh));
     security_handleinit(&rh->sech, &rsh_security_driver);
     rh->hostname = NULL;
     rh->rs = NULL;
     rh->ev_timeout = NULL;
+    rh->rc = NULL;
 
-    if ((he = gethostbyname(hostname)) == NULL) {
+    rh->hostname = NULL;
+    if (resolve_hostname(hostname, 0, NULL, &rh->hostname) || rh->hostname == NULL) {
        security_seterror(&rh->sech,
-           "%s: could not resolve hostname", hostname);
+           _("%s: could not resolve hostname"), hostname);
        (*fn)(arg, &rh->sech, S_ERROR);
        return;
     }
-    rh->hostname = stralloc(he->h_name);       /* will be replaced */
     rh->rs = tcpma_stream_client(rh, newhandle++);
 
     if (rh->rs == NULL)
@@ -167,7 +158,7 @@ rsh_connect(
     }
     if(rh->rc->read == -1) {
        if (runrsh(rh->rs->rc, amandad_path, client_username) < 0) {
-           security_seterror(&rh->sech, "can't connect to %s: %s",
+           security_seterror(&rh->sech, _("can't connect to %s: %s"),
                              hostname, rh->rs->rc->errmsg);
            goto error;
        }
@@ -212,13 +203,13 @@ runrsh(
     memset(rpipe, -1, SIZEOF(rpipe));
     memset(wpipe, -1, SIZEOF(wpipe));
     if (pipe(rpipe) < 0 || pipe(wpipe) < 0) {
-       rc->errmsg = newvstralloc(rc->errmsg, "pipe: ", strerror(errno), NULL);
+       rc->errmsg = newvstrallocf(rc->errmsg, _("pipe: %s"), strerror(errno));
        return (-1);
     }
 
     switch (rc->pid = fork()) {
     case -1:
-       rc->errmsg = newvstralloc(rc->errmsg, "fork: ", strerror(errno), NULL);
+       rc->errmsg = newvstrallocf(rc->errmsg, _("fork: %s"), strerror(errno));
        aclose(rpipe[0]);
        aclose(rpipe[1]);
        aclose(wpipe[0]);
@@ -239,7 +230,7 @@ runrsh(
     safe_fd(-1, 0);
 
     if(!xamandad_path || strlen(xamandad_path) <= 1) 
-       xamandad_path = vstralloc(libexecdir, "/", "amandad",
+       xamandad_path = vstralloc(amlibexecdir, "/", "amandad",
                                 versionsuffix(), NULL);
     if(!xclient_username || strlen(xclient_username) <= 1)
        xclient_username = CLIENT_LOGIN;
@@ -247,10 +238,8 @@ runrsh(
     execlp(RSH_PATH, RSH_PATH, "-l", xclient_username,
           rc->hostname, xamandad_path, "-auth=rsh", "amdump", "amindexd",
           "amidxtaped", (char *)NULL);
-    error("error: couldn't exec %s: %s", RSH_PATH, strerror(errno));
+    error(_("error: couldn't exec %s: %s"), RSH_PATH, strerror(errno));
 
     /* should never go here, shut up compiler warning */
     return(-1);
 }
-
-#endif /* RSH_SECURITY */