source: TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_statfs.c @ 1328

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_statfs.c@1328
Revision 1328, 5.4 KB checked in by spascoe, 13 years ago (diff)

I've created a bbftpd log facility to replace syslog.
At present it allows you to log messages to a file in addition
to syslog. This should help testing on other machines.

Line 
1/*
2 * bbftpd/bbftpd_statfs.c
3 * Copyright (C) 1999, 2000, 2001, 2002 IN2P3, CNRS
4 * bbftp@in2p3.fr
5 * http://doc.in2p3.fr/bbftp
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */ 
21
22/****************************************************************************
23
24 
25 RETURN:
26        0  Keep the connection open (does not mean that the file has been
27           successfully created)
28        -1 Tell the calling program to close the connection
29 
30 *****************************************************************************/
31#include <bbftpd.h>
32#ifdef DARWIN
33#define HAVE_STRUCT_STATFS 1
34#endif
35
36#include <stdio.h>
37#include <bbftpd_log.h>
38#include <utime.h>
39#include <errno.h>
40#ifdef HAVE_SYS_STATVFS_H
41# include <sys/types.h>
42# include <sys/statvfs.h>
43#elif defined(HAVE_SYS_VFS_H)
44# include <sys/vfs.h>
45#endif
46#ifdef DARWIN
47#include <sys/mount.h>
48#endif
49
50#if HAVE_STRING_H
51# include <string.h>
52#endif
53#include <netinet/in.h>
54#include <common.h>
55#include <daemon.h>
56#include <daemon_proto.h>
57#include <structures.h>
58
59extern int transferoption ;
60extern  int     recvcontrolto ;
61
62int bbftpd_statfs(int sock,int msglen) 
63{
64#if defined(HAVE_STATVFS64) || defined(HAVE_STATVFS) || defined(HAVE_STATFS)
65    char    *buffer ;
66    char    *logmessage ;
67    struct  mess_dir *msg_file ;
68    char    *dirname ;
69    int     recursif ;
70    int     retcode ;
71
72# ifdef HAVE_STRUCT_STATVFS64
73    struct statvfs64 statfsbuf;
74# elif defined(HAVE_STRUCT_STATVFS)
75    struct statvfs statfsbuf;
76# elif defined(HAVE_STRUCT_STATFS)
77    struct statfs statfsbuf;
78# endif
79#ifdef _SX
80    int statlen, fstyp=0;
81# endif
82
83    if ( (buffer = (char *) malloc (msglen+1) ) == NULL ) {
84        bbftpd_log(BBFTPD_ERR,"Unable to malloc space for dir name (%d)",msglen) ;
85        reply(MSG_BAD,"Unable to malloc space for file name") ;
86        return 0 ;
87    }
88    if ( (logmessage = (char *) malloc (msglen+1024) ) == NULL ) {
89        bbftpd_log(BBFTPD_ERR,"Unable to malloc space for logmessage ") ;
90        reply(MSG_BAD,"Unable to malloc space for logmessage") ;
91        FREE(buffer) ;
92        return 0 ;
93    }
94    /*
95    ** Read the characteristics of the file
96    */
97    if ( readmessage(sock,buffer,msglen,recvcontrolto) < 0 ) {
98        /*
99        ** Error ...
100        */
101        bbftpd_log(BBFTPD_ERR,"Error reading dir name") ;
102        FREE(buffer) ;
103        FREE(logmessage) ;
104        return -1 ;
105    }
106    buffer[msglen] = '\0' ;
107    msg_file = (struct mess_dir *) buffer ;
108#ifdef NDG_AUTH
109    if (bbftpd_private_authz_control(MSG_DF, msg_file->transferoption, msg_file->dirname,
110                                     logmessage) != 0) {
111      bbftpd_log(BBFTPD_ERR, logmessage);
112      reply(MSG_BAD, logmessage);
113      FREE(buffer);
114      FREE(logmessage);
115      return 0;
116    }
117#endif // NDG_AUTH
118    transferoption  = msg_file->transferoption ;
119    dirname = msg_file->dirname ;
120   
121    if ( (transferoption & TROPT_RFIO) == TROPT_RFIO ) {
122#if defined(WITH_RFIO) || defined(WITH_RFIO64)
123        sprintf(logmessage,"df is not supported by RFIO") ;
124#else
125        sprintf(logmessage,"RFIO is not supported by the server") ;
126#endif
127        reply(MSG_BAD_NO_RETRY,logmessage) ;
128        FREE(buffer) ;
129        FREE(logmessage) ;
130        return 0 ;
131    }
132
133#ifdef HAVE_STATVFS64
134    if (statvfs64(dirname,&statfsbuf) < 0) {
135#elif defined(HAVE_STATVFS)
136    if (statvfs(dirname,&statfsbuf) < 0) {
137#elif _SX
138    if (statfs(dirname,&statfsbuf, statlen, fstyp) < 0) {
139#else
140    if (statfs(dirname,&statfsbuf) < 0) {
141#endif
142        sprintf(logmessage,"Unable to df %s: %s",dirname,strerror(errno)) ;
143        reply(MSG_BAD_NO_RETRY,logmessage) ;
144        FREE(buffer) ;
145        FREE(logmessage) ;
146        return 0 ;
147    } else {
148#ifdef HAVE_STATVFS64
149        sprintf(logmessage,"%" LONG_LONG_FORMAT " %" LONG_LONG_FORMAT " %lu %" LONG_LONG_FORMAT " %" LONG_LONG_FORMAT " %lu", statfsbuf.f_blocks, statfsbuf.f_bavail, statfsbuf.f_frsize, statfsbuf.f_files, statfsbuf.f_ffree, statfsbuf.f_namemax) ;
150#elif defined(HAVE_STATVFS)
151        sprintf(logmessage,"%ld %ld %lu %ld %ld %lu", statfsbuf.f_blocks, statfsbuf.f_bavail, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree, statfsbuf.f_namemax) ;
152#elif _SX
153        sprintf(logmessage,"%ld %ld %ld %ld %ld %ld", statfsbuf.f_blocks, statfsbuf.f_bfree, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree, 0) ;
154#else
155#ifdef DARWIN
156                sprintf(logmessage,"%ld %ld %ld %ld", statfsbuf.f_blocks, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree) ;
157#else
158        sprintf(logmessage,"%ld %ld %ld %ld %ld %ld", statfsbuf.f_blocks, statfsbuf.f_b_avail, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree, statfsbuf.f_namelen) ;
159#endif
160#endif
161        reply(MSG_OK,logmessage) ;
162        FREE(buffer) ;
163        FREE(logmessage) ;
164        return 0 ;
165    }
166#else
167    reply(MSG_BAD_NO_RETRY,"operation not supported by the server") ;
168    return 0 ;
169#endif
170}
Note: See TracBrowser for help on using the repository browser.