[vhffs-dev] [681] Move vhffsfs and autokill into separate directories in order to autotoolize them |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [681] Move vhffsfs and autokill into separate directories in order to autotoolize them
- From: subversion@xxxxxxxxx
- Date: Sat, 07 Jul 2007 17:01:52 +0200
Revision: 681
Author: gradator
Date: 2007-07-07 15:01:51 +0000 (Sat, 07 Jul 2007)
Log Message:
-----------
Move vhffsfs and autokill into separate directories in order to autotoolize them
Added Paths:
-----------
trunk/vhffs-autokill/
trunk/vhffs-autokill/autokill.c
trunk/vhffs-fs/
trunk/vhffs-fs/md5.h
trunk/vhffs-fs/md5c.c
trunk/vhffs-fs/vhffsfs.c
trunk/vhffs-fs/vhffsfs.conf
trunk/vhffs-fs/vhffsfs_compil.sh
trunk/vhffs-fs/vhffsfs_run.sh
Removed Paths:
-------------
trunk/vhffs-tools/src/autokill.c
trunk/vhffs-tools/src/md5.h
trunk/vhffs-tools/src/md5c.c
trunk/vhffs-tools/src/vhffsfs.c
trunk/vhffs-tools/src/vhffsfs.conf
trunk/vhffs-tools/src/vhffsfs_compil.sh
trunk/vhffs-tools/src/vhffsfs_run.sh
Copied: trunk/vhffs-autokill/autokill.c (from rev 680, trunk/vhffs-tools/src/autokill.c)
Copied: trunk/vhffs-fs/md5.h (from rev 680, trunk/vhffs-tools/src/md5.h)
Copied: trunk/vhffs-fs/md5c.c (from rev 680, trunk/vhffs-tools/src/md5c.c)
Copied: trunk/vhffs-fs/vhffsfs.c (from rev 680, trunk/vhffs-tools/src/vhffsfs.c)
Copied: trunk/vhffs-fs/vhffsfs.conf (from rev 680, trunk/vhffs-tools/src/vhffsfs.conf)
Copied: trunk/vhffs-fs/vhffsfs_compil.sh (from rev 680, trunk/vhffs-tools/src/vhffsfs_compil.sh)
Copied: trunk/vhffs-fs/vhffsfs_run.sh (from rev 680, trunk/vhffs-tools/src/vhffsfs_run.sh)
Deleted: trunk/vhffs-tools/src/autokill.c
===================================================================
--- trunk/vhffs-tools/src/autokill.c 2007-07-07 02:11:55 UTC (rev 680)
+++ trunk/vhffs-tools/src/autokill.c 2007-07-07 15:01:51 UTC (rev 681)
@@ -1,260 +0,0 @@
-/*
- * autokill - A program to kill all process running during a certain
- * period of time or using too much cpu
- *
- * Copyright (C) 2006 Sylvain Rochet
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <dirent.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <time.h>
-#include <sys/time.h>
-#include <pwd.h>
-
-#define FALSE 0
-#define TRUE !FALSE
-
-// Assume you are using a system with jiffies at 100 HZ (all linux >= 2.4 kernels)
-#define HERTZ 100.0
-
-// All process between MINUID included and MAXUID included will be killed
-#define MINUID 10000
-#define MAXUID 65000
-
-// Interval between checks, in centiseconds (100 = 1 sec)
-#define WAITTIME 100
-
-// The maximum time the process are allowed to run, in jiffies
-#define MAXRUNTIMESIGTERM 30000
-#define MAXRUNTIMESIGKILL 30120
-
-// The maximum cpu time the process are allowed to use, in jiffies
-#define MAXCPUTIMESIGTERM 3100
-#define MAXCPUTIMESIGKILL 3210
-
-// Demo mode ?
-#define DEMOMODE FALSE
-
-// Daemonize ?
-#define DAEMONIZE TRUE
-
-// Logs ?
-#define LOGENABLE TRUE
-#define LOGFILE "/var/log/autokill.log"
-
-
-
-void addlogline(char *line);
-
-int main(int argc, char *argv[]) {
-
- if(LOGENABLE) {
- if(DEMOMODE) addlogline("Starting autokill in DEMOMODE");
- else addlogline("Starting autokill");
- }
-
- if(DAEMONIZE && fork()) exit(0);
-
- while(1) {
- char path[256], data[8192];
- FILE *f;
- int br;
- unsigned long long uptime;
- DIR *d;
- struct dirent *dir;
-
- // just wait, nothing more, really, I am not kidding, you can trust me
- // be serious, if I tell you that it is only a stupid wait inside an
- // infinite loop it is probably true, it is not an uncommon thing
- // as far as I know !
- // ok... give up... and let me do my job right now, want you ?
- if(WAITTIME/100) sleep(WAITTIME/100);
- if(WAITTIME%100) usleep((WAITTIME%100)*10000);
-
- // read uptime
- f = fopen("/proc/uptime", "r");
- if(!f) continue;
- br = fread(data, 1, 8192, f);
- fclose(f);
- if(!br) continue;
-
- uptime = (unsigned long long)(atof(data)*HERTZ);
- if(!uptime) continue;
-
- // search running process
- d = opendir("/proc");
- if(!d) continue;
-
- while( (dir = readdir(d) ) ) {
- int i, c, s, pid, zombie;
- unsigned long long uid, starttime, rtime, cputime;
- int signal;
- char *signame;
-
- // discard non directory and non numerical name
- if(dir->d_type != DT_DIR || dir->d_name[0] < '0' || dir->d_name[0] > '9') continue;
-
- pid = atoi(dir->d_name);
- if(!pid) continue;
-
- // read /proc/pid/status
- snprintf(path, 256, "/proc/%d/status", pid);
- f = fopen(path, "r");
- if(!f) continue;
- br = fread(data, 1, 8192, f);
- fclose(f);
- if(!br) continue;
-
- uid = -1;
- for(i = 0 ; i < br-4 ; i++) {
- if( (i == 0 || data[i-1] == '\n') && data[i] == 'U' && data[i+1] == 'i' && data[i+2] == 'd') {
- for(; i < br ; i++) {
- if(data[i] >= '0' && data[i] <= '9') {
- uid = atoll(data+i);
- break;
- }
- }
- break;
- }
- }
-
- if(uid < MINUID || uid > MAXUID) continue;
-
- // read /proc/pid/stats
- snprintf(path, 256, "/proc/%d/stat", pid);
- f = fopen(path, "r");
- if(!f) continue;
- br = fread(data, 1, 8192, f);
- fclose(f);
- if(!br) continue;
-
- starttime = -1;
- zombie = FALSE;
- cputime = 0;
- for(i = c = s = 0 ; i < br ; i++) {
- if(data[i] == ' ' || data[i] == '\t') {
- s = 0;
- } else {
- if(!s) {
- // triggered
- s = 1;
- c++;
-
- if(c == 3) {
- if(data[i] == 'Z') {
- zombie = TRUE;
- break;
- }
- }
-
- if(c >= 14 && c <= 17) {
- cputime += atoll(data+i);
- }
-
- if(c == 22) {
- starttime = atoll(data+i);
- break;
- }
- }
- }
- }
-
- if(zombie) continue;
- if(starttime < 0) continue;
-
- signal = -1;
- // check cputime
- if(cputime > MAXCPUTIMESIGTERM) {
-
- if(cputime > MAXCPUTIMESIGKILL) {
- signal = SIGKILL;
- signame = "SIGKILL";
- }
- else {
- signal = SIGTERM;
- signame = "SIGTERM";
- }
- }
-
- // check running time
- rtime = uptime - starttime;
- if(rtime > MAXRUNTIMESIGTERM) {
-
- if(rtime > MAXRUNTIMESIGKILL) {
- signal = SIGKILL;
- signame = "SIGKILL";
- }
- else {
- signal = SIGTERM;
- signame = "SIGTERM";
- }
- }
-
- if(signal >= 0) {
- if(LOGENABLE) {
- char line[128];
- struct passwd *pw;
- char *name, *demo;
-
- pw = getpwuid(uid);
- if(pw) name = pw->pw_name;
- else name = "unknown";
-
- if(DEMOMODE) demo = "[DEMO MODE] ";
- else demo = "";
-
- snprintf(line, 128, "%sSend %s to process %d, owned by %s(%d), cpu time %.2f sec, running time %.2f sec", demo, signame, pid, name, (int)uid, cputime/HERTZ, rtime/HERTZ);
- addlogline(line);
- }
-
- if(!DEMOMODE) kill(pid, signal);
- }
-
- }
- closedir(d);
- }
-
- return 0;
-}
-
-
-void addlogline(char *line) {
-
- FILE *lf;
-
- struct timeval tv;
- char date[64];
-
- gettimeofday(&tv, NULL);
- ctime_r(&tv.tv_sec, date);
- date[strlen(date)-1] = '\0';
-
- lf = fopen(LOGFILE, "a");
- if(lf) {
- fprintf(lf, "%s: %s\n", date, line);
- fclose(lf);
- }
- else {
- // use stdout if logfile is not available
- fprintf(stdout, "%s: %s\n", date, line);
- }
-}
Deleted: trunk/vhffs-tools/src/md5.h
===================================================================
--- trunk/vhffs-tools/src/md5.h 2007-07-07 02:11:55 UTC (rev 680)
+++ trunk/vhffs-tools/src/md5.h 2007-07-07 15:01:51 UTC (rev 681)
@@ -1,55 +0,0 @@
-/* MD5.H - header file for MD5C.C
- */
-
-/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
-rights reserved.
-
-License to copy and use this software is granted provided that it
-is identified as the "RSA Data Security, Inc. MD5 Message-Digest
-Algorithm" in all material mentioning or referencing this software
-or this function.
-
-License is also granted to make and use derivative works provided
-that such works are identified as "derived from the RSA Data
-Security, Inc. MD5 Message-Digest Algorithm" in all material
-mentioning or referencing the derived work.
-
-RSA Data Security, Inc. makes no representations concerning either
-the merchantability of this software or the suitability of this
-software for any particular purpose. It is provided "as is"
-without express or implied warranty of any kind.
-
-These notices must be retained in any copies of any part of this
-documentation and/or software.
- */
-
-#ifndef MD5_H
-#define MD5_H 1
-
-#include <sys/types.h>
-#include <inttypes.h>
-#include <stdint.h>
-
-/* POINTER defines a generic pointer type */
-typedef unsigned char *POINTER;
-
-#ifndef HAVE_UINT32_T
-# if SIZEOF_INT == 4
-typedef unsigned int uint32_t;
-# elif SIZEOF_LONG == 4
-typedef unsigned long int uint32_t;
-# endif
-#endif
-
-/* MD5 context. */
-typedef struct {
- uint32_t state[4]; /* state (ABCD) */
- uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
- unsigned char buffer[64]; /* input buffer */
-} MD5_CTX;
-
-void MD5Init (MD5_CTX *);
-void MD5Update (MD5_CTX *, unsigned char *, unsigned int);
-void MD5Final (unsigned char [16], MD5_CTX *);
-
-#endif
Deleted: trunk/vhffs-tools/src/md5c.c
===================================================================
--- trunk/vhffs-tools/src/md5c.c 2007-07-07 02:11:55 UTC (rev 680)
+++ trunk/vhffs-tools/src/md5c.c 2007-07-07 15:01:51 UTC (rev 681)
@@ -1,330 +0,0 @@
-/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
- */
-
-/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
-rights reserved.
-
-License to copy and use this software is granted provided that it
-is identified as the "RSA Data Security, Inc. MD5 Message-Digest
-Algorithm" in all material mentioning or referencing this software
-or this function.
-
-License is also granted to make and use derivative works provided
-that such works are identified as "derived from the RSA Data
-Security, Inc. MD5 Message-Digest Algorithm" in all material
-mentioning or referencing the derived work.
-
-RSA Data Security, Inc. makes no representations concerning either
-the merchantability of this software or the suitability of this
-software for any particular purpose. It is provided "as is"
-without express or implied warranty of any kind.
-
-These notices must be retained in any copies of any part of this
-documentation and/or software.
- */
-
-#include "md5.h"
-
-/* Constants for MD5Transform routine.
- */
-
-#define S11 7
-#define S12 12
-#define S13 17
-#define S14 22
-#define S21 5
-#define S22 9
-#define S23 14
-#define S24 20
-#define S31 4
-#define S32 11
-#define S33 16
-#define S34 23
-#define S41 6
-#define S42 10
-#define S43 15
-#define S44 21
-
-static void MD5Transform (uint32_t [4], unsigned char [64]);
-static void Encode (unsigned char *, uint32_t *, unsigned int);
-static void Decode (uint32_t *, unsigned char *, unsigned int);
-static void MD5_memcpy (POINTER, POINTER, unsigned int);
-static void MD5_memset (POINTER, int, unsigned int);
-
-static unsigned char PADDING[64] = {
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-/* F, G, H and I are basic MD5 functions.
- */
-#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
-#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
-#define H(x, y, z) ((x) ^ (y) ^ (z))
-#define I(x, y, z) ((y) ^ ((x) | (~z)))
-
-/* ROTATE_LEFT rotates x left n bits.
- */
-#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
-
-/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
-Rotation is separate from addition to prevent recomputation.
- */
-#define FF(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + (uint32_t)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define GG(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + (uint32_t)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define HH(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + (uint32_t)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define II(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + (uint32_t)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-
-/* MD5 initialization. Begins an MD5 operation, writing a new context.
- */
-void MD5Init (context)
-MD5_CTX *context; /* context */
-{
- context->count[0] = context->count[1] = 0;
- /* Load magic initialization constants.
-*/
- context->state[0] = 0x67452301;
- context->state[1] = 0xefcdab89;
- context->state[2] = 0x98badcfe;
- context->state[3] = 0x10325476;
-}
-
-/* MD5 block update operation. Continues an MD5 message-digest
- operation, processing another message block, and updating the
- context.
- */
-void MD5Update (context, input, inputLen)
-MD5_CTX *context; /* context */
-unsigned char *input; /* input block */
-unsigned int inputLen; /* length of input block */
-{
- unsigned int i, index, partLen;
-
- /* Compute number of bytes mod 64 */
- index = (unsigned int)((context->count[0] >> 3) & 0x3F);
-
- /* Update number of bits */
- if ((context->count[0] += ((uint32_t)inputLen << 3))
- < ((uint32_t)inputLen << 3))
- context->count[1]++;
- context->count[1] += ((uint32_t)inputLen >> 29);
-
- partLen = 64 - index;
-
- /* Transform as many times as possible.
-*/
- if (inputLen >= partLen) {
- MD5_memcpy
- ((POINTER)&context->buffer[index], (POINTER)input, partLen);
- MD5Transform (context->state, context->buffer);
-
- for (i = partLen; i + 63 < inputLen; i += 64)
- MD5Transform (context->state, &input[i]);
-
- index = 0;
- }
- else
- i = 0;
-
- /* Buffer remaining input */
- MD5_memcpy
- ((POINTER)&context->buffer[index], (POINTER)&input[i],
- inputLen-i);
-}
-
-/* MD5 finalization. Ends an MD5 message-digest operation, writing the
- the message digest and zeroizing the context.
- */
-void MD5Final (digest, context)
-unsigned char digest[16]; /* message digest */
-MD5_CTX *context; /* context */
-{
- unsigned char bits[8];
- unsigned int index, padLen;
-
- /* Save number of bits */
- Encode (bits, context->count, 8);
-
- /* Pad out to 56 mod 64.
-*/
- index = (unsigned int)((context->count[0] >> 3) & 0x3f);
- padLen = (index < 56) ? (56 - index) : (120 - index);
- MD5Update (context, PADDING, padLen);
-
- /* Append length (before padding) */
- MD5Update (context, bits, 8);
- /* Store state in digest */
- Encode (digest, context->state, 16);
-
- /* Zeroize sensitive information.
-*/
- MD5_memset ((POINTER)context, 0, sizeof (*context));
-}
-
-/* MD5 basic transformation. Transforms state based on block.
- */
-static void MD5Transform (state, block)
-uint32_t state[4];
-unsigned char block[64];
-{
- uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
-
- Decode (x, block, 64);
-
- /* Round 1 */
- FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
- FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
- FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
- FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
- FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
- FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
- FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
- FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
- FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
- FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
- FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
- FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
- FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
- FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
- FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
- FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
-
- /* Round 2 */
- GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
- GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
- GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
- GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
- GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
- GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
- GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
- GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
- GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
- GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
- GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
- GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
- GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
- GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
- GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
- GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
-
- /* Round 3 */
- HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
- HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
- HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
- HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
- HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
- HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
- HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
- HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
- HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
- HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
- HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
- HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
- HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
- HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
- HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
- HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
-
- /* Round 4 */
- II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
- II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
- II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
- II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
- II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
- II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
- II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
- II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
- II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
- II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
- II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
- II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
- II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
- II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
- II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
- II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
-
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
-
- /* Zeroize sensitive information. */
- MD5_memset ((POINTER)x, 0, sizeof (x));
-}
-
-/* Encodes input (uint32_t) into output (unsigned char). Assumes len is
- a multiple of 4.
- */
-static void Encode (output, input, len)
-unsigned char *output;
-uint32_t *input;
-unsigned int len;
-{
- unsigned int i, j;
-
- for (i = 0, j = 0; j < len; i++, j += 4) {
- output[j] = (unsigned char)(input[i] & 0xff);
- output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
- output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
- output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
- }
-}
-
-/* Decodes input (unsigned char) into output (uint32_t). Assumes len is
- a multiple of 4.
- */
-static void Decode (output, input, len)
-uint32_t *output;
-unsigned char *input;
-unsigned int len;
-{
- unsigned int i, j;
-
- for (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((uint32_t)input[j]) | (((uint32_t)input[j+1]) << 8) |
- (((uint32_t)input[j+2]) << 16) | (((uint32_t)input[j+3]) << 24);
-}
-
-/* Note: Replace "for loop" with standard memcpy if possible.
- */
-
-static void MD5_memcpy (output, input, len)
-POINTER output;
-POINTER input;
-unsigned int len;
-{
- unsigned int i;
-
- for (i = 0; i < len; i++)
- output[i] = input[i];
-}
-
-/* Note: Replace "for loop" with standard memset if possible.
- */
-static void MD5_memset (output, value, len)
-POINTER output;
-int value;
-unsigned int len;
-{
- unsigned int i;
-
- for (i = 0; i < len; i++)
- ((char *)output)[i] = (char)value;
-}
Deleted: trunk/vhffs-tools/src/vhffsfs.c
===================================================================
--- trunk/vhffs-tools/src/vhffsfs.c 2007-07-07 02:11:55 UTC (rev 680)
+++ trunk/vhffs-tools/src/vhffsfs.c 2007-07-07 15:01:51 UTC (rev 681)
@@ -1,1380 +0,0 @@
-/*
- VHFFSFS: Virtual chroot for your users, using FUSE !
- Copyright (C) 2007 Sylvain Rochet <gradator@xxxxxxxxxxxx>
-
- This program can be distributed under the terms of the GNU GPL.
- See the file COPYING.
-*/
-
-#define WITH_CACHE 1
-#define VHFFSFS_MAXCONNDB 5
-#define VHFFSFS_CONFIG "/etc/vhffsfs.conf"
-#define VHFFSFS_EMPTYDIR "/tmp/emptydir"
-
-#define _GNU_SOURCE
-
-#include <fuse.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <time.h>
-#ifdef HAVE_SETXATTR
-#include <sys/xattr.h>
-#endif
-#include <pthread.h>
-#include <signal.h>
-#ifdef WITH_CACHE
-#include <glib.h>
-#endif
-#include <postgresql/libpq-fe.h>
-#include "md5.h"
-
-#ifdef WITH_CACHE
-#define VHFFSFS_CACHE_QUERY_TIMEOUT 600
-#define VHFFSFS_CACHE_QUERY_FLUSH_EVERY 1800
-
-typedef struct {
- char *query;
- PGresult *result;
- time_t arrival;
- int ref;
-} vhffsfs_cache_query;
-#endif
-
-struct vhffsfs {
- pthread_mutex_t pg_lock[VHFFSFS_MAXCONNDB];
- PGconn *pg_conn[VHFFSFS_MAXCONNDB];
- char *grouppath;
- char *webspath;
- char *repositoriespath;
- char *dbhost;
- int dbport;
- char *dbuser;
- char *dbpass;
- char *dbname;
- int dbtimeout;
- char *dbconninfo;
- mode_t minimumrightfile;
- mode_t minimumrightdir;
-#ifdef WITH_CACHE
- GHashTable *cachequeries;
- GPtrArray* cachekeys;
- pthread_mutex_t cachelock;
- int cachethreadstarted;
-#endif
-};
-
-static struct vhffsfs vhffsfs;
-
-#ifdef WITH_CACHE
-time_t vhffsfs_cache_arrival() {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return tv.tv_sec;
-}
-
-int vhffsfs_cache_timeout(time_t arrival, time_t timeout) {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- if(tv.tv_sec - arrival >= timeout) return 1;
- return 0;
-}
-
-static inline void vhffsfs_cache_lock() {
- pthread_mutex_lock(&vhffsfs.cachelock);
-}
-
-static inline void vhffsfs_cache_unlock() {
- pthread_mutex_unlock(&vhffsfs.cachelock);
-}
-
-void vhffsfs_cache_add(char *query, PGresult *result) {
- vhffsfs_cache_query *vcq;
- vhffsfs_cache_lock();
- vcq = g_hash_table_lookup(vhffsfs.cachequeries, query);
- if(vcq) {
- vhffsfs_cache_unlock();
- return;
- }
- //printf("CACHE: ADDING: '%s'\n", query);
- vcq = malloc(sizeof(vhffsfs_cache_query));
- vcq->query = strdup(query);
- vcq->result = result;
- vcq->arrival = vhffsfs_cache_arrival();
- vcq->ref = 1;
- g_hash_table_insert(vhffsfs.cachequeries, vcq->query, vcq);
- g_ptr_array_add(vhffsfs.cachekeys, vcq->query);
- vhffsfs_cache_unlock();
-}
-
-void vhffsfs_cache_del(char *query) {
- vhffsfs_cache_query *vcq;
- vhffsfs_cache_lock();
- vcq = g_hash_table_lookup(vhffsfs.cachequeries, query);
- // non existing or still referenced
- if(!vcq || vcq->ref > 0) {
- vhffsfs_cache_unlock();
- return;
- }
- //printf("CACHE: DELETING: '%s'\n", query);
- //g_ptr_array_remove_fast(vhffsfs.cachekeys, vcq->query);
- g_ptr_array_remove_fast(vhffsfs.cachekeys, vcq->query);
- g_hash_table_remove(vhffsfs.cachequeries, vcq->query);
- free(vcq->query);
- PQclear(vcq->result);
- free(vcq);
- vhffsfs_cache_unlock();
-}
-
-PGresult *vhffsfs_cache_lookup(char *query) {
- vhffsfs_cache_lock();
- vhffsfs_cache_query *vcq = g_hash_table_lookup(vhffsfs.cachequeries, query);
- if(vcq) {
- // timeout
- if(vhffsfs_cache_timeout(vcq->arrival, VHFFSFS_CACHE_QUERY_TIMEOUT)) {
- //fprintf(stdout, "CACHE: TIMEOUT: '%s'\n", query);
- vhffsfs_cache_unlock();
- vhffsfs_cache_del(query);
- return NULL;
- }
- // cache hit
- //fprintf(stdout, "CACHE: HIT: '%s'\n", query);
- vcq->ref++;
- vhffsfs_cache_unlock();
- return vcq->result;
- }
- // cache miss
- //fprintf(stdout, "CACHE: MISS: '%s'\n", query);
- vhffsfs_cache_unlock();
- return NULL;
-}
-
-void vhffsfs_cache_unref(char *query) {
- vhffsfs_cache_lock();
- vhffsfs_cache_query *vcq = g_hash_table_lookup(vhffsfs.cachequeries, query);
- if(vcq && vcq->ref > 0) vcq->ref--;
- else fprintf(stderr, "CACHE: CORRUPT: '%s'\n", query);
- vhffsfs_cache_unlock();
-}
-
-
-static void *vhffsfs_cache_flush(void *data_)
-{
- (void) data_;
-
- while(1) {
- GPtrArray *keys;
- int i;
-
- sleep(VHFFSFS_CACHE_QUERY_FLUSH_EVERY);
-
- keys = g_ptr_array_sized_new(4096);
-
- //printf("FLUSH CACHE\n");
-
- // copy keys
- vhffsfs_cache_lock();
- for(i = 0 ; i < vhffsfs.cachekeys->len ; i++) {
- g_ptr_array_add(keys, strdup(vhffsfs.cachekeys->pdata[i]));
- }
- vhffsfs_cache_unlock();
-
- // sleep a bit to not lock the cache too much
- sleep(1);
-
- for(i = 0 ; i < keys->len ; i++) {
- char *query = keys->pdata[i];
- vhffsfs_cache_query *vcq;
-
- vhffsfs_cache_lock();
- vcq = g_hash_table_lookup(vhffsfs.cachequeries, query);
- if(vcq && vhffsfs_cache_timeout(vcq->arrival, VHFFSFS_CACHE_QUERY_TIMEOUT)) {
- //fprintf(stdout, "CACHE: TIMEOUT: '%s'\n", query);
- vhffsfs_cache_unlock();
- vhffsfs_cache_del(query);
- }
- else vhffsfs_cache_unlock();
-
- free(query);
- //sleep a bit to not lock the cache too much
- usleep(100000);
- }
-
- g_ptr_array_free(keys, TRUE);
- }
- return NULL;
-}
-
-
-static int vhffsfs_start_cache_flush_thread(void)
-{
- int err;
- pthread_t thread_id;
- sigset_t oldset;
- sigset_t newset;
-
- if(vhffsfs.cachethreadstarted) return 0;
-
- sigemptyset(&newset);
- sigaddset(&newset, SIGTERM);
- sigaddset(&newset, SIGINT);
- sigaddset(&newset, SIGHUP);
- sigaddset(&newset, SIGQUIT);
- pthread_sigmask(SIG_BLOCK, &newset, &oldset);
- err = pthread_create(&thread_id, NULL, vhffsfs_cache_flush, NULL);
- if(err) {
- fprintf(stderr, "Failed to create thread: %s\n", strerror(err));
- return -EIO;
- }
- pthread_detach(thread_id);
- pthread_sigmask(SIG_SETMASK, &oldset, NULL);
- vhffsfs.cachethreadstarted = 1;
- return 0;
-}
-#endif
-
-
-PGresult *vhffsfs_PGQuery(char *query) {
-
- int i;
- PGresult *res;
-
-#ifdef WITH_CACHE
- // try to fetch query from cache
- res = vhffsfs_cache_lookup(query);
- if(res) return res;
-#endif
-
- do {
- for(i = 0 ; i < VHFFSFS_MAXCONNDB && pthread_mutex_trylock(&vhffsfs.pg_lock[i]) ; i++);
- // all slots used, sleep for 100ms and try again
- } while(i == VHFFSFS_MAXCONNDB && !usleep(100000));
-
- // something very weird happened
- if(i == VHFFSFS_MAXCONNDB) return NULL;
-
- // wait until we are connected to the pgsql server
- while(!vhffsfs.pg_conn[i] || PQstatus(vhffsfs.pg_conn[i]) != CONNECTION_OK) {
- vhffsfs.pg_conn[i] = PQconnectdb(vhffsfs.dbconninfo);
-
- if(PQstatus(vhffsfs.pg_conn[i]) != CONNECTION_OK) {
- fprintf(stderr, "SLOT[%d]: CONNECT FAILED '%s': %s\n", i, PQdb(vhffsfs.pg_conn[i]), PQerrorMessage(vhffsfs.pg_conn[i]));
- PQfinish(vhffsfs.pg_conn[i]);
- sleep(1);
- }
- else {
- fprintf(stdout, "SLOT[%d]: CONNECT '%s'\n", i, PQdb(vhffsfs.pg_conn[i]));
- }
- }
-
- res = PQexec(vhffsfs.pg_conn[i], query);
- if(PQresultStatus(res) != PGRES_TUPLES_OK)
- {
- fprintf(stderr, "SLOT[%d]: QUERY: '%s' failed: %s\n", i, query, PQerrorMessage(vhffsfs.pg_conn[i]));
- PQclear(res);
- res=NULL;
- }
- else {
- //fprintf(stdout, "SLOT[%d]: QUERY: '%s'\n", i, query);
-#ifdef WITH_CACHE
- // fill cache
- vhffsfs_cache_add(query, res);
-#endif
- }
-
- pthread_mutex_unlock(&vhffsfs.pg_lock[i]);
- return res;
-}
-
-static inline void vhffsfs_PGClear(char *query, PGresult *result) {
-#ifdef WITH_CACHE
- vhffsfs_cache_unref(query);
-#endif
-#ifndef WITH_CACHE
- PQclear(result);
-#endif
-}
-
-char *vhffsfs_gethomedir() {
- char query[128];
- PGresult *res;
- char *homedir=NULL;
-
- snprintf(query, 128, "SELECT homedir FROM vhffs_users WHERE uid = %d", fuse_get_context()->uid);
- res=vhffsfs_PGQuery(query);
- if(!res) return NULL;
-
- if(PQnfields(res) == 1 && PQntuples(res) == 1)
- homedir = strdup(PQgetvalue(res, 0, 0));
-
- vhffsfs_PGClear(query, res);
- return homedir;
-}
-
-
-char *vhffsfs_getgroupdir(char *group) {
-
- char query[256];
- PGresult *res;
- char *groupname=NULL;
- char *groupdir=NULL;
- char *cur;
-
- // check if group match ^[a-z0-9]+$ to prevent SQL injections
- for(cur = group ; *cur ; cur++)
- if(! ( (*cur >= 'a' && *cur <= 'z') || (*cur >= '0' && *cur <= '9') ) ) return NULL;
-
- snprintf(query, 256, "SELECT g.groupname FROM vhffs_users u, vhffs_groups g, vhffs_user_group ug WHERE u.uid = %d AND g.groupname = '%s' AND u.uid = ug.uid AND g.gid = ug.gid", fuse_get_context()->uid, group);
- res=vhffsfs_PGQuery(query);
- if(!res) return NULL;
-
- if(PQnfields(res) == 1 && PQntuples(res) == 1)
- groupname = PQgetvalue(res, 0, 0);
-
- if(groupname) {
- groupdir = malloc(strlen(vhffsfs.grouppath)+strlen(groupname)+6);
- sprintf(groupdir, "%s/%c/%c/%s", vhffsfs.grouppath, groupname[0], groupname[1], groupname);
- }
-
- vhffsfs_PGClear(query, res);
- return groupdir;
-}
-
-
-gid_t vhffsfs_getgroupgid(char *group) {
-
- char query[256];
- PGresult *res;
- gid_t gid=0;
- char *cur;
-
- // check if group match ^[a-z0-9]+$ to prevent SQL injections
- for(cur = group ; *cur ; cur++)
- if(! ( (*cur >= 'a' && *cur <= 'z') || (*cur >= '0' && *cur <= '9') ) ) return 0;
-
- snprintf(query, 256, "SELECT gid FROM vhffs_groups WHERE groupname = '%s'", group);
- res=vhffsfs_PGQuery(query);
- if(!res) return 0;
-
- if(PQnfields(res) == 1 && PQntuples(res) == 1)
- gid = atoi(PQgetvalue(res, 0, 0));
-
- vhffsfs_PGClear(query, res);
- return gid;
-}
-
-
-char *vhffsfs_getwebdir(char *group, char *website) {
-
- char query[256];
- PGresult *res;
- char *servername=NULL;
- char *webdir=NULL;
- char *cur;
-
- // check if group match ^[a-z0-9]+$ to prevent SQL injections
- for(cur = group ; *cur ; cur++)
- if(! ( (*cur >= 'a' && *cur <= 'z') || (*cur >= '0' && *cur <= '9') ) ) return NULL;
-
- // check if website match ^[a-z0-9\-\.]+$ to prevent SQL injections
- for(cur = website ; *cur ; cur++)
- if(! ( (*cur >= 'a' && *cur <= 'z') || (*cur >= '0' && *cur <= '9') || *cur == '-' || *cur == '.') ) return NULL;
-
- snprintf(query, 256, "SELECT servername FROM vhffs_httpd WHERE owner_gid = (SELECT gid FROM vhffs_groups WHERE groupname = '%s') AND servername = '%s'", group, website);
- res=vhffsfs_PGQuery(query);
- if(!res) return NULL;
-
- if(PQnfields(res) == 1 && PQntuples(res) == 1)
- servername = PQgetvalue(res, 0, 0);
-
- if(servername) {
- MD5_CTX context;
- unsigned char digest[16];
-
- webdir = malloc(strlen(vhffsfs.webspath)+strlen(servername)+11);
- MD5Init(&context);
- MD5Update(&context, (unsigned char*)servername, strlen(servername));
- MD5Final(digest, &context);
- sprintf(webdir, "%s/%02x/%02x/%02x/%s", vhffsfs.webspath, digest[0], digest[1], digest[2], servername);
- }
-
- vhffsfs_PGClear(query, res);
- return webdir;
-}
-
-
-char *vhffsfs_getrepositorydir(char *group, char *name) {
-
- char query[256];
- PGresult *res;
- char *reponame=NULL;
- char *repodir=NULL;
- char *cur;
-
- // check if group match ^[a-z0-9]+$ to prevent SQL injections
- for(cur = group ; *cur ; cur++)
- if(! ( (*cur >= 'a' && *cur <= 'z') || (*cur >= '0' && *cur <= '9') ) ) return NULL;
-
- // check if name match ^[a-z0-9]+$ to prevent SQL injections
- for(cur = name ; *cur ; cur++)
- if(! ( (*cur >= 'a' && *cur <= 'z') || (*cur >= '0' && *cur <= '9') ) ) return NULL;
-
- snprintf(query, 256, "SELECT name FROM vhffs_repository WHERE owner_gid = (SELECT gid FROM vhffs_groups WHERE groupname = '%s') AND name = '%s'", group, name);
- res=vhffsfs_PGQuery(query);
- if(!res) return NULL;
-
- if(PQnfields(res) == 1 && PQntuples(res) == 1)
- reponame = PQgetvalue(res, 0, 0);
-
- if(reponame) {
- repodir = malloc(strlen(vhffsfs.repositoriespath)+strlen(reponame)+2);
- sprintf(repodir, "%s/%s", vhffsfs.repositoriespath, reponame);
- }
-
- vhffsfs_PGClear(query, res);
- return repodir;
-}
-
-
-char **vhffsfs_getusergroups(uid_t uid) {
-
- char query[256];
- PGresult *res;
- char **groups=NULL;
-
- snprintf(query, 256, "SELECT g.groupname FROM vhffs_users u, vhffs_groups g, vhffs_user_group ug WHERE u.uid = %d AND u.uid = ug.uid AND g.gid = ug.gid", uid);
- res=vhffsfs_PGQuery(query);
- if(!res) return NULL;
-
- if(PQnfields(res) == 1) {
- int i, x;
- groups = malloc((PQntuples(res)*2+1)*sizeof(char*));
- *(groups+PQntuples(res)*2) = '\0';
-
- for(i = x = 0 ; i < PQntuples(res) ; i++, x+=2) {
- char *groupname = PQgetvalue(res, i, 0);
- if(groupname) {
- char *groupdir = malloc(strlen(vhffsfs.grouppath)+strlen(groupname)+6);
- sprintf(groupdir, "%s/%c/%c/%s", vhffsfs.grouppath, groupname[0], groupname[1], groupname);
- *(groups+x) = strdup(groupname);
- *(groups+x+1) = groupdir;
- }
- }
- }
-
- vhffsfs_PGClear(query, res);
- return groups;
-}
-
-
-char **vhffsfs_getgroupservices(gid_t gid) {
-
- char query1[256], query2[256];
- PGresult *res1,*res2;
- char **services=NULL;
-
- // fetch websites
- snprintf(query1, 256, "SELECT servername FROM vhffs_httpd WHERE owner_gid = %d", gid);
- res1=vhffsfs_PGQuery(query1);
- if(!res1) return NULL;
-
- // fetch repositories
- snprintf(query2, 256, "SELECT name FROM vhffs_repository WHERE owner_gid = %d", gid);
- res2=vhffsfs_PGQuery(query2);
- if(!res2) {
- vhffsfs_PGClear(query1, res1);
- return NULL;
- }
-
- if(PQnfields(res1) == 1 && PQnfields(res2) == 1) {
- int i, x=0;
- int nb = PQntuples(res1)+PQntuples(res2);
-
- services = malloc((nb*2+1)*sizeof(char*) );
- *(services+nb*2) = '\0';
-
- // websites
- for(i = 0 ; i < PQntuples(res1) ; i++, x+=2) {
- char *servername = PQgetvalue(res1, i, 0);
- if(servername) {
- char *displayedname;
- char *webdir;
- MD5_CTX context;
- unsigned char digest[16];
-
- displayedname = malloc(strlen(servername)+5);
- sprintf(displayedname, "%s-web", servername);
-
- webdir = malloc(strlen(vhffsfs.webspath)+strlen(servername)+11);
- MD5Init(&context);
- MD5Update(&context, (unsigned char*)servername, strlen(servername));
- MD5Final(digest, &context);
- sprintf(webdir, "%s/%02x/%02x/%02x/%s", vhffsfs.webspath, digest[0], digest[1], digest[2], servername);
-
- *(services+x) = displayedname;
- *(services+x+1) = webdir;
- }
- }
-
- // repositories
- for(i = 0 ; i < PQntuples(res2) ; i++, x+=2) {
- char *reponame = PQgetvalue(res2, i, 0);
- if(reponame) {
- char *displayedname;
- char *repodir;
-
- displayedname = malloc(strlen(reponame)+12);
- sprintf(displayedname, "%s-repository", reponame);
-
- repodir = malloc(strlen(vhffsfs.repositoriespath)+strlen(reponame)+2);
- sprintf(repodir, "%s/%s", vhffsfs.repositoriespath, reponame);
-
- *(services+x) = displayedname;
- *(services+x+1) = repodir;
- }
- }
- }
-
- vhffsfs_PGClear(query1, res1);
- vhffsfs_PGClear(query2, res2);
- return services;
-}
-
-
-// return the real path
-char *vhffsfs_realpath(const char *path, uid_t *uid, gid_t *gid) {
- char *begin, *cur;
- char *first=NULL;
- char *homedir;
- char *rpath=NULL;
-
- //printf("======= PATH: %s\n", path);
- //printf("======= UID: %d\n", fuse_get_context()->uid);
- //printf("======= GID: %d\n", fuse_get_context()->gid);
-
- // path empty
- if(*(path+0) == '\0') return NULL;
- // set uid and gid
- if(uid) *uid = fuse_get_context()->uid;
- if(gid) *gid = fuse_get_context()->gid;
- // path relative
- if(*(path+0) == '.') return strdup(path);
- // fetch homedir
- homedir = vhffsfs_gethomedir();
- if(!homedir) return strdup(VHFFSFS_EMPTYDIR);
- // -- parse path
- // / | home directory ----------------------------|
- // /first | home file | group directory ---------------|
- // /first/second | home file | group file | service directory |
- // /first/second/third | home file | group file | service file -----|
-
- // get first node
- cur = (char*)path;
- if(*cur++) {
- for(begin = cur ; *cur && *cur != '/'; cur++);
- if(cur != begin) first = strndup(begin, cur - begin);
- }
-
- // home directory
- if(!first) rpath = strdup(homedir);
-
- // FIRST EXIST BELOW
-
- // so, try to fetch group directory
- else {
- char *groupdir = vhffsfs_getgroupdir(first);
-
- // home file
- if(!groupdir) {
- rpath = malloc(strlen(homedir)+strlen(begin)+2);
- sprintf(rpath, "%s/%s", homedir, begin);
- }
-
- else {
- char *groupname = first;
- char *second=NULL;
-
- // set gid
- if(gid) *gid = vhffsfs_getgroupgid(groupname);
-
- // get second node
- if(*cur++) {
- for(begin = cur ; *cur && *cur != '/'; cur++);
- if(cur != begin) second = strndup(begin, cur - begin);
- }
-
- // group directory
- if(!second) rpath = strdup(groupdir);
-
- // SECOND EXIST BELOW
-
- // so, try to fetch service directory
- else {
- char *servicedir=NULL;
- char *servicetype, *servicename;
-
- // fetch servicetype and servicename
- for(servicetype = servicename = second ; *servicetype ; servicetype++);
- for(; servicetype > second && *servicetype != '-' ; servicetype--);
- if(*servicetype == '-') *servicetype++ = '\0';
-
- if(!strcmp(servicetype, "web")) {
- servicedir = vhffsfs_getwebdir(groupname, servicename);
- } else if(!strcmp(servicetype, "repository")) {
- servicedir = vhffsfs_getrepositorydir(groupname, servicename);
- }
-
- // group file
- if(!servicedir) {
- rpath = malloc(strlen(groupdir)+strlen(begin)+2);
- sprintf(rpath, "%s/%s", groupdir, begin);
- }
-
- else {
- char *third=NULL;
-
- // get third node
- if(*cur++) third = strdup(cur);
-
- // service directory
- if(!third) rpath = strdup(servicedir);
-
- // THIRD EXIST BELOW
- else {
- rpath = malloc(strlen(servicedir)+strlen(third)+2);
- sprintf(rpath, "%s/%s", servicedir, third);
-
- free(third);
- }
- free(servicedir);
- }
- free(second);
- }
- free(groupdir);
- }
- free(first);
- }
- free(homedir);
-
- //printf("======= RETURN: %s\n\n", rpath);
- return rpath;
-}
-
-
-char **vhffsfs_virtualdirs(const char *path) {
-
- char *groupname=NULL;
- char **vdirs=NULL;
-
- // path empty
- if(*(path+0) == '\0') return NULL;
- // get groupname
- if(*(path+1) != '\0') groupname = (char*)path+1;
-
- if(!groupname) vdirs = vhffsfs_getusergroups(fuse_get_context()->uid);
-
- else {
- gid_t gid = vhffsfs_getgroupgid(groupname);
- if(gid > 0) vdirs = vhffsfs_getgroupservices(gid);
- }
-
- return vdirs;
-}
-
-
-static void *vhffsfs_init(void)
-{
-#ifdef WITH_CACHE
- // create cache flush thread
- vhffsfs_start_cache_flush_thread();
-#endif
- return NULL;
-}
-
-
-static int vhffsfs_getattr(const char *path, struct stat *stbuf)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = lstat(rpath, stbuf);
- free(rpath);
-
- if(res == -1) return -errno;
- // force find -noleaf
- stbuf->st_nlink = 1;
- return 0;
-}
-
-
-static int vhffsfs_fgetattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi)
-{
- int res;
-
- (void) path;
-
- res = fstat(fi->fh, stbuf);
-
- if(res == -1) return -errno;
- // force find -noleaf
- stbuf->st_nlink = 1;
- return 0;
-}
-
-
-static int vhffsfs_access(const char *path, int mask)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = access(rpath, mask);
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_readlink(const char *path, char *buf, size_t size)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = readlink(rpath, buf, size - 1);
- free(rpath);
-
- if(res == -1) return -errno;
- buf[res] = '\0';
- return 0;
-}
-
-
-static int vhffsfs_opendir(const char *path, struct fuse_file_info *fi)
-{
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- DIR *dp = opendir(rpath);
- free(rpath);
-
- if(dp == NULL) return -errno;
- fi->fh = (unsigned long) dp;
- return 0;
-}
-
-
-static inline DIR *get_dirp(struct fuse_file_info *fi)
-{
- return (DIR *) (uintptr_t) fi->fh;
-}
-
-
-static int vhffsfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
-{
- DIR *dp = get_dirp(fi);
- struct dirent *de;
- char **vdirs;
-
- //(void) path;
- seekdir(dp, offset);
- while ((de = readdir(dp)) != NULL) {
- struct stat st;
- memset(&st, 0, sizeof(st));
- st.st_ino = de->d_ino;
- st.st_mode = de->d_type << 12;
- if (filler(buf, de->d_name, &st, telldir(dp)))
- break;
- }
-
- // add virtual directories
- vdirs = vhffsfs_virtualdirs(path);
- if(vdirs) {
- char **cur;
- for(cur = vdirs ; *cur ; cur+=2) {
- char *vname = *cur;
- char *vpath = *(cur+1);
-
- struct stat st;
- stat(vpath, &st);
- filler(buf, vname, &st, 0);
-
- free(vname);
- free(vpath);
- }
- free(vdirs);
- }
-
- return 0;
-}
-
-
-static int vhffsfs_releasedir(const char *path, struct fuse_file_info *fi)
-{
- DIR *dp = get_dirp(fi);
- (void) path;
- closedir(dp);
- return 0;
-}
-
-
-static int vhffsfs_mknod(const char *path, mode_t mode, dev_t rdev)
-{
-/* -- DISABLED - user must not be allowed to create that !
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- if (S_ISFIFO(mode))
- res = mkfifo(rpath, mode);
- else
- res = mknod(rpath, mode, rdev);
-
- if(res == -1) return -errno;
- return 0;
-*/
- return -EACCES;
-}
-
-
-static int vhffsfs_mkdir(const char *path, mode_t mode)
-{
- int res;
- char *rpath;
- uid_t uid;
- gid_t gid;
-
- rpath = vhffsfs_realpath(path, &uid, &gid);
- if(!rpath) return -ENOENT;
-
- res = mkdir(rpath, mode);
- if(res == 0) {
- struct stat st;
- lchown(rpath, uid, gid);
- stat(rpath, &st);
- chmod(rpath, st.st_mode | vhffsfs.minimumrightdir);
- }
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_unlink(const char *path)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = unlink(rpath);
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_rmdir(const char *path)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = rmdir(rpath);
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_symlink(const char *from, const char *to)
-{
- int res;
- char *rfrom, *rto;
- uid_t uid;
- gid_t gid;
-
- rfrom = vhffsfs_realpath(from, NULL, NULL);
- if(!rfrom) return -ENOENT;
-
- rto = vhffsfs_realpath(to, &uid, &gid);
- if(!rto) {
- free(rfrom);
- return -ENOENT;
- }
-
- res = symlink(rfrom, rto);
- if(res == 0) lchown(rto, uid, gid);
- free(rfrom);
- free(rto);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_rename(const char *from, const char *to)
-{
- int res;
- char *rfrom, *rto;
-
- rfrom = vhffsfs_realpath(from, NULL, NULL);
- if(!rfrom) return -ENOENT;
-
- rto = vhffsfs_realpath(to, NULL, NULL);
- if(!rto) {
- free(rfrom);
- return -ENOENT;
- }
-
- res = rename(rfrom, rto);
- free(rfrom);
- free(rto);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_link(const char *from, const char *to)
-{
-/* -- DISABLED - user must not be allowed to create that !
- int res;
- char *rfrom, *rto;
- uid_t uid;
- gid_t gid;
-
- rfrom = vhffsfs_realpath(from, NULL, NULL);
- if(!rfrom) return -ENOENT;
-
- rto = vhffsfs_realpath(to, NULL, NULL);
- if(!rto) {
- free(rfrom);
- return -ENOENT;
- }
-
- res = link(rfrom, rto);
- if(res == 0) lchown(rto, uid, gid);
- free(rfrom);
- free(rto);
-
- if(res == -1) return -errno;
- return 0;
-*/
- return -EACCES;
-}
-
-
-static int vhffsfs_chmod(const char *path, mode_t mode)
-{
- int res;
- char *rpath;
- struct stat st;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- stat(rpath, &st);
- res = chmod(rpath, mode | (S_ISDIR(st.st_mode) ? vhffsfs.minimumrightdir : vhffsfs.minimumrightfile) );
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_chown(const char *path, uid_t uid, gid_t gid)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = lchown(rpath, uid, gid);
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_truncate(const char *path, off_t size)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = truncate(rpath, size);
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_ftruncate(const char *path, off_t size, struct fuse_file_info *fi)
-{
- int res;
- (void) path;
-
- res = ftruncate(fi->fh, size);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_utime(const char *path, struct utimbuf *buf)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = utime(rpath, buf);
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_create(const char *path, mode_t mode, struct fuse_file_info *fi)
-{
- int fd;
- char *rpath;
- uid_t uid;
- gid_t gid;
-
- rpath = vhffsfs_realpath(path, &uid, &gid);
- if(!rpath) return -ENOENT;
-
- fd = open(rpath, fi->flags, mode);
- if(fd >= 0) {
- struct stat st;
- lchown(rpath, uid, gid);
- stat(rpath, &st);
- chmod(rpath, st.st_mode | vhffsfs.minimumrightfile);
- }
- free(rpath);
-
- if(fd == -1) return -errno;
- fi->fh = fd;
- return 0;
-}
-
-
-static int vhffsfs_open(const char *path, struct fuse_file_info *fi)
-{
- int fd;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- fd = open(rpath, fi->flags);
- free(rpath);
-
- if(fd == -1) return -errno;
- fi->fh = fd;
- return 0;
-}
-
-
-static int vhffsfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
-{
- int res;
-
- (void) path;
- res = pread(fi->fh, buf, size, offset);
-
- if(res == -1) res = -errno;
- return res;
-}
-
-
-static int vhffsfs_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
-{
- int res;
-
- (void) path;
- res = pwrite(fi->fh, buf, size, offset);
-
- if(res == -1) res = -errno;
- return res;
-}
-
-
-static int vhffsfs_statfs(const char *path, struct statvfs *stbuf)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = statvfs(rpath, stbuf);
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_release(const char *path, struct fuse_file_info *fi)
-{
- (void) path;
- close(fi->fh);
-
- return 0;
-}
-
-
-static int vhffsfs_fsync(const char *path, int isdatasync, struct fuse_file_info *fi)
-{
- int res;
- (void) path;
-
-#ifndef HAVE_FDATASYNC
- (void) isdatasync;
-#else
- if(isdatasync)
- res = fdatasync(fi->fh);
- else
-#endif
- res = fsync(fi->fh);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-#ifdef HAVE_SETXATTR
-/* xattr operations are optional and can safely be left unimplemented */
-static int vhffsfs_setxattr(const char *path, const char *name, const char *value, size_t size, int flags)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = lsetxattr(rpath, name, value, size, flags);
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-
-
-static int vhffsfs_getxattr(const char *path, const char *name, char *value, size_t size)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = lgetxattr(rpath, name, value, size);
- free(rpath);
-
- if(res == -1) return -errno;
- return res;
-}
-
-
-static int vhffsfs_listxattr(const char *path, char *list, size_t size)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = llistxattr(rpath, list, size);
- free(rpath);
-
- if(res == -1) return -errno;
- return res;
-}
-
-
-static int vhffsfs_removexattr(const char *path, const char *name)
-{
- int res;
- char *rpath;
-
- rpath = vhffsfs_realpath(path, NULL, NULL);
- if(!rpath) return -ENOENT;
-
- res = lremovexattr(rpath, name);
- free(rpath);
-
- if(res == -1) return -errno;
- return 0;
-}
-#endif /* HAVE_SETXATTR */
-
-
-static struct fuse_operations vhffsfs_oper = {
- .init = vhffsfs_init,
- .getattr = vhffsfs_getattr,
- .fgetattr = vhffsfs_fgetattr,
- .access = vhffsfs_access,
- .readlink = vhffsfs_readlink,
- .opendir = vhffsfs_opendir,
- .readdir = vhffsfs_readdir,
- .releasedir = vhffsfs_releasedir,
- .mknod = vhffsfs_mknod,
- .mkdir = vhffsfs_mkdir,
- .symlink = vhffsfs_symlink,
- .unlink = vhffsfs_unlink,
- .rmdir = vhffsfs_rmdir,
- .rename = vhffsfs_rename,
- .link = vhffsfs_link,
- .chmod = vhffsfs_chmod,
- .chown = vhffsfs_chown,
- .truncate = vhffsfs_truncate,
- .ftruncate = vhffsfs_ftruncate,
- .utime = vhffsfs_utime,
- .create = vhffsfs_create,
- .open = vhffsfs_open,
- .read = vhffsfs_read,
- .write = vhffsfs_write,
- .statfs = vhffsfs_statfs,
- .release = vhffsfs_release,
- .fsync = vhffsfs_fsync,
-#ifdef HAVE_SETXATTR
- .setxattr = vhffsfs_setxattr,
- .getxattr = vhffsfs_getxattr,
- .listxattr = vhffsfs_listxattr,
- .removexattr = vhffsfs_removexattr,
-#endif
-};
-
-int vhffsfs_readconfig(char *conffile) {
-
- FILE *conf;
- char line[128];
-
- conf = fopen(conffile, "r");
- if(!conf) return -1;
-
- while( fgets(line, 128, conf) ) {
- line[strlen(line)-1] = '\0';
- if(!strncmp("grouppath ", line, 10)) {
- vhffsfs.grouppath = strdup(line+10);
- }
- else if(!strncmp("webspath ", line, 9)) {
- vhffsfs.webspath = strdup(line+9);
- }
- else if(!strncmp("repositoriespath ", line, 17)) {
- vhffsfs.repositoriespath = strdup(line+17);
- }
- else if(!strncmp("dbhost ", line, 7)) {
- vhffsfs.dbhost = strdup(line+7);
- }
- else if(!strncmp("dbport ", line, 7)) {
- vhffsfs.dbport = atoi(line+7);
- }
- else if(!strncmp("dbuser ", line, 7)) {
- vhffsfs.dbuser = strdup(line+7);
- }
- else if(!strncmp("dbpass ", line, 7)) {
- vhffsfs.dbpass = strdup(line+7);
- }
- else if(!strncmp("dbname ", line, 7)) {
- vhffsfs.dbname = strdup(line+7);
- }
- else if(!strncmp("dbtimeout ", line, 10)) {
- vhffsfs.dbtimeout = atoi(line+10);
- }
- else if(!strncmp("minimumrightfile ", line, 17)) {
- vhffsfs.minimumrightfile = strtoul(line+17, NULL, 8);
- }
- else if(!strncmp("minimumrightdir ", line, 16)) {
- vhffsfs.minimumrightdir = strtoul(line+16, NULL, 8);
- }
- }
-
- fclose(conf);
- return 0;
-}
-
-int main(int argc, char *argv[])
-{
- int i, res;
- struct stat st;
-
- // create empty directory
- stat(VHFFSFS_EMPTYDIR, &st);
- if(!S_ISDIR(st.st_mode)) {
- res = mkdir(VHFFSFS_EMPTYDIR, 0700);
- if(res) {
- printf("Unable to create empty directory: '%s': %s\n", VHFFSFS_EMPTYDIR, strerror(errno));
- exit(1);
- }
- }
-
- // init vhffsfs struct
- for(i = 0 ; i < VHFFSFS_MAXCONNDB ; i++) {
- vhffsfs.pg_conn[i] = NULL;
- pthread_mutex_init(&vhffsfs.pg_lock[i], NULL);
- }
- vhffsfs.grouppath = "/data/groups";
- vhffsfs.webspath = "/data/web";
- vhffsfs.repositoriespath = "/data/repository";
- vhffsfs.dbhost = "127.0.0.1";
- vhffsfs.dbport = 5432;
- vhffsfs.dbuser = "vhffs";
- vhffsfs.dbpass = "pass";
- vhffsfs.dbname = "vhffs";
- vhffsfs.dbtimeout = 30;
-// vhffsfs.defaultrightfile = 00664;
-// vhffsfs.defaultrightdir = 02775;
- vhffsfs.minimumrightfile = 00400;
- vhffsfs.minimumrightdir = 02700;
-#ifdef WITH_CACHE
- vhffsfs.cachequeries = g_hash_table_new(g_str_hash, g_str_equal);
- vhffsfs.cachekeys = g_ptr_array_sized_new(4096);
- pthread_mutex_init(&vhffsfs.cachelock, NULL);
- vhffsfs.cachethreadstarted = 0;
-#endif
-
- vhffsfs_readconfig(VHFFSFS_CONFIG);
-
- // generate dbconninfo
- vhffsfs.dbconninfo = malloc(256);
- snprintf(vhffsfs.dbconninfo, 256, "host='%s' port='%d' user='%s' password='%s' dbname='%s' connect_timeout='%d'", vhffsfs.dbhost, vhffsfs.dbport, vhffsfs.dbuser, vhffsfs.dbpass, vhffsfs.dbname, vhffsfs.dbtimeout);
- vhffsfs.dbconninfo = realloc(vhffsfs.dbconninfo, strlen(vhffsfs.dbconninfo)+1);
-
- umask(0);
- return fuse_main(argc, argv, &vhffsfs_oper);
-}
Deleted: trunk/vhffs-tools/src/vhffsfs.conf
===================================================================
--- trunk/vhffs-tools/src/vhffsfs.conf 2007-07-07 02:11:55 UTC (rev 680)
+++ trunk/vhffs-tools/src/vhffsfs.conf 2007-07-07 15:01:51 UTC (rev 681)
@@ -1,11 +0,0 @@
-grouppath /data/groups
-webspath /data/web
-repositoriespath /data/repository
-dbhost 127.0.0.1
-dbport 5432
-dbuser vhffs
-dbpass mypass
-dbname vhffs
-dbtimeout 10
-minimumrightfile 00400
-minimumrightdir 02700
Deleted: trunk/vhffs-tools/src/vhffsfs_compil.sh
===================================================================
--- trunk/vhffs-tools/src/vhffsfs_compil.sh 2007-07-07 02:11:55 UTC (rev 680)
+++ trunk/vhffs-tools/src/vhffsfs_compil.sh 2007-07-07 15:01:51 UTC (rev 681)
@@ -1 +0,0 @@
-gcc -I/usr/include/fuse `pkg-config --cflags glib-2.0` -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DFUSE_USE_VERSION=25 -Wall -O2 -lfuse -lpthread -lpq `pkg-config --libs glib-2.0` vhffsfs.c md5c.c -o vhffsfs
Deleted: trunk/vhffs-tools/src/vhffsfs_run.sh
===================================================================
--- trunk/vhffs-tools/src/vhffsfs_run.sh 2007-07-07 02:11:55 UTC (rev 680)
+++ trunk/vhffs-tools/src/vhffsfs_run.sh 2007-07-07 15:01:51 UTC (rev 681)
@@ -1 +0,0 @@
-./vhffsfs -o allow_other,default_permissions,kernel_cache /mnt/fuse/