struct spwd * pwd_to_spwd(const struct passwd *pw) { static struct spwd sp; /* * Nice, easy parts first. The name and passwd map directly * from the old password structure to the new one. */ sp.sp_namp = pw->pw_name; sp.sp_pwdp = pw->pw_passwd; #ifdef ATT_AGE /* * AT&T-style password aging maps the sp_min, sp_max, and * sp_lstchg information from the pw_age field, which appears * after the encrypted password. */ if (pw->pw_age[0]) { sp.sp_max = (c64i(pw->pw_age[0]) * WEEK) / SCALE; if (pw->pw_age[1]) sp.sp_min = (c64i(pw->pw_age[1]) * WEEK) / SCALE; else sp.sp_min = (10000L * DAY) / SCALE; if (pw->pw_age[1] && pw->pw_age[2]) sp.sp_lstchg = (a64l(pw->pw_age + 2) * WEEK) / SCALE; else sp.sp_lstchg = time((time_t *) 0) / SCALE; } else #endif { /* * Defaults used if there is no pw_age information. */ sp.sp_min = 0; sp.sp_max = (10000L * DAY) / SCALE; sp.sp_lstchg = time((time_t *) 0) / SCALE; } /* * These fields have no corresponding information in the password * file. They are set to uninitialized values. */ sp.sp_warn = -1; sp.sp_expire = -1; sp.sp_inact = -1; sp.sp_flag = -1; return &sp; }
/* * a64l - convert a radix 64 string to a long integer */ long a64l(const char *s) { int i; long value; long shift = 0; for (i = 0, value = 0L;i < 6 && *s;s++) { value += (c64i (*s) << shift); shift += 6; } return (value); }