aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/grp.h1
-rw-r--r--include/pwd.h1
-rw-r--r--src/passwd/fgetspent.c11
-rw-r--r--src/passwd/putgrent.c14
-rw-r--r--src/passwd/putpwent.c9
5 files changed, 36 insertions, 0 deletions
diff --git a/include/grp.h b/include/grp.h
index 8e2e1f2..b331d32 100644
--- a/include/grp.h
+++ b/include/grp.h
@@ -36,6 +36,7 @@ void setgrent(void);
#ifdef _GNU_SOURCE
struct group *fgetgrent(FILE *stream);
+int putgrent(const struct group *, FILE *);
#endif
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
diff --git a/include/pwd.h b/include/pwd.h
index 91fe426..55d9d42 100644
--- a/include/pwd.h
+++ b/include/pwd.h
@@ -39,6 +39,7 @@ int getpwnam_r (const char *, struct passwd *, char *, size_t, struct passwd **)
#ifdef _GNU_SOURCE
struct passwd *fgetpwent(FILE *);
+int putpwent(const struct passwd *, FILE *);
#endif
#ifdef __cplusplus
diff --git a/src/passwd/fgetspent.c b/src/passwd/fgetspent.c
new file mode 100644
index 0000000..a9a3c97
--- /dev/null
+++ b/src/passwd/fgetspent.c
@@ -0,0 +1,11 @@
+#include "pwf.h"
+
+struct spwd *fgetspent(FILE *f)
+{
+ return 0;
+}
+
+int putspent(const struct spwd *sp, FILE *f)
+{
+ return -1;
+}
diff --git a/src/passwd/putgrent.c b/src/passwd/putgrent.c
new file mode 100644
index 0000000..d7847b1
--- /dev/null
+++ b/src/passwd/putgrent.c
@@ -0,0 +1,14 @@
+#include <grp.h>
+#include <stdio.h>
+
+int putgrent(const struct group *gr, FILE *f)
+{
+ int r;
+ size_t i;
+ flockfile(f);
+ r = fprintf(f, "%s:%s:%d:", gr->gr_name, gr->gr_passwd, gr->gr_gid);
+ if (gr->gr_mem) for (i=0; gr->gr_mem[i]; i++)
+ if (fprintf(f, "%s%s", i?",":"", gr->gr_mem[i])<0) r = -1;
+ funlockfile(f);
+ return r<0 ? -1 : 0;
+}
diff --git a/src/passwd/putpwent.c b/src/passwd/putpwent.c
new file mode 100644
index 0000000..80fbf38
--- /dev/null
+++ b/src/passwd/putpwent.c
@@ -0,0 +1,9 @@
+#include <pwd.h>
+#include <stdio.h>
+
+int putpwent(const struct passwd *pw, FILE *f)
+{
+ return fprintf(f, "%s:%s:%d:%d:%s:%s:%s\n",
+ pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
+ pw->pw_gecos, pw->pw_dir, pw->pw_shell)<0 ? -1 : 0;
+}