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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_mkdir.c@983
Revision 983, 3.7 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_mkdir.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 directory has been
27           successfully created)
28        -1 Tell the calling program to close the connection
29 
30 bbftpd_mkdir.c v 2.0.0  2001/02/12 - Creation of the routine.
31                v 2.0.1  2001/04/23 - Correct indentation
32                                    - Port to IRIX
33                v 2.1.0  2001/06/01 - Reorganise routines as in bbftp_
34                                     
35 *****************************************************************************/
36
37
38#include <stdio.h>
39#include <syslog.h>
40#include <utime.h>
41
42
43#include <bbftpd.h>
44#include <common.h>
45#include <daemon.h>
46#include <daemon_proto.h>
47#include <netinet/in.h>
48#include <structures.h>
49
50extern int transferoption ;
51extern  int     recvcontrolto ;
52
53int bbftpd_mkdir(int sock,int msglen) 
54{
55    char    *buffer ;
56    char    *logmessage ;
57    struct  mess_dir *msg_dir ;
58    char    *dirname ;
59    int     recursif ;
60    int     retcode ;
61
62    if ( (buffer = (char *) malloc (msglen+1) ) == NULL ) {
63        syslog(BBFTPD_ERR,"Unable to malloc space for directory name (%d)",msglen) ;
64        reply(MSG_BAD,"Unable to malloc space for directory name") ;
65        return 0 ;
66    }
67    if ( (logmessage = (char *) malloc (msglen+1024) ) == NULL ) {
68        syslog(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 directory
75    */
76    if ( readmessage(sock,buffer,msglen,recvcontrolto) < 0 ) {
77        /*
78        ** Error ...
79        */
80        syslog(BBFTPD_ERR,"Error reading directory name") ;
81        FREE(buffer) ;
82        FREE(logmessage) ;
83        return -1 ;
84    }
85    buffer[msglen] = '\0' ;
86    msg_dir = (struct mess_dir *) buffer ;
87#ifdef NDG_AUTH
88    if (bbftpd_private_authz(MSG_MKDIR_V2, (void *)msg_dir, logmessage) != 0) {
89      syslog(BBFTPD_ERR, logmessage);
90      reply(MSG_BAD, logmessage);
91      FREE(buffer);
92      FREE(logmessage);
93      return 0;
94    }
95#endif // NDG_AUTH
96
97    transferoption  = msg_dir->transferoption ;
98    dirname = msg_dir->dirname ;
99    if ( (transferoption & TROPT_DIR ) == TROPT_DIR ) {
100        recursif = 1 ;
101    } else {
102        recursif = 0 ;
103    }
104    if ( (retcode = bbftpd_storemkdir(dirname,logmessage,recursif)) < 0 ) {
105        reply(MSG_BAD_NO_RETRY,logmessage) ;
106        FREE(buffer) ;
107        FREE(logmessage) ;
108        return 0 ;
109    } else if (retcode > 0 ) {
110        reply(MSG_BAD,logmessage) ;
111        FREE(buffer) ;
112        FREE(logmessage) ;
113        return 0 ;
114    } else {
115        sprintf(logmessage,"Directory %s created",dirname) ;
116        reply(MSG_OK,logmessage) ;
117        FREE(buffer) ;
118        FREE(logmessage) ;
119        return 0 ;
120    }
121}
Note: See TracBrowser for help on using the repository browser.