]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libncp/ncpl_misc.c
This commit was generated by cvs2svn to compensate for changes in r164146,
[FreeBSD/FreeBSD.git] / lib / libncp / ncpl_misc.c
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  * calls that don't fit to any other category
33  */
34
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37
38 #include <sys/types.h>
39 #include <sys/time.h>
40 #include <arpa/inet.h>
41 #include <errno.h>
42 #include <stdio.h>
43 #include <string.h>
44 #include <strings.h>
45
46 #include <netncp/ncp_lib.h>
47
48 static time_t
49 ncp_nw_to_ctime(struct nw_time_buffer *source) {
50         struct tm u_time;
51
52         bzero(&u_time,sizeof(struct tm));
53         /*
54          * XXX: NW 4.x tracks daylight automatically
55          */
56         u_time.tm_isdst = -1;
57         u_time.tm_sec = source->second;
58         u_time.tm_min = source->minute;
59         u_time.tm_hour = source->hour;
60         u_time.tm_mday = source->day;
61         u_time.tm_mon = source->month - 1;
62         u_time.tm_year = source->year;
63
64         if (u_time.tm_year < 80) {
65                 u_time.tm_year += 100;
66         }
67         return mktime(&u_time);
68 }
69
70 int
71 ncp_get_file_server_information(NWCONN_HANDLE connid,
72         struct ncp_file_server_info *target)
73 {
74         int error;
75         DECLARE_RQ;
76
77         ncp_init_request_s(conn, 17);
78         if ((error = ncp_request(connid, 23, conn)) != 0) 
79                 return error;
80         memcpy(target, ncp_reply_data(conn, 0), sizeof(*target));
81         target->MaximumServiceConnections
82             = htons(target->MaximumServiceConnections);
83         target->ConnectionsInUse
84             = htons(target->ConnectionsInUse);
85         target->MaxConnectionsEverUsed
86             = htons(target->MaxConnectionsEverUsed);
87         target->NumberMountedVolumes
88             = htons(target->NumberMountedVolumes);
89         return 0;
90 }
91
92 int
93 ncp_get_stations_logged_info(NWCONN_HANDLE connid, u_int32_t connection,
94         struct ncp_bindery_object *target, time_t *login_time)
95 {
96         int error;
97         DECLARE_RQ;
98
99         ncp_init_request_s(conn, 28);
100         ncp_add_dword_lh(conn, connection);
101
102         if ((error = ncp_request(connid, 23, conn)) != 0)
103                 return error;
104         bzero(target, sizeof(*target));
105         target->object_id = ncp_reply_dword_hl(conn, 0);
106         target->object_type = ncp_reply_word_hl(conn, 4);
107         memcpy(target->object_name, ncp_reply_data(conn, 6),
108                sizeof(target->object_name));
109         *login_time = ncp_nw_to_ctime((struct nw_time_buffer *)ncp_reply_data(conn, 54));
110         return 0;
111 }
112
113 int
114 ncp_get_internet_address(NWCONN_HANDLE connid, u_int32_t connection,
115         struct ipx_addr *target, u_int8_t * conn_type)
116 {
117         int error;
118         DECLARE_RQ;
119
120         ncp_init_request_s(conn, 26);
121         ncp_add_dword_lh(conn, connection);
122         error = ncp_request(connid, 23, conn);
123         if (error) return error;
124         bzero(target, sizeof(*target));
125         ipx_netlong(*target) = ncp_reply_dword_lh(conn, 0);
126         memcpy(&(target->x_host), ncp_reply_data(conn, 4), 6);
127         target->x_port = ncp_reply_word_lh(conn, 10);
128         *conn_type = ncp_reply_byte(conn, 12);
129         return 0;
130 }
131
132 NWCCODE
133 NWGetObjectConnectionNumbers(NWCONN_HANDLE connHandle,
134                 pnstr8 pObjName, nuint16 objType,
135                 pnuint16 pNumConns, pnuint16 pConnHandleList,
136                 nuint16 maxConns) 
137 {
138         int error, i, n;
139         nuint32 lastconn;
140         DECLARE_RQ;
141
142         lastconn = 0;
143         ncp_init_request_s(conn, 27);
144         ncp_add_dword_lh(conn, lastconn);
145         ncp_add_word_hl(conn, objType);
146         ncp_add_pstring(conn, pObjName);
147         if ((error = ncp_request(connHandle, 23, conn)) != 0) return error;
148         n = min(ncp_reply_byte(conn, 0), maxConns);
149         *pNumConns = n;
150         for (i = 0; i < n ; i++) {
151                 *pConnHandleList++ = ncp_reply_dword_lh(conn, i * 4 + 1);
152         }
153         return 0;
154 }
155
156 void
157 NWUnpackDateTime(nuint32 dateTime, NW_DATE *sDate, NW_TIME *sTime) {
158         NWUnpackDate(dateTime >> 16, sDate);
159         NWUnpackTime(dateTime & 0xffff, sTime);
160 }
161
162 void
163 NWUnpackDate(nuint16 date, NW_DATE *sDate) {
164         sDate->day = date & 0x1f;
165         sDate->month = (date >> 5) & 0xf;
166         sDate->year = ((date >> 9) & 0x7f) + 1980;
167 }
168
169 void
170 NWUnpackTime(nuint16 time, NW_TIME *sTime) {
171         sTime->seconds = time & 0x1f;
172         sTime->minutes = (time >> 5) & 0x3f;
173         sTime->hours = (time >> 11) & 0x1f;
174 }
175
176 nuint32
177 NWPackDateTime(NW_DATE *sDate, NW_TIME *sTime) {
178         return 0;
179 }
180
181 nuint16
182 NWPackDate(NW_DATE *sDate) {
183         return 0;
184 }
185
186 nuint16
187 NWPackTime(NW_TIME *sTime) {
188         return 0;
189 }
190
191 time_t
192 ncp_UnpackDateTime(nuint32 dateTime) {
193         struct tm u_time;
194         NW_DATE d;
195         NW_TIME t;
196
197         NWUnpackDateTime(dateTime, &d, &t);
198         bzero(&u_time,sizeof(struct tm));
199         u_time.tm_isdst = -1;
200         u_time.tm_sec = t.seconds;
201         u_time.tm_min = t.minutes;
202         u_time.tm_hour = t.hours;
203         u_time.tm_mday = d.day;
204         u_time.tm_mon = d.month - 1;
205         u_time.tm_year = d.year - 1900;
206
207         return mktime(&u_time);
208 }
209
210 int
211 ncp_GetFileServerDateAndTime(NWCONN_HANDLE cH, time_t *target) {
212         int error;
213         DECLARE_RQ;
214
215         ncp_init_request(conn);
216         if ((error = ncp_request(cH, 20, conn)) != 0)
217                 return error;
218         *target = ncp_nw_to_ctime((struct nw_time_buffer *) ncp_reply_data(conn, 0));
219         return 0;
220 }
221
222 int
223 ncp_SetFileServerDateAndTime(NWCONN_HANDLE cH, time_t * source) {
224         int year;
225         struct tm *utime = localtime(source);
226         DECLARE_RQ;
227
228         year = utime->tm_year;
229         if (year > 99) {
230                 year -= 100;
231         }
232         ncp_init_request_s(conn, 202);
233         ncp_add_byte(conn, year);
234         ncp_add_byte(conn, utime->tm_mon + 1);
235         ncp_add_byte(conn, utime->tm_mday);
236         ncp_add_byte(conn, utime->tm_hour);
237         ncp_add_byte(conn, utime->tm_min);
238         ncp_add_byte(conn, utime->tm_sec);
239         return ncp_request(cH, 23, conn);
240 }
241
242 NWCCODE
243 NWDownFileServer(NWCONN_HANDLE cH, int force) {
244         DECLARE_RQ;
245
246         ncp_init_request_s(conn, 211);
247         ncp_add_byte(conn, force ? 0 : 0xff);
248         return ncp_request(cH, 23, conn);
249 }
250
251 NWCCODE
252 NWCloseBindery(NWCONN_HANDLE cH) {
253         DECLARE_RQ;
254
255         ncp_init_request_s(conn, 68);
256         return ncp_request(cH, 23, conn);
257 }
258
259 NWCCODE
260 NWOpenBindery(NWCONN_HANDLE cH) {
261         DECLARE_RQ;
262
263         ncp_init_request_s(conn, 69);
264         return ncp_request(cH, 23, conn);
265 }
266
267 NWCCODE
268 NWDisableTTS(NWCONN_HANDLE cH) {
269         DECLARE_RQ;
270
271         ncp_init_request_s(conn, 207);
272         return ncp_request(cH, 23, conn);
273 }
274
275 NWCCODE
276 NWEnableTTS(NWCONN_HANDLE cH) {
277         DECLARE_RQ;
278
279         ncp_init_request_s(conn, 208);
280         return ncp_request(cH, 23, conn);
281 }
282
283 NWCCODE
284 NWDisableFileServerLogin(NWCONN_HANDLE cH) {
285         DECLARE_RQ;
286
287         ncp_init_request_s(conn, 203);
288         return ncp_request(cH, 23, conn);
289 }
290
291 NWCCODE
292 NWEnableFileServerLogin(NWCONN_HANDLE cH) {
293         DECLARE_RQ;
294
295         ncp_init_request_s(conn, 204);
296         return ncp_request(cH, 23, conn);
297 }