Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / netproto / ncp / ncp_conn.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1999, Boris Popov
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: src/sys/netncp/ncp_conn.h,v 1.3 1999/12/29 04:46:15 peter Exp $
33 */
34#ifndef _NETNCP_NCP_CONN_H_
35#define _NETNCP_NCP_CONN_H_
36
37#ifdef INET
38#ifndef _NETINET_IN_H_
39#include <netinet/in.h>
40#endif
41#endif
42
43#ifdef IPX
44#ifndef _NETIPX_IPX_H_
45#include <netipx/ipx.h>
46#endif
47#endif
48
49#ifndef _SYS_SOCKET_H_
50#include <sys/socket.h>
51#endif
52
53/* type of transport we use */
54/*#define NCP_ON_IPX 0
55#define NCP_ON_TCP 1*/
56
57/* flags field in conn structure */
58#define NCPFL_SOCONN 0x01 /* socket layer is up */
59#define NCPFL_ATTACHED 0x02 /* ncp layer is up */
60#define NCPFL_LOGGED 0x04 /* logged in to server */
61#define NCPFL_INVALID 0x08 /* last request was not completed */
62#define NCPFL_INTR 0x10 /* interrupted call */
63#define NCPFL_RESTORING 0x20 /* trying to reconnect */
64#define NCPFL_PERMANENT 0x40 /* no way to kill conn, when this set */
65#define NCPFL_PRIMARY 0x80 /* have meaning only for owner */
66#define NCPFL_SIGNACTIVE 0x1000 /* packet signing active */
67#define NCPFL_SIGNWANTED 0x2000 /* signing should start */
68
69/* access mode for connection */
70#define NCPM_READ 0400 /* able to fetch conn params */
71#define NCPM_WRITE 0200 /* modify/close */
72#define NCPM_EXECUTE 0100 /* run requests */
73
74#define NCP_DEFAULT_OWNER ((uid_t)-1)
75#define NCP_DEFAULT_GROUP ((uid_t)-1)
76
77
78/* args used to create connection */
79#define ncp_conn_loginfo ncp_conn_args
80struct ncp_conn_args {
81 int opt;
82#define NCP_OPT_WDOG 1 /* need watch dog socket */
83#define NCP_OPT_MSG 2 /* need message socket */
84#define NCP_OPT_SIGN 4 /* signatures wanted */
85#define NCP_OPT_BIND 8 /* force bindery login */
86#define NCP_OPT_PERMANENT 0x10 /* only for refernce, completly ignored */
87#define NCP_OPT_NOUPCASEPASS 0x20 /* leave password as is */
88 int sig_level; /* wanted signature level */
89 char server[NCP_BINDERY_NAME_LEN+1];
90 char *user;
91 char *password;
92 u_int32_t objtype;
93 union {
94 struct sockaddr addr;
95#ifdef IPX
96 struct sockaddr_ipx ipxaddr;
97#endif
98#ifdef INET
99 struct sockaddr_in inaddr;
100#endif
101 } addr;
102 int timeout; /* ncp rq timeout */
103 int retry_count; /* counts to give an error */
104 uid_t owner; /* proposed owner of connection */
105 gid_t group; /* proposed group of connection */
106 mode_t access_mode; /* R/W - can do rq's, X - can see the conn */
107};
108
109#define ipxaddr addr.ipxaddr
110#define inaddr addr.inaddr
111#define saddr addr.addr
112
113/* user side structure to issue ncp calls */
114struct ncp_buf {
115 int rqsize; /* request size without ncp header */
116 int rpsize; /* reply size minus ncp header */
117 int cc; /* completion code */
118 int cs; /* connection state */
119 char packet[NCP_MAX_PACKET_SIZE];/* Here we prepare requests and receive replies */
120};
121
122/*
123 * Connection status, returned via sysctl(vfs.nwfs.connstat)
124 */
125struct ncp_conn_stat {
126 struct ncp_conn_args li;
127 int connRef;
128 int ref_cnt;
129 int connid;
130 int buffer_size;
131 int flags;
132 int sign_active;
133 uid_t owner;
134 gid_t group;
135 char user[NCP_MAXUSERNAMELEN+1];
136};
137
138#ifdef _KERNEL
139
140#ifndef LK_SHARED
141#include <sys/lock.h>
142#endif
143
144struct socket;
145struct u_cred;
146
147SLIST_HEAD(ncp_conn_head,ncp_conn);
148
149struct ncp_rq;
150struct ncp_conn;
151
152/*
153 * External and internal processes can reference connection only by handle.
154 * This gives us a freedom in maintance of underlying connections.
155 */
156struct ncp_handle {
157 SLIST_ENTRY(ncp_handle) nh_next;
158 int nh_id; /* handle id */
159 struct ncp_conn*nh_conn; /* which conn we are refernce */
160 struct proc * nh_proc; /* who owns the handle */
161 int nh_ref; /* one process can asquire many handles, but we return the one */
162};
163
164/*
165 * Describes any connection to server
166 */
167struct ncp_conn {
168 SLIST_ENTRY(ncp_conn) nc_next;
169 struct ncp_conn_args li;
170 struct ucred *nc_owner;
171 gid_t nc_group;
172 int flags;
173 int nc_id;
174 struct socket *ncp_so;
175 struct socket *wdg_so;
176 struct socket *msg_so;
177 struct socket *bc_so;
178 int ref_cnt; /* how many handles leased */
179 SLIST_HEAD(ncp_ref_hd,ncp_ref) ref_list;/* list of handles */
180 struct lock nc_lock; /* excl locks */
181 int nc_lwant; /* number of wanted locks */
182 struct proc *procp; /* pid currently operates */
183 struct ucred *ucred; /* usr currently operates */
184 struct ncp_rq *nc_rq; /* current request */
185 /* Fields used to process ncp requests */
186 int connid; /* assigned by server */
187 u_int8_t seq;
188 int buffer_size; /* Negotiated bufsize */
189 /* Fields used to make packet signatures */
190 u_int32_t sign_root[2];
191 u_int32_t sign_state[4]; /* md4 state */
192#ifdef NCPBURST
193 /* Fields used for packet bursting */
194 u_long bc_pktseq; /* raw packet sequence */
195 u_short bc_seq; /* burst sequence */
196 u_long bc_locid; /* local connection id */
197 u_long bc_remid; /* remote connection id */
198 u_long bc_pktsize; /* negotiated burst packet size */
199#endif
200};
201
202#define ncp_conn_signwanted(conn) ((conn)->flags & NCPFL_SIGNWANTED)
203#define ncp_conn_valid(conn) ((conn->flags & NCPFL_INVALID) == 0)
204#define ncp_conn_invalidate(conn) {conn->flags |= NCPFL_INVALID;}
205
206int ncp_conn_init(void);
207int ncp_conn_alloc(struct proc *p,struct ucred *cred, struct ncp_conn **connid);
208int ncp_conn_free(struct ncp_conn *conn);
209int ncp_conn_access(struct ncp_conn *conn,struct ucred *cred,mode_t mode);
210int ncp_conn_lock(struct ncp_conn *conn,struct proc *p,struct ucred *cred,int mode);
211void ncp_conn_unlock(struct ncp_conn *conn,struct proc *p);
212int ncp_conn_assert_locked(struct ncp_conn *conn,char *checker,struct proc *p);
213/*int ncp_conn_ref(struct ncp_conn *conn, pid_t pid);
214int ncp_conn_rm_ref(struct ncp_conn *conn, pid_t pid, int force);
215void ncp_conn_list_rm_ref(pid_t pid);*/
216int ncp_conn_getbyref(int connRef,struct proc *p,struct ucred *cred, int mode,
217 struct ncp_conn **connpp);
218int ncp_conn_getbyli(struct ncp_conn_loginfo *li,struct proc *p,struct ucred *cred,
219 int mode, struct ncp_conn **connpp);
220int ncp_conn_setprimary(struct ncp_conn *conn, int on);
221int ncp_conn_locklist(int flags, struct proc *p);
222void ncp_conn_unlocklist(struct proc *p);
223int ncp_conn_gethandle(struct ncp_conn *conn, struct proc *p, struct ncp_handle **handle);
224int ncp_conn_puthandle(struct ncp_handle *handle, struct proc *p, int force);
225int ncp_conn_findhandle(int connHandle, struct proc *p, struct ncp_handle **handle);
226int ncp_conn_getattached(struct ncp_conn_args *li,struct proc *p,struct ucred *cred,int mode, struct ncp_conn **connpp);
227int ncp_conn_putprochandles(struct proc *p);
228int ncp_conn_getinfo(struct ncp_conn *ncp, struct ncp_conn_stat *ncs);
229
230extern struct ncp_conn_head conn_list;
231extern int ncp_burst_enabled;
232
233#ifdef MALLOC_DECLARE
234MALLOC_DECLARE(M_NCPDATA);
235#endif
236
237#endif /* _KERNEL */
238#endif /* _NCP_CONN_H_ */