Browse Source

New command line option 'resetpwd'.

default 2 years ago
parent
commit
48ebc54b6e
3 changed files with 35 additions and 12 deletions
  1. 5 12
      main.c
  2. 1 0
      snac.h
  3. 29 0
      utils.c

+ 5 - 12
main.c

@@ -24,21 +24,10 @@ int usage(void)
     printf("queue {basedir} {uid}            Processes a user queue\n");
     printf("follow {basedir} {uid} {actor}   Follows an actor\n");
     printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
-
-//    printf("check {basedir} [{uid}]          Checks the database\n");
-
-//    printf("update {basedir} {uid}           Sends a user update to followers\n");
-//    printf("passwd {basedir} {uid}           Sets the password for {uid}\n");
-//    printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
-//    printf("mute {basedir} {uid} {actor}     Mutes an actor\n");
-//    printf("unmute {basedir} {uid} {actor}   Unmutes an actor\n");
-//    printf("like {basedir} {uid} {url}       Likes an url\n");
-//    printf("announce {basedir} {uid} {url}   Announces (boosts) an url\n");
-//    printf("note {basedir} {uid} {'text'}    Sends a note to followers\n");
-
     printf("request {basedir} {uid} {url}    Requests an object\n");
     printf("actor {basedir} {uid} {url}      Requests an actor\n");
     printf("note {basedir} {uid} {'text'}    Sends a note to followers\n");
+    printf("resetpwd {basedir} {uid}         Resets the password of a user\n");
 
     return 1;
 }
@@ -150,6 +139,10 @@ int main(int argc, char *argv[])
         return 1;
     }
 
+    if (strcmp(cmd, "resetpwd") == 0) {
+        return resetpwd(&snac);
+    }
+
     if (strcmp(cmd, "queue") == 0) {
         process_queue(&snac);
         return 0;

+ 1 - 0
snac.h

@@ -174,3 +174,4 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
 
 int initdb(const char *_basedir);
 int adduser(const char *uid);
+int resetpwd(snac *snac);

+ 29 - 0
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;
+}