tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
pam_ssh_agent_auth: 0.9.5 -> 0.10.3
Robin Gloster
9 years ago
64370336
96b4d691
+2
-346
2 changed files
expand all
collapse all
unified
split
pkgs
os-specific
linux
pam_ssh_agent_auth
default.nix
multiple-key-files.patch
+2
-8
pkgs/os-specific/linux/pam_ssh_agent_auth/default.nix
···
1
1
{ stdenv, fetchurl, pam, openssl, perl }:
2
2
3
3
stdenv.mkDerivation rec {
4
4
-
name = "pam_ssh_agent_auth-0.9.5";
4
4
+
name = "pam_ssh_agent_auth-0.10.3";
5
5
6
6
src = fetchurl {
7
7
url = "mirror://sourceforge/pamsshagentauth/${name}.tar.bz2";
8
8
-
sha256 = "1aihfyj17nvqhf0d5i0dg2lsly3r24xjyx0sfqpf60s0libkp4y0";
8
8
+
sha256 = "0qx78x7nvqdscyp04hfijl4rgyf64xy03prr28hipvgasrcd6lrw";
9
9
};
10
10
-
11
11
-
patches =
12
12
-
[ # Allow multiple colon-separated authorized keys files to be
13
13
-
# specified in the file= option.
14
14
-
./multiple-key-files.patch
15
15
-
];
16
10
17
11
buildInputs = [ pam openssl perl ];
18
12
-338
pkgs/os-specific/linux/pam_ssh_agent_auth/multiple-key-files.patch
···
1
1
-
diff -ru -x '*~' pam_ssh_agent_auth-0.9.4-orig/iterate_ssh_agent_keys.c pam_ssh_agent_auth-0.9.4/iterate_ssh_agent_keys.c
2
2
-
--- pam_ssh_agent_auth-0.9.4-orig/iterate_ssh_agent_keys.c 2012-06-28 01:47:49.000000000 +0000
3
3
-
+++ pam_ssh_agent_auth-0.9.4/iterate_ssh_agent_keys.c 2012-12-17 19:29:16.014226336 +0000
4
4
-
@@ -69,14 +69,14 @@
5
5
-
return cookie;
6
6
-
}
7
7
-
8
8
-
-int
9
9
-
+const char *
10
10
-
pamsshagentauth_find_authorized_keys(uid_t uid)
11
11
-
{
12
12
-
Identity *id;
13
13
-
Key *key;
14
14
-
AuthenticationConnection *ac;
15
15
-
char *comment;
16
16
-
- uint8_t retval = 0;
17
17
-
+ const char *key_file = 0;
18
18
-
19
19
-
OpenSSL_add_all_digests();
20
20
-
session_id2 = pamsshagentauth_session_id2_gen();
21
21
-
@@ -90,13 +90,11 @@
22
22
-
id->key = key;
23
23
-
id->filename = comment;
24
24
-
id->ac = ac;
25
25
-
- if(userauth_pubkey_from_id(id)) {
26
26
-
- retval = 1;
27
27
-
- }
28
28
-
+ key_file = userauth_pubkey_from_id(id);
29
29
-
pamsshagentauth_xfree(id->filename);
30
30
-
pamsshagentauth_key_free(id->key);
31
31
-
pamsshagentauth_xfree(id);
32
32
-
- if(retval == 1)
33
33
-
+ if(key_file)
34
34
-
break;
35
35
-
}
36
36
-
}
37
37
-
@@ -107,5 +105,5 @@
38
38
-
}
39
39
-
pamsshagentauth_xfree(session_id2);
40
40
-
EVP_cleanup();
41
41
-
- return retval;
42
42
-
+ return key_file;
43
43
-
}
44
44
-
diff -ru -x '*~' pam_ssh_agent_auth-0.9.4-orig/iterate_ssh_agent_keys.h pam_ssh_agent_auth-0.9.4/iterate_ssh_agent_keys.h
45
45
-
--- pam_ssh_agent_auth-0.9.4-orig/iterate_ssh_agent_keys.h 2012-06-28 01:47:49.000000000 +0000
46
46
-
+++ pam_ssh_agent_auth-0.9.4/iterate_ssh_agent_keys.h 2012-12-17 19:28:57.454334806 +0000
47
47
-
@@ -31,6 +31,6 @@
48
48
-
#ifndef _ITERATE_SSH_AGENT_KEYS_H
49
49
-
#define _ITERATE_SSH_AGENT_KEYS_H
50
50
-
51
51
-
-int pamsshagentauth_find_authorized_keys(uid_t);
52
52
-
+const char * pamsshagentauth_find_authorized_keys(uid_t);
53
53
-
54
54
-
#endif
55
55
-
diff -ru -x '*~' pam_ssh_agent_auth-0.9.4-orig/pam_ssh_agent_auth.c pam_ssh_agent_auth-0.9.4/pam_ssh_agent_auth.c
56
56
-
--- pam_ssh_agent_auth-0.9.4-orig/pam_ssh_agent_auth.c 2012-06-28 01:47:49.000000000 +0000
57
57
-
+++ pam_ssh_agent_auth-0.9.4/pam_ssh_agent_auth.c 2012-12-17 19:30:24.013830673 +0000
58
58
-
@@ -60,7 +60,6 @@
59
59
-
60
60
-
#define strncasecmp_literal(A,B) strncasecmp( A, B, sizeof(B) - 1)
61
61
-
62
62
-
-char *authorized_keys_file = NULL;
63
63
-
uint8_t allow_user_owned_authorized_keys_file = 0;
64
64
-
65
65
-
#if ! HAVE___PROGNAME || HAVE_BUNDLE
66
66
-
@@ -161,15 +160,13 @@
67
67
-
goto cleanexit;
68
68
-
}
69
69
-
70
70
-
- if(authorized_keys_file_input && user) {
71
71
-
- /*
72
72
-
- * user is the name of the target-user, and so must be used for validating the authorized_keys file
73
73
-
- */
74
74
-
- parse_authorized_key_file(user, authorized_keys_file_input);
75
75
-
- } else {
76
76
-
- pamsshagentauth_verbose("Using default file=/etc/security/authorized_keys");
77
77
-
- authorized_keys_file = pamsshagentauth_xstrdup("/etc/security/authorized_keys");
78
78
-
- }
79
79
-
+ if (!authorized_keys_file_input || !user)
80
80
-
+ authorized_keys_file_input = "/etc/security/authorized_keys";
81
81
-
+
82
82
-
+ /*
83
83
-
+ * user is the name of the target-user, and so must be used for validating the authorized_keys file
84
84
-
+ */
85
85
-
+ parse_authorized_key_files(user, authorized_keys_file_input);
86
86
-
87
87
-
/*
88
88
-
* PAM_USER and PAM_RUSER do not necessarily have to get set by the calling application, and we may be unable to divine the latter.
89
89
-
@@ -177,16 +174,17 @@
90
90
-
*/
91
91
-
92
92
-
if(user && strlen(ruser) > 0) {
93
93
-
- pamsshagentauth_verbose("Attempting authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
94
94
-
+ pamsshagentauth_verbose("Attempting authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file_input);
95
95
-
96
96
-
/*
97
97
-
* this pw_uid is used to validate the SSH_AUTH_SOCK, and so must be the uid of the ruser invoking the program, not the target-user
98
98
-
*/
99
99
-
- if(pamsshagentauth_find_authorized_keys(getpwnam(ruser)->pw_uid)) {
100
100
-
- pamsshagentauth_logit("Authenticated: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
101
101
-
+ const char *key_file;
102
102
-
+ if((key_file = pamsshagentauth_find_authorized_keys(getpwnam(ruser)->pw_uid))) {
103
103
-
+ pamsshagentauth_logit("Authenticated: `%s' as `%s' using %s", ruser, user, key_file);
104
104
-
retval = PAM_SUCCESS;
105
105
-
} else {
106
106
-
- pamsshagentauth_logit("Failed Authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
107
107
-
+ pamsshagentauth_logit("Failed Authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file_input);
108
108
-
}
109
109
-
} else {
110
110
-
pamsshagentauth_logit("No %s specified, cannot continue with this form of authentication", (user) ? "ruser" : "user" );
111
111
-
@@ -198,7 +196,7 @@
112
112
-
free(__progname);
113
113
-
#endif
114
114
-
115
115
-
- free(authorized_keys_file);
116
116
-
+ free_authorized_key_files();
117
117
-
118
118
-
return retval;
119
119
-
}
120
120
-
diff -ru -x '*~' pam_ssh_agent_auth-0.9.4-orig/pam_ssh_agent_auth.pod pam_ssh_agent_auth-0.9.4/pam_ssh_agent_auth.pod
121
121
-
--- pam_ssh_agent_auth-0.9.4-orig/pam_ssh_agent_auth.pod 2012-06-28 01:47:49.000000000 +0000
122
122
-
+++ pam_ssh_agent_auth-0.9.4/pam_ssh_agent_auth.pod 2012-12-17 19:52:35.968965448 +0000
123
123
-
@@ -26,7 +26,7 @@
124
124
-
125
125
-
=item file=<path to authorized_keys>
126
126
-
127
127
-
-Specify the path to the authorized_keys file(s) you would like to use for authentication. Subject to tilde and % EXPANSIONS (below)
128
128
-
+Specify the path(s) to the authorized_keys file(s) you would like to use for authentication. Subject to tilde and % EXPANSIONS (below). Paths are separated using colons.
129
129
-
130
130
-
=item allow_user_owned_authorized_keys_file
131
131
-
132
132
-
diff -ru -x '*~' pam_ssh_agent_auth-0.9.4-orig/pam_user_authorized_keys.c pam_ssh_agent_auth-0.9.4/pam_user_authorized_keys.c
133
133
-
--- pam_ssh_agent_auth-0.9.4-orig/pam_user_authorized_keys.c 2012-06-28 01:47:49.000000000 +0000
134
134
-
+++ pam_ssh_agent_auth-0.9.4/pam_user_authorized_keys.c 2012-12-17 19:32:20.830157313 +0000
135
135
-
@@ -79,66 +79,96 @@
136
136
-
137
137
-
#include "identity.h"
138
138
-
#include "pam_user_key_allowed2.h"
139
139
-
+#include "pam_user_authorized_keys.h"
140
140
-
141
141
-
-extern char *authorized_keys_file;
142
142
-
+#define MAX_AUTHORIZED_KEY_FILES 16
143
143
-
+
144
144
-
+char *authorized_keys_files[MAX_AUTHORIZED_KEY_FILES];
145
145
-
+unsigned int nr_authorized_keys_files = 0;
146
146
-
extern uint8_t allow_user_owned_authorized_keys_file;
147
147
-
uid_t authorized_keys_file_allowed_owner_uid;
148
148
-
149
149
-
void
150
150
-
-parse_authorized_key_file(const char *user, const char *authorized_keys_file_input)
151
151
-
+parse_authorized_key_files(const char *user, const char *authorized_keys_file_input)
152
152
-
{
153
153
-
- char fqdn[HOST_NAME_MAX] = "";
154
154
-
+ const char *pos = authorized_keys_file_input;
155
155
-
char hostname[HOST_NAME_MAX] = "";
156
156
-
- char auth_keys_file_buf[4096] = "";
157
157
-
- char *slash_ptr = NULL;
158
158
-
- char owner_uname[128] = "";
159
159
-
- size_t owner_uname_len = 0;
160
160
-
-
161
161
-
- /*
162
162
-
- * temporary copy, so that both tilde expansion and percent expansion both get to apply to the path
163
163
-
- */
164
164
-
- strncat(auth_keys_file_buf, authorized_keys_file_input, sizeof(auth_keys_file_buf) - 1);
165
165
-
+ char fqdn[HOST_NAME_MAX] = "";
166
166
-
+
167
167
-
+#if HAVE_GETHOSTNAME
168
168
-
+ *hostname = '\0';
169
169
-
+ gethostname(fqdn, HOST_NAME_MAX);
170
170
-
+ strncat(hostname, fqdn, strcspn(fqdn,"."));
171
171
-
+#endif
172
172
-
173
173
-
- if(allow_user_owned_authorized_keys_file)
174
174
-
- authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
175
175
-
+ while (pos) {
176
176
-
+ const char *colon = strchr(pos, ':');
177
177
-
+ char auth_keys_file_buf[4096] = "";
178
178
-
+ char *slash_ptr = NULL;
179
179
-
+ char owner_uname[128] = "";
180
180
-
+ size_t owner_uname_len = 0;
181
181
-
+
182
182
-
+ strncat(auth_keys_file_buf, pos, sizeof(auth_keys_file_buf) - 1);
183
183
-
+ if (colon) {
184
184
-
+ auth_keys_file_buf[colon - pos] = 0;
185
185
-
+ pos = colon + 1;
186
186
-
+ } else {
187
187
-
+ pos = 0;
188
188
-
+ }
189
189
-
190
190
-
- if(*auth_keys_file_buf == '~') {
191
191
-
- if(*(auth_keys_file_buf+1) == '/') {
192
192
-
+ if(allow_user_owned_authorized_keys_file)
193
193
-
authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
194
194
-
+
195
195
-
+ if(*auth_keys_file_buf == '~') {
196
196
-
+ if(*(auth_keys_file_buf+1) == '/') {
197
197
-
+ authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
198
198
-
+ }
199
199
-
+ else {
200
200
-
+ slash_ptr = strchr(auth_keys_file_buf,'/');
201
201
-
+ if(!slash_ptr)
202
202
-
+ pamsshagentauth_fatal("cannot expand tilde in path without a `/'");
203
203
-
+
204
204
-
+ owner_uname_len = slash_ptr - auth_keys_file_buf - 1;
205
205
-
+ if(owner_uname_len > (sizeof(owner_uname) - 1) )
206
206
-
+ pamsshagentauth_fatal("Username too long");
207
207
-
+
208
208
-
+ strncat(owner_uname, auth_keys_file_buf + 1, owner_uname_len);
209
209
-
+ if(!authorized_keys_file_allowed_owner_uid)
210
210
-
+ authorized_keys_file_allowed_owner_uid = getpwnam(owner_uname)->pw_uid;
211
211
-
+ }
212
212
-
+ char *tmp = pamsshagentauth_tilde_expand_filename(auth_keys_file_buf, authorized_keys_file_allowed_owner_uid);
213
213
-
+ strncpy(auth_keys_file_buf, tmp, sizeof(auth_keys_file_buf) - 1 );
214
214
-
+ pamsshagentauth_xfree(tmp);
215
215
-
}
216
216
-
- else {
217
217
-
- slash_ptr = strchr(auth_keys_file_buf,'/');
218
218
-
- if(!slash_ptr)
219
219
-
- pamsshagentauth_fatal("cannot expand tilde in path without a `/'");
220
220
-
-
221
221
-
- owner_uname_len = slash_ptr - auth_keys_file_buf - 1;
222
222
-
- if(owner_uname_len > (sizeof(owner_uname) - 1) )
223
223
-
- pamsshagentauth_fatal("Username too long");
224
224
-
-
225
225
-
- strncat(owner_uname, auth_keys_file_buf + 1, owner_uname_len);
226
226
-
- if(!authorized_keys_file_allowed_owner_uid)
227
227
-
- authorized_keys_file_allowed_owner_uid = getpwnam(owner_uname)->pw_uid;
228
228
-
+
229
229
-
+ if(strstr(auth_keys_file_buf, "%h")) {
230
230
-
+ authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
231
231
-
}
232
232
-
- authorized_keys_file = pamsshagentauth_tilde_expand_filename(auth_keys_file_buf, authorized_keys_file_allowed_owner_uid);
233
233
-
- strncpy(auth_keys_file_buf, authorized_keys_file, sizeof(auth_keys_file_buf) - 1 );
234
234
-
- pamsshagentauth_xfree(authorized_keys_file) /* when we percent_expand later, we'd step on this, so free it immediately */;
235
235
-
- }
236
236
-
237
237
-
- if(strstr(auth_keys_file_buf, "%h")) {
238
238
-
- authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
239
239
-
+ if (nr_authorized_keys_files >= MAX_AUTHORIZED_KEY_FILES)
240
240
-
+ pamsshagentauth_fatal("Too many authorized key files");
241
241
-
+ authorized_keys_files[nr_authorized_keys_files++] =
242
242
-
+ pamsshagentauth_percent_expand(auth_keys_file_buf, "h", getpwnam(user)->pw_dir, "H", hostname, "f", fqdn, "u", user, NULL);
243
243
-
}
244
244
-
+}
245
245
-
246
246
-
-#if HAVE_GETHOSTNAME
247
247
-
- *hostname = '\0';
248
248
-
- gethostname(fqdn, HOST_NAME_MAX);
249
249
-
- strncat(hostname, fqdn, strcspn(fqdn,"."));
250
250
-
-#endif
251
251
-
- authorized_keys_file = pamsshagentauth_percent_expand(auth_keys_file_buf, "h", getpwnam(user)->pw_dir, "H", hostname, "f", fqdn, "u", user, NULL);
252
252
-
+void
253
253
-
+free_authorized_key_files()
254
254
-
+{
255
255
-
+ unsigned int n;
256
256
-
+ for (n = 0; n < nr_authorized_keys_files; n++)
257
257
-
+ free(authorized_keys_files[n]);
258
258
-
+ nr_authorized_keys_files = 0;
259
259
-
}
260
260
-
261
261
-
-int
262
262
-
+const char *
263
263
-
pam_user_key_allowed(Key * key)
264
264
-
{
265
265
-
- return pam_user_key_allowed2(getpwuid(authorized_keys_file_allowed_owner_uid), key, authorized_keys_file)
266
266
-
- || pam_user_key_allowed2(getpwuid(0), key, authorized_keys_file);
267
267
-
+ unsigned int n;
268
268
-
+ for (n = 0; n < nr_authorized_keys_files; n++) {
269
269
-
+ if (pam_user_key_allowed2(getpwuid(authorized_keys_file_allowed_owner_uid), key, authorized_keys_files[n])
270
270
-
+ || pam_user_key_allowed2(getpwuid(0), key, authorized_keys_files[n]))
271
271
-
+ return authorized_keys_files[n];
272
272
-
+ }
273
273
-
+ return 0;
274
274
-
}
275
275
-
diff -ru -x '*~' pam_ssh_agent_auth-0.9.4-orig/pam_user_authorized_keys.h pam_ssh_agent_auth-0.9.4/pam_user_authorized_keys.h
276
276
-
--- pam_ssh_agent_auth-0.9.4-orig/pam_user_authorized_keys.h 2010-01-13 02:17:01.000000000 +0000
277
277
-
+++ pam_ssh_agent_auth-0.9.4/pam_user_authorized_keys.h 2012-12-17 19:24:34.477894517 +0000
278
278
-
@@ -28,11 +28,12 @@
279
279
-
*/
280
280
-
281
281
-
282
282
-
-#ifndef _PAM_USER_KEY_ALLOWED_H
283
283
-
-#define _PAM_USER_KEY_ALLOWED_H
284
284
-
+#ifndef _PAM_USER_AUTHORIZED_KEYS_H
285
285
-
+#define _PAM_USER_AUTHORIZED_KEYS_H
286
286
-
287
287
-
#include "identity.h"
288
288
-
-int pam_user_key_allowed(Key *);
289
289
-
-void parse_authorized_key_file(const char *, const char *);
290
290
-
+const char * pam_user_key_allowed(Key *);
291
291
-
+void parse_authorized_key_files(const char *, const char *);
292
292
-
+void free_authorized_key_files();
293
293
-
294
294
-
#endif
295
295
-
diff -ru -x '*~' pam_ssh_agent_auth-0.9.4-orig/userauth_pubkey_from_id.c pam_ssh_agent_auth-0.9.4/userauth_pubkey_from_id.c
296
296
-
--- pam_ssh_agent_auth-0.9.4-orig/userauth_pubkey_from_id.c 2012-06-28 01:47:49.000000000 +0000
297
297
-
+++ pam_ssh_agent_auth-0.9.4/userauth_pubkey_from_id.c 2012-12-17 19:27:30.813843933 +0000
298
298
-
@@ -51,7 +51,7 @@
299
299
-
extern u_char *session_id2;
300
300
-
extern uint8_t session_id_len;
301
301
-
302
302
-
-int
303
303
-
+const char *
304
304
-
userauth_pubkey_from_id(Identity * id)
305
305
-
{
306
306
-
Buffer b = { 0 };
307
307
-
@@ -59,11 +59,12 @@
308
308
-
u_char *pkblob = NULL, *sig = NULL;
309
309
-
u_int blen = 0, slen = 0;
310
310
-
int authenticated = 0;
311
311
-
+ const char *key_file;
312
312
-
313
313
-
pkalg = (char *) key_ssh_name(id->key);
314
314
-
315
315
-
/* first test if this key is even allowed */
316
316
-
- if(! pam_user_key_allowed(id->key))
317
317
-
+ if(!(key_file = pam_user_key_allowed(id->key)))
318
318
-
goto user_auth_clean_exit;
319
319
-
320
320
-
if(pamsshagentauth_key_to_blob(id->key, &pkblob, &blen) == 0)
321
321
-
@@ -96,5 +97,5 @@
322
322
-
if(pkblob != NULL)
323
323
-
pamsshagentauth_xfree(pkblob);
324
324
-
CRYPTO_cleanup_all_ex_data();
325
325
-
- return authenticated;
326
326
-
+ return authenticated ? key_file : 0;
327
327
-
}
328
328
-
diff -ru -x '*~' pam_ssh_agent_auth-0.9.4-orig/userauth_pubkey_from_id.h pam_ssh_agent_auth-0.9.4/userauth_pubkey_from_id.h
329
329
-
--- pam_ssh_agent_auth-0.9.4-orig/userauth_pubkey_from_id.h 2010-01-13 02:17:01.000000000 +0000
330
330
-
+++ pam_ssh_agent_auth-0.9.4/userauth_pubkey_from_id.h 2012-12-17 19:25:54.893412987 +0000
331
331
-
@@ -32,6 +32,6 @@
332
332
-
#define _USERAUTH_PUBKEY_FROM_ID_H
333
333
-
334
334
-
#include <identity.h>
335
335
-
-int userauth_pubkey_from_id(Identity *);
336
336
-
+const char * userauth_pubkey_from_id(Identity *);
337
337
-
338
338
-
#endif