openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/nbd/3.19-r0/nbd-3.19/nbd-server.c
static bool commit_client(CLIENT* client, SERVER* server)
{
    char acl;
    uint32_t len;

    client->server = server;
    client->exportsize = OFFT_MAX;
    client->transactionlogfd = -1;
    if (pthread_mutex_init(&(client->lock), NULL))
    {
        msg(LOG_ERR, "Unable to initialize mutex");
        return false;
    }
    if (pthread_rwlock_init(&client->export_lock, NULL))
    {
        msg(LOG_ERR, "Unable to initialize write lock");
        return false;
    }
    /* Check whether we exceeded the maximum number of allowed
     * clients already */
    if (dontfork)
    {
        acl = 'Y';
    }
    else
    {
        len = strlen(client->server->servename);
        writeit(commsocket, &len, sizeof len);
        writeit(commsocket, client->server->servename, len);
        readit(commsocket, &acl, 1);
        close(commsocket);
    }
    switch (acl)
    {
        case 'N':
            msg(LOG_ERR, "Connection not allowed (too many clients)");
            return false;
        case 'X':
            msg(LOG_ERR, "Connection not allowed (unknown by parent?!?)");
            return false;
    }

    /* Check whether the client is listed in the authfile */
    if (set_peername(client->net, client))
    {
        msg(LOG_ERR, "Failed to set peername");
        return false;
    }

    if (!authorized_client(client))
    {
        msg(LOG_INFO, "Client '%s' is not authorized to access",
            client->clientname);
        return false;
    }

    /* Set up the transactionlog, if we need one */
    if (client->server->transactionlog && (client->transactionlogfd == -1))
    {
        if ((client->transactionlogfd =
                 open(client->server->transactionlog, O_WRONLY | O_CREAT,
                      S_IRUSR | S_IWUSR)) == -1)
        {
            msg(LOG_INFO,
                "Could not open transactionlog %s, moving on without it",
                client->server->transactionlog);
        }
    }

    /* Run any pre scripts that we may need */
    if (do_run(client->server->prerun, client->exportname))
    {
        msg(LOG_INFO, "Client '%s' not allowed access by prerun script",
            client->clientname);
        return false;
    }
    client->socket_closed = socket_closed_transmission;
    if (!setupexport(client))
    {
        return false;
    }

    if (client->server->flags & F_COPYONWRITE)
    {
        if (!copyonwrite_prepare(client))
        {
            return false;
        }
    }

    if (client->server->flags & F_WAIT)
    {
        if (!copyonwrite_prepare(client))
        {
            return false;
        }
    }

    setmysockopt(client->net);

    return true;
}
/**
 * Commit to exporting the chosen export
 *
 * When a client sends NBD_OPT_EXPORT_NAME or NBD_OPT_GO, we need to do
 * a number of things (verify whether the client is allowed access, try
 * to open files, etc etc) before we're ready to actually serve the
 * export.
 *
 * This function does all those things.
 *
 * @param client the CLIENT structure with .server and .net members set
 * up correctly
 * @return true if the client is allowed access to the export, false
 * otherwise
 */
Commit to exporting the chosen export
When a client sends NBD_OPT_EXPORT_NAME or NBD_OPT_GO, we need to do
a number of things (verify whether the client is allowed access, try
to open files, etc etc) before we're ready to actually serve the
export.

This function does all those things.

