Ubuntu Pastebin

Paste from sergiusens at Fri, 26 Jun 2015 13:23:05 +0000

Download as text
  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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
Description: Add support to passwd for updating libnss-extrausers locations
Author: Michael Terry <michael.terry@canonical.com>

Index: shadow-4.1.5.1/lib/defines.h
===================================================================
--- shadow-4.1.5.1.orig/lib/defines.h
+++ shadow-4.1.5.1/lib/defines.h
@@ -316,6 +316,14 @@ char *strchr (), *strrchr (), *strtok ()
 #endif
 #endif
 
+#ifndef EXTRAUSERS_PASSWD_FILE
+#define EXTRAUSERS_PASSWD_FILE "/var/lib/extrausers/passwd"
+#endif
+
+#ifndef EXTRAUSERS_SHADOW_FILE
+#define EXTRAUSERS_SHADOW_FILE "/var/lib/extrausers/shadow"
+#endif
+
 #ifndef NULL
 #define NULL ((void *) 0)
 #endif
Index: shadow-4.1.5.1/src/passwd.c
===================================================================
--- shadow-4.1.5.1.orig/src/passwd.c
+++ shadow-4.1.5.1/src/passwd.c
@@ -544,8 +544,15 @@ static void update_noshadow (void)
 {
 	const struct passwd *pw;
 	struct passwd *npw;
+	bool try_extrausers = strcmp (pw_dbname (), EXTRAUSERS_PASSWD_FILE) != 0 &&
+	                      access (EXTRAUSERS_PASSWD_FILE, F_OK) == 0;
 
 	if (pw_lock () == 0) {
+		if (try_extrausers) {
+			pw_setdbname (EXTRAUSERS_PASSWD_FILE);
+			update_noshadow ();
+			return;
+		}
 		(void) fprintf (stderr,
 		                _("%s: cannot lock %s; try again later.\n"),
 		                Prog, pw_dbname ());
@@ -553,6 +560,20 @@ static void update_noshadow (void)
 	}
 	pw_locked = true;
 	if (pw_open (O_RDWR) == 0) {
+		if (try_extrausers) {
+			if (pw_unlock () == 0) {
+				(void) fprintf (stderr,
+				                _("%s: failed to unlock %s\n"),
+				                Prog, pw_dbname ());
+				SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
+				/* continue */
+			}
+			pw_locked = false;
+
+			pw_setdbname (EXTRAUSERS_PASSWD_FILE);
+			update_noshadow ();
+			return;
+		}
 		(void) fprintf (stderr,
 		                _("%s: cannot open %s\n"),
 		                Prog, pw_dbname ());
@@ -561,6 +582,21 @@ static void update_noshadow (void)
 	}
 	pw = pw_locate (name);
 	if (NULL == pw) {
+		if (try_extrausers) {
+			(void) pw_close ();
+			if (pw_unlock () == 0) {
+				(void) fprintf (stderr,
+				                _("%s: failed to unlock %s\n"),
+				                Prog, pw_dbname ());
+				SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
+				/* continue */
+			}
+			pw_locked = false;
+
+			pw_setdbname (EXTRAUSERS_PASSWD_FILE);
+			update_noshadow ();
+			return;
+		}
 		(void) fprintf (stderr,
 		                _("%s: user '%s' does not exist in %s\n"),
 		                Prog, name, pw_dbname ());
@@ -598,8 +634,15 @@ static void update_shadow (void)
 {
 	const struct spwd *sp;
 	struct spwd *nsp;
+	bool try_extrausers = strcmp (spw_dbname (), EXTRAUSERS_SHADOW_FILE) != 0 &&
+	                      access (EXTRAUSERS_SHADOW_FILE, F_OK) == 0;
 
 	if (spw_lock () == 0) {
+		if (try_extrausers) {
+			spw_setdbname (EXTRAUSERS_SHADOW_FILE);
+			update_shadow ();
+			return;
+		}
 		(void) fprintf (stderr,
 		                _("%s: cannot lock %s; try again later.\n"),
 		                Prog, spw_dbname ());
@@ -607,6 +650,20 @@ static void update_shadow (void)
 	}
 	spw_locked = true;
 	if (spw_open (O_RDWR) == 0) {
+		if (try_extrausers) {
+			if (spw_unlock () == 0) {
+				(void) fprintf (stderr,
+						        _("%s: failed to unlock %s\n"),
+						        Prog, spw_dbname ());
+				SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
+				/* continue */
+			}
+			spw_locked = false;
+
+			spw_setdbname (EXTRAUSERS_SHADOW_FILE);
+			update_shadow ();
+			return;
+		}
 		(void) fprintf (stderr,
 		                _("%s: cannot open %s\n"),
 		                Prog, spw_dbname ());
@@ -617,7 +674,9 @@ static void update_shadow (void)
 	if (NULL == sp) {
 		/* Try to update the password in /etc/passwd instead. */
 		(void) spw_close ();
-		update_noshadow ();
+		if (!try_extrausers) {
+			update_noshadow ();
+		}
 		if (spw_unlock () == 0) {
 			(void) fprintf (stderr,
 			                _("%s: failed to unlock %s\n"),
@@ -626,6 +685,10 @@ static void update_shadow (void)
 			/* continue */
 		}
 		spw_locked = false;
+		if (try_extrausers) {
+			spw_setdbname (EXTRAUSERS_SHADOW_FILE);
+			update_shadow ();
+		}
 		return;
 	}
 	nsp = __spw_dup (sp);
Index: shadow-4.1.5.1/lib/commonio.c
===================================================================
--- shadow-4.1.5.1.orig/lib/commonio.c
+++ shadow-4.1.5.1/lib/commonio.c
@@ -401,6 +401,7 @@ int commonio_lock_nowait (struct commoni
 int commonio_lock (struct commonio_db *db)
 {
 #ifdef HAVE_LCKPWDF
+  if (strncmp(db->filename, "/etc/", 5) == 0) {
 	/*
 	 * only if the system libc has a real lckpwdf() - the one from
 	 * lockpw.c calls us and would cause infinite recursion!
@@ -428,7 +429,9 @@ int commonio_lock (struct commonio_db *d
 
 	ulckpwdf ();
 	return 0;		/* failure */
-#else				/* !HAVE_LCKPWDF */
+  } else /* strncmp(db->filename, "/etc/", 5) == 0 */
+#endif				/* HAVE_LCKPWDF */
+  {
 	int i;
 
 	/*
@@ -456,7 +459,7 @@ int commonio_lock (struct commonio_db *d
 		}
 	}
 	return 0;		/* failure */
-#endif				/* !HAVE_LCKPWDF */
+  }
 }
 
 static void dec_lock_count (void)
Download as text