Kaynağa Gözat

vccd: support intiauth, but no auth

intirain 4 yıl önce
ebeveyn
işleme
30d48f9716
6 değiştirilmiş dosya ile 90 ekleme ve 43 silme
  1. 1 1
      Makefile
  2. 3 0
      include/vcc/vcc.h
  3. 19 18
      include/vcc/vccd.h
  4. 2 2
      include/vcc/version.h
  5. 59 22
      users.c
  6. 6 0
      vcc.c

+ 1 - 1
Makefile

@@ -1,5 +1,5 @@
 VCCD_MAJOR 		= 1
-VCCD_MINOR 		= 11
+VCCD_MINOR 		= 12
 VCCD_PATCH 		= 0
 VCCD_STR 		= -rc 
 

+ 3 - 0
include/vcc/vcc.h

@@ -61,6 +61,9 @@
 /* client -> server. send new message. */
 #define REQ_REL_MSG 	10
 
+/* client -> server. intiauth login. */
+#define REQ_CTL_IALOG 	11
+
 /* server -> client. new message */
 #define REQ_REL_NEW 	11
 #define REQ_MAX 	12

+ 19 - 18
include/vcc/vccd.h

@@ -30,6 +30,23 @@
 
 #define vcc_log(msg, ...) 	fprintf(stderr, "[%ld] " msg, times(NULL), ##__VA_ARGS__)
 
+#define LJEST_LEVEL 	16
+#define NBEST_LEVEL 	0
+
+#define MIN_LEVEL 	LJEST_LEVEL
+#define BEST_LEVEL 	NBEST_LEVEL
+
+struct user {
+	/* they're interesting, aren't them? :-) */
+	int 		score;
+	int 		level;
+
+	char 		username[USRNAME_SIZE];
+	char 		passwd[PASSWD_SIZE];
+}
+/* we don't need __attribute__((packed)), this struct is local.*/
+;
+
 
 void *__amalloc(int nbytes, const char *);
 int afree(void *, int nbytes);
@@ -47,7 +64,9 @@ int vcc_send_req(struct klist_node *, void *);
 int vcc_message_broadcast(char *msg, char *usr, int except_fd, int flags);
 
 int do_user_login(int fd, struct vcc_request *buf);
+int do_ia_login(int fd, struct vcc_request *req);
 int do_user_logout(int fd);
+int init_user_info(int fd, char *usrname, struct user *u);
 
 int create_session(int fd, char *name);
 int session_broadcast(int sid, char *msg, char *usr, int except_fd, int flags);
@@ -66,23 +85,5 @@ int read_until(int fd, void *, int);
 
 struct klist_node *find_connection(int fd);
 
-#define LJEST_LEVEL 	16
-#define NBEST_LEVEL 	0
-
-#define MIN_LEVEL 	LJEST_LEVEL
-#define BEST_LEVEL 	NBEST_LEVEL
-
-struct user {
-	/* they're interesting, aren't them? :-) */
-	int 		score;
-	int 		level;
-
-	char 		username[USRNAME_SIZE];
-	char 		passwd[PASSWD_SIZE];
-}
-/* we don't need __attribute__((packed)), this struct is local.*/
-;
-
-
 #endif
 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.11.0 Sun May 22 11:09:46 AM CST 2022 root"
-#define VCCD_SEMVER "vccd 1.11.0-rc "
+#define VCCD_VERSION "vccd 1.12.0 Sun May 29 01:59:15 PM CST 2022 root"
+#define VCCD_SEMVER "vccd 1.12.0-rc "

+ 59 - 22
users.c

@@ -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);

+ 6 - 0
vcc.c

@@ -307,6 +307,12 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 
 		break;
 
+	case REQ_CTL_IALOG:
+		do_ia_login(fd, req);
+		vcc_update_usrname(fd, req->usrname);
+
+		break;
+
 	case REQ_CTL_NEWSE:
 		create_session(fd, req->usrname);