Exemplo n.º 1
0
int
lsRecvMsg_(int sock, char *buf, int bufLen, struct LSFHeader *hdr,
	   char *data, bool_t (*xdrFunc)(), int (*readFunc)())
{
    XDR xdrs;
    int cc;

    xdrmem_create(&xdrs, buf, bufLen, XDR_DECODE);

    if ((cc = readDecodeHdr_(sock, buf, readFunc, &xdrs, hdr)) < 0) {
	xdr_destroy(&xdrs);
	return (cc);
    }

    if (hdr->length == 0 || data == NULL) {
	xdr_destroy(&xdrs);
	return (0);
    }

    XDR_SETPOS(&xdrs, 0);

    if ((cc = readDecodeMsg_(sock, buf, hdr, readFunc, &xdrs, data,
			      xdrFunc, NULL))	< 0) {
	xdr_destroy(&xdrs);
	return (cc);
    }

    return (0);
}
Exemplo n.º 2
0
static int
rgetmnthost (int sock, struct LSFHeader *hdr)
{
  static char fname[] = "rgetmnthost()";
  char buf[LSRCP_MSGSIZE];
  char fn[MAXFILENAMELEN], *host;
  XDR xdrs;
  struct stringLen fnStr;
  struct stringLen hostStr;

  fnStr.len = MAXFILENAMELEN;
  fnStr.name = fn;

  xdrmem_create (&xdrs, buf, LSRCP_MSGSIZE, XDR_DECODE);
  if (readDecodeMsg_ (sock, buf, hdr, SOCK_READ_FIX, &xdrs,
		      (char *) &fnStr, xdr_stringLen, NULL))
    {
      ls_errlog (stderr, I18N_FUNC_FAIL_MM, fname, "readDecodeMsg_");
      xdr_destroy (&xdrs);
      close (sock);
      return (-1);
    }
  xdr_destroy (&xdrs);

  if ((host = ls_getmnthost (fn)) == NULL)
    {
      if (lsSendMsg_ (sock, -errnoEncode_ (errno), 0, NULL, buf,
		      sizeof (struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL)
	  < 0)
	{
	  ls_errlog (stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
	  close (sock);
	  return (-1);
	}
      return (0);
    }

  hostStr.len = MAXHOSTNAMELEN;
  hostStr.name = host;
  if (lsSendMsg_
      (sock, 0, 0, (char *) &hostStr, buf, LSRCP_MSGSIZE, xdr_stringLen,
       SOCK_WRITE_FIX, NULL) < 0)
    {
      ls_errlog (stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
      close (sock);
      return (-1);
    }

  return (0);
}
Exemplo n.º 3
0
static int
rlseek (int sock, struct LSFHeader *hdr)
{
  static char fname[] = "rlseek()";
  struct rlseekReq req;
  char msgBuf[LSRCP_MSGSIZE];
  XDR xdrs;
  off_t pos;

  xdrmem_create (&xdrs, msgBuf, LSRCP_MSGSIZE, XDR_DECODE);
  if (readDecodeMsg_ (sock, msgBuf, hdr, SOCK_READ_FIX, &xdrs, (char *) &req,
		      xdr_rlseekReq, NULL))
    {
      ls_errlog (stderr, I18N_FUNC_FAIL_MM, fname, "readDecodeMsg_");
      xdr_destroy (&xdrs);
      close (sock);
      return (-1);
    }
  xdr_destroy (&xdrs);

  if ((pos = lseek (req.fd, (off_t) req.offset, req.whence)) < 0)
    {
      goto fail;
    }

  if (lsSendMsg_ (sock, 0, (int) pos, NULL, msgBuf,
		  sizeof (struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL) < 0)
    {
      ls_errlog (stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
      close (sock);
      return (-1);
    }

  return (0);

fail:
  if (lsSendMsg_ (sock, -errnoEncode_ (errno), 0, NULL, msgBuf,
		  sizeof (struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL) < 0)
    {
      ls_errlog (stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
      close (sock);
      return (-1);
    }

  return (0);
}
Exemplo n.º 4
0
static int
rfstat (int sock, struct LSFHeader *hdr)
{
  static char fname[] = "rfstat()";
  int reqfd;
  char msgBuf[LSRCP_MSGSIZE];
  XDR xdrs;
  struct stat st;

  xdrmem_create (&xdrs, msgBuf, LSRCP_MSGSIZE, XDR_DECODE);
  if (readDecodeMsg_
      (sock, msgBuf, hdr, SOCK_READ_FIX, &xdrs, (char *) &reqfd, xdr_int,
       NULL))
    {
      ls_errlog (stderr, I18N_FUNC_FAIL_MM, fname, "readDecodeMsg_");
      xdr_destroy (&xdrs);
      close (sock);
      return (-1);
    }
  xdr_destroy (&xdrs);

  if (fstat (reqfd, &st) == -1)
    {
      if (lsSendMsg_ (sock, -errnoEncode_ (errno), 0, NULL, msgBuf,
		      sizeof (struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL)
	  < 0)
	{
	  ls_errlog (stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
	  close (sock);
	  return (-1);
	}
      return (0);
    }

  if (lsSendMsg_ (sock, 0, 0, (char *) &st, msgBuf, LSRCP_MSGSIZE, xdr_stat,
		  SOCK_WRITE_FIX, NULL) < 0)
    {
      ls_errlog (stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
      close (sock);
      return (-1);
    }

  return (0);
}
Exemplo n.º 5
0
static int
rstat(int sock, struct LSFHeader *hdr)
{
    static char fname[] = "rstat()";
    struct stat st;
    char buf[LSRCP_MSGSIZE];
    char fn[MAXFILENAMELEN];
    XDR xdrs;
    struct stringLen fnStr;

    fnStr.len = MAXFILENAMELEN;
    fnStr.name = fn;

    xdrmem_create(&xdrs, buf, LSRCP_MSGSIZE, XDR_DECODE);
    if (readDecodeMsg_(sock, buf, hdr, SOCK_READ_FIX, &xdrs,
                       (char *) &fnStr, xdr_stringLen, NULL)) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "readDeocdeMsg_");
        xdr_destroy(&xdrs);
        close(sock);
        return -1;
    }
    xdr_destroy(&xdrs);

    if (stat(fn, &st) == -1) {
        if (lsSendMsg_(sock, -errnoEncode_(errno), 0, NULL, buf,
                       sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL)
            < 0) {
            ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
            close(sock);
            return -1;
        }
        return 0;
    }

    if (lsSendMsg_(sock, 0, 0, (char *) &st, buf, LSRCP_MSGSIZE, xdr_stat,
                   SOCK_WRITE_FIX, NULL) < 0) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
        close(sock);
        return -1;
    }

    return 0;
}
Exemplo n.º 6
0
static int
rclose(int sock, struct LSFHeader *hdr)
{
    static char fname[] = "rclose()";
    int reqfd;
    char buf[LSRCP_MSGSIZE];
    XDR xdrs;

    xdrmem_create(&xdrs, buf, LSRCP_MSGSIZE, XDR_DECODE);
    if (readDecodeMsg_(sock, buf, hdr, SOCK_READ_FIX, &xdrs, (char *) &reqfd,
                       xdr_int, NULL)) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "readDecodeMsg_");
        xdr_destroy(&xdrs);
        closesocket(sock);
        return -1;
    }
    xdr_destroy(&xdrs);

    if (close(reqfd) == -1) {
        if (lsSendMsg_(sock, -errnoEncode_(errno), 0, NULL, buf,
                       sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL)
            < 0) {
            ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
            close(sock);
        }
        return 0;
    }

    if (lsSendMsg_(sock, 0, 0, NULL, buf,
                   sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL) < 0) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
        close(sock);
        return -1;
    }

    return 0;
}
Exemplo n.º 7
0
static int
runlink(int sock, struct LSFHeader *hdr)
{
    static char fname[] = "runlink()";
    char buf[LSRCP_MSGSIZE];
    char fn[MAXFILENAMELEN];
    XDR xdrs;
    struct stringLen fnStr;
    struct stat st;

    fnStr.len = MAXFILENAMELEN;
    fnStr.name = fn;

    xdrmem_create(&xdrs, buf, LSRCP_MSGSIZE, XDR_DECODE);
    if (readDecodeMsg_(sock, buf, hdr, SOCK_READ_FIX, &xdrs,
                       (char *) &fnStr, xdr_stringLen, NULL)) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "readDecodeMsg_");
        xdr_destroy(&xdrs);
        close(sock);
        return -1;
    }
    xdr_destroy(&xdrs);

    if ((stat(fn, &st) == 0) && (st.st_mode & S_IFDIR)) {


        DIR *dirp;
        struct dirent *dp;
        char path[MAXPATHLEN];

        if ((dirp = opendir(fn)) == NULL) {
            goto errrtn;
        }

        for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
            if (strcmp(dp->d_name, ".") != 0 &&
                strcmp(dp->d_name, "..") != 0) {
                sprintf (path, "%s/%s", fn, dp->d_name);
                rmdir (path);
                unlink (path);
            }
        }

        closedir (dirp);
        if (rmdir(fn) != 0) {
            goto errrtn;
        }
    }

    if (unlink(fn) < 0) {
        goto errrtn;
    }

    if (lsSendMsg_(sock, 0, 0, NULL, buf,
                   sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL) < 0) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
        closesocket(sock);
        return -1;
    }

    return 0;

errrtn:

    if (lsSendMsg_(sock, -errnoEncode_(errno), 0, NULL, buf,
                   sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL)
        < 0) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
        closesocket(sock);
        return -1;
    }
    return 0;
}
Exemplo n.º 8
0
static int
rread(int sock, struct LSFHeader *hdr)
{
    static char fname[] = "rread()";
    struct rrdwrReq req;
    char msgBuf[LSRCP_MSGSIZE];
    XDR xdrs;
    char *buf;

    xdrmem_create(&xdrs, msgBuf, LSRCP_MSGSIZE, XDR_DECODE);
    if (readDecodeMsg_(sock, msgBuf, hdr, SOCK_READ_FIX, &xdrs, (char *) &req,
                       xdr_rrdwrReq, NULL)) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "readDecodeMsg_");
        xdr_destroy(&xdrs);
        close(sock);
        return -1;
    }
    xdr_destroy(&xdrs);

    if ((buf = (char *) malloc(req.len)) == NULL) {
        if (lsSendMsg_(sock, -errnoEncode_(errno), 0, NULL, msgBuf,
                       sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL)
            < 0) {
            ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
            close(sock);
        }
        return 0;
    }

    if ((req.len = read(req.fd, buf, req.len)) < 0) {
        goto fail;
    }

    if (lsSendMsg_(sock, 0, req.len, NULL, msgBuf,
                   sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL) < 0) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
        close(sock);
        free(buf);
        return -1;
    }

    if (SOCK_WRITE_FIX(sock, buf, req.len) != req.len) {
        ls_errlog(stderr, I18N_FUNC_FAIL_M, fname, "SOCK_WRITE_FIX");
        close(sock);
        free(buf);
        return -1;
    }

    free(buf);
    return 0;

