source: TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/createadir.c @ 1395

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

Eliminated all "implicit declaration" warnings from "python setup.py
build"

Line 
1/*
2 * bbftpd/createadir.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 createadir.c v 1.8.5  2000/04/28   - Creation of the routine.
31              v 1.8.6  2000/04/04   - Add portage to OSF1
32                                    - Avoid buffer overflow
33              v 1.8.7  2000/05/24   - Correct portage to OSF1
34              v 1.8.10 2000/08/11   - Portage to Linux
35              v 1.9.0  2000/08/18   - Use configure to help portage
36              v 1.9.4  2000/10/16   - Supress %m
37                                    - Correct typo
38              v 2.0.1  2001/04/23   - Correct indentation
39              v 2.1.0  2001/05/30   - Correct bbftpd_log level
40                                     
41 *****************************************************************************/
42#include <bbftpd.h>
43
44#include <errno.h>
45#include <fcntl.h>
46#include <netinet/in.h>
47#include <stdio.h>
48#if HAVE_STRING_H
49# include <string.h>
50#endif
51#include <bbftpd_private_log.h>
52#include <sys/stat.h>
53#include <sys/types.h>
54#include <unistd.h>
55
56#include <bbftpd.h>
57#include <common.h>
58#include <daemon.h>
59#include <structures.h>
60#include <daemon_proto.h>
61
62extern int msgsock ;
63extern  int     recvcontrolto ;
64
65int createadir(int code, int msglen) {
66
67    char    receive_buffer[MAXMESSLEN] ;
68    int        savederrno ;
69    char    logmessage[256] ;
70
71#ifndef WORDS_BIGENDIAN
72    msglen = ntohl(msglen) ;
73#endif
74    if ( msglen > MAXMESSLEN ) {
75        /*
76        ** In order to avoid buffer overflow we reject message to
77        ** big
78        */
79        bbftpd_log(BBFTPD_ERR,"Message to big in createdir (%d,%d)",msglen,MAXMESSLEN) ;
80        reply(MSG_BAD_NO_RETRY,"Directory too long") ;
81        return -1 ;
82    }
83    /*
84    ** Read the characteristics of the directory
85    */
86    if ( readmessage(msgsock,receive_buffer,msglen,recvcontrolto) < 0 ) {
87        /*
88        ** Error ...
89        */
90        return -1 ;
91    }
92    /*
93    ** receive_buffer contains the directory to create
94    */
95    receive_buffer[msglen] = '\0' ;
96    if ( code == MSG_MKDIR ) {
97        bbftpd_log(BBFTPD_DEBUG,"Creating directory %s",receive_buffer) ;
98    }
99    /*
100    ** We create the directory
101    */
102    if ( mkdir(receive_buffer,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP) < 0 ) {
103        /*
104        ** Depending on errno we are going to tell the client to
105        ** retry or not
106        */
107        savederrno = errno ;
108        sprintf(logmessage,"Error creation directory %s : %s",receive_buffer,strerror(errno)) ;
109        bbftpd_log(BBFTPD_ERR,"Error creation directory %s : %s",receive_buffer,strerror(errno)) ;
110        /*
111        ** We tell the client not to retry in the following case (even in waiting
112        ** WAITRETRYTIME the problem will not be solved) :
113        **        EACCES        : Search permission denied
114        **        EDQUOT        : No more quota
115        **        ENOSPC        : No more space
116        **        ELOOP        : To many symbolic links on path
117        **        ENAMETOOLONG: Path argument too long
118        **        ENOTDIR        : A component in path is not a directory
119        **        EROFS        : The path prefix resides on a read-only file system.
120        **        ENOENT      : A component of the path prefix does not exist or is a null pathname.
121        **        EEXIST      : The named file already exists.
122        */
123        if ( savederrno == EACCES ||
124                savederrno == EDQUOT ||
125                savederrno == ENOSPC ||
126                savederrno == ELOOP ||
127                savederrno == ENAMETOOLONG ||
128                savederrno == ENOTDIR ||
129                savederrno == EROFS ||
130                savederrno == ENOENT ||
131                savederrno == EEXIST ) {
132            reply(MSG_BAD_NO_RETRY,logmessage) ;
133        } else {
134            reply(MSG_BAD,logmessage) ;
135        }
136        return 0 ;
137    }
138    reply(MSG_OK,"OK") ;
139    return 0 ;
140}
Note: See TracBrowser for help on using the repository browser.