summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-12-04 21:26:24 +0100
committerdefault <nobody@localhost>2022-12-04 21:26:24 +0100
commit48ebc54b6eabf16fb5ab34618eb4b4de4f8b5fd7 (patch)
tree861c34d7df89344d605a6cba82093835c3dcfe68 /utils.c
parent7787a2ded9a0ab445c9bd310dfc8b909509d763f (diff)
New command line option 'resetpwd'.
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 300115b..14b4816 100644
--- a/utils.c
+++ b/utils.c
@@ -310,3 +310,32 @@ int adduser(const char *uid)
return 0;
}
+
+
+int resetpwd(snac *snac)
+/* creates a new password for the user */
+{
+ xs *clear_pwd = NULL;
+ xs *hashed_pwd = NULL;
+ xs *fn = xs_fmt("%s/user.json", snac->basedir);
+ FILE *f;
+ int ret = 0;
+
+ new_password(snac->uid, &clear_pwd, &hashed_pwd);
+
+ snac->config = xs_dict_set(snac->config, "passwd", hashed_pwd);
+
+ if ((f = fopen(fn, "w")) != NULL) {
+ xs *j = xs_json_dumps_pp(snac->config, 4);
+ fwrite(j, strlen(j), 1, f);
+ fclose(f);
+
+ printf("New password for user %s is %s\n", snac->uid, clear_pwd);
+ }
+ else {
+ printf("ERROR: cannot write to %s\n", fn);
+ ret = 1;
+ }
+
+ return ret;
+}