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