clnt_unix.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*
  2. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  3. * unrestricted use provided that this legend is included on all tape
  4. * media and as a part of the software program in whole or part. Users
  5. * may copy or modify Sun RPC without charge, but are not authorized
  6. * to license or distribute it to anyone else except as part of a product or
  7. * program developed by the user.
  8. *
  9. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12. *
  13. * Sun RPC is provided with no support and without any obligation on the
  14. * part of Sun Microsystems, Inc. to assist in its use, correction,
  15. * modification or enhancement.
  16. *
  17. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19. * OR ANY PART THEREOF.
  20. *
  21. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22. * or profits or other special, indirect and consequential damages, even if
  23. * Sun has been advised of the possibility of such damages.
  24. *
  25. * Sun Microsystems, Inc.
  26. * 2550 Garcia Avenue
  27. * Mountain View, California 94043
  28. */
  29. /*
  30. * clnt_unix.c, Implements a TCP/IP based, client side RPC.
  31. *
  32. * Copyright (C) 1984, Sun Microsystems, Inc.
  33. *
  34. * TCP based RPC supports 'batched calls'.
  35. * A sequence of calls may be batched-up in a send buffer. The rpc call
  36. * return immediately to the client even though the call was not necessarily
  37. * sent. The batching occurs if the results' xdr routine is NULL (0) AND
  38. * the rpc timeout value is zero (see clnt.h, rpc).
  39. *
  40. * Clients should NOT casually batch calls that in fact return results; that is,
  41. * the server side should be aware that a call is batched and not produce any
  42. * return message. Batched calls that produce many result messages can
  43. * deadlock (netlock) the client and the server....
  44. *
  45. * Now go hang yourself.
  46. */
  47. #define __FORCE_GLIBC
  48. #include <features.h>
  49. #include <netdb.h>
  50. #include <errno.h>
  51. #include <stdio.h>
  52. #include <unistd.h>
  53. #include <rpc/rpc.h>
  54. #include <sys/uio.h>
  55. #include <sys/poll.h>
  56. #include <sys/socket.h>
  57. #include <rpc/pmap_clnt.h>
  58. #ifdef USE_IN_LIBIO
  59. # include <wchar.h>
  60. libc_hidden_proto(fwprintf)
  61. #endif
  62. /* Experimentally off - libc_hidden_proto(strlen) */
  63. /* Experimentally off - libc_hidden_proto(memcpy) */
  64. libc_hidden_proto(socket)
  65. libc_hidden_proto(close)
  66. libc_hidden_proto(getpid)
  67. libc_hidden_proto(authnone_create)
  68. libc_hidden_proto(xdrrec_create)
  69. libc_hidden_proto(xdrrec_endofrecord)
  70. libc_hidden_proto(xdrrec_skiprecord)
  71. libc_hidden_proto(xdr_callhdr)
  72. libc_hidden_proto(xdr_replymsg)
  73. libc_hidden_proto(xdr_opaque_auth)
  74. libc_hidden_proto(xdrmem_create)
  75. libc_hidden_proto(xdr_void)
  76. libc_hidden_proto(getegid)
  77. libc_hidden_proto(geteuid)
  78. libc_hidden_proto(_seterr_reply)
  79. libc_hidden_proto(setsockopt)
  80. libc_hidden_proto(connect)
  81. libc_hidden_proto(recvmsg)
  82. libc_hidden_proto(sendmsg)
  83. libc_hidden_proto(poll)
  84. libc_hidden_proto(fputs)
  85. libc_hidden_proto(__rpc_thread_createerr)
  86. extern u_long _create_xid (void) attribute_hidden;
  87. #define MCALL_MSG_SIZE 24
  88. struct ct_data
  89. {
  90. int ct_sock;
  91. bool_t ct_closeit;
  92. struct timeval ct_wait;
  93. bool_t ct_waitset; /* wait set by clnt_control? */
  94. struct sockaddr_un ct_addr;
  95. struct rpc_err ct_error;
  96. char ct_mcall[MCALL_MSG_SIZE]; /* marshalled callmsg */
  97. u_int ct_mpos; /* pos after marshal */
  98. XDR ct_xdrs;
  99. };
  100. static int readunix (char *, char *, int);
  101. static int writeunix (char *, char *, int);
  102. static enum clnt_stat clntunix_call (CLIENT *, u_long, xdrproc_t, caddr_t,
  103. xdrproc_t, caddr_t, struct timeval);
  104. static void clntunix_abort (void);
  105. static void clntunix_geterr (CLIENT *, struct rpc_err *);
  106. static bool_t clntunix_freeres (CLIENT *, xdrproc_t, caddr_t);
  107. static bool_t clntunix_control (CLIENT *, int, char *);
  108. static void clntunix_destroy (CLIENT *);
  109. static struct clnt_ops unix_ops =
  110. {
  111. clntunix_call,
  112. clntunix_abort,
  113. clntunix_geterr,
  114. clntunix_freeres,
  115. clntunix_destroy,
  116. clntunix_control
  117. };
  118. /*
  119. * Create a client handle for a tcp/ip connection.
  120. * If *sockp<0, *sockp is set to a newly created TCP socket and it is
  121. * connected to raddr. If *sockp non-negative then
  122. * raddr is ignored. The rpc/tcp package does buffering
  123. * similar to stdio, so the client must pick send and receive buffer sizes,];
  124. * 0 => use the default.
  125. * If raddr->sin_port is 0, then a binder on the remote machine is
  126. * consulted for the right port number.
  127. * NB: *sockp is copied into a private area.
  128. * NB: It is the clients responsibility to close *sockp.
  129. * NB: The rpch->cl_auth is set null authentication. Caller may wish to set this
  130. * something more useful.
  131. */
  132. libc_hidden_proto(clntunix_create)
  133. CLIENT *
  134. clntunix_create (struct sockaddr_un *raddr, u_long prog, u_long vers,
  135. int *sockp, u_int sendsz, u_int recvsz)
  136. {
  137. CLIENT *h;
  138. struct ct_data *ct = (struct ct_data *) mem_alloc (sizeof (*ct));
  139. struct rpc_msg call_msg;
  140. int len;
  141. h = (CLIENT *) mem_alloc (sizeof (*h));
  142. if (h == NULL || ct == NULL)
  143. {
  144. struct rpc_createerr *ce = &get_rpc_createerr ();
  145. #ifdef USE_IN_LIBIO
  146. if (_IO_fwide (stderr, 0) > 0)
  147. (void) fwprintf (stderr, L"%s",
  148. _("clntunix_create: out of memory\n"));
  149. else
  150. #endif
  151. (void) fputs (_("clntunix_create: out of memory\n"), stderr);
  152. ce->cf_stat = RPC_SYSTEMERROR;
  153. ce->cf_error.re_errno = ENOMEM;
  154. goto fooy;
  155. }
  156. /*
  157. * If no socket given, open one
  158. */
  159. if (*sockp < 0)
  160. {
  161. *sockp = socket (AF_UNIX, SOCK_STREAM, 0);
  162. len = strlen (raddr->sun_path) + sizeof (raddr->sun_family) + 1;
  163. if (*sockp < 0
  164. || connect (*sockp, (struct sockaddr *) raddr, len) < 0)
  165. {
  166. struct rpc_createerr *ce = &get_rpc_createerr ();
  167. ce->cf_stat = RPC_SYSTEMERROR;
  168. ce->cf_error.re_errno = errno;
  169. if (*sockp != -1)
  170. close (*sockp);
  171. goto fooy;
  172. }
  173. ct->ct_closeit = TRUE;
  174. }
  175. else
  176. {
  177. ct->ct_closeit = FALSE;
  178. }
  179. /*
  180. * Set up private data struct
  181. */
  182. ct->ct_sock = *sockp;
  183. ct->ct_wait.tv_usec = 0;
  184. ct->ct_waitset = FALSE;
  185. ct->ct_addr = *raddr;
  186. /*
  187. * Initialize call message
  188. */
  189. call_msg.rm_xid = _create_xid ();
  190. call_msg.rm_direction = CALL;
  191. call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
  192. call_msg.rm_call.cb_prog = prog;
  193. call_msg.rm_call.cb_vers = vers;
  194. /*
  195. * pre-serialize the static part of the call msg and stash it away
  196. */
  197. xdrmem_create (&(ct->ct_xdrs), ct->ct_mcall, MCALL_MSG_SIZE, XDR_ENCODE);
  198. if (!xdr_callhdr (&(ct->ct_xdrs), &call_msg))
  199. {
  200. if (ct->ct_closeit)
  201. close (*sockp);
  202. goto fooy;
  203. }
  204. ct->ct_mpos = XDR_GETPOS (&(ct->ct_xdrs));
  205. XDR_DESTROY (&(ct->ct_xdrs));
  206. /*
  207. * Create a client handle which uses xdrrec for serialization
  208. * and authnone for authentication.
  209. */
  210. xdrrec_create (&(ct->ct_xdrs), sendsz, recvsz,
  211. (caddr_t) ct, readunix, writeunix);
  212. h->cl_ops = &unix_ops;
  213. h->cl_private = (caddr_t) ct;
  214. h->cl_auth = authnone_create ();
  215. return h;
  216. fooy:
  217. /*
  218. * Something goofed, free stuff and barf
  219. */
  220. mem_free ((caddr_t) ct, sizeof (struct ct_data));
  221. mem_free ((caddr_t) h, sizeof (CLIENT));
  222. return (CLIENT *) NULL;
  223. }
  224. libc_hidden_def(clntunix_create)
  225. static enum clnt_stat
  226. clntunix_call (h, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout)
  227. CLIENT *h;
  228. u_long proc;
  229. xdrproc_t xdr_args;
  230. caddr_t args_ptr;
  231. xdrproc_t xdr_results;
  232. caddr_t results_ptr;
  233. struct timeval timeout;
  234. {
  235. struct ct_data *ct = (struct ct_data *) h->cl_private;
  236. XDR *xdrs = &(ct->ct_xdrs);
  237. struct rpc_msg reply_msg;
  238. u_long x_id;
  239. u_int32_t *msg_x_id = (u_int32_t *) (ct->ct_mcall); /* yuk */
  240. bool_t shipnow;
  241. int refreshes = 2;
  242. if (!ct->ct_waitset)
  243. {
  244. ct->ct_wait = timeout;
  245. }
  246. shipnow =
  247. (xdr_results == (xdrproc_t) 0 && ct->ct_wait.tv_sec == 0
  248. && ct->ct_wait.tv_usec == 0) ? FALSE : TRUE;
  249. call_again:
  250. xdrs->x_op = XDR_ENCODE;
  251. ct->ct_error.re_status = RPC_SUCCESS;
  252. x_id = ntohl (--(*msg_x_id));
  253. if ((!XDR_PUTBYTES (xdrs, ct->ct_mcall, ct->ct_mpos)) ||
  254. (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
  255. (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
  256. (!(*xdr_args) (xdrs, args_ptr)))
  257. {
  258. if (ct->ct_error.re_status == RPC_SUCCESS)
  259. ct->ct_error.re_status = RPC_CANTENCODEARGS;
  260. (void) xdrrec_endofrecord (xdrs, TRUE);
  261. return ct->ct_error.re_status;
  262. }
  263. if (!xdrrec_endofrecord (xdrs, shipnow))
  264. return ct->ct_error.re_status = RPC_CANTSEND;
  265. if (!shipnow)
  266. return RPC_SUCCESS;
  267. /*
  268. * Hack to provide rpc-based message passing
  269. */
  270. if (ct->ct_wait.tv_sec == 0 && ct->ct_wait.tv_usec == 0)
  271. return ct->ct_error.re_status = RPC_TIMEDOUT;
  272. /*
  273. * Keep receiving until we get a valid transaction id
  274. */
  275. xdrs->x_op = XDR_DECODE;
  276. while (TRUE)
  277. {
  278. reply_msg.acpted_rply.ar_verf = _null_auth;
  279. reply_msg.acpted_rply.ar_results.where = NULL;
  280. reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
  281. if (!xdrrec_skiprecord (xdrs))
  282. return ct->ct_error.re_status;
  283. /* now decode and validate the response header */
  284. if (!xdr_replymsg (xdrs, &reply_msg))
  285. {
  286. if (ct->ct_error.re_status == RPC_SUCCESS)
  287. continue;
  288. return ct->ct_error.re_status;
  289. }
  290. if (reply_msg.rm_xid == x_id)
  291. break;
  292. }
  293. /*
  294. * process header
  295. */
  296. _seterr_reply (&reply_msg, &(ct->ct_error));
  297. if (ct->ct_error.re_status == RPC_SUCCESS)
  298. {
  299. if (!AUTH_VALIDATE (h->cl_auth, &reply_msg.acpted_rply.ar_verf))
  300. {
  301. ct->ct_error.re_status = RPC_AUTHERROR;
  302. ct->ct_error.re_why = AUTH_INVALIDRESP;
  303. }
  304. else if (!(*xdr_results) (xdrs, results_ptr))
  305. {
  306. if (ct->ct_error.re_status == RPC_SUCCESS)
  307. ct->ct_error.re_status = RPC_CANTDECODERES;
  308. }
  309. /* free verifier ... */
  310. if (reply_msg.acpted_rply.ar_verf.oa_base != NULL)
  311. {
  312. xdrs->x_op = XDR_FREE;
  313. (void) xdr_opaque_auth (xdrs, &(reply_msg.acpted_rply.ar_verf));
  314. }
  315. } /* end successful completion */
  316. else
  317. {
  318. /* maybe our credentials need to be refreshed ... */
  319. if (refreshes-- && AUTH_REFRESH (h->cl_auth))
  320. goto call_again;
  321. } /* end of unsuccessful completion */
  322. return ct->ct_error.re_status;
  323. }
  324. static void
  325. clntunix_geterr (CLIENT *h, struct rpc_err *errp)
  326. {
  327. struct ct_data *ct = (struct ct_data *) h->cl_private;
  328. *errp = ct->ct_error;
  329. }
  330. static bool_t
  331. clntunix_freeres (cl, xdr_res, res_ptr)
  332. CLIENT *cl;
  333. xdrproc_t xdr_res;
  334. caddr_t res_ptr;
  335. {
  336. struct ct_data *ct = (struct ct_data *) cl->cl_private;
  337. XDR *xdrs = &(ct->ct_xdrs);
  338. xdrs->x_op = XDR_FREE;
  339. return (*xdr_res) (xdrs, res_ptr);
  340. }
  341. static void
  342. clntunix_abort ()
  343. {
  344. }
  345. static bool_t
  346. clntunix_control (CLIENT *cl, int request, char *info)
  347. {
  348. struct ct_data *ct = (struct ct_data *) cl->cl_private;
  349. switch (request)
  350. {
  351. case CLSET_FD_CLOSE:
  352. ct->ct_closeit = TRUE;
  353. break;
  354. case CLSET_FD_NCLOSE:
  355. ct->ct_closeit = FALSE;
  356. break;
  357. case CLSET_TIMEOUT:
  358. ct->ct_wait = *(struct timeval *) info;
  359. break;
  360. case CLGET_TIMEOUT:
  361. *(struct timeval *) info = ct->ct_wait;
  362. break;
  363. case CLGET_SERVER_ADDR:
  364. *(struct sockaddr_un *) info = ct->ct_addr;
  365. break;
  366. case CLGET_FD:
  367. *(int *)info = ct->ct_sock;
  368. break;
  369. case CLGET_XID:
  370. /*
  371. * use the knowledge that xid is the
  372. * first element in the call structure *.
  373. * This will get the xid of the PREVIOUS call
  374. */
  375. *(u_long *) info = ntohl (*(u_long *)ct->ct_mcall);
  376. break;
  377. case CLSET_XID:
  378. /* This will set the xid of the NEXT call */
  379. *(u_long *) ct->ct_mcall = htonl (*(u_long *)info - 1);
  380. /* decrement by 1 as clntunix_call() increments once */
  381. case CLGET_VERS:
  382. /*
  383. * This RELIES on the information that, in the call body,
  384. * the version number field is the fifth field from the
  385. * begining of the RPC header. MUST be changed if the
  386. * call_struct is changed
  387. */
  388. *(u_long *) info = ntohl (*(u_long *) (ct->ct_mcall
  389. + 4 * BYTES_PER_XDR_UNIT));
  390. break;
  391. case CLSET_VERS:
  392. *(u_long *) (ct->ct_mcall + 4 * BYTES_PER_XDR_UNIT)
  393. = htonl (*(u_long *) info);
  394. break;
  395. case CLGET_PROG:
  396. /*
  397. * This RELIES on the information that, in the call body,
  398. * the program number field is the field from the
  399. * begining of the RPC header. MUST be changed if the
  400. * call_struct is changed
  401. */
  402. *(u_long *) info = ntohl (*(u_long *) (ct->ct_mcall
  403. + 3 * BYTES_PER_XDR_UNIT));
  404. break;
  405. case CLSET_PROG:
  406. *(u_long *) (ct->ct_mcall + 3 * BYTES_PER_XDR_UNIT)
  407. = htonl(*(u_long *) info);
  408. break;
  409. /* The following are only possible with TI-RPC */
  410. case CLGET_RETRY_TIMEOUT:
  411. case CLSET_RETRY_TIMEOUT:
  412. case CLGET_SVC_ADDR:
  413. case CLSET_SVC_ADDR:
  414. case CLSET_PUSH_TIMOD:
  415. case CLSET_POP_TIMOD:
  416. default:
  417. return FALSE;
  418. }
  419. return TRUE;
  420. }
  421. static void
  422. clntunix_destroy (CLIENT *h)
  423. {
  424. struct ct_data *ct =
  425. (struct ct_data *) h->cl_private;
  426. if (ct->ct_closeit)
  427. {
  428. (void) close (ct->ct_sock);
  429. }
  430. XDR_DESTROY (&(ct->ct_xdrs));
  431. mem_free ((caddr_t) ct, sizeof (struct ct_data));
  432. mem_free ((caddr_t) h, sizeof (CLIENT));
  433. }
  434. static int
  435. __msgread (int sock, void *data, size_t cnt)
  436. {
  437. struct iovec iov;
  438. struct msghdr msg;
  439. #ifdef SCM_CREDENTIALS
  440. static char cm[CMSG_SPACE(sizeof (struct ucred))];
  441. #endif
  442. int len;
  443. iov.iov_base = data;
  444. iov.iov_len = cnt;
  445. msg.msg_iov = &iov;
  446. msg.msg_iovlen = 1;
  447. msg.msg_name = NULL;
  448. msg.msg_namelen = 0;
  449. #ifdef SCM_CREDENTIALS
  450. msg.msg_control = (caddr_t) &cm;
  451. msg.msg_controllen = CMSG_SPACE(sizeof (struct ucred));
  452. #endif
  453. msg.msg_flags = 0;
  454. #ifdef SO_PASSCRED
  455. {
  456. int on = 1;
  457. if (setsockopt (sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on)))
  458. return -1;
  459. }
  460. #endif
  461. restart:
  462. len = recvmsg (sock, &msg, 0);
  463. if (len >= 0)
  464. {
  465. if (msg.msg_flags & MSG_CTRUNC || len == 0)
  466. return 0;
  467. else
  468. return len;
  469. }
  470. if (errno == EINTR)
  471. goto restart;
  472. return -1;
  473. }
  474. static int
  475. __msgwrite (int sock, void *data, size_t cnt)
  476. {
  477. #ifndef SCM_CREDENTIALS
  478. /* We cannot implement this reliably. */
  479. __set_errno (ENOSYS);
  480. return -1;
  481. #else
  482. struct iovec iov;
  483. struct msghdr msg;
  484. struct cmsghdr *cmsg = alloca (CMSG_SPACE(sizeof (struct ucred)));
  485. struct ucred cred;
  486. int len;
  487. /* XXX I'm not sure, if gete?id() is always correct, or if we should use
  488. get?id(). But since keyserv needs geteuid(), we have no other chance.
  489. It would be much better, if the kernel could pass both to the server. */
  490. cred.pid = getpid ();
  491. cred.uid = geteuid ();
  492. cred.gid = getegid ();
  493. memcpy (CMSG_DATA(cmsg), &cred, sizeof (struct ucred));
  494. cmsg->cmsg_level = SOL_SOCKET;
  495. cmsg->cmsg_type = SCM_CREDENTIALS;
  496. cmsg->cmsg_len = sizeof(*cmsg) + sizeof(struct ucred);
  497. iov.iov_base = data;
  498. iov.iov_len = cnt;
  499. msg.msg_iov = &iov;
  500. msg.msg_iovlen = 1;
  501. msg.msg_name = NULL;
  502. msg.msg_namelen = 0;
  503. msg.msg_control = cmsg;
  504. msg.msg_controllen = CMSG_ALIGN(cmsg->cmsg_len);
  505. msg.msg_flags = 0;
  506. restart:
  507. len = sendmsg (sock, &msg, 0);
  508. if (len >= 0)
  509. return len;
  510. if (errno == EINTR)
  511. goto restart;
  512. return -1;
  513. #endif
  514. }
  515. /*
  516. * Interface between xdr serializer and unix connection.
  517. * Behaves like the system calls, read & write, but keeps some error state
  518. * around for the rpc level.
  519. */
  520. static int
  521. readunix (char *ctptr, char *buf, int len)
  522. {
  523. struct ct_data *ct = (struct ct_data *) ctptr;
  524. struct pollfd fd;
  525. int milliseconds = ((ct->ct_wait.tv_sec * 1000)
  526. + (ct->ct_wait.tv_usec / 1000));
  527. if (len == 0)
  528. return 0;
  529. fd.fd = ct->ct_sock;
  530. fd.events = POLLIN;
  531. while (TRUE)
  532. {
  533. switch (poll (&fd, 1, milliseconds))
  534. {
  535. case 0:
  536. ct->ct_error.re_status = RPC_TIMEDOUT;
  537. return -1;
  538. case -1:
  539. if (errno == EINTR)
  540. continue;
  541. ct->ct_error.re_status = RPC_CANTRECV;
  542. ct->ct_error.re_errno = errno;
  543. return -1;
  544. }
  545. break;
  546. }
  547. switch (len = __msgread (ct->ct_sock, buf, len))
  548. {
  549. case 0:
  550. /* premature eof */
  551. ct->ct_error.re_errno = ECONNRESET;
  552. ct->ct_error.re_status = RPC_CANTRECV;
  553. len = -1; /* it's really an error */
  554. break;
  555. case -1:
  556. ct->ct_error.re_errno = errno;
  557. ct->ct_error.re_status = RPC_CANTRECV;
  558. break;
  559. }
  560. return len;
  561. }
  562. static int
  563. writeunix (char *ctptr, char *buf, int len)
  564. {
  565. int i, cnt;
  566. struct ct_data *ct = (struct ct_data *) ctptr;
  567. for (cnt = len; cnt > 0; cnt -= i, buf += i)
  568. {
  569. if ((i = __msgwrite (ct->ct_sock, buf, cnt)) == -1)
  570. {
  571. ct->ct_error.re_errno = errno;
  572. ct->ct_error.re_status = RPC_CANTSEND;
  573. return -1;
  574. }
  575. }
  576. return len;
  577. }