This source file includes following definitions.
- pw_dup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include "config.h"
34
35 #include <sys/param.h>
36
37 #if !defined(OpenBSD) || OpenBSD < 200105
38
39 #include <pwd.h>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43
44 #include "funcs.h"
45 #include "globals.h"
46
47 struct passwd *
48 pw_dup(const struct passwd *pw) {
49 char *cp;
50 size_t nsize=0, psize=0, gsize=0, dsize=0, ssize=0, total;
51 struct passwd *newpw;
52
53
54 total = sizeof(struct passwd);
55 if (pw->pw_name) {
56 nsize = strlen(pw->pw_name) + 1;
57 total += nsize;
58 }
59 if (pw->pw_passwd) {
60 psize = strlen(pw->pw_passwd) + 1;
61 total += psize;
62 }
63 #ifdef LOGIN_CAP
64 if (pw->pw_class) {
65 csize = strlen(pw->pw_class) + 1;
66 total += csize;
67 }
68 #endif
69 if (pw->pw_gecos) {
70 gsize = strlen(pw->pw_gecos) + 1;
71 total += gsize;
72 }
73 if (pw->pw_dir) {
74 dsize = strlen(pw->pw_dir) + 1;
75 total += dsize;
76 }
77 if (pw->pw_shell) {
78 ssize = strlen(pw->pw_shell) + 1;
79 total += ssize;
80 }
81 if ((cp = malloc(total)) == NULL)
82 return (NULL);
83 newpw = (struct passwd *)cp;
84
85
86
87
88
89 (void)memcpy(newpw, pw, sizeof(struct passwd));
90 cp += sizeof(struct passwd);
91 if (pw->pw_name) {
92 (void)memcpy(cp, pw->pw_name, nsize);
93 newpw->pw_name = cp;
94 cp += nsize;
95 }
96 if (pw->pw_passwd) {
97 (void)memcpy(cp, pw->pw_passwd, psize);
98 newpw->pw_passwd = cp;
99 cp += psize;
100 }
101 #ifdef LOGIN_CAP
102 if (pw->pw_class) {
103 (void)memcpy(cp, pw->pw_class, csize);
104 newpw->pw_class = cp;
105 cp += csize;
106 }
107 #endif
108 if (pw->pw_gecos) {
109 (void)memcpy(cp, pw->pw_gecos, gsize);
110 newpw->pw_gecos = cp;
111 cp += gsize;
112 }
113 if (pw->pw_dir) {
114 (void)memcpy(cp, pw->pw_dir, dsize);
115 newpw->pw_dir = cp;
116 cp += dsize;
117 }
118 if (pw->pw_shell) {
119 (void)memcpy(cp, pw->pw_shell, ssize);
120 newpw->pw_shell = cp;
121 cp += ssize;
122 }
123
124 return (newpw);
125 }
126
127 #endif