summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c17
-rw-r--r--snac.h1
-rw-r--r--utils.c29
3 files changed, 35 insertions, 12 deletions
diff --git a/main.c b/main.c
index 8fbdb88..7048426 100644
--- a/main.c
+++ b/main.c
@@ -24,21 +24,10 @@ int usage(void)
24 printf("queue {basedir} {uid} Processes a user queue\n"); 24 printf("queue {basedir} {uid} Processes a user queue\n");
25 printf("follow {basedir} {uid} {actor} Follows an actor\n"); 25 printf("follow {basedir} {uid} {actor} Follows an actor\n");
26 printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); 26 printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
27
28// printf("check {basedir} [{uid}] Checks the database\n");
29
30// printf("update {basedir} {uid} Sends a user update to followers\n");
31// printf("passwd {basedir} {uid} Sets the password for {uid}\n");
32// printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
33// printf("mute {basedir} {uid} {actor} Mutes an actor\n");
34// printf("unmute {basedir} {uid} {actor} Unmutes an actor\n");
35// printf("like {basedir} {uid} {url} Likes an url\n");
36// printf("announce {basedir} {uid} {url} Announces (boosts) an url\n");
37// printf("note {basedir} {uid} {'text'} Sends a note to followers\n");
38
39 printf("request {basedir} {uid} {url} Requests an object\n"); 27 printf("request {basedir} {uid} {url} Requests an object\n");
40 printf("actor {basedir} {uid} {url} Requests an actor\n"); 28 printf("actor {basedir} {uid} {url} Requests an actor\n");
41 printf("note {basedir} {uid} {'text'} Sends a note to followers\n"); 29 printf("note {basedir} {uid} {'text'} Sends a note to followers\n");
30 printf("resetpwd {basedir} {uid} Resets the password of a user\n");
42 31
43 return 1; 32 return 1;
44} 33}
@@ -150,6 +139,10 @@ int main(int argc, char *argv[])
150 return 1; 139 return 1;
151 } 140 }
152 141
142 if (strcmp(cmd, "resetpwd") == 0) {
143 return resetpwd(&snac);
144 }
145
153 if (strcmp(cmd, "queue") == 0) { 146 if (strcmp(cmd, "queue") == 0) {
154 process_queue(&snac); 147 process_queue(&snac);
155 return 0; 148 return 0;
diff --git a/snac.h b/snac.h
index 636fcb3..6f3899b 100644
--- a/snac.h
+++ b/snac.h
@@ -174,3 +174,4 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
174 174
175int initdb(const char *_basedir); 175int initdb(const char *_basedir);
176int adduser(const char *uid); 176int adduser(const char *uid);
177int resetpwd(snac *snac);
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}