Browse Source

Add uid, pid, user of peer to ksession_t structure

Serj Kalichev 1 year ago
parent
commit
10631fac96
3 changed files with 33 additions and 3 deletions
  1. 12 0
      klish/ksession.h
  2. 21 0
      klish/ksession/ksession.c
  3. 0 3
      klish/ktp/ktpd_session.c

+ 12 - 0
klish/ksession.h

@@ -34,6 +34,18 @@ bool_t ksession_set_term_width(ksession_t *session, size_t term_width);
 size_t ksession_term_height(const ksession_t *session);
 bool_t ksession_set_term_height(ksession_t *session, size_t term_height);
 
+// PID of client (Unix socket peer)
+pid_t ksession_pid(const ksession_t *session);
+bool_t ksession_set_pid(ksession_t *session, pid_t pid);
+
+// UID of client (Unix socket peer)
+uid_t ksession_uid(const ksession_t *session);
+bool_t ksession_set_uid(ksession_t *session, uid_t uid);
+
+// Client user name (Unix socket peer)
+const char *ksession_user(const ksession_t *session);
+bool_t ksession_set_user(ksession_t *session, const char *user);
+
 C_DECL_END
 
 #endif // _klish_ksession_h

+ 21 - 0
klish/ksession/ksession.c

@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
 
 #include <klish/khelper.h>
 #include <klish/kscheme.h>
@@ -17,6 +18,9 @@ struct ksession_s {
 	bool_t done; // Indicates that session is over and must be closed
 	size_t term_width;
 	size_t term_height;
+	pid_t pid;
+	uid_t uid;
+	char *user;
 };
 
 
@@ -38,6 +42,18 @@ KSET(session, size_t, term_width);
 KGET(session, size_t, term_height);
 KSET(session, size_t, term_height);
 
+// PID of client (Unix socket peer)
+KGET(session, pid_t, pid);
+KSET(session, pid_t, pid);
+
+// UID of client (Unix socket peer)
+KGET(session, uid_t, uid);
+KSET(session, uid_t, uid);
+
+// Client user name (Unix socket peer)
+KSET_STR(session, user);
+KGET_STR(session, user);
+
 
 ksession_t *ksession_new(kscheme_t *scheme, const char *start_entry)
 {
@@ -80,6 +96,10 @@ ksession_t *ksession_new(kscheme_t *scheme, const char *start_entry)
 	session->done = BOOL_FALSE;
 	session->term_width = 0;
 	session->term_height = 0;
+	// Peer data
+	session->pid = -1;
+	session->uid = -1;
+	session->user = NULL;
 
 	return session;
 }
@@ -91,6 +111,7 @@ void ksession_free(ksession_t *session)
 		return;
 
 	kpath_free(session->path);
+	faux_str_free(session->user);
 
 	free(session);
 }

+ 0 - 3
klish/ktp/ktpd_session.c

@@ -35,9 +35,6 @@ typedef enum {
 struct ktpd_session_s {
 	ksession_t *session;
 	ktpd_session_state_e state;
-	uid_t uid;
-	gid_t gid;
-	char *user;
 	faux_async_t *async; // Object for data exchange with client (KTP)
 	faux_hdr_t *hdr; // Engine will receive header and then msg
 	faux_eloop_t *eloop; // External link, dont's free()