home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1990, John F. Haugh II
- * All rights reserved.
- *
- * Use, duplication, and disclosure prohibited without
- * the express written permission of the author.
- *
- * Duplication is permitted for non-commercial [ profit making ]
- * purposes provided this and other copyright notices remain
- * intact.
- */
-
- #include <pwd.h>
-
- int pw_pack (passwd, buf)
- struct passwd *passwd;
- char *buf;
- {
- char *cp;
-
- cp = buf;
- strcpy (cp, passwd->pw_name);
- cp += strlen (cp) + 1;
-
- strcpy (cp, passwd->pw_passwd);
- cp += strlen (cp) + 1;
-
- memcpy (cp, (void *) &passwd->pw_uid, sizeof passwd->pw_uid);
- cp += sizeof passwd->pw_uid;
-
- memcpy (cp, (void *) &passwd->pw_gid, sizeof passwd->pw_gid);
- cp += sizeof passwd->pw_gid;
-
- strcpy (cp, passwd->pw_gecos);
- cp += strlen (cp) + 1;
-
- strcpy (cp, passwd->pw_dir);
- cp += strlen (cp) + 1;
-
- strcpy (cp, passwd->pw_shell);
- cp += strlen (cp) + 1;
-
- return cp - buf;
- }
-
- int pw_unpack (buf, len, passwd)
- char *buf;
- int len;
- struct passwd *passwd;
- {
- char *org = buf;
-
- passwd->pw_name = buf;
- buf += strlen (buf) + 1;
- if (buf - org > len)
- return -1;
-
- passwd->pw_passwd = buf;
- buf += strlen (buf) + 1;
- if (buf - org > len)
- return -1;
-
- memcpy ((void *) &passwd->pw_uid, (void *) buf, sizeof passwd->pw_uid);
- buf += sizeof passwd->pw_uid;
- if (buf - org > len)
- return -1;
-
- memcpy ((void *) &passwd->pw_gid, (void *) buf, sizeof passwd->pw_gid);
- buf += sizeof passwd->pw_gid;
- if (buf - org > len)
- return -1;
-
- passwd->pw_gecos = buf;
- buf += strlen (buf) + 1;
- if (buf - org > len)
- return -1;
-
- passwd->pw_dir = buf;
- buf += strlen (buf) + 1;
- if (buf - org > len)
- return -1;
-
- passwd->pw_shell = buf;
- buf += strlen (buf) + 1;
- if (buf - org > len)
- return -1;
-
- return 0;
- }
-