source: TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_rm.c @ 987

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

Closer inspection of the bbftp code reveals I'll need to refactor the
authz interface slightly. bbftpd_private_authz has been renamed
bbftpd_private_authz_control with a slightly different prototype.
This function now doesn't authorise store/retrieve requests.

Line 
1/*
2 * bbftpd/bbftpd_rm.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
37#include <bbftpd.h>
38#include <common.h>
39#include <daemon.h>
40#include <daemon_proto.h>
41#include <netinet/in.h>
42#include <structures.h>
43
44extern int transferoption ;
45extern  int     recvcontrolto ;
46
47int bbftpd_rm(int sock,int msglen) 
48{
49    char    *buffer ;
50    char    *logmessage ;
51    struct  mess_dir *msg_file ;
52    char    *filename ;
53    int     recursif ;
54    int     retcode ;
55
56    if ( (buffer = (char *) malloc (msglen+1) ) == NULL ) {
57        syslog(BBFTPD_ERR,"Unable to malloc space for file name (%d)",msglen) ;
58        reply(MSG_BAD,"Unable to malloc space for file name") ;
59        return 0 ;
60    }
61    if ( (logmessage = (char *) malloc (msglen+1024) ) == NULL ) {
62        syslog(BBFTPD_ERR,"Unable to malloc space for logmessage ") ;
63        reply(MSG_BAD,"Unable to malloc space for logmessage") ;
64        FREE(buffer) ;
65        return 0 ;
66    }
67    /*
68    ** Read the characteristics of the file
69    */
70    if ( readmessage(sock,buffer,msglen,recvcontrolto) < 0 ) {
71        /*
72        ** Error ...
73        */
74        syslog(BBFTPD_ERR,"Error reading file name") ;
75        FREE(buffer) ;
76        FREE(logmessage) ;
77        return -1 ;
78    }
79    buffer[msglen] = '\0' ;
80    msg_file = (struct mess_dir *) buffer ;
81#ifdef NDG_AUTH
82    if (bbftpd_private_authz_control(MSG_RM, msg_file->transferoption, msg_file->dirname,
83                                     logmessage) != 0) {
84      syslog(BBFTPD_ERR, logmessage);
85      reply(MSG_BAD, logmessage);
86      FREE(buffer);
87      FREE(logmessage);
88      return 0;
89    }
90#endif // NDG_AUTH
91
92    transferoption  = msg_file->transferoption ;
93    filename = msg_file->dirname ;
94    /*
95        if ( (transferoption & TROPT_DIR ) == TROPT_DIR ) {
96        recursif = 1 ;
97    } else {
98        recursif = 0 ;
99    }*/
100    if ( (retcode = bbftpd_storeunlink(filename)) < 0 ) {
101        sprintf(logmessage,"Unable to delete %s",filename) ;
102        reply(MSG_BAD_NO_RETRY,logmessage) ;
103        FREE(buffer) ;
104        FREE(logmessage) ;
105        return 0 ;
106    } else {
107        sprintf(logmessage,"%s has been deleted",filename) ;
108        reply(MSG_OK,logmessage) ;
109        FREE(buffer) ;
110        FREE(logmessage) ;
111        return 0 ;
112    }
113}
Note: See TracBrowser for help on using the repository browser.