PERFORCE change 122744 for review
Alexey Mikhailov
karma at FreeBSD.org
Mon Jul 2 20:46:42 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=122744
Change 122744 by karma at karma_ez on 2007/07/02 20:46:32
* T-Tree implementation
* Configuration parsing
* Basic network stuff
Affected files ...
.. //depot/projects/soc2007/karma_audit/dlog/config.h#3 edit
.. //depot/projects/soc2007/karma_audit/dlog/daemon/client.c#2 edit
.. //depot/projects/soc2007/karma_audit/dlog/daemon/client.h#2 edit
.. //depot/projects/soc2007/karma_audit/dlog/daemon/config.c#2 edit
.. //depot/projects/soc2007/karma_audit/dlog/daemon/config.h#2 edit
.. //depot/projects/soc2007/karma_audit/dlog/daemon/config_client.l#1 add
.. //depot/projects/soc2007/karma_audit/dlog/daemon/config_client.y#1 add
.. //depot/projects/soc2007/karma_audit/dlog/daemon/config_server.l#1 add
.. //depot/projects/soc2007/karma_audit/dlog/daemon/config_server.y#1 add
.. //depot/projects/soc2007/karma_audit/dlog/daemon/server.c#2 edit
.. //depot/projects/soc2007/karma_audit/dlog/daemon/server.h#2 edit
.. //depot/projects/soc2007/karma_audit/dlog/daemon/ttree.c#1 add
.. //depot/projects/soc2007/karma_audit/dlog/daemon/ttree.h#1 add
.. //depot/projects/soc2007/karma_audit/dlog/daemon/util.c#1 add
.. //depot/projects/soc2007/karma_audit/dlog/daemon/util.h#1 add
Differences ...
==== //depot/projects/soc2007/karma_audit/dlog/config.h#3 (text+ko) ====
@@ -7,4 +7,11 @@
#define KEYWORD_MAX 128
+#define MAX_COUNT 5
+
+#define CLIENT_CONFIG "client.conf"
+#define SERVER_CONFIG "server.conf"
+
+#define SERVER_PORT "9991"
+
#endif
==== //depot/projects/soc2007/karma_audit/dlog/daemon/client.c#2 (text+ko) ====
@@ -1,0 +1,39 @@
+#include "../config.h"
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/param.h>
+#include <sys/ucred.h>
+
+extern int errno;
+
+void
+client_main()
+{
+ int s, opt = 1;
+ struct sockaddr_un n;
+
+ s = socket(PF_LOCAL, SOCK_STREAM, 0);
+
+ if (s < 0)
+ {
+ err_fatal("can't create PF_LOCAL socket");
+ }
+
+ if ((setsockopt(s, 0, LOCAL_CREDS, &opt, sizeof(opt))) < 0)
+ {
+ err_fatal("can't receive credentials from PF_LOCAL socket");
+ }
+
+ bzero(&n, sizeof(n));
+ n.sun_family = PF_LOCAL;
+ strncpy(n.sun_path, DL_SOCKET, sizeof(DL_SOCKET));
+
+ if ((bind(s, (struct sockaddr *) &n, SUN_LEN (&n))) < 0)
+ {
+ err_fatal("can't bind PF_LOCAL socket");
+ }
+
+}
==== //depot/projects/soc2007/karma_audit/dlog/daemon/client.h#2 (text+ko) ====
@@ -1,0 +1,6 @@
+#ifndef DLOG_CLIENT_H
+#define DLOG_CLIENT_H
+
+void client_main();
+
+#endif
==== //depot/projects/soc2007/karma_audit/dlog/daemon/config.c#2 (text+ko) ====
@@ -1,0 +1,247 @@
+#include "config.h"
+#include "../config.h"
+#include "util.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <pwd.h>
+#include <errno.h>
+#include <grp.h>
+#include <stdio.h>
+
+cl_kw_access * cka = NULL;
+cl_kw_access * pcka = NULL;
+cl_kw_hosts * ckh = NULL;
+cl_kw_hosts * pckh = NULL;
+sv_kw_hostdir * svhd = NULL;
+sv_kw_hostdir * psvhd = NULL;
+
+extern int errno;
+extern FILE * yyin;
+
+#if 0
+int
+main (int argc, char **argv)
+{
+ client_kw_tree = allocate_ttree();
+ server_kw_tree = allocate_ttree();
+ (void)parse_client_config();
+}
+#endif
+
+void
+parse_client_config (void)
+{
+ int error;
+
+ yyin = fopen("client.conf", "r");
+
+ if (yyin == NULL)
+ {
+ err_fatal("cannot open client configuration file");
+ }
+
+ error = yyparse();
+
+ if (error)
+ {
+ err_fatal("cannot parse client configuration file");
+ }
+}
+
+void
+parse_server_config (void)
+{
+ int error;
+
+ yyin = fopen("server.conf", "r");
+
+ if (yyin == NULL)
+ {
+ err_fatal("cannot open server configuration file");
+ }
+
+ error = yyparse();
+
+ if (error)
+ {
+ err_fatal("cannot parse server configuration file");
+ }
+}
+
+int
+add_client_keyword (char * keyword)
+{
+ cl_kw_data * cd;
+
+ cd = xmalloc(sizeof(cl_kw_data));
+ cd -> access = cka;
+ cd -> hosts = ckh;
+
+ insert_tree (&client_kw_tree, keyword, (void *) cd);
+ cka = NULL;
+ pcka = NULL;
+ ckh = NULL;
+ pckh = NULL;
+
+ return 0;
+}
+
+int
+add_client_kw_access (char * id, char * val)
+{
+ if (cka == NULL)
+ {
+ cka = xmalloc(sizeof(cl_kw_access));
+ pcka = cka;
+ }
+ else
+ {
+ pcka -> next = xmalloc(sizeof(cl_kw_access));
+ pcka = pcka -> next;
+ pcka -> next = NULL;
+ }
+
+ if (strcmp(id, "uid") == 0)
+ {
+ pcka -> id = 1;
+ pcka -> ut = (uid_t)strtol(val, (char **)NULL, 10);
+ if (pcka -> ut == 0)
+ {
+ err_fatal("wrong UID.");
+ }
+
+ struct passwd * psw = getpwuid(pcka -> ut);
+
+ if (psw == NULL)
+ {
+ err_fatal("getpwuid() failed. Probably wrong UID.");
+ }
+ return 0;
+ }
+
+ if (strcmp(id, "gid") == 0)
+ {
+ pcka -> id = 2;
+ pcka -> gt = (gid_t)strtol(val, (char **)NULL, 10);
+ if (pcka -> gt == 0)
+ {
+ err_fatal("wrong gid");
+ }
+
+ struct group * grp = getgrgid (pcka -> gt);
+
+ if (grp = NULL)
+ {
+ err_fatal("getgrgid() failed. Probably wrong GID.");
+ }
+
+ return 0;
+ }
+
+ if (strcmp(id, "user") == 0)
+ {
+ pcka -> id = 1;
+
+ struct passwd * psw = getpwnam(val);
+ if (psw == NULL)
+ {
+ err_fatal("getpwnam() failed. Probably wrong username.");
+ }
+
+ pcka -> ut = psw -> pw_uid;
+ return 0;
+ }
+
+ if (strcmp(id, "group") == 0)
+ {
+ pcka -> id = 2;
+ struct group * grp = getgrnam(val);
+ if (grp == NULL)
+ {
+ err_fatal("getgrnam() failed. Probably wrong groupname.");
+ }
+
+ pcka -> gt = grp -> gr_gid;
+ return 0;
+ }
+
+ return 1;
+}
+
+int
+add_client_kw_host (char * host)
+{
+ if (ckh == NULL)
+ {
+ ckh = xmalloc(sizeof(cl_kw_hosts));
+ pckh = ckh;
+ }
+ else
+ {
+ pckh -> next = xmalloc(sizeof(cl_kw_hosts));
+ pckh = pckh -> next;
+ pckh -> next = NULL;
+ }
+
+ pckh -> host = strdup (host);
+
+ if (pckh -> host == NULL)
+ {
+ err_fatal("out of memory.");
+ }
+
+ return 0;
+}
+
+int
+add_client_host (char * host)
+{
+ return 0;
+}
+
+int
+add_server_keyword (char * keyword)
+{
+ sv_kw_data * sd;
+
+ sd = xmalloc(sizeof(sv_kw_data));
+ sd -> hds = svhd;
+
+ insert_tree (&server_kw_tree, keyword, (void *) sd);
+ svhd = NULL;
+ psvhd = NULL;
+
+ return 0;
+}
+
+int
+add_server_kw_host (char * hostname, char * dir)
+{
+ if (svhd == NULL)
+ {
+ svhd = xmalloc(sizeof(sv_kw_hostdir));
+ psvhd = svhd;
+ }
+ else
+ {
+ psvhd -> next = xmalloc(sizeof(sv_kw_hostdir));
+ psvhd = psvhd -> next;
+ psvhd -> next = NULL;
+ }
+
+ psvhd -> host = strdup (hostname);
+ psvhd -> dir = strdup (dir);
+
+ if (psvhd -> host == NULL || psvhd -> dir == NULL)
+ {
+ err_fatal("out of memory!");
+ }
+
+ return 0;
+}
+
+int
+add_server_host (char * host)
+{
+ return 0;
+}
==== //depot/projects/soc2007/karma_audit/dlog/daemon/config.h#2 (text+ko) ====
@@ -1,0 +1,49 @@
+#ifndef DLOG_CONFIG_H
+#define DLOG_CONFIG_H
+#include "ttree.h"
+#include <sys/types.h>
+
+typedef struct client_kw_access {
+ int id;
+ uid_t ut;
+ gid_t gt;
+ struct client_kw_access * next;
+} cl_kw_access;
+
+typedef struct client_kw_host {
+ char *host;
+ struct client_kw_host * next;
+} cl_kw_hosts;
+
+typedef struct server_kw_host {
+ char *host;
+ char *dir;
+ struct server_kw_host * next;
+} sv_kw_hostdir;
+
+typedef struct keyword_cli_data {
+ cl_kw_access *access;
+ cl_kw_hosts *hosts;
+} cl_kw_data;
+
+typedef struct keyword_srv_data {
+ sv_kw_hostdir *hds;
+} sv_kw_data;
+
+
+TTree * client_kw_tree;
+TTree * server_kw_tree;
+TTree * client_host_tree;
+TTree * server_host_tree;
+
+int add_client_keyword (char * keyword);
+int add_client_kw_access (char * id, char * val);
+int add_client_kw_host (char * host);
+
+int add_server_keyword (char * keyword);
+int add_server_kw_host (char * hostname, char * dir);
+
+void parse_client_config();
+void parse_server_config();
+
+#endif
==== //depot/projects/soc2007/karma_audit/dlog/daemon/server.c#2 (text+ko) ====
@@ -1,0 +1,69 @@
+#include "../config.h"
+#include <netdb.h>
+#include <limits.h>
+#include <stdio.h>
+#include <sys/socket.h>
+
+#define QLEN 10
+
+void
+server_serve (int s)
+{
+ return;
+}
+
+void
+server_main()
+{
+ int s,err;
+ struct addrinfo *aip, *ailist;
+ struct addrinfo hint;
+ char *host;
+
+ hint.ai_flags = AI_CANONNAME;
+ hint.ai_family = 0;
+ hint.ai_socktype = SOCK_STREAM;
+ hint.ai_protocol = 0;
+ hint.ai_addrlen = 0;
+ hint.ai_canonname = NULL;
+ hint.ai_addr = NULL;
+ hint.ai_next = NULL;
+
+ if (gethostname(host, _POSIX_HOST_NAME_MAX) < 0)
+ {
+ err_fatal("gethostname() error");
+ }
+
+
+ err = getaddrinfo(host, SERVER_PORT, &hint, &ailist);
+
+ if (err < 0)
+ {
+ err_fatal("getaddrinfo() error");
+ }
+
+ for (aip = ailist; aip != NULL; aip = aip -> ai_next)
+ {
+
+ s = socket(PF_INET, SOCK_STREAM, 0);
+
+ if (s < 0)
+ {
+ err_fatal("can't create PF_INET socket");
+ }
+
+ if (bind(s, aip -> ai_addr, aip -> ai_addrlen) < 0)
+ {
+ err_fatal("bind() error on PF_INET socket");
+ }
+
+ if (listen(s, QLEN) < 0)
+ {
+ err_fatal("listen() error on PF_INET socket");
+ }
+
+ server_serve(s);
+ return;
+ }
+}
+
==== //depot/projects/soc2007/karma_audit/dlog/daemon/server.h#2 (text+ko) ====
@@ -1,0 +1,6 @@
+#ifndef DLOG_SERVER_H
+#define DLOG_SERVER_H
+
+void server_main();
+
+#endif
More information about the p4-projects
mailing list