fail:
    free(buf);

    if (lsSendMsg_(sock, -errnoEncode_(errno), 0, NULL, buf,
                   sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL) < 0) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
        close(sock);
        return -1;
    }
    return 0;

}
Exemplo n.º 9
0
static int
ropen(int sock, struct LSFHeader *hdr)
{
    static char fname[] = "ropen()";
    struct ropenReq req;
    char buf[LSRCP_MSGSIZE];
    char fn[MAXFILENAMELEN];
    int fd;
    XDR xdrs;
    req.fn = fn;

    xdrmem_create(&xdrs, buf, LSRCP_MSGSIZE, XDR_DECODE);
    if (readDecodeMsg_(sock, buf, hdr, SOCK_READ_FIX, &xdrs, (char *) &req,
                       xdr_ropenReq, NULL)) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "readDecodeMsg_");
        xdr_destroy(&xdrs);
        closesocket(sock);
        return -1;
    }
    xdr_destroy(&xdrs);

    if (req.flags & LSF_O_CREAT_DIR) {
        req.flags &= ~LSF_O_CREAT_DIR;


        if (createSpoolSubDir(fn) < 0) {
            if (lsSendMsg_(sock, -errnoEncode_(errno), 0, NULL, buf,
                           sizeof(struct LSFHeader),
                           NULL, SOCK_WRITE_FIX, NULL) < 0) {
                ls_errlog(stderr, I18N_FUNC_FAIL_MM,
                          fname, "lsSendMsg_");
                closesocket(sock);
                return -1;
            }
            return 0;
        }
    }


    if ((fd = open(req.fn, req.flags, req.mode)) == -1) {
        if (lsSendMsg_(sock, -errnoEncode_(errno), 0, NULL, buf,
                       sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL)
            < 0) {
            ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
            closesocket(sock);
            return -1;
        }
        return 0;
    }


    if (lsSendMsg_(sock, fd, 0, NULL, buf,
                   sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL) < 0) {
        ls_errlog(stderr,  I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
        closesocket(sock);
        close(fd);
        return -1;
    }

    return 0;
}