Forráskód Böngészése

vcc: -sname to show name of the session

intirain 4 éve
szülő
commit
ba0c40d617
9 módosított fájl, 108 hozzáadás és 6 törlés
  1. 2 2
      Makefile
  2. 32 1
      cmd.c
  3. 2 0
      include/vcc/interfaces.h
  4. 1 0
      include/vcc/pretty.h
  5. 3 1
      include/vcc/vcc.h
  6. 2 2
      include/vcc/version.h
  7. 5 0
      pretty.c
  8. 39 0
      scripts/randkey.py
  9. 22 0
      vcc.c

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 29
-VCC_PATCH 		= 1
+VCC_MINOR 		= 30
+VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 VCC_STR 		= -rc 
 
 
 # change this to '/usr/share/' or '/opt/vcc/' etc
 # change this to '/usr/share/' or '/opt/vcc/' etc

+ 32 - 1
cmd.c

@@ -64,7 +64,7 @@ int do_cmd_prem(int, char **);
 int do_cmd_ml(int, char **);
 int do_cmd_ml(int, char **);
 int do_cmd_rl(int, char **);
 int do_cmd_rl(int, char **);
 int do_cmd_sys(int, char **);
 int do_cmd_sys(int, char **);
-
+int do_cmd_sename(int, char **);
 
 
 int did_warn = 0;
 int did_warn = 0;
 
 
@@ -89,6 +89,7 @@ struct cmdtable cmdtab[] = {
 	{ "-ml", do_cmd_ml, "Multi-line. " }, 
 	{ "-ml", do_cmd_ml, "Multi-line. " }, 
 	{ "-rl", do_cmd_rl, "Send a relay message. " }, 
 	{ "-rl", do_cmd_rl, "Send a relay message. " }, 
 	{ "-sys", do_cmd_sys, "Get system info. " }, 
 	{ "-sys", do_cmd_sys, "Get system info. " }, 
+	{ "-sname", do_cmd_sename, "Get session name. " }, 
 
 
 	{ NULL, NULL, NULL }
 	{ NULL, NULL, NULL }
 };
 };
@@ -706,6 +707,7 @@ int do_cmd_encry(int argc, char **argv) {
 
 
 	encrypt(p);
 	encrypt(p);
 	send_msg_encrypted(p, usrname);
 	send_msg_encrypted(p, usrname);
+	pretty_new_msg(usrname, p, current_sid, MSG_ENCRYPTED);
 
 
 	return 0;
 	return 0;
 }
 }
@@ -788,3 +790,32 @@ int do_cmd_sys(int argc, char **argv) {
 	return get_sys_info();
 	return get_sys_info();
 }
 }
 
 
+int do_cmd_sename(int argc, char **argv) {
+	int sid;
+	char buf[USRNAME_SIZE];
+
+	memset(buf, 0, USRNAME_SIZE);
+
+	switch (argc) {
+	case 1:
+		fprintf(stderr, "sid: ");
+		scanf("%d", &sid);
+
+		break;
+	
+	case 2:
+		sid = atoi(argv[1]);
+
+		break;
+
+	default:
+		fprintf(stderr, _("usage: -sename [sid]"));
+		return 1;
+	}
+
+	session_name(sid, buf);
+	printf("%d: %s\n", sid, buf);
+
+	return 0;
+}
+

+ 2 - 0
include/vcc/interfaces.h

@@ -74,10 +74,12 @@ int vcc_create_session(char *name);
 int get_sessions(void);
 int get_sessions(void);
 int join_session(int sid);
 int join_session(int sid);
 int get_sys_info(void);
 int get_sys_info(void);
+int session_name(int, char *);
 
 
 int robot_new_msg(struct vcc_request *);
 int robot_new_msg(struct vcc_request *);
 
 
 int vcc_login_bh(struct vcc_request *);
 int vcc_login_bh(struct vcc_request *);
