2 * Copyright (c) 2000, 2002, 2012 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 * Sponsored in part by the Defense Advanced Research Projects
17 * Agency (DARPA) and Air Force Research Laboratory, Air Force
18 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
23 #include <sys/types.h>
33 #endif /* STDC_HEADERS */
36 #endif /* HAVE_STRING_H */
39 #endif /* HAVE_STRINGS_H */
40 #if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
42 #endif /* HAVE_MALLOC_H && !STDC_HEADERS */
45 #define PW_SIZE(name, size) \
48 size = strlen(pw->name) + 1; \
53 #define PW_COPY(name, size) \
56 (void)memcpy(cp, pw->name, size); \
63 pw_dup(const struct passwd *pw)
66 size_t nsize, psize, gsize, dsize, ssize, total;
67 #ifdef HAVE_LOGIN_CAP_H
72 /* Allocate in one big chunk for easy freeing */
73 total = sizeof(struct passwd);
74 PW_SIZE(pw_name, nsize);
75 PW_SIZE(pw_passwd, psize);
76 #ifdef HAVE_LOGIN_CAP_H
77 PW_SIZE(pw_class, csize);
79 PW_SIZE(pw_gecos, gsize);
80 PW_SIZE(pw_dir, dsize);
81 PW_SIZE(pw_shell, ssize);
83 if ((cp = malloc(total)) == NULL)
85 newpw = (struct passwd *)cp;
88 * Copy in passwd contents and make strings relative to space
89 * at the end of the buffer.
91 (void)memcpy(newpw, pw, sizeof(struct passwd));
92 cp += sizeof(struct passwd);
94 PW_COPY(pw_name, nsize);
95 PW_COPY(pw_passwd, psize);
96 #ifdef HAVE_LOGIN_CAP_H
97 PW_COPY(pw_class, csize);
99 PW_COPY(pw_gecos, gsize);
100 PW_COPY(pw_dir, dsize);
101 PW_COPY(pw_shell, ssize);