Add missing return
[dragonfly.git] / lib / libncp / ncpl_misc.c
blob869fab356317ca8acd95a39aff9b001f68e3f969
1 /*
2 * Copyright (c) 1999, Boris Popov
3 * All rights reserved.
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.
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.
32 * $FreeBSD: src/lib/libncp/ncpl_misc.c,v 1.3 1999/10/31 03:39:03 bp Exp $
33 * $DragonFly: src/lib/libncp/ncpl_misc.c,v 1.2 2003/06/17 04:26:50 dillon Exp $
35 * calls that don't fit to any other category
38 #include <sys/types.h>
39 #include <sys/time.h>
40 #include <errno.h>
41 #include <stdio.h>
42 #include <strings.h>
44 #include <netncp/ncp_lib.h>
46 static time_t
47 ncp_nw_to_ctime(struct nw_time_buffer *source) {
48 struct tm u_time;
50 bzero(&u_time,sizeof(struct tm));
52 * XXX: NW 4.x tracks daylight automatically
54 u_time.tm_isdst = -1;
55 u_time.tm_sec = source->second;
56 u_time.tm_min = source->minute;
57 u_time.tm_hour = source->hour;
58 u_time.tm_mday = source->day;
59 u_time.tm_mon = source->month - 1;
60 u_time.tm_year = source->year;
62 if (u_time.tm_year < 80) {
63 u_time.tm_year += 100;
65 return mktime(&u_time);
68 int
69 ncp_get_file_server_information(NWCONN_HANDLE connid,
70 struct ncp_file_server_info *target)
72 int error;
73 DECLARE_RQ;
75 ncp_init_request_s(conn, 17);
76 if ((error = ncp_request(connid, 23, conn)) != 0)
77 return error;
78 memcpy(target, ncp_reply_data(conn, 0), sizeof(*target));
79 target->MaximumServiceConnections
80 = htons(target->MaximumServiceConnections);
81 target->ConnectionsInUse
82 = htons(target->ConnectionsInUse);
83 target->MaxConnectionsEverUsed
84 = htons(target->MaxConnectionsEverUsed);
85 target->NumberMountedVolumes
86 = htons(target->NumberMountedVolumes);
87 return 0;
90 int
91 ncp_get_stations_logged_info(NWCONN_HANDLE connid, u_int32_t connection,
92 struct ncp_bindery_object *target, time_t *login_time)
94 int error;
95 DECLARE_RQ;
97 ncp_init_request_s(conn, 28);
98 ncp_add_dword_lh(conn, connection);
100 if ((error = ncp_request(connid, 23, conn)) != 0)
101 return error;
102 bzero(target, sizeof(*target));
103 target->object_id = ncp_reply_dword_hl(conn, 0);
104 target->object_type = ncp_reply_word_hl(conn, 4);
105 memcpy(target->object_name, ncp_reply_data(conn, 6),
106 sizeof(target->object_name));
107 *login_time = ncp_nw_to_ctime((struct nw_time_buffer *)ncp_reply_data(conn, 54));
108 return 0;
112 ncp_get_internet_address(NWCONN_HANDLE connid, u_int32_t connection,
113 struct ipx_addr *target, u_int8_t * conn_type)
115 int error;
116 DECLARE_RQ;
118 ncp_init_request_s(conn, 26);
119 ncp_add_dword_lh(conn, connection);
120 error = ncp_request(connid, 23, conn);
121 if (error) return error;
122 bzero(target, sizeof(*target));
123 ipx_netlong(*target) = ncp_reply_dword_lh(conn, 0);
124 memcpy(&(target->x_host), ncp_reply_data(conn, 4), 6);
125 target->x_port = ncp_reply_word_lh(conn, 10);
126 *conn_type = ncp_reply_byte(conn, 12);
127 return 0;
130 NWCCODE
131 NWGetObjectConnectionNumbers(NWCONN_HANDLE connHandle,
132 pnstr8 pObjName, nuint16 objType,
133 pnuint16 pNumConns, pnuint16 pConnHandleList,
134 nuint16 maxConns)
136 int error, i, n;
137 nuint32 lastconn;
138 DECLARE_RQ;
140 lastconn = 0;
141 ncp_init_request_s(conn, 27);
142 ncp_add_dword_lh(conn, lastconn);
143 ncp_add_word_hl(conn, objType);
144 ncp_add_pstring(conn, pObjName);
145 if ((error = ncp_request(connHandle, 23, conn)) != 0) return error;
146 n = min(ncp_reply_byte(conn, 0), maxConns);
147 *pNumConns = n;
148 for (i = 0; i < n ; i++) {
149 *pConnHandleList++ = ncp_reply_dword_lh(conn, i * 4 + 1);
151 return 0;
154 void
155 NWUnpackDateTime(nuint32 dateTime, NW_DATE *sDate, NW_TIME *sTime) {
156 NWUnpackDate(dateTime >> 16, sDate);
157 NWUnpackTime(dateTime & 0xffff, sTime);
160 void
161 NWUnpackDate(nuint16 date, NW_DATE *sDate) {
162 sDate->day = date & 0x1f;
163 sDate->month = (date >> 5) & 0xf;
164 sDate->year = ((date >> 9) & 0x7f) + 1980;
167 void
168 NWUnpackTime(nuint16 time, NW_TIME *sTime) {
169 sTime->seconds = time & 0x1f;
170 sTime->minutes = (time >> 5) & 0x3f;
171 sTime->hours = (time >> 11) & 0x1f;
174 nuint32
175 NWPackDateTime(NW_DATE *sDate, NW_TIME *sTime) {
176 return 0;
179 nuint16
180 NWPackDate(NW_DATE *sDate) {
181 return 0;
184 nuint16
185 NWPackTime(NW_TIME *sTime) {
186 return 0;
189 time_t
190 ncp_UnpackDateTime(nuint32 dateTime) {
191 struct tm u_time;
192 NW_DATE d;
193 NW_TIME t;
195 NWUnpackDateTime(dateTime, &d, &t);
196 bzero(&u_time,sizeof(struct tm));
197 u_time.tm_isdst = -1;
198 u_time.tm_sec = t.seconds;
199 u_time.tm_min = t.minutes;
200 u_time.tm_hour = t.hours;
201 u_time.tm_mday = d.day;
202 u_time.tm_mon = d.month - 1;
203 u_time.tm_year = d.year - 1900;
205 return mktime(&u_time);
209 ncp_GetFileServerDateAndTime(NWCONN_HANDLE cH, time_t *target) {
210 int error;
211 DECLARE_RQ;
213 ncp_init_request(conn);
214 if ((error = ncp_request(cH, 20, conn)) != 0)
215 return error;
216 *target = ncp_nw_to_ctime((struct nw_time_buffer *) ncp_reply_data(conn, 0));
217 return 0;
221 ncp_SetFileServerDateAndTime(NWCONN_HANDLE cH, time_t * source) {
222 int year;
223 struct tm *utime = localtime(source);
224 DECLARE_RQ;
226 year = utime->tm_year;
227 if (year > 99) {
228 year -= 100;
230 ncp_init_request_s(conn, 202);
231 ncp_add_byte(conn, year);
232 ncp_add_byte(conn, utime->tm_mon + 1);
233 ncp_add_byte(conn, utime->tm_mday);
234 ncp_add_byte(conn, utime->tm_hour);
235 ncp_add_byte(conn, utime->tm_min);
236 ncp_add_byte(conn, utime->tm_sec);
237 return ncp_request(cH, 23, conn);
240 NWCCODE
241 NWDownFileServer(NWCONN_HANDLE cH, int force) {
242 DECLARE_RQ;
244 ncp_init_request_s(conn, 211);
245 ncp_add_byte(conn, force ? 0 : 0xff);
246 return ncp_request(cH, 23, conn);
249 NWCCODE
250 NWCloseBindery(NWCONN_HANDLE cH) {
251 DECLARE_RQ;
253 ncp_init_request_s(conn, 68);
254 return ncp_request(cH, 23, conn);
257 NWCCODE
258 NWOpenBindery(NWCONN_HANDLE cH) {
259 DECLARE_RQ;
261 ncp_init_request_s(conn, 69);
262 return ncp_request(cH, 23, conn);
265 NWCCODE
266 NWDisableTTS(NWCONN_HANDLE cH) {
267 DECLARE_RQ;
269 ncp_init_request_s(conn, 207);
270 return ncp_request(cH, 23, conn);
273 NWCCODE
274 NWEnableTTS(NWCONN_HANDLE cH) {
275 DECLARE_RQ;
277 ncp_init_request_s(conn, 208);
278 return ncp_request(cH, 23, conn);
281 NWCCODE
282 NWDisableFileServerLogin(NWCONN_HANDLE cH) {
283 DECLARE_RQ;
285 ncp_init_request_s(conn, 203);
286 return ncp_request(cH, 23, conn);
289 NWCCODE
290 NWEnableFileServerLogin(NWCONN_HANDLE cH) {
291 DECLARE_RQ;
293 ncp_init_request_s(conn, 204);
294 return ncp_request(cH, 23, conn);