home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / nfsd / src / rpc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-24  |  2.5 KB  |  93 lines

  1. /*  Functions for handling RPC
  2.  
  3.     ©1999 Joseph Walton
  4.  
  5.     This software is distributed under the terms of the GNU General Public
  6.     License; either version 2 of the License, or (at your option) any
  7.     later version.
  8. */
  9.  
  10. #include "rpc.h"
  11. #include <stdio.h>
  12. #include <proto/exec.h>
  13. #include <proto/socket.h>
  14.  
  15. int32 *getString(int32 *ptr, int32 *limit, char *buf, int bufchars)
  16. {
  17.         int numChars;
  18.         if (!ptr || (ptr >= limit))
  19.                 return NULL;
  20.  
  21.         numChars = G_UINT(*ptr++);
  22.         if ((INT32S(numChars) > (limit - ptr)) || (numChars >= bufchars))
  23.         {
  24.                 return NULL;
  25.         }
  26.  
  27.         CopyMem(ptr, buf, numChars);
  28.         buf[numChars] = '\0';
  29.         return ptr + INT32S(numChars);
  30. }
  31.  
  32. int32 *readAuth(int32 *ptr, int32 *limit, struct authunix *auth)
  33. {
  34.         int flavor, length, numIds, i;
  35.  
  36.         if ((limit - ptr) < 2)
  37.                 return NULL;
  38.  
  39.         flavor = G_INT(*ptr++);
  40.         length = G_UINT(*ptr++);
  41.  
  42.         switch (flavor) {
  43.                 case AUTH_SYS:
  44.                         auth->isUnix = TRUE;
  45.                         if ((limit - ptr) < 2)
  46.                                 return NULL;
  47.  
  48.                         ptr++; // Discard the stamp
  49.  
  50.                         ptr = getString(ptr, limit, auth->machineName,
  51.                             AUTH_SYS_MACHINENAMELEN);
  52.                         if (!ptr)
  53.                                 return NULL;
  54.  
  55.                         if ((limit - ptr) < 3) {
  56.                                 return NULL;
  57.                         }
  58.  
  59.                         auth->uid = G_UINT(*ptr++);
  60.                         auth->gid = G_UINT(*ptr++);
  61.                         numIds = G_UINT(*ptr++);
  62.  
  63.                         if ((numIds > 16) || (numIds > (limit - ptr)))
  64.                                 return NULL;
  65.  
  66.                         for (i = 0 ; i < numIds ; i++) {
  67.                                 auth->gids[i] = G_UINT(*ptr++);
  68.                         }
  69.                         auth->numGids = numIds;
  70.                         break;
  71.  
  72.                 default:
  73.                         auth->isUnix = FALSE;
  74.                         ptr += INT32S(length);
  75.                         if (ptr >= limit)
  76.                                 return NULL;
  77.                         break;
  78.         }
  79.  
  80.         return ptr;
  81. }
  82.  
  83. // Uses 5 int32s
  84. int32 *PrepareAcceptedHeader(int32 id, int32 *ptr)
  85. {
  86.         *ptr++ = P_UINT(id);
  87.         *ptr++ = P_ENUM(REPLY);
  88.         *ptr++ = P_ENUM(MSG_ACCEPTED);
  89.         *ptr++ = P_ENUM(AUTH_NONE);
  90.         *ptr++ = P_UINT(0);
  91.         return ptr;
  92. }
  93.