diff options
author | Joseph Hunkeler <jhunk@stsci.edu> | 2011-03-28 14:31:23 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunk@stsci.edu> | 2011-03-28 14:31:23 -0400 |
commit | f58a7e75bb87eb22594d2f96c6961f3ad4c2fd60 (patch) | |
tree | 67b015480db0b008e3f31416e55c2473712bdcd6 | |
parent | d078ff2fdc4719d283efc225f043009638977fca (diff) | |
download | duser-f58a7e75bb87eb22594d2f96c6961f3ad4c2fd60.tar.gz |
Initial commit
-rw-r--r-- | duser.h | 54 | ||||
-rw-r--r-- | log.c | 52 |
2 files changed, 106 insertions, 0 deletions
@@ -0,0 +1,54 @@ +#ifndef DUSER_H +#define DUSER_H +#include <limits.h> + +#define REGEX_MAX 60 +#define CMD_FLAG_NOOPT 0x00 +#define CMD_FLAG_DEL 0x02 +#define CMD_FLAG_MOD 0x04 +#define CMD_FLAG_ADD 0x08 +#define CMD_FLAG_LIST 0x16 +#define CMD_FLAG_HELP 0x32 +#define CMD_FLAG_LOOK 0x64 +#define CMD_FLAG_NULL 0x254 + +#define regex_fmt "\%s$" +#define LOGFILE "/var/log/duser" +#define list_path "/internal/1/domotest/opt/majordomo/majordomo-1.94.3/lists/" + +typedef struct stats_t +{ + int lines; + int files; + int matches; + int added; + int deleted; + int modified; +} stats_t; +//Global statistics struct +stats_t processed; + +typedef struct record_t +{ + int index; + int match; + int pad1; + char name[REGEX_MAX]; + int pad2; + char file[PATH_MAX]; + int pad3; +} record_t; + + +char* basename(const char* path); +record_t* find_in_file(const char* filename, const char* needle); +int get_file_count(const char* path); +char** get_file_list(const char* path, int count); +void stats_init(stats_t *s); +int user_list(const char* needle); +int find_in_file_ex(record_t* rec); +int user_del(record_t* rec); +int user_cmd(const char* arg); +int user_choice(char c); + +#endif @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> +#include <unistd.h> +#include <limits.h> +#include <errno.h> +#include <time.h> +#include "duser.h" + +int logcleanup() +{ + int status = 0; + if((access(LOGFILE, W_OK)) == 0) + { + status = unlink(LOGFILE); + } + + return status; +} + +int COM(const char* func, char *format, ...) +{ + struct tm *logtm; + time_t logtime = time(NULL); + char timestr[64]; + char *str = (char*)malloc(sizeof(char) * 256); + char tmpstr[255]; + int n; + + FILE *logfp = NULL; + logfp = fopen(LOGFILE, "a+"); + if(logfp == NULL) + { + fprintf(stderr, "Unable to open %s\n", LOGFILE); + } + + va_list args; + va_start (args, format); + n = vsprintf (str, format, args); + va_end (args); + + logtm = localtime(&logtime); + + snprintf(timestr, sizeof(timestr), "%02d-%02d-%02d %02d:%02d:%02d", logtm->tm_year+1900, logtm->tm_mon+1, logtm->tm_mday, logtm->tm_hour, logtm->tm_min, logtm->tm_sec); + snprintf(tmpstr, sizeof(tmpstr), "%s _%s_: %s", timestr, func, str); + fprintf(logfp, "%s", tmpstr); + fclose(logfp); + + free(str); + return 0; +} |