summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorGravatar default2022-12-04 21:26:24 +0100
committerGravatar default2022-12-04 21:26:24 +0100
commit48ebc54b6eabf16fb5ab34618eb4b4de4f8b5fd7 (patch)
tree861c34d7df89344d605a6cba82093835c3dcfe68 /utils.c
parentNew function new_password(). (diff)
downloadsnac2-48ebc54b6eabf16fb5ab34618eb4b4de4f8b5fd7.tar.gz
snac2-48ebc54b6eabf16fb5ab34618eb4b4de4f8b5fd7.tar.xz
snac2-48ebc54b6eabf16fb5ab34618eb4b4de4f8b5fd7.zip
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)
310 310
311 return 0; 311 return 0;
312} 312}
313
314
315int resetpwd(snac *snac)
316/* creates a new password for the user */
317{
318 xs *clear_pwd = NULL;
319 xs *hashed_pwd = NULL;
320 xs *fn = xs_fmt("%s/user.json", snac->basedir);
321 FILE *f;
322 int ret = 0;
323
324 new_password(snac->uid, &clear_pwd, &hashed_pwd);
325
326 snac->config = xs_dict_set(snac->config, "passwd", hashed_pwd);
327
328 if ((f = fopen(fn, "w")) != NULL) {
329 xs *j = xs_json_dumps_pp(snac->config, 4);
330 fwrite(j, strlen(j), 1, f);
331 fclose(f);
332
333 printf("New password for user %s is %s\n", snac->uid, clear_pwd);
334 }
335 else {
336 printf("ERROR: cannot write to %s\n", fn);
337 ret = 1;
338 }
339
340 return ret;
341}