|
Lines 187-213
done:
Link Here
|
| 187 |
|
187 |
|
| 188 |
/* return 1 if user allows given key */ |
188 |
/* return 1 if user allows given key */ |
| 189 |
static int |
189 |
static int |
| 190 |
user_key_allowed2(struct passwd *pw, Key *key, char *file) |
190 |
user_search_key_in_file(FILE *f, char *file, Key* key, struct passwd *pw) |
| 191 |
{ |
191 |
{ |
| 192 |
char line[SSH_MAX_PUBKEY_BYTES]; |
192 |
char line[SSH_MAX_PUBKEY_BYTES]; |
| 193 |
const char *reason; |
193 |
const char *reason; |
| 194 |
int found_key = 0; |
194 |
int found_key = 0; |
| 195 |
FILE *f; |
|
|
| 196 |
u_long linenum = 0; |
195 |
u_long linenum = 0; |
| 197 |
Key *found; |
196 |
Key *found; |
| 198 |
char *fp; |
197 |
char *fp; |
| 199 |
|
198 |
|
| 200 |
/* Temporarily use the user's uid. */ |
|
|
| 201 |
temporarily_use_uid(pw); |
| 202 |
|
| 203 |
debug("trying public key file %s", file); |
| 204 |
f = auth_openkeyfile(file, pw, options.strict_modes); |
| 205 |
|
| 206 |
if (!f) { |
| 207 |
restore_uid(); |
| 208 |
return 0; |
| 209 |
} |
| 210 |
|
| 211 |
found_key = 0; |
199 |
found_key = 0; |
| 212 |
found = key_new(key_is_cert(key) ? KEY_UNSPEC : key->type); |
200 |
found = key_new(key_is_cert(key) ? KEY_UNSPEC : key->type); |
| 213 |
|
201 |
|
|
Lines 278-285
user_key_allowed2(struct passwd *pw, Key
Link Here
|
| 278 |
break; |
266 |
break; |
| 279 |
} |
267 |
} |
| 280 |
} |
268 |
} |
| 281 |
restore_uid(); |
|
|
| 282 |
fclose(f); |
| 283 |
key_free(found); |
269 |
key_free(found); |
| 284 |
if (!found_key) |
270 |
if (!found_key) |
| 285 |
debug2("key not found"); |
271 |
debug2("key not found"); |
|
Lines 327-339
user_cert_trusted_ca(struct passwd *pw,
Link Here
|
| 327 |
return ret; |
313 |
return ret; |
| 328 |
} |
314 |
} |
| 329 |
|
315 |
|
| 330 |
/* check whether given key is in .ssh/authorized_keys* */ |
316 |
/* return 1 if user allows given key */ |
|
|
317 |
static int |
| 318 |
user_key_allowed2(struct passwd *pw, Key *key, char *file) |
| 319 |
{ |
| 320 |
FILE *f; |
| 321 |
int found_key = 0; |
| 322 |
|
| 323 |
/* Temporarily use the user's uid. */ |
| 324 |
temporarily_use_uid(pw); |
| 325 |
|
| 326 |
debug("trying public key file %s", file); |
| 327 |
f = auth_openkeyfile(file, pw, options.strict_modes); |
| 328 |
|
| 329 |
if (f) { |
| 330 |
found_key = user_search_key_in_file (f, file, key, pw); |
| 331 |
fclose(f); |
| 332 |
} |
| 333 |
|
| 334 |
restore_uid(); |
| 335 |
return found_key; |
| 336 |
} |
| 337 |
|
| 338 |
#ifdef WITH_PUBKEY_AGENT |
| 339 |
|
| 340 |
#define WHITESPACE " \t\r\n" |
| 341 |
|
| 342 |
/* return 1 if user allows given key */ |
| 343 |
static int |
| 344 |
user_key_via_agent_allowed2(struct passwd *pw, Key *key) |
| 345 |
{ |
| 346 |
FILE *f; |
| 347 |
int found_key = 0; |
| 348 |
char *pubkey_agent_string = NULL; |
| 349 |
char *tmp_pubkey_agent_string = NULL; |
| 350 |
char *progname; |
| 351 |
char *cp; |
| 352 |
struct passwd *runas_pw; |
| 353 |
struct stat st; |
| 354 |
|
| 355 |
if (options.pubkey_agent == NULL || options.pubkey_agent[0] != '/') |
| 356 |
return -1; |
| 357 |
|
| 358 |
/* get the run as identity from config */ |
| 359 |
runas_pw = (options.pubkey_agent_runas == NULL)? pw |
| 360 |
: getpwnam (options.pubkey_agent_runas); |
| 361 |
if (!runas_pw) { |
| 362 |
error("%s: getpwnam(\"%s\"): %s", __func__, |
| 363 |
options.pubkey_agent_runas, strerror(errno)); |
| 364 |
return 0; |
| 365 |
} |
| 366 |
|
| 367 |
/* Temporarily use the specified uid. */ |
| 368 |
if (runas_pw->pw_uid != 0) |
| 369 |
temporarily_use_uid(runas_pw); |
| 370 |
|
| 371 |
pubkey_agent_string = percent_expand(options.pubkey_agent, |
| 372 |
"h", pw->pw_dir, "u", pw->pw_name, (char *)NULL); |
| 373 |
|
| 374 |
/* Test whether agent can be modified by non root user */ |
| 375 |
tmp_pubkey_agent_string = xstrdup (pubkey_agent_string); |
| 376 |
progname = strtok (tmp_pubkey_agent_string, WHITESPACE); |
| 377 |
|
| 378 |
debug3("%s: checking program '%s'", __func__, progname); |
| 379 |
|
| 380 |
if (stat (progname, &st) < 0) { |
| 381 |
error("%s: stat(\"%s\"): %s", __func__, |
| 382 |
progname, strerror(errno)); |
| 383 |
goto go_away; |
| 384 |
} |
| 385 |
|
| 386 |
if (st.st_uid != 0 || (st.st_mode & 022) != 0) { |
| 387 |
error("bad ownership or modes for pubkey agent \"%s\"", |
| 388 |
progname); |
| 389 |
goto go_away; |
| 390 |
} |
| 391 |
|
| 392 |
if (!S_ISREG(st.st_mode)) { |
| 393 |
error("pubkey agent \"%s\" is not a regular file", |
| 394 |
progname); |
| 395 |
goto go_away; |
| 396 |
} |
| 397 |
|
| 398 |
/* |
| 399 |
* Descend the path, checking that each component is a |
| 400 |
* root-owned directory with strict permissions. |
| 401 |
*/ |
| 402 |
do { |
| 403 |
if ((cp = strrchr(progname, '/')) == NULL) |
| 404 |
break; |
| 405 |
else |
| 406 |
*cp = '\0'; |
| 407 |
|
| 408 |
debug3("%s: checking component '%s'", __func__, progname); |
| 409 |
|
| 410 |
if (stat(progname, &st) != 0) { |
| 411 |
error("%s: stat(\"%s\"): %s", __func__, |
| 412 |
progname, strerror(errno)); |
| 413 |
goto go_away; |
| 414 |
} |
| 415 |
if (st.st_uid != 0 || (st.st_mode & 022) != 0) { |
| 416 |
error("bad ownership or modes for pubkey agent path component \"%s\"", |
| 417 |
progname); |
| 418 |
goto go_away; |
| 419 |
} |
| 420 |
if (!S_ISDIR(st.st_mode)) { |
| 421 |
error("pubkey agent path component \"%s\" is not a directory", |
| 422 |
progname); |
| 423 |
goto go_away; |
| 424 |
} |
| 425 |
} while (0); |
| 426 |
|
| 427 |
/* open the pipe and read the keys */ |
| 428 |
f = popen (pubkey_agent_string, "r"); |
| 429 |
if (!f) { |
| 430 |
error("%s: popen (\"%s\", \"r\"): %s", __func__, |
| 431 |
pubkey_agent_string, strerror (errno)); |
| 432 |
goto go_away; |
| 433 |
} |
| 434 |
|
| 435 |
found_key = user_search_key_in_file (f, options.pubkey_agent, key, pw); |
| 436 |
pclose (f); |
| 437 |
|
| 438 |
go_away: |
| 439 |
if (tmp_pubkey_agent_string) |
| 440 |
xfree (tmp_pubkey_agent_string); |
| 441 |
if (pubkey_agent_string) |
| 442 |
xfree (pubkey_agent_string); |
| 443 |
|
| 444 |
if (runas_pw->pw_uid != 0) |
| 445 |
restore_uid(); |
| 446 |
return found_key; |
| 447 |
} |
| 448 |
#endif |
| 449 |
|
| 450 |
/* check whether given key is in <pkey_agent or .ssh/authorized_keys* */ |
| 331 |
int |
451 |
int |
| 332 |
user_key_allowed(struct passwd *pw, Key *key) |
452 |
user_key_allowed(struct passwd *pw, Key *key) |
| 333 |
{ |
453 |
{ |
| 334 |
int success; |
454 |
int success; |
| 335 |
char *file; |
455 |
char *file; |
| 336 |
|
456 |
|
|
|
457 |
#ifdef WITH_PUBKEY_AGENT |
| 458 |
success = user_key_via_agent_allowed2(pw, key); |
| 459 |
if (success >= 0) |
| 460 |
return success; |
| 461 |
#endif |
| 462 |
|
| 337 |
if (auth_key_is_revoked(key)) |
463 |
if (auth_key_is_revoked(key)) |
| 338 |
return 0; |
464 |
return 0; |
| 339 |
if (key_is_cert(key) && auth_key_is_revoked(key->cert->signature_key)) |
465 |
if (key_is_cert(key) && auth_key_is_revoked(key->cert->signature_key)) |