]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - pw/grupd.c
Close some file descriptor leaks in pw
[pw-darwin.git] / pw / grupd.c
index 8735831595f0912ad75c270194adec2eaa35ebde..38d5e5bc956ce26b01dae3e2ca470e08132d485e 100644 (file)
@@ -29,38 +29,23 @@ static const char rcsid[] =
   "$FreeBSD$";
 #endif /* not lint */
 
+#include <err.h>
 #include <grp.h>
 #include <libutil.h>
-#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <sys/param.h>
+#include <unistd.h>
 
 #include "pwupd.h"
 
-static char * grpath = _PATH_PWD;
-
-int
-setgrdir(const char * dir)
-{
-       if (dir == NULL)
-               return -1;
-       else
-               grpath = strdup(dir);
-       if (grpath == NULL)
-               return -1;
-
-       return 0;
-}
-
 char *
 getgrpath(const char * file)
 {
        static char pathbuf[MAXPATHLEN];
 
-       snprintf(pathbuf, sizeof pathbuf, "%s/%s", grpath, file);
-       return pathbuf;
+       snprintf(pathbuf, sizeof pathbuf, "%s/%s", conf.etcpath, file);
+
+       return (pathbuf);
 }
 
 static int
@@ -76,7 +61,7 @@ gr_update(struct group * grp, char const * group)
        if (group != NULL)
                old_gr = GETGRNAM(group);
 
-       if (gr_init(grpath, NULL))
+       if (gr_init(conf.etcpath, NULL))
                err(1, "gr_init()");
 
        if ((pfd = gr_lock()) == -1) {
@@ -89,8 +74,10 @@ gr_update(struct group * grp, char const * group)
        }
        if (gr_copy(pfd, tfd, gr, old_gr) == -1) {
                gr_fini();
+               close(tfd);
                err(1, "gr_copy()");
        }
+       close(tfd);
        if (gr_mkdb() == -1) {
                gr_fini();
                err(1, "gr_mkdb()");