2 Unix SMB/Netbios implementation.
4 Samba utility functions
5 Copyright (C) Simo Sorce 2001
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 /****************************************************************
25 Returns a single linked list of group entries.
26 Use grent_free() to free it after use.
27 ****************************************************************/
29 struct sys_grent * getgrent_list(void)
31 struct sys_grent *glist;
32 struct sys_grent *gent;
35 gent = (struct sys_grent *) malloc(sizeof(struct sys_grent));
37 DEBUG (0, ("Out of memory in getgrent_list!\n"));
47 memset(gent, '\0', sizeof(struct sys_grent));
49 if ((gent->gr_name = strdup(grp->gr_name)) == NULL)
53 if ((gent->gr_passwd = strdup(grp->gr_passwd)) == NULL)
56 gent->gr_gid = grp->gr_gid;
58 /* number of strings in gr_mem */
59 for (num = 0; grp->gr_mem[num]; num++)
62 /* alloc space for gr_mem string pointers */
63 if ((gent->gr_mem = (char **) malloc(num+1 * sizeof(char *))) == NULL)
66 for (i=0; i < num; i++) {
67 if ((gent->gr_mem[i] = strdup(grp->gr_mem[i])) == NULL)
70 gent->gr_mem[num] = NULL;
74 gent->next = (struct sys_grent *) malloc(sizeof(struct sys_grent));
75 if (gent->next == NULL)
87 DEBUG(0, ("Out of memory in getgrent_list!\n"));
92 /****************************************************************
93 Free the single linked list of group entries made by
95 ****************************************************************/
97 void grent_free (struct sys_grent *glist)
101 struct sys_grent *temp;
104 free(glist->gr_name);
105 if (glist->gr_passwd)
106 free(glist->gr_passwd);
121 /****************************************************************
122 Returns a single linked list of passwd entries.
123 Use pwent_free() to free it after use.
124 ****************************************************************/
126 struct sys_pwent * getpwent_list(void)
128 struct sys_pwent *plist;
129 struct sys_pwent *pent;
132 pent = (struct sys_pwent *) malloc(sizeof(struct sys_pwent));
134 DEBUG (0, ("Out of memory in getpwent_list!\n"));
141 while (pwd != NULL) {
142 memset(pent, '\0', sizeof(struct sys_pwent));
144 if ((pent->pw_name = strdup(pwd->pw_name)) == NULL)
147 if (pwd->pw_passwd) {
148 if ((pent->pw_passwd = strdup(pwd->pw_passwd)) == NULL)
151 pent->pw_uid = pwd->pw_uid;
152 pent->pw_gid = pwd->pw_gid;
154 if ((pent->pw_name = strdup(pwd->pw_gecos)) == NULL)
158 if ((pent->pw_name = strdup(pwd->pw_dir)) == NULL)
162 if ((pent->pw_name = strdup(pwd->pw_shell)) == NULL)
168 pent->next = (struct sys_pwent *) malloc(sizeof(struct sys_pwent));
169 if (pent->next == NULL)
181 DEBUG(0, ("Out of memory in getpwent_list!\n"));
186 /****************************************************************
187 Free the single linked list of passwd entries made by
189 ****************************************************************/
191 void pwent_free (struct sys_pwent *plist)
194 struct sys_pwent *temp;
197 free(plist->pw_name);
198 if (plist->pw_passwd)
199 free(plist->pw_passwd);
201 free(plist->pw_gecos);
205 free(plist->pw_shell);