|
|
@@ -168,12 +168,19 @@ int sync_user(char *usr, struct user *buf) {
|
|
|
}
|
|
|
|
|
|
|
|
|
+int do_login_failed(int fd, struct vcc_request *out) {
|
|
|
+ out->magic = htonl(VCC_MAGIC);
|
|
|
+ out->reqtype = htonl(REQ_CTL_LOGIN);
|
|
|
+ out->uid = 0;
|
|
|
+
|
|
|
+ vcc_send_req(find_connection(fd), out);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
int do_user_login(int fd, struct vcc_request *req) {
|
|
|
- struct vcc_request *out;
|
|
|
struct user *usr;
|
|
|
- struct klist_node *n;
|
|
|
- static const char *join_msg = "%s logged in. now there are %d users. \n";
|
|
|
- char *t;
|
|
|
+ struct vcc_request *out;
|
|
|
|
|
|
if (unlikely(!(out = amalloc(sizeof(struct vcc_request))))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
|
@@ -187,48 +194,76 @@ int do_user_login(int fd, struct vcc_request *req) {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
- memset(out, 0, sizeof(struct vcc_request));
|
|
|
- memset(usr, 0, sizeof(struct user));
|
|
|
-
|
|
|
- out->magic = htonl(VCC_MAGIC);
|
|
|
- out->reqtype = htonl(REQ_CTL_LOGIN);
|
|
|
-
|
|
|
if (get_user(req->usrname, usr) || strncmp(req->msg, usr->passwd, PASSWD_SIZE)) {
|
|
|
vcc_log("%s:%s login failed. \n", req->usrname, req->msg);
|
|
|
|
|
|
- out->uid = 0;
|
|
|
- vcc_send_req(find_connection(fd), out);
|
|
|
-
|
|
|
+ do_login_failed(fd, out);
|
|
|
afree(usr, sizeof(struct user));
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- if (!strncmp(req->usrname, "system", USRNAME_SIZE)) {
|
|
|
+ init_user_info(fd, req->usrname, usr);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int do_ia_login(int fd, struct vcc_request *req) {
|
|
|
+ struct user *u;
|
|
|
+
|
|
|
+ if (unlikely(!(u = amalloc(sizeof(struct user))))) {
|
|
|
+ vcc_log("*** malloc() failed\n");
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ strcpy(u->username, req->usrname);
|
|
|
+ init_user_info(fd, req->usrname, u);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int init_user_info(int fd, char *usrname, struct user *u) {
|
|
|
+ struct klist_node *n;
|
|
|
+ static const char *join_msg = "%s logged in. now there are %d users. \n";
|
|
|
+ char *t;
|
|
|
+ struct vcc_request *out;
|
|
|
+
|
|
|
+ if (unlikely(!(out = amalloc(sizeof(struct user))))) {
|
|
|
+ vcc_log("*** malloc() failed\n");
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ memset(out, 0, sizeof(struct user));
|
|
|
+
|
|
|
+ if (!strncmp(usrname, "system", USRNAME_SIZE)) {
|
|
|
if (system_fd) {
|
|
|
vcc_log("system already logged-in. \n");
|
|
|
+ do_login_failed(fd, out);
|
|
|
|
|
|
- out->uid = 0;
|
|
|
- vcc_send_req(find_connection(fd), out);
|
|
|
+ afree(u, sizeof(struct user));
|
|
|
|
|
|
- afree(usr, sizeof(struct user));
|
|
|
-
|
|
|
- return 0;
|
|
|
+ return 1;
|
|
|
}
|
|
|
|
|
|
system_fd = fd;
|
|
|
}
|
|
|
|
|
|
- vcc_log("%s logged in. \n", req->usrname);
|
|
|
+ vcc_log("%s logged in. \n", usrname);
|
|
|
|
|
|
if (unlikely(!(t = amalloc(128)))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
|
+ afree(u, sizeof(struct user));
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
if (unlikely(!(n = amalloc(sizeof(struct klist_node))))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
|
+ afree(u, sizeof(struct user));
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
@@ -237,16 +272,18 @@ int do_user_login(int fd, struct vcc_request *req) {
|
|
|
klist_init(n);
|
|
|
|
|
|
n->value = fd;
|
|
|
- n->data = usr;
|
|
|
+ n->data = u;
|
|
|
|
|
|
klist_add(&logged_users, n);
|
|
|
|
|
|
+ out->magic = htonl(VCC_MAGIC);
|
|
|
+ out->reqtype = htonl(REQ_CTL_LOGIN);
|
|
|
out->uid = htonl(1);
|
|
|
vcc_send_req(find_connection(fd), out);
|
|
|
|
|
|
/* nusers already inc'ed when it connects */
|
|
|
|
|
|
- sprintf(t, join_msg, req->usrname, nusers);
|
|
|
+ sprintf(t, join_msg, usrname, nusers);
|
|
|
vcc_message_broadcast(t, "system", 0, 0);
|
|
|
|
|
|
afree(t, 128);
|