Răsfoiți Sursa

vcc: support intiauth

intirain 4 ani în urmă
părinte
comite
07c42df802
6 a modificat fișierele cu 94 adăugiri și 10 ștergeri
  1. 4 4
      Makefile
  2. 3 0
      include/vcc/vcc.h
  3. 2 2
      include/vcc/version.h
  4. 70 0
      intiauth.c
  5. 2 2
      main.c
  6. 13 2
      vcc.c

+ 4 - 4
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 21
-VCC_PATCH 		= 1
+VCC_MINOR 		= 22
+VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 
 # change this to '/usr/share/' or '/opt/vcc/' etc
@@ -11,8 +11,8 @@ VCC_COMPILE_TIME 	= $(shell date)
 VCC_COMPILE_BY 		= $(shell whoami)
 VCC_SEMVER 		= vcc $(VCC_MAJOR).$(VCC_MINOR).$(VCC_PATCH)$(VCC_STR)
 
-srcs 			= main.c vcc.c pretty.c cmd.c crypt.c klist.c plugins.c robot.c 
-objs 			= main.o vcc.o pretty.o cmd.o crypt.o klist.o plugins.o robot.o 
+srcs 			= main.c vcc.c pretty.c cmd.c crypt.c klist.c plugins.c robot.c intiauth.c 
+objs 			= main.o vcc.o pretty.o cmd.o crypt.o klist.o plugins.o robot.o intiauth.o 
 target 			= vcc 
 libgcrypt_cflags 	= $(shell libgcrypt-config --libs)
 CFLAGS 			= -std=gnu11 -Wall -Wextra -Werror -Iinclude -g $(libgcrypt_cflags) -Lplugins -lplugins 

+ 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

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.21.0 Sun May 22 08:12:44 PM CST 2022 root"
-#define VCC_SEMVER "vcc 1.21.0-rc "
+#define VCC_VERSION "VCC 1.22.0 Sun May 29 01:08:04 PM CST 2022 root"
+#define VCC_SEMVER "vcc 1.22.0-rc "

+ 70 - 0
intiauth.c

@@ -0,0 +1,70 @@
+/* vcc/intiauth.c 
+ * 
+ * This file is part of vcc. 
+ * 
+ * vcc is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * vcc is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with vcc. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+#include <vcc/vcc.h>
+#include <vcc/plugin.h>
+#include <vcc/version.h>
+
+
+extern char usrname[];
+int ia_login(char *session);
+
+int do_intiauth(void) {
+	char auth_session[65];
+	int fdt, fdu;
+
+	if ((fdt = open("/var/run/intiauth-session", O_RDONLY)) < 0) 
+		return 0;
+
+	if ((fdu = open("/var/run/intiauth-user", O_RDONLY)) < 0) {
+		close(fdt);
+
+		return 0;
+	}
+
+	memset(auth_session, 0, 65);
+
+	if (unlikely(read(fdt, auth_session, 64) != 64)) {
+		fprintf(stderr, "/var/run/intiauth-session: wrong file format: too short. \n");
+		close(fdt);
+
+		return 0;
+	}
+
+	read(fdu, usrname, USRNAME_SIZE);
+
+	close(fdt);
+	close(fdu);
+
+	printf("intiauth: %s %s\n", usrname, auth_session);
+
+	ia_login(auth_session);
+
+	return 1;
+}
+

+ 2 - 2
main.c

@@ -58,6 +58,7 @@ int read_msg(struct vcc_request *buf);
 int get_msgs(void);
 int is_user_banned(char *);
 char *relay_get_msg(int fd, struct vcc_relay_header *);
+int do_intiauth(void);
 
 int show_algo_info(void);
 int crypt_init(void *key, void *iv);
@@ -345,9 +346,8 @@ int main(int argc, char **argv) {
 	if (mode == MODE_ROBOT) 
 		return robot();
 
-	if (!vos_login()) {
+	if (!vos_login() && !do_intiauth()) {
 		/* normally startup */
-
 		login(n);
 		show_algo_info();
 

+ 13 - 2
vcc.c

@@ -43,6 +43,7 @@
 
 extern struct klist_node banned_people;
 extern int fd;
+extern char usrname[];
 
 int current_sid = 0;
 
@@ -263,13 +264,15 @@ int do_bh(struct vcc_request *req) {
 }
 
 
-int vcc_login(char *usrname, char *passwd) {
+int __login(char *usrname, char *passwd, int type) {
 	struct vcc_request req;
 
 	clear_req(&req);
 
 	req.magic = htonl(VCC_MAGIC);
-	req.reqtype = htonl(REQ_CTL_LOGIN);
+
+	/* REQ_CTL_LOGIN or REQ_CTL_IALOG */
+	req.reqtype = htonl(type);
 
 	strncpy(req.usrname, usrname, USRNAME_SIZE);
 	strncpy(req.msg, passwd, MSG_SIZE);
@@ -279,6 +282,14 @@ int vcc_login(char *usrname, char *passwd) {
 	return 0;
 }
 
+int vcc_login(char *usrname, char *passwd) {
+	return __login(usrname, passwd, REQ_CTL_LOGIN);
+}
+
+int ia_login(char *session) {
+	return __login(usrname, session, REQ_CTL_IALOG);
+}
+
 
 int vcc_login_bh(struct vcc_request *req) {
 	if (ntohl(req->reqtype) != REQ_CTL_LOGIN) {