+int sename_bh(struct vcc_request *);
 int do_cmd_ls_bh(struct vcc_relay_header *);
 int do_cmd_ls_bh(struct vcc_relay_header *);
 int do_cmd_lsse_bh(struct vcc_request *);
 int do_cmd_lsse_bh(struct vcc_request *);
 int do_cmd_uinfo_bh(struct vcc_request *);
 int do_cmd_uinfo_bh(struct vcc_request *);

+ 1 - 0
include/vcc/pretty.h

@@ -60,6 +60,7 @@
 
 
 #define MSG_NEW_RELAY 		1
 #define MSG_NEW_RELAY 		1
 #define MSG_NEW_ONLY_VISIBLE 	2
 #define MSG_NEW_ONLY_VISIBLE 	2
+#define MSG_ENCRYPTED 		4
 
 
 struct color {
 struct color {
 	int 		fg;
 	int 		fg;

+ 3 - 1
include/vcc/vcc.h

@@ -69,7 +69,9 @@
 
 
 /* client -> server. get server info (root). */
 /* client -> server. get server info (root). */
 #define REQ_SYS_INFO 	13
 #define REQ_SYS_INFO 	13
-#define REQ_MAX 	14
+#define REQ_CTL_SENAME 	14
+
+#define REQ_MAX 	15
 
 
 #define REQ_SIZE 	512
 #define REQ_SIZE 	512
 #define USRNAME_SIZE 	32
 #define USRNAME_SIZE 	32

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.29.1 Sun Jun 12 07:56:17 PM CST 2022 root"
-#define VCC_SEMVER "vcc 1.29.1-rc "
+#define VCC_VERSION "VCC 1.30.0 Sun Jun 12 09:10:00 PM CST 2022 root"
+#define VCC_SEMVER "vcc 1.30.0-rc "

+ 5 - 0
pretty.c

@@ -216,6 +216,11 @@ int pretty_new_msg(char *usrname, char *buf, int sid, int flags) {
 			printf("[broadcast] ");
 			printf("[broadcast] ");
 	}
 	}
 
 
+	if (flags & MSG_ENCRYPTED) {
+		setcolor(stdout, curr_time);
+		printf("[encrypted] ");
+	}
+
 	if (unlikely(!strcmp(usrname, "system"))) {
 	if (unlikely(!strcmp(usrname, "system"))) {
 		setcolor(stdout, curr_sysusername);
 		setcolor(stdout, curr_sysusername);
 		printf("system");
 		printf("system");

+ 39 - 0
scripts/randkey.py

@@ -0,0 +1,39 @@
+#!/bin/python3
+
+# vcc/scripts/randkey.py 
+# 
+# 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/>
+
+
+
+
+import argparse
+import random
+
+parser = argparse.ArgumentParser(description="Create random key", prog="randkey")
+parser.add_argument("-s", "--block-size", type=int, default=32, help="Specified the size of a block")
+args = parser.parse_args()
+
+table = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
+key = ""
+iv = ""
+
+for i in range(args.block_size):
+    key += random.choice(table)
+    iv += random.choice(table)
+
+print("Key: %s\nIV: %s" % (key, iv))
+

+ 22 - 0
vcc.c

@@ -355,6 +355,28 @@ int join_session(int sid) {
 }
 }
 
 
 
 
+int session_name(int sid, char *buf) {
+	struct vcc_request req;
+
+	clear_req(&req);
+
+	req.magic = htonl(VCC_MAGIC);
+	req.reqtype = htonl(REQ_CTL_SENAME);
+	req.session = htonl(sid);
+
+	write(fd, &req, REQ_SIZE);
+	read(fd, &req, REQ_SIZE);
+
+	if (ntohl(req.session) == -1u) 
+		strcpy(buf, "*** no such session");
+
+	else 
+		strcpy(buf, req.msg);
+
+	return 0;
+}
+
+
 int incr_score(char *name, int incr) {
 int incr_score(char *name, int incr) {
 	struct vcc_request req;
 	struct vcc_request req;