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.

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