local.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * $Id: local.c,v 1.5 2007/01/06 20:15:35 pnixon Exp $
  3. *
  4. * Copyright (C) 1996 Lars Fenneberg
  5. *
  6. * See the file COPYRIGHT for the respective terms and conditions.
  7. * If the file is missing contact me at lf@elemental.net
  8. * and I'll send you a copy.
  9. *
  10. */
  11. #include <config.h>
  12. #include <includes.h>
  13. #include <freeradius-client.h>
  14. #include <messages.h>
  15. #include <radlogin.h>
  16. extern ENV *env;
  17. LFUNC auth_local(char const *username, char const *passwd)
  18. {
  19. struct passwd *pw;
  20. char *xpasswd;
  21. #ifdef SHADOW_PASSWORD
  22. struct spwd *spw;
  23. #endif
  24. if ((pw = getpwnam(username)) == NULL) {
  25. endpwent();
  26. rc_log(LOG_NOTICE, "authentication FAILED, type local, username %s", username);
  27. printf(SC_LOCAL_FAILED);
  28. return NULL;
  29. }
  30. endpwent();
  31. #ifdef SHADOW_PASSWORD
  32. if((spw = getspnam(pw->pw_name)) == NULL) {
  33. endspent();
  34. rc_log(LOG_NOTICE, "authentication FAILED, type local, username %s", username);
  35. printf(SC_LOCAL_FAILED);
  36. return NULL;
  37. }
  38. else
  39. {
  40. pw->pw_passwd = spw->sp_pwdp;
  41. }
  42. endspent();
  43. #endif /* SHADOW_PASSWORD */
  44. xpasswd = crypt(passwd, pw->pw_passwd);
  45. if (*pw->pw_passwd == '\0' || !xpasswd || strcmp(xpasswd, pw->pw_passwd)) {
  46. rc_log(LOG_NOTICE, "authentication FAILED, type local, username %s", username);
  47. printf(SC_LOCAL_FAILED);
  48. return NULL;
  49. }
  50. rc_log(LOG_NOTICE, "authentication OK, type local, username %s", username);
  51. printf(SC_LOCAL_OK);
  52. return local_login;
  53. }
  54. void
  55. local_login(rc_handle *rh, char const *username)
  56. {
  57. char *login_local = rc_conf_str(rh, "login_local");
  58. /* login should spot this... but who knows what old /bin/logins
  59. * may be still around
  60. */
  61. if (*username == '-') {
  62. rc_log(LOG_WARNING, "username can't start with a dash");
  63. exit(ERROR_RC);
  64. }
  65. /* the new shadow login seems to require either a -r or a -h
  66. * flag for -f to work (so source code, lmain.c) so we supply
  67. * it here. shouldn't hurt on other systems, -lf, 03/13/96
  68. */
  69. execle(login_local, login_local, "-h", "localhost", "-f", username, NULL, env->env);
  70. rc_log(LOG_ERR, "couldn't execute %s: %s", login_local, strerror(errno));
  71. sleep(1); /* give the user time to read */
  72. exit(ERROR_RC);
  73. }