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 <stdio.h>
- #include <pwd.h>
- #ifdef BSD
- #include <strings.h>
- #else
- #include <string.h>
- #endif
-
- #ifndef lint
- static char sccsid[] = "@(#)pwpack.c 2.3 23:06:29 8/5/90";
- #endif
-
- 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);
- if (passwd->pw_age && passwd->pw_age[0]) {
- cp += strlen (cp);
- *cp++ = ',';
- strcpy (cp, passwd->pw_age);
- }
- 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;
- char *cp;
-
- 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;
-
- if (cp = strchr (passwd->pw_passwd, ',')) {
- *cp++ = '\0';
- passwd->pw_age = cp;
- } else
- passwd->pw_age = "";
-
- 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;
- }
-