intirain 4 rokov pred
rodič
commit
69365bc1e8
8 zmenil súbory, kde vykonal 26 pridanie a 6 odobranie
  1. 2 2
      Makefile
  2. 2 0
      include/vcc/vccd.h
  3. 2 2
      include/vcc/version.h
  4. 8 1
      main.c
  5. 1 0
      monitor.c
  6. 1 0
      session.c
  7. 3 0
      users.c
  8. 7 1
      vcc.c

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCCD_MAJOR 		= 1
-VCCD_MINOR 		= 15
-VCCD_PATCH 		= 1
+VCCD_MINOR 		= 17
+VCCD_PATCH 		= 0
 VCCD_STR 		= -rc 
 
 VCCD_COMPILE_TIME 	= $(shell date)

+ 2 - 0
include/vcc/vccd.h

@@ -29,6 +29,7 @@
 #include <klist.h>
 
 #define vcc_log(msg, ...) 	fprintf(stderr, "[%ld] " msg, times(NULL), ##__VA_ARGS__)
+#define vcc_info(msg, ...) 	dprintf(infofd, "info [%ld] " msg, times(NULL), ##__VA_ARGS__)
 
 #define LJEST_LEVEL 	16
 #define NBEST_LEVEL 	0
@@ -97,6 +98,7 @@ int relay_send_packet(int fd, const char *restrict msg, const struct vcc_relay_h
 int read_until(int fd, void *, int);
 
 struct klist_node *find_connection(int fd);
+extern int infofd;
 
 #endif
 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.15.0 Fri Jun 17 10:13:09 PM CST 2022 root"
-#define VCCD_SEMVER "vccd 1.15.0-rc "
+#define VCCD_VERSION "vccd 1.17.0 Fri Jun 17 10:42:57 PM CST 2022 root"
+#define VCCD_SEMVER "vccd 1.17.0-rc "

+ 8 - 1
main.c

@@ -50,6 +50,7 @@
 
 int 			fd;
 int 			next_fd;
+int 			infofd = 1;
 
 #define POLLFDS 	1024
 struct pollfd 		*fds;
@@ -86,6 +87,12 @@ int becomes_daemon(void) {
 	(void) dup(0);
 	(void) dup(0);
 
+	if (unlikely((infofd = open("/var/log/vccd-info.log", O_WRONLY | O_CREAT | O_APPEND | O_SYNC, 0644)) < 0)) {
+		perror("open(/var/run/vccd-info.log)");
+
+		exit(1);
+	}
+
 	setsid();
 
 	if (unlikely((fd = open("/var/run/vccd.pid", O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)) {
@@ -202,7 +209,7 @@ int main(int argc, const char **argv) {
 	if (unlikely(argc != 1)) 
 		return usage();
 
-//	becomes_daemon();
+	becomes_daemon();
 	init_socket();
 	users_init();
 

+ 1 - 0
monitor.c

@@ -132,6 +132,7 @@ int monitor_info(int fd, struct vcc_request *req) {
 	if (fd != system_fd) {
 		relay_send_msg(fd, "sysinfo: only root can do that. ", "system");
 		vcc_log("%d:%s tried to get sysinfo. \n", fd, req->usrname);
+		vcc_info("WSYSINFO %s %d\n", req->usrname, fd);
 
 		return 1;
 	}

+ 1 - 0
session.c

@@ -83,6 +83,7 @@ int create_session(int fd, char *name) {
 	klist_add(s, p);
 
 	vcc_log("New session '%s' created by %d. \n", name, fd);
+	vcc_info("INEWSESS %s %d\n", name, fd);
 
 	return 0;
 }

+ 3 - 0
users.c

@@ -196,6 +196,7 @@ int do_user_login(int fd, struct vcc_request *req) {
 
 	if (get_user(req->usrname, usr) || strncmp(req->msg, usr->passwd, PASSWD_SIZE)) {
 		vcc_log("%s:%s login failed. \n", req->usrname, req->msg);
+		vcc_info("WLOGFAIL %s %s %d\n", req->usrname, req->msg, fd);
 
 		do_login_failed(fd, out);
 		afree(usr, sizeof(struct user));
@@ -253,6 +254,7 @@ int init_user_info(int fd, char *usrname, struct user *u) {
 	}
 
 	vcc_log("%s logged in. \n", usrname);
+	vcc_info("ISYSLOG %s %d\n", usrname, fd);
 
 	if (unlikely(!(t = amalloc(128)))) {
 		vcc_log("*** malloc() failed\n");
@@ -371,6 +373,7 @@ int incr_score(int fd, struct vcc_request *req) {
 		vcc_send_req(find_connection(fd), out);
 
 		vcc_log("%d:%s tried to modify the score. \n", fd, req->usrname);
+		vcc_info("WSCRMOD %s %d\n", req->usrname, fd);
 
 		return 1;
 	}

+ 7 - 1
vcc.c

@@ -47,6 +47,7 @@ int vcc_new_connection(int fd, struct in_addr *addr) {
 	struct klist_node *n;
 
 	vcc_log("New connection from %s\n", inet_ntoa(*addr));
+	vcc_info("ICONN %s %d\n", inet_ntoa(*addr), fd);
 
 	if (unlikely(!(n = amalloc(sizeof(struct klist_node))))) {
 		vcc_log("*** malloc() failed\n");
@@ -94,6 +95,7 @@ int vcc_close_connection(int fd) {
 
 	afree(n->sending, sizeof(struct klist_node));
 	vcc_log("Client closed. \n");
+	vcc_info("ILEFT %d\n", fd);
 
 	return 0;
 }
@@ -108,6 +110,7 @@ struct klist_node *find_connection(int fd) {
 
 	if (unlikely(n == &connections)) {
 		vcc_log("--- connection not found: %d\n", fd);
+		vcc_info("WCONNOTFND %d\n", fd);
 
 		return NULL;
 	}
@@ -223,6 +226,7 @@ int vcc_update_usrname(int fd, const char *usrname) {
 
 	n->usrname = strndup(usrname, USRNAME_SIZE);
 	vcc_log("user name %s updated for %d\n", usrname, fd);
+	vcc_info("IUSR %s %d\n", usrname, fd);
 
 	return 0;
 }
@@ -280,8 +284,9 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 
 	magic = ntohl(req->magic);
 
-	if (magic != VCC_MAGIC || magic != VCC_MAGIC_RL) {
+	if (magic != VCC_MAGIC && magic != VCC_MAGIC_RL) {
 		vcc_log("--- bad magic from %d. \n", fd);
+		vcc_info("WBADMAGIC %d\n", fd);
 
 		return 1;
 	}
@@ -362,6 +367,7 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 
 	default:
 		vcc_log("--- bad request type from %d\n", fd);
+		vcc_info("WBADREQ %d\n", fd);
 	
 		break;
 	}