3 #include "backuppcd-auth.h"
5 struct bpcd_auth_userinfo;
6 struct bpcd_auth_userinfo {
9 backuppc_privs_t privs;
10 struct bpcd_auth_userinfo *_next;
13 struct bpcd_auth_userinfo *userlist = NULL;
16 static int bpcd_auth_opt_user(const char *shortvar, const char *var, const char *arguments, const char *value, lc_flags_t flags, void *extra) {
17 struct bpcd_auth_userinfo *newnode;
18 char *valcopy_s, *valcopy;
21 newnode = malloc(sizeof(*newnode));
22 if (newnode == NULL) {
26 valcopy_s = valcopy = strdup(value);
28 newnode->username = strsep(&valcopy, " ,\t");
29 if (newnode->username == NULL) {
32 fprintf(stderr, "error: usage: USER <Username> <Password> <Privilegs>\n");
36 newnode->passhash = strsep(&valcopy, " ,\t");
37 if (newnode->passhash == NULL) {
40 fprintf(stderr, "error: usage: USER <Username> <Password> <Privilegs>\n");
44 privstr = strsep(&valcopy, " ,\t");
45 if (privstr == NULL) {
48 fprintf(stderr, "error: usage: USER <Username> <Password> <Privilegs>\n");
52 if (strlen(newnode->passhash) != 40) {
55 fprintf(stderr, "error: Password hash must be exactly 40 charectars long.\n");
59 if (strcasecmp(privstr, "Read") == 0) {
60 newnode->privs = BPC_PRIV_READ;
61 } else if (strcasecmp(privstr, "Write") == 0) {
62 newnode->privs = BPC_PRIV_WRITE;
63 } else if (strcasecmp(privstr, "ReadWrite") == 0) {
64 newnode->privs = BPC_PRIV_RDWR;
65 } else if (strcasecmp(privstr, "RD") == 0) {
66 newnode->privs = BPC_PRIV_READ;
67 } else if (strcasecmp(privstr, "WR") == 0) {
68 newnode->privs = BPC_PRIV_WRITE;
69 } else if (strcasecmp(privstr, "RDWR") == 0) {
70 newnode->privs = BPC_PRIV_RDWR;
71 } else if (strcasecmp(privstr, "r") == 0) {
72 newnode->privs = BPC_PRIV_READ;
73 } else if (strcasecmp(privstr, "w") == 0) {
74 newnode->privs = BPC_PRIV_WRITE;
75 } else if (strcasecmp(privstr, "rw") == 0) {
76 newnode->privs = BPC_PRIV_RDWR;
80 fprintf(stderr, "error: usage: Privileges must be one of: READ, WRITE, or READWRITE\n");
84 newnode->_next = userlist;
91 void bpcd_auth_init(void) {
93 lc_register_callback("User", 'u', LC_VAR_STRING, bpcd_auth_opt_user, NULL);
98 backuppc_privs_t bpcd_auth_verify(const char *username, const char *passhash, uint32_t address) {
99 struct bpcd_auth_userinfo *tmp;
101 for (tmp = userlist; tmp; tmp = tmp->_next) {
104 * Should the username be case-sensitive ? (XXX)
106 if (strcasecmp(tmp->username, username) == 0) {
107 if (strcasecmp(tmp->passhash, passhash) == 0) {
110 return(BPC_PRIV_ERROR);
115 return(BPC_PRIV_ERROR);