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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_stat.c@983
Revision 983, 5.9 KB checked in by spascoe, 13 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_stat.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
32
33#include <stdio.h>
34#include <syslog.h>
35#include <utime.h>
36#if TIME_WITH_SYS_TIME
37# include <sys/time.h>
38# include <time.h>
39#else
40# if HAVE_SYS_TIME_H
41#  include <sys/time.h>
42# else
43#  include <time.h>
44# endif
45#endif
46#include <netinet/in.h>
47#include <sys/types.h>
48#include <sys/stat.h>
49#include <unistd.h>
50#include <bbftpd.h>
51#include <common.h>
52#include <daemon.h>
53#include <daemon_proto.h>
54#include <structures.h>
55
56extern int transferoption ;
57extern  int     recvcontrolto ;
58
59int bbftpd_stat(int sock,int msglen) 
60{
61    char    *buffer ;
62    char    *logmessage ;
63    struct  mess_dir *msg_file ;
64    char    *filename ;
65    int     recursif ;
66    int     retcode ;
67
68#ifdef STANDART_FILE_CALL
69    struct stat statbuf;
70    struct stat rfstatbuf;
71#else
72    struct stat64 statbuf ;
73# ifdef WITH_RFIO64
74    struct stat64 rfstatbuf ;
75# else
76    struct stat rfstatbuf;
77# endif
78#endif
79
80    if ( (buffer = (char *) malloc (msglen+1) ) == NULL ) {
81        syslog(BBFTPD_ERR,"Unable to malloc space for file name (%d)",msglen) ;
82        reply(MSG_BAD,"Unable to malloc space for file name") ;
83        return 0 ;
84    }
85    if ( (logmessage = (char *) malloc (msglen+1024) ) == NULL ) {
86        syslog(BBFTPD_ERR,"Unable to malloc space for logmessage ") ;
87        reply(MSG_BAD,"Unable to malloc space for logmessage") ;
88        FREE(buffer) ;
89        return 0 ;
90    }
91    /*
92    ** Read the characteristics of the file
93    */
94    if ( readmessage(sock,buffer,msglen,recvcontrolto) < 0 ) {
95        /*
96        ** Error ...
97        */
98        syslog(BBFTPD_ERR,"Error reading file name") ;
99        FREE(buffer) ;
100        FREE(logmessage) ;
101        return -1 ;
102    }
103    buffer[msglen] = '\0' ;
104    msg_file = (struct mess_dir *) buffer ;
105#ifdef NDG_AUTH
106    if (bbftpd_private_authz(MSG_STAT, (void *)msg_file, logmessage) != 0) {
107      syslog(BBFTPD_ERR, logmessage);
108      reply(MSG_BAD, logmessage);
109      FREE(buffer);
110      FREE(logmessage);
111      return 0;
112    }
113#endif // NDG_AUTH
114
115    transferoption  = msg_file->transferoption ;
116    filename = msg_file->dirname ;
117   
118    if ( (transferoption & TROPT_RFIO) == TROPT_RFIO ) {
119#if defined(WITH_RFIO) || defined(WITH_RFIO64)
120        sprintf(logmessage,"Unable to stat %s",filename) ;
121# ifdef WITH_RFIO64
122        retcode = rfio_stat64(filename,&rfstatbuf);
123# else
124        retcode = rfio_stat(filename,&rfstatbuf);
125# endif
126#else
127        retcode = -1;
128        sprintf(logmessage,"RFIO is not supported by the server") ;
129#endif
130    } else {
131        sprintf(logmessage,"Unable to stat %s",filename) ;
132#ifdef STANDART_FILE_CALL
133        retcode = stat(filename,&statbuf);
134#else
135        retcode = stat64(filename,&statbuf);
136#endif
137    }     
138    if (retcode < 0) {
139        reply(MSG_BAD_NO_RETRY,logmessage) ;
140        FREE(buffer) ;
141        FREE(logmessage) ;
142        return 0 ;
143    } else {
144      char *at, *mt, *ct;
145      if ( (transferoption & TROPT_RFIO) == TROPT_RFIO ) {
146        at = strdup(ctime(&rfstatbuf.st_atime));
147        at[strlen(at)-1]='\0';
148        mt = strdup(ctime(&rfstatbuf.st_mtime));
149        mt[strlen(mt)-1]='\0';
150        ct = strdup(ctime(&rfstatbuf.st_ctime));
151        ct[strlen(ct)-1]='\0';
152
153#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
154# define RF_ST_BLKSIZE_FORMAT "d"
155#else
156# define RF_ST_BLKSIZE_FORMAT "s"
157#endif
158
159#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
160# define RF_ST_BLOCKS_FORMAT LONG_LONG_FORMAT
161#else
162# define RF_ST_BLOCKS_FORMAT "s"
163#endif
164
165        sprintf(logmessage,"%" LONG_LONG_FORMAT " %#08o %" LONG_LONG_FORMAT " %" RF_ST_BLKSIZE_FORMAT " %" RF_ST_BLOCKS_FORMAT "  %d %d (%s) (%s) (%s)",
166                        (long long)rfstatbuf.st_ino, 
167                        rfstatbuf.st_mode,
168                        (long long)rfstatbuf.st_size, 
169#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
170                        rfstatbuf.st_blksize, 
171#else
172                        "N/A",
173#endif
174#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
175                        (long long)rfstatbuf.st_blocks, 
176#else
177                        "N/A",
178#endif
179                        rfstatbuf.st_uid, 
180                        rfstatbuf.st_gid, 
181                        at, 
182                        mt, 
183                        ct) ;
184      } else {
185        at = strdup(ctime(&statbuf.st_atime));
186        at[strlen(at)-1]='\0';
187        mt = strdup(ctime(&statbuf.st_mtime));
188        mt[strlen(mt)-1]='\0';
189        ct = strdup(ctime(&statbuf.st_ctime));
190        ct[strlen(ct)-1]='\0';
191
192#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
193# define ST_BLKSIZE_FORMAT "d"
194#else
195# define ST_BLKSIZE_FORMAT "s"
196#endif
197
198#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
199# define ST_BLOCKS_FORMAT LONG_LONG_FORMAT
200#else
201# define ST_BLOCKS_FORMAT "s"
202#endif
203
204        sprintf(logmessage,"%" LONG_LONG_FORMAT " %#08o %" LONG_LONG_FORMAT " %" ST_BLKSIZE_FORMAT " %" ST_BLOCKS_FORMAT "  %d %d (%s) (%s) (%s)",
205                        (long long)statbuf.st_ino, 
206                        statbuf.st_mode, 
207                        (long long)statbuf.st_size, 
208#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
209                        statbuf.st_blksize, 
210#else
211                        "N/A",
212#endif
213#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
214                        (long long)statbuf.st_blocks, 
215#else
216                        "N/A",
217#endif
218                        statbuf.st_uid, 
219                        statbuf.st_gid, 
220                        at, 
221                        mt, 
222                        ct) ;
223      }
224      reply(MSG_OK,logmessage) ;
225      FREE(buffer) ;
226      FREE(logmessage) ;
227      FREE(at) ;
228      FREE(mt) ;
229      FREE(ct) ;
230      return 0 ;
231    }
232}
Note: See TracBrowser for help on using the repository browser.