]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/netncp/ncp_conn.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / netncp / ncp_conn.h
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$
33  */
34 #ifndef _NETNCP_NCP_CONN_H_
35 #define _NETNCP_NCP_CONN_H_
36
37 #ifndef _NETINET_IN_H_
38 #include <netinet/in.h>
39 #endif
40
41 #ifndef _NETIPX_IPX_H_
42 #include <netipx/ipx.h>
43 #endif
44
45 #ifndef _SYS_SOCKET_H_
46 #include <sys/socket.h>
47 #endif
48
49 /* type of transport we use */
50 /*#define       NCP_ON_IPX      0
51 #define NCP_ON_TCP      1*/
52
53 /* flags field in conn structure */
54 #define NCPFL_SOCONN            0x0001  /* socket layer is up */
55 #define NCPFL_ATTACHED          0x0002  /* ncp layer is up */
56 #define NCPFL_LOGGED            0x0004  /* logged in to server */
57 #define NCPFL_INVALID           0x0008  /* last request was not completed */
58 #define NCPFL_INTR              0x0010  /* interrupted call */
59 #define NCPFL_RESTORING         0x0020  /* trying to reconnect */
60 #define NCPFL_PERMANENT         0x0040  /* no way to kill conn, when this set */
61 #define NCPFL_PRIMARY           0x0080  /* have meaning only for owner */
62 #define NCPFL_WASATTACHED       0x0100  /* there was at least one successfull connect */
63 #define NCPFL_WASLOGGED         0x0200  /* there was at least one successfull login */
64 #define NCPFL_SIGNACTIVE        0x1000  /* packet signing active */
65 #define NCPFL_SIGNWANTED        0x2000  /* signing should start */
66
67 /* access mode for connection */
68 #define NCPM_READ               0400    /* able to fetch conn params */
69 #define NCPM_WRITE              0200    /* modify/close */
70 #define NCPM_EXECUTE            0100    /* run requests */
71
72 #define NCP_DEFAULT_OWNER       ((uid_t)-1)
73 #define NCP_DEFAULT_GROUP       ((uid_t)-1)
74
75
76 /* args used to create connection */
77 #define ncp_conn_loginfo        ncp_conn_args
78 struct ncp_conn_args {
79         int             opt;
80 #define NCP_OPT_WDOG            1       /* need watch dog socket */
81 #define NCP_OPT_MSG             2       /* need message socket */
82 #define NCP_OPT_SIGN            4       /* signatures wanted */
83 #define NCP_OPT_BIND            8       /* force bindery login */
84 #define NCP_OPT_PERMANENT       0x10    /* only for refernce, completly ignored */
85 #define NCP_OPT_NOUPCASEPASS    0x20    /* leave password as is */
86         int             sig_level;      /* wanted signature level */
87         char            server[NCP_BINDERY_NAME_LEN+1];
88         char            *user;
89         char            *password;
90         u_int32_t       objtype;
91         union {
92                 struct sockaddr addr;
93                 struct sockaddr_ipx ipxaddr;
94                 struct sockaddr_in inaddr;
95         } addr;
96         int             timeout;        /* ncp rq timeout */
97         int             retry_count;    /* counts to give an error */
98         uid_t           owner;          /* proposed owner of connection */
99         gid_t           group;          /* proposed group of connection */
100         mode_t          access_mode;    /* R/W - can do rq's, X - can see the conn */
101 };
102
103 #define ipxaddr         addr.ipxaddr
104 #define inaddr          addr.inaddr
105 #define saddr           addr.addr
106
107 /* user side structure to issue ncp calls */
108 struct ncp_buf {
109         int     rqsize;                 /* request size without ncp header */
110         int     rpsize;                 /* reply size minus ncp header */
111         int     cc;                     /* completion code */
112         int     cs;                     /* connection state */
113         char    packet[NCP_MAX_PACKET_SIZE];/* Here we prepare requests and receive replies */
114 };
115
116 /*
117  * Connection status, returned via sysctl(vfs.nwfs.connstat)
118  */
119 struct ncp_conn_stat {
120         struct ncp_conn_args li;
121         int             connRef;
122         int             ref_cnt;
123         int             connid;
124         int             buffer_size;
125         int             flags;
126         int             sign_active;
127         uid_t           owner;
128         gid_t           group;
129         char            user[NCP_MAXUSERNAMELEN+1];
130 };
131
132 #ifdef _KERNEL
133
134 #ifndef LK_SHARED
135 #include <sys/lock.h>
136 #include <sys/lockmgr.h>
137 #endif
138
139 struct socket;
140 struct u_cred;
141
142 SLIST_HEAD(ncp_conn_head,ncp_conn);
143
144 struct ncp_rq;
145 struct ncp_conn;
146
147 /*
148  * External and internal processes can reference connection only by handle.
149  * This gives us a freedom in maintance of underlying connections.
150  */
151 struct ncp_handle {
152         SLIST_ENTRY(ncp_handle) nh_next;
153         int             nh_id;          /* handle id */
154         struct ncp_conn*nh_conn;        /* which conn we are refernce */
155         struct thread * nh_td;          /* who owns the handle  */
156         int             nh_ref;         /* one process can asquire many handles, but we return the one */
157 };
158
159 /* 
160  * Describes any connection to server 
161  */
162 struct ncp_conn {
163         SLIST_ENTRY(ncp_conn) nc_next;
164         struct ncp_conn_args li;
165         struct ucred    *nc_owner;
166         gid_t           nc_group;
167         int             flags;
168         int             nc_id;
169         struct socket   *ncp_so;
170         struct socket   *wdg_so;
171         struct socket   *msg_so;
172         struct socket   *bc_so;
173         int             ref_cnt;                /* how many handles leased */
174         SLIST_HEAD(ncp_ref_hd,ncp_ref) ref_list;/* list of handles */
175         struct lock     nc_lock;                /* excl locks */
176         int             nc_lwant;               /* number of wanted locks */
177         struct thread   *td;                    /* pid currently operates */
178         struct ucred    *ucred;                 /* usr currently operates */
179         /* Fields used to process ncp requests */
180         int             connid;                 /* assigned by server */
181         u_int8_t        seq;
182         int             buffer_size;            /* Negotiated bufsize */
183         /* Fields used to make packet signatures */
184         u_int32_t       sign_root[2];
185         u_int32_t       sign_state[4];          /* md4 state */
186 #ifdef NCPBURST
187         /* Fields used for packet bursting */
188         u_long          bc_pktseq;              /* raw packet sequence */
189         u_short         bc_seq;                 /* burst sequence */
190         u_long          bc_locid;               /* local connection id */
191         u_long          bc_remid;               /* remote connection id */
192         u_long          bc_pktsize;             /* negotiated burst packet size */
193 #endif
194 };
195
196 int  ncp_conn_init(void);
197 int  ncp_conn_destroy(void);
198 int  ncp_conn_alloc(struct ncp_conn_args *cap,
199         struct thread *td, struct ucred *cred, struct ncp_conn **connid);
200 int  ncp_conn_free(struct ncp_conn *conn);
201 int  ncp_conn_access(struct ncp_conn *conn,struct ucred *cred,mode_t mode);
202 int  ncp_conn_lock(struct ncp_conn *conn,struct thread *td, struct ucred *cred,int mode);
203 void ncp_conn_unlock(struct ncp_conn *conn,struct thread *td);
204 int  ncp_conn_assert_locked(struct ncp_conn *conn,const char *checker,struct thread *td);
205 void ncp_conn_invalidate(struct ncp_conn *ncp);
206 int  ncp_conn_invalid(struct ncp_conn *ncp);
207 /*int  ncp_conn_ref(struct ncp_conn *conn, pid_t pid);
208 int  ncp_conn_rm_ref(struct ncp_conn *conn, pid_t pid, int force);
209 void ncp_conn_list_rm_ref(pid_t pid);*/
210 int  ncp_conn_getbyref(int connRef,struct thread *td, struct ucred *cred, int mode,
211         struct ncp_conn **connpp);
212 int  ncp_conn_getbyli(struct ncp_conn_loginfo *li,struct thread *td, struct ucred *cred, 
213         int mode, struct ncp_conn **connpp);
214 int  ncp_conn_setprimary(struct ncp_conn *conn, int on);
215 int  ncp_conn_locklist(int flags, struct thread *td);
216 void ncp_conn_unlocklist(struct thread *td);
217 int  ncp_conn_gethandle(struct ncp_conn *conn, struct thread *td, struct ncp_handle **handle);
218 int  ncp_conn_puthandle(struct ncp_handle *handle, struct thread *td, int force);
219 int  ncp_conn_findhandle(int connHandle, struct thread *td, struct ncp_handle **handle);
220 int  ncp_conn_getattached(struct ncp_conn_args *li,struct thread *td, struct ucred *cred,int mode, struct ncp_conn **connpp);
221 int  ncp_conn_putprochandles(struct thread *td);
222 int  ncp_conn_getinfo(struct ncp_conn *ncp, struct ncp_conn_stat *ncs);
223
224 int  ncp_conn_reconnect(struct ncp_conn *ncp);
225 int  ncp_conn_login(struct ncp_conn *conn, struct thread *td, struct ucred *cred);
226
227 extern struct ncp_conn_head conn_list;
228 extern int ncp_burst_enabled;
229
230 #ifdef MALLOC_DECLARE
231 MALLOC_DECLARE(M_NCPDATA);
232 #endif
233
234 #endif /* _KERNEL */
235 #endif /* _NCP_CONN_H_ */