summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--RELEASE_NOTES.md2
-rw-r--r--data.c2
-rw-r--r--doc/snac.16
-rw-r--r--main.c17
-rw-r--r--snac.c6
-rw-r--r--snac.h11
-rw-r--r--utils.c55
7 files changed, 67 insertions, 32 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index e79bf2a..f713cb9 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -2,6 +2,8 @@
## 2.14
+New command-line operation, `resetpwd`, to reset a user's password to a new, random one.
+
Added a user setup option to toggle if sensitive content is shown or not by default (contributed by kensanata).
Fixed crash when debug level >= 2 (contributed by kensanata).
diff --git a/data.c b/data.c
index e3d1268..f36c01d 100644
--- a/data.c
+++ b/data.c
@@ -120,7 +120,7 @@ void user_free(snac *snac)
}
-int user_open(snac *snac, char *uid)
+int user_open(snac *snac, const char *uid)
/* opens a user */
{
int ret = 0;
diff --git a/doc/snac.1 b/doc/snac.1
index 0b6d75a..e1d0398 100644
--- a/doc/snac.1
+++ b/doc/snac.1
@@ -150,6 +150,8 @@ Upgrades the data storage after installing a new version.
Only necessary if
.Nm
complains and demands it.
+.It Cm httpd Ar basedir
+Starts the daemon.
.It Cm purge Ar basedir
Purges old data from the timeline of all users.
.It Cm adduser Ar basedir Op uid
@@ -160,8 +162,8 @@ the server
is installed in the user's
.Pa static/
directory.
-.It Cm httpd Ar basedir
-Starts the daemon.
+.It Cm resetpwd Ar basedir Ar uid
+Resets a user's password to a new, random one.
.It Cm queue Ar basedir Ar uid
Processes the output queue of the specied user, sending all
enqueued messages and re-enqueing the failing ones. This command
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)
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;
diff --git a/snac.c b/snac.c
index 4de34f0..903713b 100644
--- a/snac.c
+++ b/snac.c
@@ -57,7 +57,7 @@ double ftime(void)
}
-int validate_uid(char *uid)
+int validate_uid(const char *uid)
/* returns if uid is a valid identifier */
{
while (*uid) {
@@ -103,7 +103,7 @@ void snac_debug(snac *snac, int level, d_char *str)
}
-d_char *hash_password(char *uid, char *passwd, char *nonce)
+d_char *hash_password(const char *uid, const char *passwd, const char *nonce)
/* hashes a password */
{
xs *d_nonce = NULL;
@@ -120,7 +120,7 @@ d_char *hash_password(char *uid, char *passwd, char *nonce)
}
-int check_password(char *uid, char *passwd, char *hash)
+int check_password(const char *uid, const char *passwd, const char *hash)
/* checks a password */
{
int ret = 0;
diff --git a/snac.h b/snac.h
index 00443f9..6f3899b 100644
--- a/snac.h
+++ b/snac.h
@@ -36,17 +36,17 @@ typedef struct _snac {
d_char *md5; /* actor url md5 */
} snac;
-int user_open(snac *snac, char *uid);
+int user_open(snac *snac, const char *uid);
void user_free(snac *snac);
d_char *user_list(void);
void snac_debug(snac *snac, int level, d_char *str);
#define snac_log(snac, str) snac_debug(snac, 0, str)
-int validate_uid(char *uid);
+int validate_uid(const char *uid);
-d_char *hash_password(char *uid, char *passwd, char *nonce);
-int check_password(char *uid, char *passwd, char *hash);
+d_char *hash_password(const char *uid, const char *passwd, const char *nonce);
+int check_password(const char *uid, const char *passwd, const char *hash);
void srv_archive(char *direction, char *req, char *payload, int p_size,
int status, char *headers, char *body, int b_size);
@@ -173,4 +173,5 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
char **body, int *b_size, char **ctype);
int initdb(const char *_basedir);
-int adduser(char *uid);
+int adduser(const char *uid);
+int resetpwd(snac *snac);
diff --git a/utils.c b/utils.c
index 8b0b458..14b4816 100644
--- a/utils.c
+++ b/utils.c
@@ -187,13 +187,27 @@ int initdb(const char *basedir)
}
-int adduser(char *uid)
+void new_password(const char *uid, d_char **clear_pwd, d_char **hashed_pwd)
+/* creates a random password */
+{
+ int rndbuf[3];
+
+ srandom(time(NULL) ^ getpid());
+ rndbuf[0] = random() & 0xffffffff;
+ rndbuf[1] = random() & 0xffffffff;
+ rndbuf[2] = random() & 0xffffffff;
+
+ *clear_pwd = xs_base64_enc((char *)rndbuf, sizeof(rndbuf));
+ *hashed_pwd = hash_password(uid, *clear_pwd, NULL);
+}
+
+
+int adduser(const char *uid)
/* creates a new user */
{
snac snac;
xs *config = xs_dict_new();
xs *date = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ");
- int rndbuf[3];
xs *pwd = NULL;
xs *pwd_f = NULL;
xs *key = NULL;
@@ -214,13 +228,7 @@ int adduser(char *uid)
return 1;
}
- srandom(time(NULL) ^ getpid());
- rndbuf[0] = random() & 0xffffffff;
- rndbuf[1] = random() & 0xffffffff;
- rndbuf[2] = random() & 0xffffffff;
-
- pwd = xs_base64_enc((char *)rndbuf, sizeof(rndbuf));
- pwd_f = hash_password(uid, pwd, NULL);
+ new_password(uid, &pwd, &pwd_f);
config = xs_dict_append(config, "uid", uid);
config = xs_dict_append(config, "name", uid);
@@ -302,3 +310,32 @@ int adduser(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;
+}