1999-10-02 04:06:24 +00:00
|
|
|
/*
|
2001-03-10 05:24:45 +00:00
|
|
|
* Copyright (c) 1999, 2000, 2001 Boris Popov
|
1999-10-02 04:06:24 +00:00
|
|
|
* 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.
|
|
|
|
* 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. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Boris Popov.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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$
|
|
|
|
*/
|
1999-12-12 05:50:07 +00:00
|
|
|
#ifndef _NETNCP_NCP_RQ_H_
|
|
|
|
#define _NETNCP_NCP_RQ_H_
|
1999-10-02 04:06:24 +00:00
|
|
|
|
|
|
|
#include <machine/endian.h>
|
|
|
|
|
|
|
|
#define getb(buf,ofs) (((const u_int8_t *)(buf))[ofs])
|
|
|
|
#define setb(buf,ofs,val) (((u_int8_t*)(buf))[ofs])=val
|
|
|
|
#define getbw(buf,ofs) ((u_int16_t)(getb(buf,ofs)))
|
|
|
|
|
|
|
|
#if (BYTE_ORDER == LITTLE_ENDIAN)
|
|
|
|
|
|
|
|
#define getwle(buf,ofs) (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))
|
|
|
|
#define getdle(buf,ofs) (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))
|
|
|
|
#define getwbe(buf,ofs) (ntohs(getwle(buf,ofs)))
|
|
|
|
#define getdbe(buf,ofs) (ntohl(getdle(buf,ofs)))
|
|
|
|
|
|
|
|
#define setwle(buf,ofs,val) getwle(buf,ofs)=val
|
|
|
|
#define setwbe(buf,ofs,val) getwle(buf,ofs)=htons(val)
|
|
|
|
#define setdle(buf,ofs,val) getdle(buf,ofs)=val
|
|
|
|
#define setdbe(buf,ofs,val) getdle(buf,ofs)=htonl(val)
|
|
|
|
|
|
|
|
#define htoles(x) ((u_int16_t)(x))
|
|
|
|
#define letohs(x) ((u_int16_t)(x))
|
|
|
|
#define htolel(x) ((u_int32_t)(x))
|
|
|
|
#define letohl(x) ((u_int32_t)(x))
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "Macros for Big-Endians are incomplete"
|
|
|
|
#define getwle(buf,ofs) ((u_int16_t)(getb(buf, ofs) | (getb(buf, ofs + 1) << 8)))
|
|
|
|
#define getdle(buf,ofs) ((u_int32_t)(getb(buf, ofs) | \
|
|
|
|
(getb(buf, ofs + 1) << 8) | \
|
|
|
|
(getb(buf, ofs + 2) << 16) | \
|
|
|
|
(getb(buf, ofs + 3) << 24)))
|
|
|
|
#define getwbe(buf,ofs) (*((u_int16_t*)(&((u_int8_t*)(buf))[ofs])))
|
|
|
|
#define getdbe(buf,ofs) (*((u_int32_t*)(&((u_int8_t*)(buf))[ofs])))
|
|
|
|
/*
|
|
|
|
#define setwle(buf,ofs,val) getwle(buf,ofs)=val
|
|
|
|
#define setdle(buf,ofs,val) getdle(buf,ofs)=val
|
|
|
|
*/
|
|
|
|
#define setwbe(buf,ofs,val) getwle(buf,ofs)=val
|
|
|
|
#define setdbe(buf,ofs,val) getdle(buf,ofs)=val
|
|
|
|
/*
|
|
|
|
#define htoles(x) ((u_int16_t)(x))
|
|
|
|
#define letohs(x) ((u_int16_t)(x))
|
|
|
|
#define htolel(x) ((u_int32_t)(x))
|
|
|
|
#define letohl(x) ((u_int32_t)(x))
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-12-29 04:46:21 +00:00
|
|
|
#ifdef _KERNEL
|
2001-03-10 05:24:45 +00:00
|
|
|
|
|
|
|
#include <sys/mchain.h>
|
|
|
|
|
|
|
|
#define NCPR_ALLOCED 0x0001 /* request structure was allocated */
|
|
|
|
#define NCPR_DONTFREEONERR 0x0002 /* do not free structure on error */
|
|
|
|
|
1999-10-02 04:06:24 +00:00
|
|
|
/*
|
|
|
|
* Structure to prepare ncp request and receive reply
|
|
|
|
*/
|
|
|
|
struct ncp_rq {
|
2001-03-10 05:24:45 +00:00
|
|
|
int nr_flags;
|
|
|
|
struct mbchain rq;
|
|
|
|
struct mdchain rp;
|
|
|
|
int nr_minrplen; /* minimal rp size (-1 if not known) */
|
|
|
|
int nr_rpsize; /* reply size minus ncp header */
|
|
|
|
int nr_cc; /* completion code */
|
|
|
|
int nr_cs; /* connection state */
|
|
|
|
struct proc * nr_p; /* proc that did rq */
|
|
|
|
struct ucred * nr_cred; /* user that did rq */
|
1999-10-02 04:06:24 +00:00
|
|
|
int rexmit;
|
2001-03-10 05:24:45 +00:00
|
|
|
struct ncp_conn*nr_conn; /* back link */
|
1999-10-02 04:06:24 +00:00
|
|
|
};
|
|
|
|
|
2001-03-10 05:24:45 +00:00
|
|
|
int ncp_rq_alloc(u_int8_t fn, struct ncp_conn *ncp, struct proc *p,
|
|
|
|
struct ucred *cred, struct ncp_rq **rqpp);
|
|
|
|
int ncp_rq_alloc_any(u_int32_t ptype, u_int8_t fn, struct ncp_conn *ncp,
|
|
|
|
struct proc *p, struct ucred *cred, struct ncp_rq **rqpp);
|
|
|
|
int ncp_rq_alloc_subfn(u_int8_t fn, u_int8_t subfn, struct ncp_conn *ncp,
|
|
|
|
struct proc *p, struct ucred *cred, struct ncp_rq **rqpp);
|
|
|
|
int ncp_rq_init_any(struct ncp_rq *rqp, u_int32_t ptype, u_int8_t fn,
|
|
|
|
struct ncp_conn *ncp,
|
|
|
|
struct proc *p, struct ucred *cred);
|
|
|
|
void ncp_rq_done(struct ncp_rq *rqp);
|
|
|
|
int ncp_request(struct ncp_rq *rqp);
|
|
|
|
int ncp_request_int(struct ncp_rq *rqp);
|
|
|
|
|
|
|
|
struct ncp_nlstables;
|
|
|
|
|
|
|
|
int ncp_rq_pathstring(struct ncp_rq *rqp, int size, const char *name, struct ncp_nlstables*);
|
|
|
|
int ncp_rq_dbase_path(struct ncp_rq *, u_int8_t vol_num,
|
1999-10-02 04:06:24 +00:00
|
|
|
u_int32_t dir_base, int namelen, u_char *name, struct ncp_nlstables *nt);
|
2001-03-10 05:24:45 +00:00
|
|
|
int ncp_rq_pstring(struct ncp_rq *rqp, const char *s);
|
|
|
|
|
1999-10-02 04:06:24 +00:00
|
|
|
void ncp_sign_init(const char *logindata, char *sign_root);
|
|
|
|
|
1999-12-29 04:46:21 +00:00
|
|
|
#else /* ifdef _KERNEL */
|
1999-10-02 04:06:24 +00:00
|
|
|
|
|
|
|
#define DECLARE_RQ struct ncp_buf conn1, *conn=&conn1
|
|
|
|
|
|
|
|
#define ncp_add_byte(conn,x) (conn)->packet[(conn)->rqsize++]=x
|
|
|
|
|
2000-01-14 19:54:42 +00:00
|
|
|
struct ncp_buf;
|
|
|
|
|
1999-12-12 05:50:07 +00:00
|
|
|
__BEGIN_DECLS
|
|
|
|
|
|
|
|
void ncp_init_request(struct ncp_buf *);
|
|
|
|
void ncp_init_request_s(struct ncp_buf *, int);
|
|
|
|
void ncp_add_word_lh(struct ncp_buf *, u_int16_t);
|
|
|
|
void ncp_add_dword_lh(struct ncp_buf *, u_int32_t);
|
|
|
|
void ncp_add_word_hl(struct ncp_buf *, u_int16_t);
|
|
|
|
void ncp_add_dword_hl(struct ncp_buf *, u_int32_t);
|
|
|
|
void ncp_add_mem(struct ncp_buf *, const void *, int);
|
|
|
|
void ncp_add_mem_nls(struct ncp_buf *, const void *, int);
|
|
|
|
void ncp_add_pstring(struct ncp_buf *, const char *);
|
|
|
|
void ncp_add_handle_path(struct ncp_buf *, nuint32, nuint32, int, const char *);
|
1999-10-02 04:06:24 +00:00
|
|
|
|
|
|
|
#define ncp_reply_data(conn,offset) ((conn)->packet+offset)
|
|
|
|
#define ncp_reply_byte(conn,offset) (*(u_int8_t*)(ncp_reply_data(conn, offset)))
|
|
|
|
|
1999-12-12 05:50:07 +00:00
|
|
|
u_int16_t ncp_reply_word_hl(struct ncp_buf *, int);
|
|
|
|
u_int16_t ncp_reply_word_lh(struct ncp_buf *, int);
|
|
|
|
u_int32_t ncp_reply_dword_hl(struct ncp_buf *, int);
|
|
|
|
u_int32_t ncp_reply_dword_lh(struct ncp_buf *, int);
|
1999-10-02 04:06:24 +00:00
|
|
|
|
|
|
|
static __inline void
|
|
|
|
ConvertToNWfromDWORD(u_int32_t sfd, ncp_fh *fh) {
|
|
|
|
fh->val1 = (fh->val.val32 = sfd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-12 05:50:07 +00:00
|
|
|
__END_DECLS
|
|
|
|
|
1999-12-29 04:46:21 +00:00
|
|
|
#endif /* ifdef _KERNEL */
|
1999-10-02 04:06:24 +00:00
|
|
|
|
1999-12-12 05:50:07 +00:00
|
|
|
#endif /* !_NETNCP_NCP_RQ_H_ */
|