grupd.c (30259) | grupd.c (44229) |
---|---|
1/*- 2 * Copyright (C) 1996 3 * David L. Nugent. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef lint 28static const char rcsid[] = | 1/*- 2 * Copyright (C) 1996 3 * David L. Nugent. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef lint 28static const char rcsid[] = |
29 "$Id$"; | 29 "$Id: grupd.c,v 1.5 1997/10/10 06:23:32 charnier Exp $"; |
30#endif /* not lint */ 31 32#include <stdio.h> 33#include <stdlib.h> 34#include <string.h> 35#include <unistd.h> 36#include <stdarg.h> 37#include <sys/types.h> 38#include <sys/stat.h> | 30#endif /* not lint */ 31 32#include <stdio.h> 33#include <stdlib.h> 34#include <string.h> 35#include <unistd.h> 36#include <stdarg.h> 37#include <sys/types.h> 38#include <sys/stat.h> |
39#include <sys/param.h> |
|
39 40#include "pwupd.h" 41 | 40 41#include "pwupd.h" 42 |
43static char * grpath = _PATH_PWD; 44 |
|
42int | 45int |
46setgrdir(const char * dir) 47{ 48 if (dir == NULL) 49 return -1; 50 else { 51 char * d = malloc(strlen(dir)+1); 52 if (d == NULL) 53 return -1; 54 grpath = strcpy(d, dir); 55 } 56 return 0; 57} 58 59char * 60getgrpath(const char * file) 61{ 62 static char pathbuf[MAXPATHLEN]; 63 64 snprintf(pathbuf, sizeof pathbuf, "%s/%s", grpath, file); 65 return pathbuf; 66} 67 68int 69grdb(char *arg,...) 70{ 71 /* 72 * This is a stub for now, but maybe eventually be functional 73 * if ever an indexed version of /etc/groups is implemented. 74 */ 75 arg=arg; 76 return 0; 77} 78 79int |
|
43fmtgrentry(char **buf, int * buflen, struct group * grp, int type) 44{ 45 int i, l; 46 47 /* 48 * Since a group line is of arbitrary length, 49 * we need to calculate up-front just how long 50 * it will need to be... --- 40 unchanged lines hidden (view full) --- 91static int 92gr_update(struct group * grp, char const * group, int mode) 93{ 94 int l; 95 char pfx[64]; 96 int grbuflen = 0; 97 char *grbuf = NULL; 98 | 80fmtgrentry(char **buf, int * buflen, struct group * grp, int type) 81{ 82 int i, l; 83 84 /* 85 * Since a group line is of arbitrary length, 86 * we need to calculate up-front just how long 87 * it will need to be... --- 40 unchanged lines hidden (view full) --- 128static int 129gr_update(struct group * grp, char const * group, int mode) 130{ 131 int l; 132 char pfx[64]; 133 int grbuflen = 0; 134 char *grbuf = NULL; 135 |
99 endgrent(); | 136 ENDGRENT(); |
100 l = snprintf(pfx, sizeof pfx, "%s:", group); 101 102 /* 103 * Update the group file 104 */ 105 if (grp != NULL && fmtgrentry(&grbuf, &grbuflen, grp, PWF_PASSWD) == -1) 106 l = -1; | 137 l = snprintf(pfx, sizeof pfx, "%s:", group); 138 139 /* 140 * Update the group file 141 */ 142 if (grp != NULL && fmtgrentry(&grbuf, &grbuflen, grp, PWF_PASSWD) == -1) 143 l = -1; |
107 else 108 l = fileupdate(_PATH_GROUP, 0644, grbuf, pfx, l, mode); | 144 else { 145 if ((l = fileupdate(getgrpath(_GROUP), 0644, grbuf, pfx, l, mode)) != 0) 146 l = grdb(NULL) == 0; 147 } |
109 if (grbuf != NULL) 110 free(grbuf); 111 return l; 112} 113 114 115int 116addgrent(struct group * grp) --- 15 unchanged lines hidden --- | 148 if (grbuf != NULL) 149 free(grbuf); 150 return l; 151} 152 153 154int 155addgrent(struct group * grp) --- 15 unchanged lines hidden --- |