Deleted Added
full compact
pw_user.c (20576) pw_user.c (20590)
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: pw_user.c,v 1.3 1996/12/16 17:37:58 davidn Exp $
26 * $Id: pw_user.c,v 1.4 1996/12/17 01:43:30 davidn Exp $
27 */
28
29#include <unistd.h>
30#include <fcntl.h>
31#include <ctype.h>
32#include <paths.h>
33#include <sys/param.h>
34#include <dirent.h>

--- 702 unchanged lines hidden (view full) ---

737 srandom((unsigned) (time(NULL) ^ getpid()));
738 for (i = 0; i < 8; i++)
739 salt[i] = chars[random() % 63];
740 salt[i] = '\0';
741
742 return strcpy(buf, crypt(password, salt));
743}
744
27 */
28
29#include <unistd.h>
30#include <fcntl.h>
31#include <ctype.h>
32#include <paths.h>
33#include <sys/param.h>
34#include <dirent.h>

--- 702 unchanged lines hidden (view full) ---

737 srandom((unsigned) (time(NULL) ^ getpid()));
738 for (i = 0; i < 8; i++)
739 salt[i] = chars[random() % 63];
740 salt[i] = '\0';
741
742 return strcpy(buf, crypt(password, salt));
743}
744
745#if defined(__FreeBSD__)
746
747#if defined(USE_MD5RAND)
745u_char *
748u_char *
746pw_genmd5rand (u_char *d) /* cryptographically secure rng */
749pw_getrand(u_char *buf, int len) /* cryptographically secure rng */
747{
750{
748 MD5_CTX md5_ctx;
749 struct timeval tv, tvo;
750 struct rusage ru;
751 int n=0;
752 int t;
753 MD5Init (&md5_ctx);
754 t=getpid();
755 MD5Update (&md5_ctx, (u_char*)&t, sizeof t);
756 t=getppid();
757 MD5Update (&md5_ctx, (u_char*)&t, sizeof t);
758 gettimeofday (&tvo, NULL);
759 do {
760 getrusage (RUSAGE_SELF, &ru);
761 MD5Update (&md5_ctx, (u_char*)&ru, sizeof ru);
762 gettimeofday (&tv, NULL);
763 MD5Update (&md5_ctx, (u_char*)&tv, sizeof tv);
764 } while (n++<20 || tv.tv_usec-tvo.tv_usec<100*1000);
765 MD5Final (d, &md5_ctx);
766 return d;
751 int i;
752 for (i=0;i<len;i+=16) {
753 u_char ubuf[16];
754
755 MD5_CTX md5_ctx;
756 struct timeval tv, tvo;
757 struct rusage ru;
758 int n=0;
759 int t;
760
761 MD5Init (&md5_ctx);
762 t=getpid();
763 MD5Update (&md5_ctx, (u_char*)&t, sizeof t);
764 t=getppid();
765 MD5Update (&md5_ctx, (u_char*)&t, sizeof t);
766 gettimeofday (&tvo, NULL);
767 do {
768 getrusage (RUSAGE_SELF, &ru);
769 MD5Update (&md5_ctx, (u_char*)&ru, sizeof ru);
770 gettimeofday (&tv, NULL);
771 MD5Update (&md5_ctx, (u_char*)&tv, sizeof tv);
772 } while (n++<20 || tv.tv_usec-tvo.tv_usec<100*1000);
773 MD5Final (ubuf, &md5_ctx);
774 memcpy(buf+i, ubuf, MIN(16, len-n));
775 }
776 return buf;
767}
768
777}
778
779#else /* Use random device (preferred) */
780
769static u_char *
770pw_getrand(u_char *buf, int len)
771{
772 int fd;
773 fd = open("/dev/urandom", O_RDONLY);
781static u_char *
782pw_getrand(u_char *buf, int len)
783{
784 int fd;
785 fd = open("/dev/urandom", O_RDONLY);
774 if (fd==-1 || read(fd, buf, len)!=len) {
775 int n;
776 for (n=0;n<len;n+=16) {
777 u_char ubuf[16];
778 pw_genmd5rand(ubuf);
779 memcpy(buf+n, ubuf, MIN(16, len-n));
780 }
781 }
786 if (fd==-1)
787 cmderr(EX_OSFILE, "can't open /dev/urandom: %s\n", strerror(errno));
788 else if (read(fd, buf, len)!=len)
789 cmderr(EX_IOERR, "read error on /dev/urandom\n");
782 close(fd);
783 return buf;
784}
785
790 close(fd);
791 return buf;
792}
793
794#endif
795
796#else /* Portable version */
797
798static u_char *
799pw_getrand(u_char *buf, int len)
800{
801 int i;
802
803 for (i = 0; i < len; i++) {
804 unsigned val = random();
805 /* Use all bits in the random value */
806 buf[i]=(u_char)((val >> 24) ^ (val >> 16) ^ (val >> 8) ^ val);
807 }
808 return buf;
809}
810
811#endif
812
786static char *
787pw_password(struct userconf * cnf, struct cargs * args, char const * user)
788{
789 int i, l;
790 char pwbuf[32];
791 u_char rndbuf[sizeof pwbuf];
792
793 switch (cnf->default_password) {

--- 41 unchanged lines hidden (view full) ---

835 fmtpwent(buf, pwd);
836 fputs(buf, stdout);
837 } else {
838 int j;
839 char *p;
840 struct group *grp = getgrgid(pwd->pw_gid);
841 char uname[60] = "User &", office[60] = "[None]",
842 wphone[60] = "[None]", hphone[60] = "[None]";
813static char *
814pw_password(struct userconf * cnf, struct cargs * args, char const * user)
815{
816 int i, l;
817 char pwbuf[32];
818 u_char rndbuf[sizeof pwbuf];
819
820 switch (cnf->default_password) {

--- 41 unchanged lines hidden (view full) ---

862 fmtpwent(buf, pwd);
863 fputs(buf, stdout);
864 } else {
865 int j;
866 char *p;
867 struct group *grp = getgrgid(pwd->pw_gid);
868 char uname[60] = "User &", office[60] = "[None]",
869 wphone[60] = "[None]", hphone[60] = "[None]";
870 char acexpire[32] = "[None]", pwexpire[32] = "[None]";
871 struct tm * tptr;
843
844 if ((p = strtok(pwd->pw_gecos, ",")) != NULL) {
845 strncpy(uname, p, sizeof uname);
846 uname[sizeof uname - 1] = '\0';
847 if ((p = strtok(NULL, ",")) != NULL) {
848 strncpy(office, p, sizeof office);
849 office[sizeof office - 1] = '\0';
850 if ((p = strtok(NULL, ",")) != NULL) {

--- 12 unchanged lines hidden (view full) ---

863 if ((p = strchr(uname, '&')) != NULL) {
864 int l = strlen(pwd->pw_name);
865 int m = strlen(p);
866
867 memmove(p + l, p + 1, m);
868 memmove(p, pwd->pw_name, l);
869 *p = (char) toupper(*p);
870 }
872
873 if ((p = strtok(pwd->pw_gecos, ",")) != NULL) {
874 strncpy(uname, p, sizeof uname);
875 uname[sizeof uname - 1] = '\0';
876 if ((p = strtok(NULL, ",")) != NULL) {
877 strncpy(office, p, sizeof office);
878 office[sizeof office - 1] = '\0';
879 if ((p = strtok(NULL, ",")) != NULL) {

--- 12 unchanged lines hidden (view full) ---

892 if ((p = strchr(uname, '&')) != NULL) {
893 int l = strlen(pwd->pw_name);
894 int m = strlen(p);
895
896 memmove(p + l, p + 1, m);
897 memmove(p, pwd->pw_name, l);
898 *p = (char) toupper(*p);
899 }
900 if (pwd->pw_expire > (time_t)0 && (tptr = localtime(&pwd->pw_expire)) != NULL)
901 strftime(acexpire, sizeof acexpire, "%c", tptr);
902 if (pwd->pw_change > (time_t)9 && (tptr = localtime(&pwd->pw_change)) != NULL)
903 strftime(pwexpire, sizeof pwexpire, "%c", tptr);
871 printf("Login Name : %-10s #%-22ld Group : %-10s #%ld\n"
872 " Full Name : %s\n"
873 " Home : %-32.32s Class : %s\n"
874 " Shell : %-32.32s Office : %s\n"
904 printf("Login Name : %-10s #%-22ld Group : %-10s #%ld\n"
905 " Full Name : %s\n"
906 " Home : %-32.32s Class : %s\n"
907 " Shell : %-32.32s Office : %s\n"
875 "Work Phone : %-32.32s Home Phone : %s\n",
876
908 "Work Phone : %-32.32s Home Phone : %s\n"
909 "Acc Expire : %-32.32s Pwd Expire : %s\n",
877 pwd->pw_name, (long) pwd->pw_uid,
878 grp ? grp->gr_name : "(invalid)", (long) pwd->pw_gid,
879 uname, pwd->pw_dir, pwd->pw_class,
910 pwd->pw_name, (long) pwd->pw_uid,
911 grp ? grp->gr_name : "(invalid)", (long) pwd->pw_gid,
912 uname, pwd->pw_dir, pwd->pw_class,
880 pwd->pw_shell, office, wphone, hphone);
913 pwd->pw_shell, office, wphone, hphone,
914 acexpire, pwexpire);
881 setgrent();
882 j = 0;
883 while ((grp=getgrent()) != NULL)
884 {
885 int i = 0;
886 while (i < _UC_MAXGROUPS && grp->gr_mem[i] != NULL)
887 {
888 if (strcmp(grp->gr_mem[i], pwd->pw_name)==0)

--- 57 unchanged lines hidden ---
915 setgrent();
916 j = 0;
917 while ((grp=getgrent()) != NULL)
918 {
919 int i = 0;
920 while (i < _UC_MAXGROUPS && grp->gr_mem[i] != NULL)
921 {
922 if (strcmp(grp->gr_mem[i], pwd->pw_name)==0)

--- 57 unchanged lines hidden ---