@param client the CLIENT structure with .server and .net members set
up correctly
@return true if the client is allowed access to the export, false
otherwise
Commit to exporting the chosen export When a client sends NBD_OPT_EXPORT_NAME or NBD_OPT_GO we need to do a number of things ( verify whether the client is allowed access try to open files etc etc ) before we ' re ready to actually serve the export . This function does all those things . @param client the CLIENT structure with . server and . net members set up correctly @return true if the client is allowed access to the export false otherwise
static bool commit_client(CLIENT* client, SERVER* server)
{
    char acl;
    uint32_t len;
    client->server = server;
    client->exportsize = OFFT_MAX;
    client->transactionlogfd = -1;
    if (pthread_mutex_init(&(client->lock), NULL))
    {
        msg(LOG_ERR, "Unable to initialize mutex");
        return false;
    }
    if (pthread_rwlock_init(&client->export_lock, NULL))
    {
        msg(LOG_ERR, "Unable to initialize write lock");
        return false;
    }
    if (dontfork)
    {
        acl = 'Y';
    }
    else
    {
        len = strlen(client->server->servename);
        writeit(commsocket, &len, sizeof len);
        writeit(commsocket, client->server->servename, len);
        readit(commsocket, &acl, 1);
        close(commsocket);
    }
    switch (acl)
    {
        case 'N':
            msg(LOG_ERR, "Connection not allowed (too many clients)");
            return false;
        case 'X':
            msg(LOG_ERR, "Connection not allowed (unknown by parent?!?)");
            return false;
    }
    if (set_peername(client->net, client))
    {
        msg(LOG_ERR, "Failed to set peername");
        return false;
    }
    if (!authorized_client(client))
    {
        msg(LOG_INFO, "Client '%s' is not authorized to access",
            client->clientname);
        return false;
    }
    if (client->server->transactionlog && (client->transactionlogfd == -1))
    {
        if ((client->transactionlogfd =
                 open(client->server->transactionlog, O_WRONLY | O_CREAT,
                      S_IRUSR | S_IWUSR)) == -1)
        {
            msg(LOG_INFO,
                "Could not open transactionlog %s, moving on without it",
                client->server->transactionlog);
        }
    }
    if (do_run(client->server->prerun, client->exportname))
    {
        msg(LOG_INFO, "Client '%s' not allowed access by prerun script",
            client->clientname);
        return false;
    }
    client->socket_closed = socket_closed_transmission;
    if (!setupexport(client))
    {
        return false;
    }
    if (client->server->flags & F_COPYONWRITE)
    {
        if (!copyonwrite_prepare(client))
        {
            return false;
        }
    }
    if (client->server->flags & F_WAIT)
    {
        if (!copyonwrite_prepare(client))
        {
            return false;
        }
    }
    setmysockopt(client->net);
    return true;
}
static bool commit_client ( CLIENT * client , SERVER * server ) { char acl ; uint32_t len ; client -> server = server ; client -> exportsize = OFFT_MAX ; client -> transactionlogfd = -1 ; if ( pthread_mutex_init ( & ( client -> lock ) , NULL ) ) { msg ( LOG_ERR , " " ) ; return false ; } if ( pthread_rwlock_init ( & client -> export_lock , NULL ) ) { msg ( LOG_ERR , " " ) ; return false ; } if ( dontfork ) { acl = ' ' ; } else { len = strlen ( client -> server -> servename ) ; writeit ( commsocket , & len , sizeof len ) ; writeit ( commsocket , client -> server -> servename , len ) ; readit ( commsocket , & acl , 1 ) ; close ( commsocket ) ; } switch ( acl ) { case ' ' : msg ( LOG_ERR , " " ) ; return false ; case ' ' : msg ( LOG_ERR , " " ) ; return false ; } if ( set_peername ( client -> net , client ) ) { msg ( LOG_ERR , " " ) ; return false ; } if ( ! authorized_client ( client ) ) { msg ( LOG_INFO , " " , client -> clientname ) ; return false ; } if ( client -> server -> transactionlog && ( client -> transactionlogfd == -1 ) ) { if ( ( client -> transactionlogfd = open ( client -> server -> transactionlog , O_WRONLY | O_CREAT , S_IRUSR | S_IWUSR ) ) == -1 ) { msg ( LOG_INFO , " " , client -> server -> transactionlog ) ; } } if ( do_run ( client -> server -> prerun , client -> exportname ) ) { msg ( LOG_INFO , " " , client -> clientname ) ; return false ; } client -> socket_closed = socket_closed_transmission ; if ( ! setupexport ( client ) ) { return false ; } if ( client -> server -> flags & F_COPYONWRITE ) { if ( ! copyonwrite_prepare ( client ) ) { return false ; } } if ( client -> server -> flags & F_WAIT ) { if ( ! copyonwrite_prepare ( client ) ) { return false ; } } setmysockopt ( client -> net ) ; return true ; }
Commit to exporting the chosen export
 When a client sends NBD_OPT_EXPORT_NAME or NBD_OPT_GO, we need to do
 a number of things (verify whether the client is allowed access, try
 to open files, etc etc) before we're ready to actually serve the
 export.
Commit to exporting the chosen export When a client sends NBD_OPT_EXPORT_NAME or NBD_OPT_GO we need to do a number of things ( verify whether the client is allowed access try to open files etc etc ) before we ' re ready to actually serve the export .
/* Check whether we exceeded the maximum number of allowed
     * clients already */ /* Check whether the client is listed in the authfile */ /* Set up the transactionlog, if we need one */ /* Run any pre scripts that we may need */