From owner-p4-projects@FreeBSD.ORG Mon Jul 2 20:46:42 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BC9D616A46E; Mon, 2 Jul 2007 20:46:41 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7B25E16A469 for ; Mon, 2 Jul 2007 20:46:41 +0000 (UTC) (envelope-from karma@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 6A95813C468 for ; Mon, 2 Jul 2007 20:46:41 +0000 (UTC) (envelope-from karma@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l62KkfkO096536 for ; Mon, 2 Jul 2007 20:46:41 GMT (envelope-from karma@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l62KkfWR096533 for perforce@freebsd.org; Mon, 2 Jul 2007 20:46:41 GMT (envelope-from karma@FreeBSD.org) Date: Mon, 2 Jul 2007 20:46:41 GMT Message-Id: <200707022046.l62KkfWR096533@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to karma@FreeBSD.org using -f From: Alexey Mikhailov To: Perforce Change Reviews Cc: Subject: PERFORCE change 122744 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jul 2007 20:46:42 -0000 http://perforce.freebsd.org/chv.cgi?CH=122744 Change 122744 by karma@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 +#include +#include +#include +#include +#include +#include + +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 +#include +#include +#include +#include +#include + +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 + +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 +#include +#include +#include + +#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