Ejemplo n.º 1
0
RpcChannel *
BackdoorChannel_New(void)
{
   RpcChannel *ret;
   BackdoorChannel *bdoor;

   ret = RpcChannel_Create();
   bdoor = g_malloc0(sizeof *bdoor);

   g_static_mutex_init(&bdoor->outLock);
   bdoor->out = RpcOut_Construct();
   ASSERT(bdoor->out != NULL);

   bdoor->inStarted = FALSE;
   bdoor->outStarted = FALSE;

   ret->start = RpcInStart;
   ret->stop = RpcInStop;
   ret->send = RpcInSend;
   ret->setup = RpcInSetup;
   ret->shutdown = RpcInShutdown;
   ret->_private = bdoor;

   return ret;
}
Ejemplo n.º 2
0
gboolean
BackdoorChannel_Fallback(RpcChannel *chan)
{
   BackdoorChannel *bdoor;

   ASSERT(chan);
   ASSERT(chan->_private == NULL);

   bdoor = g_malloc0(sizeof *bdoor);
   bdoor->out = RpcOut_Construct();
   ASSERT(bdoor->out != NULL);

   BackdoorChannelSetCallbacks(chan);
   chan->_private = bdoor;

   return chan->funcs->start(chan);
}
Ejemplo n.º 3
0
RpcChannel *
BackdoorChannel_New(void)
{
   RpcChannel *ret;
   BackdoorChannel *bdoor;

   ret = RpcChannel_Create();
   bdoor = g_malloc0(sizeof *bdoor);

   bdoor->out = RpcOut_Construct();
   ASSERT(bdoor->out != NULL);

   ret->inStarted = FALSE;
   ret->outStarted = FALSE;

   BackdoorChannelSetCallbacks(ret);
   ret->_private = bdoor;

   return ret;
}
Ejemplo n.º 4
0
Bool
RpcOut_SendOneRaw(void *request,       // IN: RPCI command
                  size_t reqLen,       // IN: Size of request buffer
                  char **reply,        // OUT: Result
                  size_t *repLen)      // OUT: Length of the result
{
    Bool status;
    RpcOut *out = NULL;
    char const *myReply;
    size_t myRepLen;

    status = FALSE;

    Debug("Rpci: Sending request='%s'\n", (char *)request);
    out = RpcOut_Construct();
    if (out == NULL) {
        myReply = "RpcOut: Unable to create the RpcOut object";
        myRepLen = strlen(myReply);

        goto sent;
    } else if (RpcOut_start(out) == FALSE) {
        myReply = "RpcOut: Unable to open the communication channel";
        myRepLen = strlen(myReply);

        goto sent;
    } else if (RpcOut_send(out, request, reqLen, &myReply, &myRepLen)
               == FALSE) {
        /* We already have the description of the error */
        goto sent;
    }

    status = TRUE;

sent:
    Debug("Rpci: Sent request='%s', reply='%s', len=%"FMTSZ"u, status=%d\n",
          (char *)request, myReply, myRepLen, status);

    if (reply != NULL) {
        /*
         * If we got a non-NULL reply, make a copy of it, because the reply
         * we got back is inside the channel buffer, which will get destroyed
         * at the end of this function.
         */
        if (myReply != NULL) {
            /*
             * We previously used strdup to duplicate myReply, but that
             * breaks if you are sending binary (not string) data over the
             * backdoor. Don't assume the data is a string.
             *
             * myRepLen is strlen(myReply), so we need an extra byte to
             * cover the NUL terminator.
             */
            *reply = malloc(myRepLen + 1);
            if (*reply != NULL) {
                memcpy(*reply, myReply, myRepLen);
                /*
                 * The message layer already writes a trailing NUL but we might
                 * change that someday, so do it again here.
                 */
                (*reply)[myRepLen] = 0;
            }
        } else {
            /*
             * Our reply was NULL, so just pass the NULL back up to the caller.
             */
            *reply = NULL;
        }

        /*
         * Only set the length if the caller wanted it and if we got a good
         * reply.
         */
        if (repLen != NULL && *reply != NULL) {
            *repLen = myRepLen;
        }
    }

    if (out) {
        if (RpcOut_stop(out) == FALSE) {
            /*
             * We couldn't stop the channel. Free anything we allocated, give our
             * client a reply of NULL, and return FALSE.
             */

            if (reply != NULL) {
                free(*reply);
                *reply = NULL;
            }
            Debug("Rpci: unable to close the communication channel\n");
            status = FALSE;
        }

        RpcOut_Destruct(out);
        out = NULL;
    }

    return status;
}