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

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

Added the autorisation hook bbftpd_private_authz. It appears to be called
correctly for a dir command.

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 <syslog.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        syslog(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        syslog(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        syslog(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(MSG_DF, (void *)msg_file, logmessage) != 0) {
110      syslog(BBFTPD_ERR, logmessage);
111      reply(MSG_BAD, logmessage);
112      FREE(buffer);
113      FREE(logmessage);
114      return 0;
115    }
116#endif // NDG_AUTH
117    transferoption  = msg_file->transferoption ;
118    dirname = msg_file->dirname ;
119   
120    if ( (transferoption & TROPT_RFIO) == TROPT_RFIO ) {
121#if defined(WITH_RFIO) || defined(WITH_RFIO64)
122        sprintf(logmessage,"df is not supported by RFIO") ;
123#else
124        sprintf(logmessage,"RFIO is not supported by the server") ;
125#endif
126        reply(MSG_BAD_NO_RETRY,logmessage) ;
127        FREE(buffer) ;
128        FREE(logmessage) ;
129        return 0 ;
130    }
131
132#ifdef HAVE_STATVFS64
133    if (statvfs64(dirname,&statfsbuf) < 0) {
134#elif defined(HAVE_STATVFS)
135    if (statvfs(dirname,&statfsbuf) < 0) {
136#elif _SX
137    if (statfs(dirname,&statfsbuf, statlen, fstyp) < 0) {
138#else
139    if (statfs(dirname,&statfsbuf) < 0) {
140#endif
141        sprintf(logmessage,"Unable to df %s: %s",dirname,strerror(errno)) ;
142        reply(MSG_BAD_NO_RETRY,logmessage) ;
143        FREE(buffer) ;
144        FREE(logmessage) ;
145        return 0 ;
146    } else {
147#ifdef HAVE_STATVFS64
148        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) ;
149#elif defined(HAVE_STATVFS)
150        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) ;
151#elif _SX
152        sprintf(logmessage,"%ld %ld %ld %ld %ld %ld", statfsbuf.f_blocks, statfsbuf.f_bfree, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree, 0) ;
153#else
154#ifdef DARWIN
155                sprintf(logmessage,"%ld %ld %ld %ld", statfsbuf.f_blocks, statfsbuf.f_bsize, statfsbuf.f_files, statfsbuf.f_ffree) ;
156#else
157        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) ;
158#endif
159#endif
160        reply(MSG_OK,logmessage) ;
161        FREE(buffer) ;
162        FREE(logmessage) ;
163        return 0 ;
164    }
165#else
166    reply(MSG_BAD_NO_RETRY,"operation not supported by the server") ;
167    return 0 ;
168#endif
169}
Note: See TracBrowser for help on using the repository browser.