summaryrefslogtreecommitdiff
path: root/net-misc/netkit-rsh/files/patches/050_all_prompt.patch
blob: 5f6a89dc1d94a8211dd5c2ff0ed592d803e07f49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--- a/rexec/rexec.c
+++ b/rexec/rexec.c
@@ -164,12 +164,30 @@
     user_name[strlen(user_name)-1] = '\0'; /* Hopefully fgets always adds
 					      a newline. */
     passwd = getpass("Password: ");
+  } else {
+
+    if ( user_name == NULL )
+      user_name = getenv("REXEC_USER");
+    if ( user_name == NULL ) {
+      uid_t uid = getuid();
+      struct passwd *pw = getpwuid(uid);
+      if (!(pw && pw->pw_name)) {
+        fprintf(stderr, "Can't lookup uid %d\n", uid);
+	exit(1);
+      }
+      user_name = strdup(pw->pw_name);
+    }
+    if ( passwd == NULL )
+      passwd = getenv("REXEC_PASS");
+    if ( passwd == NULL )
+       passwd = getpass("Password: ");
   }
 
-  if ( user_name == NULL )
-    user_name = getenv("REXEC_USER");
-  if ( passwd == NULL )
-    passwd = getenv("REXEC_PASS");
+  if (!(user_name && passwd)) {
+    fprintf(stderr, "Can't use %s without supplying a user and password\n",
+    	progname);
+    exit(1);
+  }
 
   if ( (sock = rexec(&host, port_exec, user_name, passwd, command, 
 		     p_to_aux_sock)) < 0 )