Remote Administration Daemon Developer Guide

Exit Print View

Updated: July 2014
 
 

Connecting to RAD

Communication with a RAD instance is provided through the rc_connect_*() family of functions. There are various functions to get different types of connections to RAD. Each function returns a rc_conn_t reference which acts as a handle for interactions with RAD over that connection. Every connect function has two common arguments: a boolean to specify whether the connection be multithreaded (TRUE is recommended) and the locale to use for the connection. When locale is NULL, the locale of the local client is used. Each connection type also has differing transport specific arguments.

To close the connection,rc_disconnect() needs to be called with the connection handle.

Connecting to a Local Instance

Implicit authentication is performed against your user id and most RAD tasks you request with this connection are performed with the privileges available to your user account. The function rc_connect_unix() takes three arguments: The path to the unix socket, a boolean to determine if the connection is to be multithreaded, and the desired locale for the connection. If the socket path is NULL, the default RAD unix socket path is used; it is recommended that the connection be run in multithreaded mode; if the locale is NULL, the locale of the local client system is used.

Example 3-1  Creating a Local Connection
#include <rad/radclient.h>
rc_conn_t conn = rc_connect_unix(NULL, B_TRUE, NULL);

// do something with conn

Connecting to a Remote Instance and Authenticating

When connecting to a remote instance, there is no implicit authentication, so the connection is not useful until authentication is performed. To authenticate with PAM, a function rc_pam_login() is provided. However, the client application source must #include <rad/client/1/pam_login.h> and link against the PAM C binding library, /usr/lib/rad/client/c/libpam_client.so.

Authentication is done non-interactively and a username and password should be provided. Optionally, a handle to the PAM Authentication object can be returned if a reference is provided as the second argument to rc_pam_login().

Example 3-2  Remote Connection over TCP IPv4 on port 7777
#include <rad/radclient.h>
#include <rad/client/1/pam_login.h>

rc_instance_t *pam_inst;
rc_conn_t conn = rc_connect_tcp("henry",7777, B_TRUE, NULL);

if (conn !=NULL) {
            rc_err_t status = rc_pam_login(conn, &pam_inst, "user", "password");
            if (status == RCE_OK){
                printf("Connected and authenticated!\n");
                }    
}