mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

530 lines
15 KiB

  1. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  2. #
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. # Please add additional copyright information _after_ the line containing
  5. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  6. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  7. #
  8. # ROCK Linux: rock-src/package/base/pam/cvs-fixes.patch
  9. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version. A copy of the GNU General Public
  15. # License can be found at Documentation/COPYING.
  16. #
  17. # Many people helped and are helping developing ROCK Linux. Please
  18. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  19. # file for details.
  20. #
  21. # --- ROCK-COPYRIGHT-NOTE-END ---
  22. Some fixes from PAM cvs (checked out at 2003-05-03).
  23. diff -x CVS -x '*cvs*' -ruN Linux-PAM-0.77/modules/pam_unix/Makefile Linux-PAM/modules/pam_unix/Makefile
  24. --- Linux-PAM-0.77/modules/pam_unix/Makefile 2001-02-11 07:33:53.000000000 +0100
  25. +++ Linux-PAM/modules/pam_unix/Makefile 2003-01-14 06:43:07.000000000 +0100
  26. @@ -41,8 +41,10 @@
  27. ########################################################################
  28. -CFLAGS += $(USE_CRACKLIB) $(USE_LCKPWDF) $(NEED_LCKPWDF) $(EXTRAS)
  29. -LDLIBS = $(EXTRALS)
  30. +CFLAGS += $(USE_CRACKLIB) $(USE_LCKPWDF) $(NEED_LCKPWDF) $(EXTRAS) \
  31. + -I../pammodutil/include
  32. +
  33. +LDLIBS = $(EXTRALS) -L../pammodutil -lpammodutil
  34. ifdef USE_CRACKLIB
  35. CRACKLIB = -lcrack
  36. diff -x CVS -x '*cvs*' -ruN Linux-PAM-0.77/modules/pam_unix/pam_unix_passwd.c Linux-PAM/modules/pam_unix/pam_unix_passwd.c
  37. --- Linux-PAM-0.77/modules/pam_unix/pam_unix_passwd.c 2002-07-09 06:44:18.000000000 +0200
  38. +++ Linux-PAM/modules/pam_unix/pam_unix_passwd.c 2003-01-14 06:43:07.000000000 +0100
  39. @@ -88,7 +88,7 @@
  40. */
  41. #ifdef NEED_LCKPWDF
  42. -#include "./lckpwdf.-c"
  43. +# include "./lckpwdf.-c"
  44. #endif
  45. extern char *bigcrypt(const char *key, const char *salt);
  46. @@ -471,10 +471,7 @@
  47. D(("called"));
  48. - setpwent();
  49. pwd = getpwnam(forwho);
  50. - endpwent();
  51. -
  52. if (pwd == NULL)
  53. return PAM_AUTHTOK_ERR;
  54. @@ -544,6 +541,24 @@
  55. if (save_old_password(forwho, fromwhat, remember)) {
  56. return PAM_AUTHTOK_ERR;
  57. }
  58. +
  59. +#ifdef USE_LCKPWDF
  60. + /*
  61. + * These values for the number of attempts and the sleep time
  62. + * are, of course, completely arbitrary.
  63. + *
  64. + * My reading of the PAM docs is that, once pam_chauthtok()
  65. + * has been called with PAM_UPDATE_AUTHTOK, we are obliged to
  66. + * take any reasonable steps to make sure the token is
  67. + * updated; so retrying for 1/10 sec. isn't overdoing it.
  68. + */
  69. +
  70. + retval = lckpwdf();
  71. + if (retval != 0) {
  72. + return PAM_AUTHTOK_LOCK_BUSY;
  73. + }
  74. +#endif /* def USE_LCKPWDF */
  75. +
  76. if (on(UNIX_SHADOW, ctrl) || (strcmp(pwd->pw_passwd, "x") == 0)) {
  77. retval = _update_shadow(forwho, towhat);
  78. if (retval == PAM_SUCCESS)
  79. @@ -552,6 +567,10 @@
  80. retval = _update_passwd(pamh, forwho, towhat);
  81. }
  82. +#ifdef USE_LCKPWDF
  83. + ulckpwdf();
  84. +#endif /* def USE_LCKPWDF */
  85. +
  86. return retval;
  87. }
  88. @@ -563,9 +582,7 @@
  89. int retval = PAM_SUCCESS;
  90. /* UNIX passwords area */
  91. - setpwent();
  92. pwd = getpwnam(user); /* Get password file entry... */
  93. - endpwent();
  94. if (pwd == NULL)
  95. return PAM_AUTHINFO_UNAVAIL; /* We don't need to do the rest... */
  96. @@ -679,7 +696,7 @@
  97. int argc, const char **argv)
  98. {
  99. unsigned int ctrl, lctrl;
  100. - int retval, i;
  101. + int retval;
  102. int remember = -1;
  103. /* <DO NOT free() THESE> */
  104. @@ -689,33 +706,12 @@
  105. D(("called."));
  106. -#ifdef USE_LCKPWDF
  107. - /* our current locking system requires that we lock the
  108. - entire password database. This avoids both livelock
  109. - and deadlock. */
  110. - /* These values for the number of attempts and the sleep time
  111. - are, of course, completely arbitrary.
  112. - My reading of the PAM docs is that, once pam_chauthtok() has been
  113. - called with PAM_UPDATE_AUTHTOK, we are obliged to take any
  114. - reasonable steps to make sure the token is updated; so retrying
  115. - for 1/10 sec. isn't overdoing it.
  116. - The other possibility is to call lckpwdf() on the first
  117. - pam_chauthtok() pass, and hold the lock until released in the
  118. - second pass--but is this guaranteed to work? -SRL */
  119. - i=0;
  120. - while((retval = lckpwdf()) != 0 && i < 100) {
  121. - usleep(1000);
  122. - }
  123. - if(retval != 0) {
  124. - return PAM_AUTHTOK_LOCK_BUSY;
  125. - }
  126. -#endif
  127. ctrl = _set_ctrl(pamh, flags, &remember, argc, argv);
  128. /*
  129. * First get the name of a user
  130. */
  131. - retval = pam_get_user(pamh, &user, "Username: ");
  132. + retval = pam_get_user(pamh, &user, NULL);
  133. if (retval == PAM_SUCCESS) {
  134. /*
  135. * Various libraries at various times have had bugs related to
  136. @@ -725,9 +721,6 @@
  137. */
  138. if (user == NULL || !isalnum(*user)) {
  139. _log_err(LOG_ERR, pamh, "bad username [%s]", user);
  140. -#ifdef USE_LCKPWDF
  141. - ulckpwdf();
  142. -#endif
  143. return PAM_USER_UNKNOWN;
  144. }
  145. if (retval == PAM_SUCCESS && on(UNIX_DEBUG, ctrl))
  146. @@ -737,9 +730,6 @@
  147. if (on(UNIX_DEBUG, ctrl))
  148. _log_err(LOG_DEBUG, pamh,
  149. "password - could not identify user");
  150. -#ifdef USE_LCKPWDF
  151. - ulckpwdf();
  152. -#endif
  153. return retval;
  154. }
  155. @@ -761,9 +751,6 @@
  156. D(("prelim check"));
  157. if (_unix_blankpasswd(ctrl, user)) {
  158. -#ifdef USE_LCKPWDF
  159. - ulckpwdf();
  160. -#endif
  161. return PAM_SUCCESS;
  162. } else if (off(UNIX__IAMROOT, ctrl)) {
  163. @@ -773,9 +760,6 @@
  164. if (Announce == NULL) {
  165. _log_err(LOG_CRIT, pamh,
  166. "password - out of memory");
  167. -#ifdef USE_LCKPWDF
  168. - ulckpwdf();
  169. -#endif
  170. return PAM_BUF_ERR;
  171. }
  172. (void) strcpy(Announce, greeting);
  173. @@ -795,9 +779,6 @@
  174. if (retval != PAM_SUCCESS) {
  175. _log_err(LOG_NOTICE, pamh
  176. ,"password - (old) token not obtained");
  177. -#ifdef USE_LCKPWDF
  178. - ulckpwdf();
  179. -#endif
  180. return retval;
  181. }
  182. /* verify that this is the password for this user */
  183. @@ -812,9 +793,6 @@
  184. if (retval != PAM_SUCCESS) {
  185. D(("Authentication failed"));
  186. pass_old = NULL;
  187. -#ifdef USE_LCKPWDF
  188. - ulckpwdf();
  189. -#endif
  190. return retval;
  191. }
  192. retval = pam_set_item(pamh, PAM_OLDAUTHTOK, (const void *) pass_old);
  193. @@ -867,17 +845,11 @@
  194. if (retval != PAM_SUCCESS) {
  195. _log_err(LOG_NOTICE, pamh, "user not authenticated");
  196. -#ifdef USE_LCKPWDF
  197. - ulckpwdf();
  198. -#endif
  199. return retval;
  200. }
  201. retval = _unix_verify_shadow(user, ctrl);
  202. if (retval != PAM_SUCCESS) {
  203. _log_err(LOG_NOTICE, pamh, "user not authenticated 2");
  204. -#ifdef USE_LCKPWDF
  205. - ulckpwdf();
  206. -#endif
  207. return retval;
  208. }
  209. D(("get new password now"));
  210. @@ -908,9 +880,6 @@
  211. ,"password - new password not obtained");
  212. }
  213. pass_old = NULL; /* tidy up */
  214. -#ifdef USE_LCKPWDF
  215. - ulckpwdf();
  216. -#endif
  217. return retval;
  218. }
  219. D(("returned to _unix_chauthtok"));
  220. @@ -931,9 +900,6 @@
  221. _log_err(LOG_NOTICE, pamh,
  222. "new password not acceptable");
  223. pass_new = pass_old = NULL; /* tidy up */
  224. -#ifdef USE_LCKPWDF
  225. - ulckpwdf();
  226. -#endif
  227. return retval;
  228. }
  229. /*
  230. @@ -974,9 +940,6 @@
  231. _log_err(LOG_CRIT, pamh,
  232. "out of memory for password");
  233. pass_new = pass_old = NULL; /* tidy up */
  234. -#ifdef USE_LCKPWDF
  235. - ulckpwdf();
  236. -#endif
  237. return PAM_BUF_ERR;
  238. }
  239. /* copy first 8 bytes of password */
  240. @@ -998,6 +961,7 @@
  241. retval = _do_setpass(pamh, user, pass_old, tpass, ctrl,
  242. remember);
  243. +
  244. _pam_delete(tpass);
  245. pass_old = pass_new = NULL;
  246. } else { /* something has broken with the module */
  247. @@ -1008,9 +972,6 @@
  248. D(("retval was %d", retval));
  249. -#ifdef USE_LCKPWDF
  250. - ulckpwdf();
  251. -#endif
  252. return retval;
  253. }
  254. diff -x CVS -x '*cvs*' -ruN Linux-PAM-0.77/modules/pam_unix/pam_unix_sess.c Linux-PAM/modules/pam_unix/pam_unix_sess.c
  255. --- Linux-PAM-0.77/modules/pam_unix/pam_unix_sess.c 2000-12-20 06:15:05.000000000 +0100
  256. +++ Linux-PAM/modules/pam_unix/pam_unix_sess.c 2003-01-14 06:43:07.000000000 +0100
  257. @@ -53,6 +53,7 @@
  258. #include <security/_pam_macros.h>
  259. #include <security/pam_modules.h>
  260. +#include <security/_pam_modutil.h>
  261. #ifndef LINUX_PAM
  262. #include <security/pam_appl.h>
  263. @@ -71,6 +72,7 @@
  264. char *user_name, *service;
  265. unsigned int ctrl;
  266. int retval;
  267. + const char *login_name;
  268. D(("called."));
  269. @@ -89,9 +91,12 @@
  270. "open_session - error recovering service");
  271. return PAM_SESSION_ERR;
  272. }
  273. - _log_err(LOG_INFO, pamh, "session opened for user %s by %s(uid=%d)"
  274. - ,user_name
  275. - ,PAM_getlogin() == NULL ? "" : PAM_getlogin(), getuid());
  276. + login_name = _pammodutil_getlogin(pamh);
  277. + if (login_name == NULL) {
  278. + login_name = "";
  279. + }
  280. + _log_err(LOG_INFO, pamh, "session opened for user %s by %s(uid=%d)",
  281. + user_name, login_name, getuid());
  282. return PAM_SUCCESS;
  283. }
  284. diff -x CVS -x '*cvs*' -ruN Linux-PAM-0.77/modules/pam_unix/support.c Linux-PAM/modules/pam_unix/support.c
  285. --- Linux-PAM-0.77/modules/pam_unix/support.c 2002-09-23 19:33:22.000000000 +0200
  286. +++ Linux-PAM/modules/pam_unix/support.c 2003-01-14 06:43:07.000000000 +0100
  287. @@ -20,6 +20,7 @@
  288. #include <security/_pam_macros.h>
  289. #include <security/pam_modules.h>
  290. +#include <security/_pam_modutil.h>
  291. #include "md5.h"
  292. #include "support.h"
  293. @@ -107,36 +108,6 @@
  294. return retval;
  295. }
  296. - /*
  297. - * Beacause getlogin() is braindead and sometimes it just
  298. - * doesn't work, we reimplement it here.
  299. - */
  300. -char *PAM_getlogin(void)
  301. -{
  302. - struct utmp *ut, line;
  303. - char *curr_tty, *retval;
  304. - static char curr_user[sizeof(ut->ut_user) + 4];
  305. -
  306. - retval = NULL;
  307. -
  308. - curr_tty = ttyname(0);
  309. - if (curr_tty != NULL) {
  310. - D(("PAM_getlogin ttyname: %s", curr_tty));
  311. - curr_tty += 5;
  312. - setutent();
  313. - strncpy(line.ut_line, curr_tty, sizeof(line.ut_line));
  314. - if ((ut = getutline(&line)) != NULL) {
  315. - strncpy(curr_user, ut->ut_user, sizeof(ut->ut_user));
  316. - curr_user[sizeof(curr_user) - 1] = '\0';
  317. - retval = curr_user;
  318. - }
  319. - endutent();
  320. - }
  321. - D(("PAM_getlogin retval: %s", retval));
  322. -
  323. - return retval;
  324. -}
  325. -
  326. /*
  327. * set the control flags for the UNIX module.
  328. */
  329. @@ -668,10 +639,17 @@
  330. if (new != NULL) {
  331. - new->user = x_strdup(name ? name : "");
  332. + const char *login_name;
  333. +
  334. + login_name = _pammodutil_getlogin(pamh);
  335. + if (login_name == NULL) {
  336. + login_name = "";
  337. + }
  338. +
  339. + new->user = x_strdup(name ? name : "");
  340. new->uid = getuid();
  341. new->euid = geteuid();
  342. - new->name = x_strdup(PAM_getlogin()? PAM_getlogin() : "");
  343. + new->name = x_strdup(login_name);
  344. /* any previous failures for this user ? */
  345. pam_get_data(pamh, data_name, (const void **) &old);
  346. diff -x CVS -x '*cvs*' -ruN Linux-PAM-0.77/modules/pam_unix/support.h Linux-PAM/modules/pam_unix/support.h
  347. --- Linux-PAM-0.77/modules/pam_unix/support.h 2002-07-11 07:43:51.000000000 +0200
  348. +++ Linux-PAM/modules/pam_unix/support.h 2003-01-14 06:43:07.000000000 +0100
  349. @@ -125,7 +125,6 @@
  350. _pam_drop(xx); \
  351. }
  352. -extern char *PAM_getlogin(void);
  353. extern void _log_err(int err, pam_handle_t *pamh, const char *format,...);
  354. extern int _make_remark(pam_handle_t * pamh, unsigned int ctrl
  355. ,int type, const char *text);
  356. diff -x CVS -x '*cvs*' -ruN Linux-PAM-0.77/modules/pam_wheel/pam_wheel.c Linux-PAM/modules/pam_wheel/pam_wheel.c
  357. --- Linux-PAM-0.77/modules/pam_wheel/pam_wheel.c 2002-07-13 07:48:19.000000000 +0200
  358. +++ Linux-PAM/modules/pam_wheel/pam_wheel.c 2003-01-14 06:43:07.000000000 +0100
  359. @@ -43,6 +43,7 @@
  360. #define PAM_SM_ACCOUNT
  361. #include <security/pam_modules.h>
  362. +#include <security/_pam_modutil.h>
  363. /* some syslogging */
  364. @@ -110,7 +111,7 @@
  365. const char *use_group)
  366. {
  367. const char *username = NULL;
  368. - char *fromsu;
  369. + const char *fromsu;
  370. struct passwd *pwd, *tpwd;
  371. struct group *grp;
  372. int retval = PAM_AUTH_ERR;
  373. @@ -142,7 +143,7 @@
  374. }
  375. fromsu = tpwd->pw_name;
  376. } else {
  377. - fromsu = getlogin();
  378. + fromsu = _pammodutil_getlogin(pamh);
  379. if (fromsu) {
  380. tpwd = getpwnam(fromsu);
  381. }
  382. diff -x CVS -x '*cvs*' -ruN Linux-PAM-0.77/modules/pammodutil/Makefile Linux-PAM/modules/pammodutil/Makefile
  383. --- Linux-PAM-0.77/modules/pammodutil/Makefile 2001-12-09 23:15:12.000000000 +0100
  384. +++ Linux-PAM/modules/pammodutil/Makefile 2003-01-14 06:43:07.000000000 +0100
  385. @@ -18,7 +18,8 @@
  386. -DLIBPAM_VERSION_MINOR=$(MINOR_REL)
  387. # all the object files we care about
  388. -LIBOBJECTS = modutil_cleanup.o modutil_getpwnam.o modutil_getpwuid.o
  389. +LIBOBJECTS = modutil_cleanup.o modutil_getpwnam.o modutil_getpwuid.o \
  390. + modutil_getlogin.o
  391. # static library name
  392. LIBSTATIC = $(LIBNAME).a
  393. diff -x CVS -x '*cvs*' -ruN Linux-PAM-0.77/modules/pammodutil/include/security/_pam_modutil.h Linux-PAM/modules/pammodutil/include/security/_pam_modutil.h
  394. --- Linux-PAM-0.77/modules/pammodutil/include/security/_pam_modutil.h 2001-12-09 23:15:12.000000000 +0100
  395. +++ Linux-PAM/modules/pammodutil/include/security/_pam_modutil.h 2003-01-14 06:43:08.000000000 +0100
  396. @@ -15,7 +15,7 @@
  397. * On systems that simply can't support thread safe programming, these
  398. * functions don't support it either - sorry.
  399. *
  400. - * Copyright (c) 2001 Andrew Morgan <morgan@kernel.org>
  401. + * Copyright (c) 2001-2002 Andrew Morgan <morgan@kernel.org>
  402. */
  403. #include <pwd.h>
  404. @@ -30,4 +30,6 @@
  405. extern void _pammodutil_cleanup(pam_handle_t *pamh, void *data,
  406. int error_status);
  407. +extern const char *_pammodutil_getlogin(pam_handle_t *pamh);
  408. +
  409. #endif /* _PAM_MODUTIL_H */
  410. diff -x CVS -x '*cvs*' -ruN Linux-PAM-0.77/modules/pammodutil/modutil_getlogin.c Linux-PAM/modules/pammodutil/modutil_getlogin.c
  411. --- Linux-PAM-0.77/modules/pammodutil/modutil_getlogin.c 1970-01-01 01:00:00.000000000 +0100
  412. +++ Linux-PAM/modules/pammodutil/modutil_getlogin.c 2003-01-14 06:43:08.000000000 +0100
  413. @@ -0,0 +1,71 @@
  414. +/*
  415. + * $Id: cvs-fixes.patch,v 1.3 2003/05/18 06:06:14 clifford Exp $
  416. + *
  417. + * A central point for invoking getlogin(). Hopefully, this is a
  418. + * little harder to spoof than all the other versions that are out
  419. + * there.
  420. + */
  421. +
  422. +#include <stdlib.h>
  423. +#include <unistd.h>
  424. +#include <utmp.h>
  425. +
  426. +#include "pammodutil.h"
  427. +
  428. +#define _PAMMODUTIL_GETLOGIN "_pammodutil_getlogin"
  429. +
  430. +const char *_pammodutil_getlogin(pam_handle_t *pamh)
  431. +{
  432. + int status;
  433. + const char *logname, *curr_tty;
  434. + char *curr_user;
  435. + struct utmp *ut, line;
  436. +
  437. + status = pam_get_data(pamh, _PAMMODUTIL_GETLOGIN,
  438. + (const void **) &logname);
  439. + if (status == PAM_SUCCESS) {
  440. + return logname;
  441. + }
  442. +
  443. + status = pam_get_item(pamh, PAM_TTY, (const void **) &curr_tty);
  444. + if ((status != PAM_SUCCESS) || (curr_tty == NULL)) {
  445. + curr_tty = ttyname(0);
  446. + }
  447. +
  448. + if ((curr_tty == NULL) || memcmp(curr_tty, "/dev/", 5)) {
  449. + return NULL;
  450. + }
  451. +
  452. + curr_tty += 5; /* strlen("/dev/") */
  453. + logname = NULL;
  454. +
  455. + setutent();
  456. + strncpy(line.ut_line, curr_tty, sizeof(line.ut_line));
  457. +
  458. + if ((ut = getutline(&line)) == NULL) {
  459. + goto clean_up_and_go_home;
  460. + }
  461. +
  462. + curr_user = calloc(sizeof(line.ut_user)+1, 1);
  463. + if (curr_user == NULL) {
  464. + goto clean_up_and_go_home;
  465. + }
  466. +
  467. + strncpy(curr_user, ut->ut_user, sizeof(ut->ut_user));
  468. + curr_user[sizeof(line.ut_user)] = '\0';
  469. +
  470. + status = pam_set_data(pamh, _PAMMODUTIL_GETLOGIN, logname,
  471. + _pammodutil_cleanup);
  472. + if (status != PAM_SUCCESS) {
  473. + free(curr_user);
  474. + goto clean_up_and_go_home;
  475. + }
  476. +
  477. + logname = curr_user;
  478. +
  479. +clean_up_and_go_home:
  480. +
  481. + endutent();
  482. +
  483. + return logname;
  484. +}