diff options
Diffstat (limited to 'utils.c')
| -rw-r--r-- | utils.c | 29 |
1 files changed, 29 insertions, 0 deletions
| @@ -310,3 +310,32 @@ int adduser(const char *uid) | |||
| 310 | 310 | ||
| 311 | return 0; | 311 | return 0; |
| 312 | } | 312 | } |
| 313 | |||
| 314 | |||
| 315 | int 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 | } | ||