added feature of changing user - fiche - A pastebin adjusted for gopher use | |
git clone git://vernunftzentrum.de/fiche.git | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit d1a66efe6e498d93f7319a2cea8071a340c756d1 | |
parent d6865f63f2725bb0f447cfb3f113abeb1376a73c | |
Author: solusipse <[email protected]> | |
Date: Fri, 13 Sep 2013 23:51:58 +0200 | |
added feature of changing user | |
Diffstat: | |
fiche.c | 42 +++++++++++++++++++++++-------- | |
fiche.h | 14 ++++++++++---- | |
2 files changed, 42 insertions(+), 14 deletions(-) | |
--- | |
diff --git a/fiche.c b/fiche.c | |
@@ -10,9 +10,9 @@ Live example: http://code.solusipse.net/ | |
------------------------------------------------------------------------------- | |
usage: fiche [-bdpqs]. | |
- [-d domain] [-p port] [-s slug_size] | |
- [-o output directory] [-B buffer_size] | |
- [-l log file] [-q queue_size] [-b banlist] | |
+ [-d domain] [-p port] [-s slug size] | |
+ [-o output directory] [-B buffer size] [-u user name] | |
+ [-l log file] [-b banlist] [-w whitelist] | |
Compile with Makefile or manually with -O2 and -pthread flags. | |
To install use `make install` command. | |
@@ -254,6 +254,8 @@ int create_directory(char *slug) | |
mkdir(BASEDIR, S_IRWXU | S_IRGRP | S_IROTH | S_IXOTH | S_IXGRP); | |
int result = mkdir(directory, S_IRWXU | S_IRGRP | S_IROTH | S_IXOTH | S_IX… | |
+ change_owner(directory); | |
+ | |
free(directory); | |
return result; | |
@@ -271,11 +273,29 @@ void save_to_file(char *slug, char *buffer) | |
fprintf(fp, "%s", buffer); | |
fclose(fp); | |
+ change_owner(directory); | |
+ | |
printf("Saved to: %s\n", directory); | |
display_line(); | |
free(directory); | |
} | |
+void change_owner(char *directory) | |
+{ | |
+ if ((UID != -1)&&(GID != -1)) | |
+ chown(directory, UID, GID); | |
+} | |
+ | |
+void set_uid_gid(char *username) | |
+{ | |
+ struct passwd *userdata = getpwnam(username); | |
+ if (userdata == NULL) | |
+ error(); | |
+ | |
+ UID = userdata->pw_uid; | |
+ GID = userdata->pw_gid; | |
+} | |
+ | |
void set_basedir() | |
{ | |
BASEDIR = getenv("HOME"); | |
@@ -295,7 +315,7 @@ void parse_parameters(int argc, char **argv) | |
{ | |
int c; | |
- while ((c = getopt (argc, argv, "p:b:q:s:d:o:l:B:")) != -1) | |
+ while ((c = getopt (argc, argv, "p:b:s:d:o:l:B:u:w:")) != -1) | |
switch (c) | |
{ | |
case 'd': | |
@@ -312,10 +332,6 @@ void parse_parameters(int argc, char **argv) | |
BANFILE = optarg; | |
load_banlist(BANFILE); | |
break; | |
- case 'q': | |
- QUEUE_SIZE = atoi(optarg); | |
- printf("Queue size set to: %d.\n", QUEUE_SIZE); | |
- break; | |
case 's': | |
SLUG_SIZE = atoi(optarg); | |
printf("Slug size set to: %d.\n", SLUG_SIZE); | |
@@ -329,11 +345,17 @@ void parse_parameters(int argc, char **argv) | |
LOG = optarg; | |
printf("Log file: %s\n", LOG); | |
break; | |
+ case 'u': | |
+ set_uid_gid(optarg); | |
+ break; | |
+ case 'w': | |
+ WHITELIST = optarg; | |
+ break; | |
default: | |
printf("usage: fiche [-bdpqs].\n"); | |
printf(" [-d domain] [-p port] [-s slug_si… | |
- printf(" [-o output directory] [-B buffer_… | |
- printf(" [-l log file] [-q queue_size] [-b… | |
+ printf(" [-o output directory] [-B buffer_… | |
+ printf(" [-l log file] [-b banlist] [-w wh… | |
exit(1); | |
} | |
} | |
\ No newline at end of file | |
diff --git a/fiche.h b/fiche.h | |
@@ -10,9 +10,9 @@ Live example: http://code.solusipse.net/ | |
------------------------------------------------------------------------------- | |
usage: fiche [-bdpqs]. | |
- [-d domain] [-p port] [-s slug_size] | |
- [-o output directory] [-B buffer_size] | |
- [-l log file] [-q queue_size] | |
+ [-d domain] [-p port] [-s slug size] | |
+ [-o output directory] [-B buffer size] [-u user name] | |
+ [-l log file] [-b banlist] [-w whitelist] | |
Compile with Makefile or manually with -O2 and -pthread flags. | |
To install use `make install` command. | |
@@ -27,6 +27,7 @@ $ cat fiche.c | nc localhost 9999 | |
#ifndef FICHE_H | |
#define FICHE_H | |
+#include <pwd.h> | |
#include <time.h> | |
#include <netdb.h> | |
#include <stdio.h> | |
@@ -40,14 +41,17 @@ $ cat fiche.c | nc localhost 9999 | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
+int UID = -1; | |
+int GID = -1; | |
char *LOG; | |
char *BASEDIR; | |
char *BANLIST; | |
char *BANFILE; | |
+char *WHITELIST; | |
int PORT = 9999; | |
int SLUG_SIZE = 4; | |
int BUFSIZE = 32768; | |
-int QUEUE_SIZE = 100; | |
+int QUEUE_SIZE = 500; | |
char DOMAIN[128] = "http://localhost/"; | |
int time_seed; | |
@@ -68,6 +72,8 @@ void set_basedir(); | |
void load_banlist(); | |
void parse_parameters(int argc, char **argv); | |
void save_log(char *slug, char *hostaddrp, char *h_name); | |
+void change_owner(char *directory); | |
+void set_uid_gid(); | |
char *return_line(){return("\n====================================");} | |
char *check_banlist(char *ip_address); |