From ce9fb618e537ec5f4227607501805dc36e77580f Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sun, 28 Apr 2013 16:57:39 +0300 Subject: [PATCH] corrected bug which prevented ocpasswd adding more than a single user. --- src/ocpasswd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ocpasswd.c b/src/ocpasswd.c index 8167d7bc..e8ded36c 100644 --- a/src/ocpasswd.c +++ b/src/ocpasswd.c @@ -65,6 +65,7 @@ crypt_int(const char *fpasswd, const char *username, const char *groupname, exit(1); } + memset(salt, 0, sizeof(salt)); p = salt; p += snprintf(salt, sizeof(salt), "$5$"); @@ -110,6 +111,7 @@ crypt_int(const char *fpasswd, const char *username, const char *groupname, if (fd == NULL) { fprintf(fd2, "%s:%s:%s\n", username, groupname, cr_passwd); } else { + int found = 0; while ((len = getline(&line, &line_size, fd)) > 0) { p = strchr(line, ':'); if (p == NULL) @@ -118,12 +120,16 @@ crypt_int(const char *fpasswd, const char *username, const char *groupname, l = p-line; if (l == username_len && strncmp(line, username, l) == 0) { fprintf(fd2, "%s:%s:%s\n", username, groupname, cr_passwd); + found = 1; } else { fwrite(line, 1, len, fd2); } } free(line); fclose(fd); + + if (found == 0) + fprintf(fd2, "%s:%s:%s\n", username, groupname, cr_passwd); } fclose(fd2);