0920b4f20b
This utility uses FreeBSD's libfetch (updated for NetBSD, and to quieten lint) to provide a BSD-licensed ftp/http/https file system similar to the old alex utility. The full URL is used as the path underneath the "/ian" mountpoint. Sample use as follows: [19:09:38] agc@inspiron1300 ...examples/refuse/ian 126 > priv ian/obj/ian /ian [19:09:55] agc@inspiron1300 ...examples/refuse/ian 127 > cat /ian/ftp://localhost/motd NetBSD 4.99.27 (INSPIRON) #4: Tue Aug 7 13:04:33 BST 2007 Welcome to NetBSD! This system is running a development snapshot of the NetBSD operating system, also known as NetBSD-current. It is highly possible for it to contain serious bugs, regressions, broken features or other problems. Please bear this in mind and use the system with care. You are encouraged to test this version as thoroughly as possible. Should you encounter any problem, please report it back to the development team using the send-pr(1) utility (requires a working MTA). If yours is not properly set up, use the web interface at: http://www.netbsd.org/support/send-pr.html Thank you for helping us test and improve NetBSD. [19:10:17] agc@inspiron1300 ...examples/refuse/ian 128 > df Filesystem 1K-blocks Used Avail %Cap Mounted on /dev/dk0 28101396 19491972 7204356 73% / kernfs 1 1 0 100% /kern procfs 4 4 0 100% /proc ptyfs 1 1 0 100% /dev/pts /dev/puffs 0 0 0 100% /ian [19:10:21] agc@inspiron1300 ...examples/refuse/ian 129 > ls -al /ian/ftp://localhost/motd -rw------- 1 root wheel 705 Aug 28 19:10 /ian/ftp://localhost/motd [19:10:42] agc@inspiron1300 ...examples/refuse/ian 130 > ls -al ~ftp/motd -rw-r--r-- 1 ftp ftp 705 Aug 27 21:33 /home/ftp/motd [19:10:53] agc@inspiron1300 ...examples/refuse/ian 131 >
125 lines
4.3 KiB
C
125 lines
4.3 KiB
C
/*-
|
|
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer
|
|
* in this position and unchanged.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
* $FreeBSD: src/lib/libfetch/common.h,v 1.27.6.1 2006/11/11 00:16:07 des Exp $
|
|
*/
|
|
|
|
#ifndef _COMMON_H_INCLUDED
|
|
#define _COMMON_H_INCLUDED
|
|
|
|
#define FTP_DEFAULT_PORT 21
|
|
#define HTTP_DEFAULT_PORT 80
|
|
#define FTP_DEFAULT_PROXY_PORT 21
|
|
#define HTTP_DEFAULT_PROXY_PORT 3128
|
|
|
|
#ifdef WITH_SSL
|
|
#include <openssl/crypto.h>
|
|
#include <openssl/x509.h>
|
|
#include <openssl/pem.h>
|
|
#include <openssl/ssl.h>
|
|
#include <openssl/err.h>
|
|
#endif
|
|
|
|
/* Connection */
|
|
typedef struct fetchconn conn_t;
|
|
struct fetchconn {
|
|
int sd; /* socket descriptor */
|
|
char *buf; /* buffer */
|
|
size_t bufsize; /* buffer size */
|
|
size_t buflen; /* length of buffer contents */
|
|
int err; /* last protocol reply code */
|
|
#ifdef WITH_SSL
|
|
SSL *ssl; /* SSL handle */
|
|
SSL_CTX *ssl_ctx; /* SSL context */
|
|
X509 *ssl_cert; /* server certificate */
|
|
SSL_METHOD *ssl_meth; /* SSL method */
|
|
#endif
|
|
int ref; /* reference count */
|
|
};
|
|
|
|
/* Structure used for error message lists */
|
|
struct fetcherr {
|
|
const int num;
|
|
const int cat;
|
|
const char *string;
|
|
};
|
|
|
|
/* for _fetch_writev */
|
|
struct iovec;
|
|
|
|
void _fetch_seterr(struct fetcherr *, int);
|
|
void _fetch_syserr(void);
|
|
void _fetch_info(const char *, ...);
|
|
int _fetch_default_port(const char *);
|
|
int _fetch_default_proxy_port(const char *);
|
|
int _fetch_bind(int, int, const char *);
|
|
conn_t *_fetch_connect(const char *, int, int, int);
|
|
conn_t *_fetch_reopen(int);
|
|
conn_t *_fetch_ref(conn_t *);
|
|
int _fetch_ssl(conn_t *, int);
|
|
ssize_t _fetch_read(conn_t *, char *, size_t);
|
|
int _fetch_getln(conn_t *);
|
|
ssize_t _fetch_write(conn_t *, const char *, size_t);
|
|
ssize_t _fetch_writev(conn_t *, struct iovec *, int);
|
|
int _fetch_putln(conn_t *, const char *, size_t);
|
|
int _fetch_close(conn_t *);
|
|
int _fetch_add_entry(struct url_ent **, int *, int *,
|
|
const char *, struct url_stat *);
|
|
int _fetch_netrc_auth(struct url *url);
|
|
|
|
#define _ftp_seterr(n) _fetch_seterr(_ftp_errlist, n)
|
|
#define _http_seterr(n) _fetch_seterr(_http_errlist, n)
|
|
#define _netdb_seterr(n) _fetch_seterr(_netdb_errlist, n)
|
|
#define _url_seterr(n) _fetch_seterr(_url_errlist, n)
|
|
|
|
#ifndef NDEBUG
|
|
#define DEBUG(x) do { if (fetchDebug) { x; } } while (/* CONSTCOND */ 0)
|
|
#else
|
|
#define DEBUG(x) do { } while (/* CONSTCOND */ 0)
|
|
#endif
|
|
|
|
/*
|
|
* I don't really like exporting _http_request() and _ftp_request(),
|
|
* but the HTTP and FTP code occasionally needs to cross-call
|
|
* eachother, and this saves me from adding a lot of special-case code
|
|
* to handle those cases.
|
|
*
|
|
* Note that _*_request() free purl, which is way ugly but saves us a
|
|
* whole lot of trouble.
|
|
*/
|
|
FILE *_http_request(struct url *, const char *,
|
|
struct url_stat *, struct url *, const char *);
|
|
FILE *_ftp_request(struct url *, const char *,
|
|
struct url_stat *, struct url *, const char *);
|
|
|
|
/*
|
|
* Check whether a particular flag is set
|
|
*/
|
|
#define CHECK_FLAG(x) (flags && strchr(flags, (x)))
|
|
|
|
#endif
|