home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / netsrcs / pswd_age.2 < prev    next >
Internet Message Format  |  1988-03-13  |  29KB

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