home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / net / passwd-aging.2 / text0000.txt < prev   
Encoding:
Text File  |  1988-03-14  |  27.6 KB  |  1,064 lines

  1.  
  2. #    This is a shell archive.
  3. #    Remove everything above and including the cut line.
  4. #    Then run the rest of the file through sh.
  5. -----cut here-----cut here-----cut here-----cut here-----
  6. #!/bin/sh
  7. # shar:    Shell Archiver
  8. #    Run the following text with /bin/sh to create:
  9. #    ftpd.c.diff
  10. #    login.c.diff
  11. #    passwd.c.diff
  12. #    su.c.diff
  13. #    uucpd.c.diff
  14. #    vipw.c.diff
  15. # This archive created: Sat Mar 12 14:58:22 1988
  16. echo shar: extracting ftpd.c.diff '(1032 characters)'
  17. sed 's/^XX//' << \SHAR_EOF > ftpd.c.diff
  18. XX*** /tmp/,RCSt1007467    Thu Dec 24 11:59:54 1987
  19. XX--- ftpd.c    Thu Dec 24 11:59:36 1987
  20. XX***************
  21. XX*** 1,5 ****
  22. XX--- 1,8 ----
  23. XX  /*
  24. XX   * $Log:    ftpd.c,v $
  25. XX+  * Revision 1.5  87/12/24  11:59:22  gww
  26. XX+  * Add shadow password file support.
  27. XX+  * 
  28. XX   * Revision 1.4  87/07/31  12:15:56  gww
  29. XX   * Enable remote command execution if RMTCMD defined.
  30. XX   * 
  31. XX***************
  32. XX*** 27,33 ****
  33. XX  #endif not lint
  34. XX  
  35. XX  #ifndef lint
  36. XX! static char *ERcsId = "$Header: ftpd.c,v 1.4 87/07/31 12:15:56 gww Exp $ ENIX BSD";
  37. XX  static char sccsid[] = "@(#)ftpd.c    5.7 (Berkeley) 5/28/86";
  38. XX  #endif not lint
  39. XX  
  40. XX--- 30,36 ----
  41. XX  #endif not lint
  42. XX  
  43. XX  #ifndef lint
  44. XX! static char *ERcsId = "$Header: ftpd.c,v 1.5 87/12/24 11:59:22 gww Exp $ ENIX BSD";
  45. XX  static char sccsid[] = "@(#)ftpd.c    5.7 (Berkeley) 5/28/86";
  46. XX  #endif not lint
  47. XX  
  48. XX***************
  49. XX*** 186,191 ****
  50. XX--- 189,198 ----
  51. XX      /*
  52. XX       * Set up default state
  53. XX       */
  54. XX+ #ifdef    elxsi
  55. XX+     if (access(SHADOWPW, F_OK) == 0)
  56. XX+         setpwfile(SHADOWPW);
  57. XX+ #endif    elxsi
  58. XX      logged_in = 0;
  59. XX      data = -1;
  60. XX      type = TYPE_A;
  61. SHAR_EOF
  62. if test 1032 -ne "`wc -c ftpd.c.diff`"
  63. then
  64. echo shar: error transmitting ftpd.c.diff '(should have been 1032 characters)'
  65. fi
  66. echo shar: extracting login.c.diff '(4455 characters)'
  67. sed 's/^XX//' << \SHAR_EOF > login.c.diff
  68. XX*** /tmp/,RCSt1002049    Thu Mar 10 09:33:08 1988
  69. XX--- login.c    Mon Mar  7 17:01:59 1988
  70. XX***************
  71. XX*** 1,5 ****
  72. XX--- 1,8 ----
  73. XX  /*
  74. XX   * $Log:    login.c,v $
  75. XX+  * Revision 1.2  88/03/07  15:52:53  gww
  76. XX+  * Add shadow password file and password aging support.
  77. XX+  * 
  78. XX   * Revision 1.1  86/12/17  18:14:13  gww
  79. XX   * Initial revision
  80. XX   * 
  81. XX***************
  82. XX*** 17,23 ****
  83. XX  #endif not lint
  84. XX  
  85. XX  #ifndef lint
  86. XX! static char *ERcsId = "$Header: login.c,v 1.1 86/12/17 18:14:13 gww Exp $ ENIX BSD";
  87. XX  static char sccsid[] = "@(#)login.c    5.15 (Berkeley) 4/12/86";
  88. XX  #endif not lint
  89. XX  
  90. XX--- 20,26 ----
  91. XX  #endif not lint
  92. XX  
  93. XX  #ifndef lint
  94. XX! static char *ERcsId = "$Header: login.c,v 1.2 88/03/07 15:52:53 gww Exp $ ENIX BSD";
  95. XX  static char sccsid[] = "@(#)login.c    5.15 (Berkeley) 4/12/86";
  96. XX  #endif not lint
  97. XX  
  98. XX***************
  99. XX*** 99,104 ****
  100. XX--- 102,110 ----
  101. XX  char    rpassword[NMAX+1];
  102. XX  char    name[NMAX+1];
  103. XX  char    *rhost;
  104. XX+ #ifdef    elxsi
  105. XX+ int    spwflag=0;        /* is a shadow password file present */
  106. XX+ #endif    elxsi
  107. XX  
  108. XX  main(argc, argv)
  109. XX      char *argv[];
  110. XX***************
  111. XX*** 117,122 ****
  112. XX--- 123,132 ----
  113. XX      signal(SIGINT, SIG_IGN);
  114. XX      setpriority(PRIO_PROCESS, 0, 0);
  115. XX      quota(Q_SETUID, 0, 0, 0);
  116. XX+ #ifdef    elxsi
  117. XX+     if (spwflag = (access(SHADOWPW, F_OK) == 0))
  118. XX+         setpwfile(SHADOWPW);
  119. XX+ #endif    elxsi
  120. XX      /*
  121. XX       * -p is used by getty to tell login not to destroy the environment
  122. XX       * -r is used by rlogind to cause the autologin protocol;
  123. XX***************
  124. XX*** 308,313 ****
  125. XX--- 318,327 ----
  126. XX          write(f, (char *)&utmp, sizeof(utmp));
  127. XX          close(f);
  128. XX      }
  129. XX+ #ifdef    elxsi
  130. XX+     if (spwflag)
  131. XX+         check_age(pwd, tty);
  132. XX+ #endif    elxsi
  133. XX      if ((f = open("/usr/adm/wtmp", O_WRONLY|O_APPEND)) >= 0) {
  134. XX          write(f, (char *)&utmp, sizeof(utmp));
  135. XX          close(f);
  136. XX***************
  137. XX*** 592,594 ****
  138. XX--- 606,694 ----
  139. XX  
  140. XX      return (gid);
  141. XX  }
  142. XX+ 
  143. XX+ #ifdef    elxsi
  144. XX+ /*    check_age - Check the password aging for this user.
  145. XX+  *
  146. XX+  *    Entry    pwd = User's shadow password file entry.
  147. XX+  *        tty = User's tty name.
  148. XX+  *
  149. XX+  *    Exit    To caller, if no password change needed.
  150. XX+  *        To caller, if password change needed and successfully made.
  151. XX+  *        To exit(1), to abort the login if password change needed and 
  152. XX+  *                not made.
  153. XX+  *
  154. XX+  *    Messages
  155. XX+  *        
  156. XX+  *        "Please change your password." = The password aging schema has
  157. XX+  *            been implemented.  Please change your password.
  158. XX+  *
  159. XX+  *        "You have not changed your password in the last password aging
  160. XX+  *         period."
  161. XX+  *        "Please do so now." = Your password has become too old and must
  162. XX+  *            be changed before you will be permitted to login.
  163. XX+  *
  164. XX+  *        "You may not login because you have not changed your 
  165. XX+  *         password." = You did not change your password when you were 
  166. XX+  *            required to do so, thus you may not login.  The process
  167. XX+  *            is aborted by hanging up the phone.
  168. XX+  *
  169. XX+  *    Calls    close, exit, fflush, ioctl, printf, sleep, sscanf, syslog,
  170. XX+  *        system(PASSWD_PROG), time.
  171. XX+  *
  172. XX+  */
  173. XX+ 
  174. XX+ check_age(pwd, tty)
  175. XX+ 
  176. XX+ struct passwd *pwd;
  177. XX+ char *tty;
  178. XX+ 
  179. XX+ {
  180. XX+     int  type;        /* type of password criteria */
  181. XX+     long age_limit;        /* time limit a password is good for */
  182. XX+     long last_time;        /* time of last change */
  183. XX+     long current_time;    /* right now */
  184. XX+     int tries = 0;
  185. XX+ 
  186. XX+     sscanf(pwd->pw_gecos, "%d,%ld,%ld,", &type, &age_limit, &last_time);
  187. XX+     if ((age_limit != 0) &&
  188. XX+         ((long)time(¤t_time) > (last_time + age_limit))) {
  189. XX+         if (last_time == 0) {
  190. XX+             printf("\nPlease change your password.\n\n");
  191. XX+         } else {
  192. XX+             printf("\nYou have not changed your password ");
  193. XX+             printf("in the last %d days.\n",
  194. XX+                    (current_time - last_time)/(60*60*24));
  195. XX+             printf("Please do so now.\n\n");
  196. XX+         }
  197. XX+         fflush(stdout);
  198. XX+ 
  199. XX+         while (system(PASSWD_PROG)) {  /* require password change */
  200. XX+             if (++tries >= CHANGE_TRIES) {
  201. XX+                 printf("You may not login because you have ");
  202. XX+                 printf("not changed your password.\n");
  203. XX+                 fflush(stdout);
  204. XX+                 if (utmp.ut_host[0])
  205. XX+                     syslog(LOG_CRIT,
  206. XX+                         "EXPIRED PASSWORD UNCHANGED ON %s FROM %.*s, %.*s",
  207. XX+                         tty, HMAX, utmp.ut_host,
  208. XX+                         NMAX, utmp.ut_name);
  209. XX+                 else
  210. XX+                     syslog(LOG_CRIT,
  211. XX+                         "EXPIRED PASSWORD UNCHANGED ON %s, %.*s",
  212. XX+                         tty, NMAX, utmp.ut_name);
  213. XX+                 ioctl(0, TIOCHPCL, (struct sgttyb *) 0);
  214. XX+                 close(0);
  215. XX+                 close(1);
  216. XX+                 close(2);
  217. XX+                 sleep(10);
  218. XX+                 exit(1);
  219. XX+             } else {
  220. XX+                 printf("You did not sucessfully change your ");
  221. XX+                 printf("password, try again.\n");
  222. XX+                 fflush(stdout);
  223. XX+             }
  224. XX+         }
  225. XX+     }
  226. XX+ }
  227. XX+ #endif    elxsi
  228. SHAR_EOF
  229. if test 4455 -ne "`wc -c login.c.diff`"
  230. then
  231. echo shar: error transmitting login.c.diff '(should have been 4455 characters)'
  232. fi
  233. echo shar: extracting passwd.c.diff '(9615 characters)'
  234. sed 's/^XX//' << \SHAR_EOF > passwd.c.diff
  235. XX*** /tmp/,RCSt1002150    Thu Mar 10 09:41:14 1988
  236. XX--- passwd.c    Mon Mar  7 18:20:48 1988
  237. XX***************
  238. XX*** 1,5 ****
  239. XX--- 1,8 ----
  240. XX  /*
  241. XX   * $Log:    passwd.c,v $
  242. XX+  * Revision 1.4  88/03/07  18:19:19  gww
  243. XX+  * Add shadow password file, password aging, strong password criteria.
  244. XX+  * 
  245. XX   * Revision 1.3  87/11/17  17:22:01  gww
  246. XX   * Update chfn examples to read Office information rather than UCB example.
  247. XX   * 
  248. XX***************
  249. XX*** 23,29 ****
  250. XX  #endif not lint
  251. XX  
  252. XX  #ifndef lint
  253. XX! static char *ERcsId = "$Header: passwd.c,v 1.3 87/11/17 17:22:01 gww Exp $ ENIX BSD";
  254. XX  static char sccsid[] = "@(#)passwd.c    4.24 (Berkeley) 5/28/86";
  255. XX  #endif not lint
  256. XX  
  257. XX--- 26,32 ----
  258. XX  #endif not lint
  259. XX  
  260. XX  #ifndef lint
  261. XX! static char *ERcsId = "$Header: passwd.c,v 1.4 88/03/07 18:19:19 gww Exp $ ENIX BSD";
  262. XX  static char sccsid[] = "@(#)passwd.c    4.24 (Berkeley) 5/28/86";
  263. XX  #endif not lint
  264. XX  
  265. XX***************
  266. XX*** 62,67 ****
  267. XX--- 65,75 ----
  268. XX  char    *malloc();
  269. XX  char    *getusershell();
  270. XX  extern    int errno;
  271. XX+ #ifdef    elxsi
  272. XX+ int    spwflag=0;        /* is a shadow password file present */
  273. XX+ char     new_gecos[BUFSIZ]='\0';    /* updated gecos field */
  274. XX+ char    *getstrpasswd();    /* strict password criteria */
  275. XX+ #endif    elxsi
  276. XX  
  277. XX  main(argc, argv)
  278. XX      char *argv[];
  279. XX***************
  280. XX*** 120,125 ****
  281. XX--- 128,137 ----
  282. XX              uname);
  283. XX      } else
  284. XX          uname = *argv++;
  285. XX+ #ifdef    elxsi
  286. XX+     if ((spwflag = (access(SHADOWPW, F_OK) == 0)) && !dochfn)
  287. XX+         setpwfile(SHADOWPW);
  288. XX+ #endif    elxsi
  289. XX      pwd = getpwnam(uname);
  290. XX      if (pwd == NULL) {
  291. XX          fprintf(stderr, "passwd: %s: unknown user.\n", uname);
  292. XX***************
  293. XX*** 135,140 ****
  294. XX--- 147,170 ----
  295. XX      else if (dochsh)
  296. XX          cp = getloginshell(pwd, u, *argv);
  297. XX      else
  298. XX+ #ifdef    elxsi
  299. XX+          if (spwflag) {
  300. XX+         int  type;    /* type of password criteria */
  301. XX+ 
  302. XX+         sscanf(pwd->pw_gecos, "%d", &type);
  303. XX+         switch (type) {
  304. XX+ 
  305. XX+         default:
  306. XX+         case BSD_CRIT:
  307. XX+             cp = getnewpasswd(pwd, u, argc);
  308. XX+             break;
  309. XX+ 
  310. XX+         case STR_CRIT:
  311. XX+             cp = getstrpasswd(pwd, u, argc);
  312. XX+             break;
  313. XX+         }
  314. XX+          } else
  315. XX+ #endif    elxsi
  316. XX          cp = getnewpasswd(pwd, u);
  317. XX      (void) signal(SIGHUP, SIG_IGN);
  318. XX      (void) signal(SIGINT, SIG_IGN);
  319. XX***************
  320. XX*** 141,147 ****
  321. XX--- 171,185 ----
  322. XX      (void) signal(SIGQUIT, SIG_IGN);
  323. XX      (void) signal(SIGTSTP, SIG_IGN);
  324. XX      (void) umask(0);
  325. XX+ #ifndef    elxsi
  326. XX      fd = open(temp, O_WRONLY|O_CREAT|O_EXCL, 0644);
  327. XX+ #else
  328. XX+     if (spwflag && !dochfn)
  329. XX+         fd = open(temp, O_WRONLY|O_CREAT|O_EXCL, 0600);
  330. XX+     else
  331. XX+         fd = open(temp, O_WRONLY|O_CREAT|O_EXCL, 0644);
  332. XX+ updatesh:
  333. XX+ #endif    !elxsi
  334. XX      if (fd < 0) {
  335. XX          err = errno;
  336. XX  
  337. XX***************
  338. XX*** 158,168 ****
  339. XX--- 196,216 ----
  340. XX          fprintf(stderr, "passwd: fdopen failed?\n");
  341. XX          exit(1);
  342. XX      }
  343. XX+ #ifndef    elxsi
  344. XX      if ((dp = dbm_open(passwd, O_RDWR, 0644)) == NULL) {
  345. XX+ #else
  346. XX+     if ((dp = dbm_open((spwflag&&!dochfn) ? SHADOWPW : passwd,
  347. XX+                O_RDWR,
  348. XX+                (spwflag&&!dochfn) ? 0600 : 0644)) == NULL) {
  349. XX+ #endif    !elxsi
  350. XX          err = errno;
  351. XX          fprintf(stderr, "Warning: dbm_open failed: ");
  352. XX          errno = err;
  353. XX+ #ifndef    elxsi
  354. XX          perror(passwd);
  355. XX+ #else
  356. XX+         perror((spwflag&&!dochfn)? SHADOWPW : passwd);
  357. XX+ #endif    !elxsi
  358. XX      } else if (flock(dp->dbm_dirf, LOCK_EX) < 0) {
  359. XX          perror("Warning: lock failed");
  360. XX          dbm_close(dp);
  361. XX***************
  362. XX*** 184,193 ****
  363. XX--- 232,249 ----
  364. XX                  pwd->pw_gecos = cp;
  365. XX              else if (dochsh)
  366. XX                  pwd->pw_shell = cp;
  367. XX+ #ifndef    elxsi
  368. XX              else
  369. XX                  pwd->pw_passwd = cp;
  370. XX              if (pwd->pw_gecos[0] == '*')    /* ??? */
  371. XX                  pwd->pw_gecos++;
  372. XX+ #else
  373. XX+             else {
  374. XX+                 pwd->pw_passwd = cp;
  375. XX+                 if (new_gecos[0] != '\0')
  376. XX+                     pwd->pw_gecos  = new_gecos;
  377. XX+             }
  378. XX+ #endif    !elxsi
  379. XX              replace(dp, pwd);
  380. XX          }
  381. XX          fprintf(tf,"%s:%s:%d:%d:%s:%s:%s\n",
  382. XX***************
  383. XX*** 211,222 ****
  384. XX--- 267,290 ----
  385. XX      (void) fclose(tf);
  386. XX      if (dp != NULL)
  387. XX          dbm_close(dp);
  388. XX+ #ifndef    elxsi
  389. XX      if (rename(temp, passwd) < 0) {
  390. XX+ #else
  391. XX+     if (rename(temp, (spwflag&&!dochfn) ? SHADOWPW : passwd) < 0) {
  392. XX+ #endif    !elxsi
  393. XX          perror("passwd: rename");
  394. XX      out:
  395. XX          (void) unlink(temp);
  396. XX          exit(1);
  397. XX      }
  398. XX+ #ifdef    elxsi
  399. XX+     if (spwflag && dochsh) {   /* change shell is user password file also */
  400. XX+         spwflag = 0;
  401. XX+         setpwfile(passwd);
  402. XX+         fd = open(temp, O_WRONLY|O_CREAT|O_EXCL, 0644);
  403. XX+         goto updatesh;
  404. XX+     }
  405. XX+ #endif    elxsi
  406. XX      exit(0);
  407. XX  }
  408. XX  
  409. XX***************
  410. XX*** 267,275 ****
  411. XX--- 335,350 ----
  412. XX  }
  413. XX  
  414. XX  char *
  415. XX+ #ifndef    elxsi
  416. XX  getnewpasswd(pwd, u)
  417. XX      register struct passwd *pwd;
  418. XX      int u;
  419. XX+ #else
  420. XX+ getnewpasswd(pwd, u, argc)
  421. XX+     register struct passwd *pwd;
  422. XX+     int u;
  423. XX+     int argc;
  424. XX+ #endif    !elxsi
  425. XX  {
  426. XX      char saltc[2];
  427. XX      long salt;
  428. XX***************
  429. XX*** 342,351 ****
  430. XX--- 417,532 ----
  431. XX              c += 6;
  432. XX          saltc[i] = c;
  433. XX      }
  434. XX+ 
  435. XX+ #ifdef    elxsi
  436. XX+     if (spwflag && (u != 0 || argc < 1))
  437. XX+         check_aging(pwd, pwbuf);
  438. XX+ #endif    elxsi
  439. XX      return (crypt(pwbuf, saltc));
  440. XX  }
  441. XX  
  442. XX+ #ifdef    elxsi
  443. XX+ /*    getstrpasswd - Get strong password
  444. XX+  *
  445. XX+  *    Entry    pwd  = Current password structure.
  446. XX+  *        u    = UID executing as.
  447. XX+  *        argc = Program call arg count - 1.
  448. XX+  *
  449. XX+  *    Exit    Encrypted password returned.
  450. XX+  *
  451. XX+  *    Uses    None.
  452. XX+  *
  453. XX+  *    Calls    check_aging, crypt, exit, getpass, getpid, isdigit, islower,
  454. XX+  *        isupper, printf, strcmp, strcpy, strlen, time.
  455. XX+  */
  456. XX+ 
  457. XX  char *
  458. XX+ getstrpasswd(pwd, u, argc)
  459. XX+     register struct passwd *pwd;
  460. XX+     int u;
  461. XX+     int argc;
  462. XX+ {
  463. XX+     char saltc[2];
  464. XX+     long salt;
  465. XX+     int i, insist = 0;
  466. XX+     int lower, upper, special;
  467. XX+     int c, pwlen;
  468. XX+     static char pwbuf[10];
  469. XX+     long time();
  470. XX+     char *crypt(), *pw, *p;
  471. XX+ 
  472. XX+     if (pwd->pw_passwd[0] && u != 0) {
  473. XX+         (void) strcpy(pwbuf, getpass("Old password:"));
  474. XX+         pw = crypt(pwbuf, pwd->pw_passwd);
  475. XX+         if (strcmp(pw, pwd->pw_passwd) != 0) {
  476. XX+             printf("Sorry.\n");
  477. XX+             exit(1);
  478. XX+         }
  479. XX+     }
  480. XX+ tryagain:
  481. XX+     lower = upper = special = 0;
  482. XX+     (void) strcpy(pwbuf, getpass("New password:"));
  483. XX+     pwlen = strlen(pwbuf);
  484. XX+     if (pwlen == 0) {
  485. XX+         printf("Password unchanged.\n");
  486. XX+         exit(1);
  487. XX+     }
  488. XX+ 
  489. XX+     /* If called by login, u == 0 and argc == 0, don't bypass check */
  490. XX+ 
  491. XX+     if (u != 0 || argc < 1) {
  492. XX+         p = pwbuf;
  493. XX+         while (c = *p++) {
  494. XX+             if (islower(c))
  495. XX+                 lower++;
  496. XX+             else if (isupper(c))
  497. XX+                 upper++;
  498. XX+             else 
  499. XX+                 special++;
  500. XX+         }
  501. XX+ 
  502. XX+         if (insist++ >= 3) {
  503. XX+             printf("Sorry.\n");
  504. XX+             exit(1);
  505. XX+         }
  506. XX+             if (pwlen < 7) {
  507. XX+             printf("Password must contain at least seven characters.\n");
  508. XX+             goto tryagain;
  509. XX+             }
  510. XX+             if ((lower > 4) || (lower < 1) || (upper > 4) || (upper < 1) ||
  511. XX+             (special > 4) || (special < 1)) {
  512. XX+             printf("%s%s%s%s",
  513. XX+                    "Password must be chosen from a larger alphabet,\n",
  514. XX+                    "try at least 1 but no more than 4 characters ",
  515. XX+                    "from lower case, upper case,\n",
  516. XX+                    "and digits and special characters.\n");
  517. XX+             goto tryagain;
  518. XX+             }
  519. XX+     }
  520. XX+     if (strcmp(pwbuf, getpass("Retype new password:")) != 0) {
  521. XX+         printf("Mismatch - password unchanged.\n");
  522. XX+         exit(1);
  523. XX+     }
  524. XX+     (void) time(&salt);
  525. XX+     salt = 9 * getpid();
  526. XX+     saltc[0] = salt & 077;
  527. XX+     saltc[1] = (salt>>6) & 077;
  528. XX+     for (i = 0; i < 2; i++) {
  529. XX+         c = saltc[i] + '.';
  530. XX+         if (c > '9')
  531. XX+             c += 7;
  532. XX+         if (c > 'Z')
  533. XX+             c += 6;
  534. XX+         saltc[i] = c;
  535. XX+     }
  536. XX+ 
  537. XX+     if (u != 0 || argc < 1)
  538. XX+         check_aging(pwd, pwbuf);
  539. XX+     return (crypt(pwbuf, saltc));
  540. XX+ }
  541. XX+ #endif    elxsi
  542. XX+ 
  543. XX+ char *
  544. XX  getloginshell(pwd, u, arg)
  545. XX      struct passwd *pwd;
  546. XX      int u;
  547. XX***************
  548. XX*** 699,701 ****
  549. XX--- 880,956 ----
  550. XX      *str = '\0';
  551. XX      return (1);
  552. XX  }
  553. XX+ 
  554. XX+ #ifdef    elxsi
  555. XX+ /*    check_aging - Check for password aging.
  556. XX+  *
  557. XX+  *    Entry    pwd = User password file entry.
  558. XX+  *        pwbuf = New password.
  559. XX+  *
  560. XX+  *    Exit    No action if user's password aging not enabled.
  561. XX+  *        new_gecos = updated if new password is different from 
  562. XX+  *            old and saved.
  563. XX+  *        Process aborted if passwords the same.
  564. XX+  *
  565. XX+  *    Messages
  566. XX+  *
  567. XX+  *        "New password must be different from old password - password
  568. XX+  *         unchanged." = The password that is trying to be set is the
  569. XX+  *            current password and may not be used again.
  570. XX+  *
  571. XX+  *        "That password was used in the last aging period - password
  572. XX+  *         unchanged." = The password that is trying to be set was 
  573. XX+  *            already used in the last aging period and may not be
  574. XX+  *            used again.
  575. XX+  *
  576. XX+  *    Calls    crypt, exit, fflush, printf, sprintf, sscanf, strcmp.
  577. XX+  */
  578. XX+ 
  579. XX+ check_aging(pwd, pwbuf)
  580. XX+ struct passwd *pwd;
  581. XX+ char *pwbuf;        /* new password */
  582. XX+ 
  583. XX+ {
  584. XX+     int  type;        /* type of password criteria */
  585. XX+     long limit;        /* aging limit, 0 if no password aging */
  586. XX+     long last_time;        /* time of last password change */
  587. XX+     long old_time;        /* time old password was saved */
  588. XX+     char old_passwd[20];    /* saved old password (encrypted) */
  589. XX+     long current_time;    /* time right now */
  590. XX+ 
  591. XX+     sscanf(pwd->pw_gecos, "%d,%ld,%ld,%ld,%20s", &type, &limit, &last_time,
  592. XX+         &old_time, old_passwd);
  593. XX+ 
  594. XX+     if (limit == 0)        /* no password aging for this user */
  595. XX+         return;
  596. XX+ 
  597. XX+     if (*pwd->pw_passwd && 
  598. XX+         (strcmp(crypt(pwbuf, pwd->pw_passwd), pwd->pw_passwd) == 0)) {
  599. XX+         printf("\nNew password must be different from old password");
  600. XX+         printf(" - password unchanged.\n");
  601. XX+         fflush(stdout);
  602. XX+         exit(1);
  603. XX+     }
  604. XX+ 
  605. XX+     if (strcmp(crypt(pwbuf, old_passwd), old_passwd) == 0) {
  606. XX+         printf("\nThat password was used in the last aging period");
  607. XX+         printf(" - password unchanged.\n\n");
  608. XX+         fflush(stdout);
  609. XX+         exit(1);
  610. XX+     }
  611. XX+ 
  612. XX+     (void)time(¤t_time);  /* set new password aging period */
  613. XX+ 
  614. XX+     if(current_time > (old_time + limit))
  615. XX+     /* save old password for next aging period to prevent reuse */
  616. XX+         sprintf(new_gecos, "%d,%ld,%ld,%ld,%s", type, limit,
  617. XX+                    current_time,
  618. XX+                    current_time,
  619. XX+                    *pwd->pw_passwd ? pwd->pw_passwd : "*******");
  620. XX+     else
  621. XX+         sprintf(new_gecos, "%d,%ld,%ld,%ld,%s", type, limit,
  622. XX+                     current_time,
  623. XX+                     old_time,
  624. XX+                     old_passwd);
  625. XX+ }
  626. XX+ #endif    elxsi
  627. SHAR_EOF
  628. if test 9615 -ne "`wc -c passwd.c.diff`"
  629. then
  630. echo shar: error transmitting passwd.c.diff '(should have been 9615 characters)'
  631. fi
  632. echo shar: extracting su.c.diff '(1275 characters)'
  633. sed 's/^XX//' << \SHAR_EOF > su.c.diff
  634. XX*** /tmp/,RCSt1007109    Thu Dec 24 11:36:10 1987
  635. XX--- su.c    Thu Dec 24 11:35:48 1987
  636. XX***************
  637. XX*** 1,5 ****
  638. XX--- 1,8 ----
  639. XX  /*
  640. XX   * $Log:    su.c,v $
  641. XX+  * Revision 1.2  87/12/24  11:35:38  gww
  642. XX+  * Add shadow password file support.
  643. XX+  * 
  644. XX   * Revision 1.1  86/12/17  18:14:45  gww
  645. XX   * Initial revision
  646. XX   * 
  647. XX***************
  648. XX*** 17,23 ****
  649. XX  #endif not lint
  650. XX  
  651. XX  #ifndef lint
  652. XX! static char *ERcsId = "$Header: su.c,v 1.1 86/12/17 18:14:45 gww Exp $ ENIX BSD";
  653. XX  static char sccsid[] = "@(#)su.c    5.4 (Berkeley) 1/13/86";
  654. XX  #endif not lint
  655. XX  
  656. XX--- 20,26 ----
  657. XX  #endif not lint
  658. XX  
  659. XX  #ifndef lint
  660. XX! static char *ERcsId = "$Header: su.c,v 1.2 87/12/24 11:35:38 gww Exp $ ENIX BSD";
  661. XX  static char sccsid[] = "@(#)su.c    5.4 (Berkeley) 1/13/86";
  662. XX  #endif not lint
  663. XX  
  664. XX***************
  665. XX*** 28,33 ****
  666. XX--- 31,39 ----
  667. XX  #include <sys/types.h>
  668. XX  #include <sys/time.h>
  669. XX  #include <sys/resource.h>
  670. XX+ #ifdef    elxsi
  671. XX+ #include <sys/file.h>
  672. XX+ #endif    elxsi
  673. XX  
  674. XX  char    userbuf[16]    = "USER=";
  675. XX  char    homebuf[128]    = "HOME=";
  676. XX***************
  677. XX*** 72,77 ****
  678. XX--- 78,87 ----
  679. XX          user = argv[1];
  680. XX          argc--, argv++;
  681. XX      }
  682. XX+ #ifdef    elxsi
  683. XX+     if (access(SHADOWPW, F_OK) == 0)
  684. XX+         setpwfile(SHADOWPW);
  685. XX+ #endif    elxsi
  686. XX      if ((pwd = getpwuid(getuid())) == NULL) {
  687. XX          fprintf(stderr, "Who are you?\n");
  688. XX          exit(1);
  689. SHAR_EOF
  690. if test 1275 -ne "`wc -c su.c.diff`"
  691. then
  692. echo shar: error transmitting su.c.diff '(should have been 1275 characters)'
  693. fi
  694. echo shar: extracting uucpd.c.diff '(1363 characters)'
  695. sed 's/^XX//' << \SHAR_EOF > uucpd.c.diff
  696. XX*** /tmp/,RCSt1002936    Mon Jan  4 14:05:23 1988
  697. XX--- uucpd.c    Mon Jan  4 14:04:59 1988
  698. XX***************
  699. XX*** 1,11 ****
  700. XX  /*
  701. XX   * $Log:    uucpd.c,v $
  702. XX   * Revision 1.1  87/06/23  16:58:30  gww
  703. XX   * Initial revision
  704. XX   * 
  705. XX   */
  706. XX  #ifndef lint
  707. XX! static char *ERcsId = "$Header: uucpd.c,v 1.1 87/06/23 16:58:30 gww Exp $ ENIX BSD";
  708. XX  static char sccsid[] = "@(#)uucpd.c    5.4 (Berkeley) 6/23/85";
  709. XX  #endif
  710. XX  
  711. XX--- 1,14 ----
  712. XX  /*
  713. XX   * $Log:    uucpd.c,v $
  714. XX+  * Revision 1.2  88/01/04  14:04:48  gww
  715. XX+  * Add shadow password file support.
  716. XX+  * 
  717. XX   * Revision 1.1  87/06/23  16:58:30  gww
  718. XX   * Initial revision
  719. XX   * 
  720. XX   */
  721. XX  #ifndef lint
  722. XX! static char *ERcsId = "$Header: uucpd.c,v 1.2 88/01/04 14:04:48 gww Exp $ ENIX BSD";
  723. XX  static char sccsid[] = "@(#)uucpd.c    5.4 (Berkeley) 6/23/85";
  724. XX  #endif
  725. XX  
  726. XX***************
  727. XX*** 28,33 ****
  728. XX--- 31,39 ----
  729. XX  #include <sys/ioctl.h>
  730. XX  #include <pwd.h>
  731. XX  #include <lastlog.h>
  732. XX+ #ifdef    elxsi
  733. XX+ #include <sys/file.h>
  734. XX+ #endif    elxsi
  735. XX  
  736. XX  #if !defined(BSD4_2) && !defined(BSD2_9)
  737. XX  --- You must have either BSD4_2 or BSD2_9 defined for this to work
  738. XX***************
  739. XX*** 158,163 ****
  740. XX--- 164,173 ----
  741. XX      char *xpasswd, *crypt();
  742. XX      struct passwd *pw, *getpwnam();
  743. XX  
  744. XX+ #ifdef    elxsi
  745. XX+     if (access(SHADOWPW, F_OK) == 0)
  746. XX+         setpwfile(SHADOWPW);
  747. XX+ #endif    elxsi
  748. XX      alarm(60);
  749. XX      printf("login: "); fflush(stdout);
  750. XX      if (readline(user, sizeof user) < 0) {
  751. SHAR_EOF
  752. if test 1363 -ne "`wc -c uucpd.c.diff`"
  753. then
  754. echo shar: error transmitting uucpd.c.diff '(should have been 1363 characters)'
  755. fi
  756. echo shar: extracting vipw.c.diff '(6653 characters)'
  757. sed 's/^XX//' << \SHAR_EOF > vipw.c.diff
  758. XX*** /tmp/,RCSt1002304    Thu Mar 10 10:06:24 1988
  759. XX--- vipw.c    Thu Mar 10 10:05:54 1988
  760. XX***************
  761. XX*** 1,5 ****
  762. XX--- 1,8 ----
  763. XX  /*
  764. XX   * $Log:    vipw.c,v $
  765. XX+  * Revision 1.2  87/12/24  12:16:11  gww
  766. XX+  * Add shadow password file support.
  767. XX+  * 
  768. XX   * Revision 1.1  87/03/25  13:31:04  gww
  769. XX   * Initial revision
  770. XX   * 
  771. XX***************
  772. XX*** 17,23 ****
  773. XX  #endif not lint
  774. XX  
  775. XX  #ifndef lint
  776. XX! static char *ERcsId = "$Header: vipw.c,v 1.1 87/03/25 13:31:04 gww Exp $ ENIX BSD";
  777. XX  static char sccsid[] = "@(#)vipw.c    5.1 (Berkeley) 5/28/85";
  778. XX  #endif not lint
  779. XX  
  780. XX--- 20,26 ----
  781. XX  #endif not lint
  782. XX  
  783. XX  #ifndef lint
  784. XX! static char *ERcsId = "$Header: vipw.c,v 1.2 87/12/24 12:16:11 gww Exp $ ENIX BSD";
  785. XX  static char sccsid[] = "@(#)vipw.c    5.1 (Berkeley) 5/28/85";
  786. XX  #endif not lint
  787. XX  
  788. XX***************
  789. XX*** 24,29 ****
  790. XX--- 27,35 ----
  791. XX  #include <sys/types.h>
  792. XX  #include <sys/stat.h>
  793. XX  #include <sys/file.h>
  794. XX+ #ifdef    elxsi
  795. XX+ #include <pwd.h>
  796. XX+ #endif    elxsi
  797. XX  
  798. XX  #include <stdio.h>
  799. XX  #include <errno.h>
  800. XX***************
  801. XX*** 38,43 ****
  802. XX--- 44,58 ----
  803. XX  char    passwd[] = "/etc/passwd";
  804. XX  char    passwd_pag[] = "/etc/passwd.pag";
  805. XX  char    passwd_dir[] = "/etc/passwd.dir";
  806. XX+ #ifdef    elxsi
  807. XX+ char    stemp[] = "/etc/sptmp";
  808. XX+ char    stemp_pag[] = "/etc/sptmp.pag";
  809. XX+ char    stemp_dir[] = "/etc/sptmp.dir";
  810. XX+ char    shadow[] = SHADOWPW;
  811. XX+ char    shadow_pag[] = SHADOWPW_PAG;
  812. XX+ char    shadow_dir[] = SHADOWPW_DIR;
  813. XX+ char    temps[] = "/etc/ptmps";
  814. XX+ #endif    elxsi
  815. XX  char    buf[BUFSIZ];
  816. XX  char    *getenv();
  817. XX  char    *index();
  818. XX***************
  819. XX*** 147,152 ****
  820. XX--- 162,218 ----
  821. XX          }
  822. XX          fclose(ft);
  823. XX          if (ok) {
  824. XX+ #ifdef    elxsi
  825. XX+             if (access(SHADOWPW, F_OK) == 0) {
  826. XX+                 /* sort temp file by uid */
  827. XX+ 
  828. XX+                 sprintf(buf, "sort -t: +2n -3 +0 -1 %s > %s",
  829. XX+                         temp, temps);
  830. XX+                 if (system(buf) != 0) {
  831. XX+                     fprintf(stderr, "vipw: sort failed\n");
  832. XX+                     goto bad;
  833. XX+                 }
  834. XX+                 if (rename(temps, temp) < 0) {
  835. XX+                     fprintf(stderr, "vipw: ");
  836. XX+                     perror(temps);
  837. XX+                     goto bad;
  838. XX+                 }
  839. XX+             
  840. XX+                 /* merge edited passwd file with shadow file */
  841. XX+             
  842. XX+                 if (merg_pw() < 0)
  843. XX+                     goto bad;
  844. XX+ 
  845. XX+                 if (makedb(stemp) < 0) {
  846. XX+                     fprintf(stderr,
  847. XX+                         "vipw: shadow mkpasswd failed\n");
  848. XX+                     goto bad;
  849. XX+                 }
  850. XX+             
  851. XX+                 /* set correct modes */
  852. XX+ 
  853. XX+                 chmod(temp, 0644);
  854. XX+                 chmod(stemp, 0600);
  855. XX+                 chmod(stemp_pag, 0600);
  856. XX+                 chmod(stemp_dir, 0600);
  857. XX+ 
  858. XX+                 /* remake shadow hash files and rename temps */
  859. XX+ 
  860. XX+                 if (rename(stemp_pag, shadow_pag) < 0) {
  861. XX+                     fprintf(stderr, "vipw: ");
  862. XX+                     perror(stemp_pag);
  863. XX+                     goto bad;
  864. XX+                 } else if (rename(stemp_dir, shadow_dir) < 0) {
  865. XX+                     fprintf(stderr, "vipw: ");
  866. XX+                     perror(stemp_dir);
  867. XX+                     goto bad;
  868. XX+                 } else if (rename(stemp, shadow) < 0) {
  869. XX+                     fprintf(stderr, "vipw: ");
  870. XX+                     perror("shadow file");
  871. XX+                     goto bad;
  872. XX+                 }
  873. XX+             }
  874. XX+ #endif    elxsi
  875. XX              if (makedb(temp) < 0)
  876. XX                  fprintf(stderr, "vipw: mkpasswd failed\n");
  877. XX              else if (rename(temp_pag, passwd_pag) < 0)
  878. XX***************
  879. XX*** 163,168 ****
  880. XX--- 229,240 ----
  881. XX                  passwd);
  882. XX      }
  883. XX  bad:
  884. XX+ #ifdef    elxsi
  885. XX+     unlink(stemp_pag);
  886. XX+     unlink(stemp_dir);
  887. XX+     unlink(stemp);
  888. XX+     unlink(temps);
  889. XX+ #endif    elxsi
  890. XX      unlink(temp_pag);
  891. XX      unlink(temp_dir);
  892. XX      unlink(temp);
  893. XX***************
  894. XX*** 184,186 ****
  895. XX--- 256,414 ----
  896. XX          status = -1;
  897. XX      return(status);
  898. XX  }
  899. XX+ 
  900. XX+ #ifdef    elxsi
  901. XX+ struct     passwd tmpent;    /* passwd temp file entry */
  902. XX+ int    fd;
  903. XX+ FILE    *ft, *fp;
  904. XX+ 
  905. XX+ /*    pskip - Skip to next password file entry field.
  906. XX+  *
  907. XX+  *    Entry    p = Pointer to current field.
  908. XX+  *
  909. XX+  *    Exit    Pointer to next field.
  910. XX+  *
  911. XX+  */
  912. XX+ 
  913. XX+ static char *
  914. XX+ pskip(p)
  915. XX+ 
  916. XX+ register char *p;
  917. XX+ {
  918. XX+     while (*p && *p != ':' && *p != '\n')
  919. XX+         ++p;
  920. XX+     if (*p)
  921. XX+         *p++ = 0;
  922. XX+     return(p);
  923. XX+ }
  924. XX+ 
  925. XX+ /*     getmpent - Get temp passwd entry (modeled off of getpwent(3)).
  926. XX+  *
  927. XX+  *
  928. XX+  *    Entry    fp = Temp passwd stream.
  929. XX+  *
  930. XX+  *    Exit    0 = End of stream.
  931. XX+  *        &tmpent = struct passwd for this temp passwd entry.
  932. XX+  *
  933. XX+  *    Uses    buf.
  934. XX+  *
  935. XX+  *    Calls    fgets, pskip.
  936. XX+  *
  937. XX+  */
  938. XX+ 
  939. XX+ static struct passwd *
  940. XX+ getmpent()
  941. XX+ {
  942. XX+     register char *p;
  943. XX+ 
  944. XX+     if ((p=fgets(buf, BUFSIZ, fp)) == NULL)
  945. XX+         return(0);
  946. XX+ 
  947. XX+     tmpent.pw_name = p;
  948. XX+     p = pskip(p);
  949. XX+     tmpent.pw_passwd = p;
  950. XX+     p = pskip(p);
  951. XX+     tmpent.pw_uid = atoi(p);
  952. XX+     p = pskip(p);
  953. XX+     tmpent.pw_gid = atoi(p);
  954. XX+     p = pskip(p);
  955. XX+     tmpent.pw_gecos = p;
  956. XX+     p = pskip(p);
  957. XX+     tmpent.pw_dir = p;
  958. XX+     p = pskip(p);
  959. XX+     tmpent.pw_shell = p;
  960. XX+     while (*p && *p != '\n')
  961. XX+         p++;
  962. XX+     *p = '\0';
  963. XX+     return(&tmpent);
  964. XX+ }
  965. XX+ 
  966. XX+ /*     merg_pw - Merge updated passwd with shadow file.
  967. XX+  *
  968. XX+  *    Entry    stemp = Shadow passwd temp file name.
  969. XX+  *        shadow = Shadow passwd file name.
  970. XX+  *        temp = Updated passwd temp file name.
  971. XX+  *
  972. XX+  *    Exit    0 = Merge completed, stemp created.
  973. XX+  *        -1 = Error, message displayed.
  974. XX+  *
  975. XX+  *    Uses    errno, fd, ft, fp.
  976. XX+  *
  977. XX+  *    Calls    fclose, fdopen, fopen, fprintf, getmpent, getpwent, open,
  978. XX+  *        perror, setpwfile.
  979. XX+  *
  980. XX+  */
  981. XX+ 
  982. XX+ static
  983. XX+ merg_pw ()
  984. XX+ {
  985. XX+     struct    passwd *pwd,    /* passwd temp file entries */
  986. XX+                       *spwd;    /* shadow passwd entries */
  987. XX+ 
  988. XX+     if ((fd = open(stemp, O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0) {
  989. XX+         if (errno == EEXIST)
  990. XX+             fprintf(stderr, "vipw: password file busy\n");
  991. XX+         else
  992. XX+             fprintf(stderr, "vipw: "),
  993. XX+             perror(stemp);
  994. XX+         exit(1);
  995. XX+     }
  996. XX+ 
  997. XX+     if ((ft = fdopen(fd, "w")) == NULL) {
  998. XX+         fprintf(stderr, "vipw: "); perror(stemp);
  999. XX+         return(-1);
  1000. XX+     }
  1001. XX+ 
  1002. XX+     if ((fp = fopen(temp, "r")) == NULL) {
  1003. XX+         fprintf(stderr, "vipw: "); perror(temp);
  1004. XX+         return(-1);
  1005. XX+     }
  1006. XX+ 
  1007. XX+     setpwfile(shadow);  spwd = getpwent();  /* initialize shadow passwd */
  1008. XX+ 
  1009. XX+     while ((pwd = getmpent()) != NULL) {
  1010. XX+     loop:
  1011. XX+         if ((spwd == NULL) ||            /* add new user */ 
  1012. XX+             (pwd->pw_uid < spwd->pw_uid) ||
  1013. XX+             (pwd->pw_uid == spwd->pw_uid &&
  1014. XX+              (strcmp(pwd->pw_name, spwd->pw_name) < 0))) {
  1015. XX+             fprintf(ft, "%s:%s:%d:%d:%d,0,0,0,*******:%s:%s\n",
  1016. XX+                 pwd->pw_name,
  1017. XX+                 pwd->pw_passwd,
  1018. XX+                 pwd->pw_uid,
  1019. XX+                 pwd->pw_gid,
  1020. XX+                 BSD_CRIT,
  1021. XX+                 pwd->pw_dir,
  1022. XX+                 pwd->pw_shell);
  1023. XX+             continue;
  1024. XX+         }
  1025. XX+         if ((pwd->pw_uid == spwd->pw_uid) &&   /* update current user */
  1026. XX+             (strcmp(pwd->pw_name, spwd->pw_name) == 0)) {
  1027. XX+             fprintf(ft, "%s:%s:%d:%d:%s:%s:%s\n",
  1028. XX+                 pwd->pw_name,
  1029. XX+                 spwd->pw_passwd,
  1030. XX+                 pwd->pw_uid,
  1031. XX+                 pwd->pw_gid,
  1032. XX+                 spwd->pw_gecos,
  1033. XX+                 pwd->pw_dir,
  1034. XX+                 pwd->pw_shell);
  1035. XX+             spwd = getpwent();
  1036. XX+             continue;
  1037. XX+         }
  1038. XX+ 
  1039. XX+         /* advance shadow passwd to skip removed users */
  1040. XX+ 
  1041. XX+         while (((spwd = getpwent()) != NULL) && 
  1042. XX+                ((pwd->pw_uid > spwd->pw_uid) ||
  1043. XX+             (pwd->pw_uid == spwd->pw_uid &&
  1044. XX+              (strcmp(pwd->pw_name, spwd->pw_name) > 0))))
  1045. XX+             continue;
  1046. XX+         goto loop;
  1047. XX+     }
  1048. XX+ 
  1049. XX+     endpwent();
  1050. XX+     fclose(ft);
  1051. XX+     fclose(fp);
  1052. XX+     return(0);
  1053. XX+ }
  1054. XX+ #endif    elxsi
  1055. SHAR_EOF
  1056. if test 6653 -ne "`wc -c vipw.c.diff`"
  1057. then
  1058. echo shar: error transmitting vipw.c.diff '(should have been 6653 characters)'
  1059. fi
  1060. #    End of shell archive
  1061. exit 0
  1062.  
  1063.  
  1064.