patch-src_auth_c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. $OpenBSD: patch-src_auth_c,v 1.1.1.1 2009/06/18 19:45:14 landry Exp $
  2. replace linux-only funcs by their posix equivalents
  3. --- src/auth.c.orig Sun Jun 29 23:45:05 2008
  4. +++ src/auth.c Wed Jun 17 22:07:23 2009
  5. @@ -45,10 +45,6 @@
  6. #include <grp.h>
  7. #include "errors.h"
  8. -struct group *fgetgrent(FILE * stream);
  9. -struct passwd *fgetpwent(FILE * stream);
  10. -int setgroups(size_t size, const gid_t * list);
  11. -
  12. char *get_real_name(const char *command)
  13. {
  14. char *real_PATH, *path, *subtoken, *PATH;
  15. @@ -106,13 +102,10 @@ inline int *fixed_realloc(int *ptr, int actual, int si
  16. int set_additional_g(const char *username)
  17. {
  18. int i, x = 0;
  19. - int *groups = NULL;
  20. + gid_t *groups = NULL;
  21. struct group *ag;
  22. - FILE *file;
  23. - if ((file = fopen("/etc/group", "r")) == NULL)
  24. - return ERR_OPEN_FILE_GROUP;
  25. - while ((ag = fgetgrent(file)) != NULL) {
  26. + while ((ag = getgrent()) != NULL) {
  27. for (i = 0; ag->gr_mem[i]; i++) {
  28. if (!strcmp(ag->gr_mem[i], username)) {
  29. x += 1;
  30. @@ -122,7 +115,7 @@ int set_additional_g(const char *username)
  31. }
  32. }
  33. }
  34. - fclose(file);
  35. + endgrent();
  36. if (x) {
  37. if (setgroups(x, groups))
  38. return ERR_FAILED_ADDITIONAL_GIDS;
  39. @@ -134,18 +127,17 @@ int set_additional_g(const char *username)
  40. int make_me_new(const char *username, const char *password, int chk_passwd)
  41. {
  42. struct passwd *pw;
  43. +#ifdef __linux__
  44. struct spwd *sp;
  45. +#endif
  46. const char *correct;
  47. - FILE *file;
  48. char *encrypted;
  49. int error;
  50. - if ((file = fopen("/etc/passwd", "r")) == NULL)
  51. - return ERR_OPEN_FILE_PASSWD;
  52. - while ((pw = fgetpwent(file)) != NULL)
  53. + while ((pw = getpwent()) != NULL)
  54. if (!strcmp(pw->pw_name, username))
  55. break;
  56. - fclose(file);
  57. + endpwent();
  58. if (pw == NULL)
  59. return ERR_INVALID_USERNAME;
  60. if (chk_passwd) {
  61. @@ -188,14 +180,11 @@ int try(const char *username, const char *password, in
  62. int check_user(const char *username)
  63. {
  64. struct passwd *pw;
  65. - FILE *file;
  66. - if ((file = fopen("/etc/passwd", "r")) == NULL)
  67. - return ERR_OPEN_FILE_PASSWD;
  68. - while ((pw = fgetpwent(file)) != NULL)
  69. + while ((pw = getpwent()) != NULL)
  70. if (!strcmp(pw->pw_name, username))
  71. break;
  72. - fclose(file);
  73. + endpwent();
  74. if (pw == NULL)
  75. return ERR_INVALID_USERNAME;
  76. return ERR_SUCCESS;