File: 303-shadow-passwords-supported.dpatch

package info (click to toggle)
cernlib 20061220%2Bdfsg3-4.3%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,872 kB
  • sloc: sh: 9,517; makefile: 187
file content (101 lines) | stat: -rw-r--r-- 2,908 bytes parent folder | download | duplicates (3)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#! /bin/sh /usr/share/dpatch/dpatch-run
## 303-shadow-passwords-supported.dpatch by  <kmccarty@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Allow CERN's server code to read from /etc/shadow.

@DPATCH@
--- a/src/packlib/cspack/tcpaw/tcpaw.c
+++ b/src/packlib/cspack/tcpaw/tcpaw.c
@@ -34,6 +34,9 @@
  *
  */
 #include "cspack/pilot.h"
+#if defined(CERNLIB_LINUX) && ! defined(CERNLIB_MACOSX)
+#define SHADOW_SUPPORT /* for Debian */
+#endif
 #if !defined(CERNLIB_IBM)||defined(CERNLIB_TCPSOCK)
 /*N.B. Must define sequence TCPLOG if a log file is required, e.g.*/
 /*#define LOGFILE "disk$dd:-ben.socks-serv.log"*/ /* VMS    */
@@ -237,7 +240,7 @@
 #endif /* OSK */
 #endif /* AUTHENT */
  
-#ifdef linux_softland
+#if defined(linux_softland) || defined(SHADOW_SUPPORT)
 #include <shadow.h>
 #endif /* linux_softland */
  
@@ -1790,10 +1793,10 @@
         union wait ret;
 #endif /* APOPWD1 */
  
-        char   *xpasswd, *crypt();
+        char   *xpasswd, *encrypted, *crypt();
         struct passwd *pw;
  
-#ifdef linux_softland
+#if defined(linux_softland) || defined(SHADOW_SUPPORT)
         struct spwd *spwd;
 #endif /* linux_softland */
  
@@ -1808,6 +1811,7 @@
                 reply("Unknown user %s.\n", user);
                 return(-2);
         }
+	encrypted = pw->pw_passwd;
  
 #ifdef linux_softland
         spwd = getspnam(user);
@@ -1815,6 +1819,29 @@
                 reply("User %s has illegal shadow password\n",user);
                 return(-2);
         }
+	encrypted = spwd->sp_pwdp;
+
+#elif defined(SHADOW_SUPPORT)
+	/* shadow passwords may not be enabled in Debian, so must check */
+	{
+		FILE *test = fopen("/etc/shadow", "r");
+		if (test) {
+			fclose(test);
+			spwd = getspnam(user);
+			if (spwd == NULL) {
+				reply("User %s has illegal shadow password\n",
+				      user);
+				return(-2);
+			}
+			encrypted = spwd->sp_pwdp;
+		}
+		else if (errno == EACCES) {
+			reply("Server has insufficient permissions to "
+			      "read /etc/shadow file\n");
+			return(-2);
+		}
+	}
+
 #endif /* linux_softland */
  
 #ifdef APOPWD1
@@ -1860,15 +1887,16 @@
 #else
  
 #ifdef linux_softland
-            xpasswd = pw_encrypt(pass,spwd->sp_pwdp);
+            xpasswd = pw_encrypt(pass, encrypted);
 #else
-            xpasswd = crypt(pass, pw->pw_passwd);
+            xpasswd = crypt(pass, encrypted);
 #endif /* linux_softland */
+
             /* The strcmp does not catch null passwords! */
-#ifdef linux_softland
-            if (spwd->sp_pwdp == '\0' || strcmp(xpasswd,spwd->sp_pwdp)) {
+#if defined(linux_softland) || defined(SHADOW_SUPPORT)
+            if (*encrypted == '\0' || strcmp(xpasswd,spwd->sp_pwdp)) {
 #else
-            if (*pw->pw_passwd == '\0' || strcmp(xpasswd,pw->pw_passwd)) {
+            if (*encrypted == '\0' || strcmp(xpasswd,pw->pw_passwd)) {
 #endif /* linux_softland */
  
 #endif /* AFS */