PreviousNext

greet_dced_server.c

Following are the contents of the greet_dced_server.c file, which contains the greet_dced server setup and cleanup routines. This is where the server's interaction with dced takes place.

/* greet_dced_server_dce.c

* Main program (initialization) for "greet_dced" server.

* NEW SERVER for DCE 1.1.

*/

#include <stdio.h>

#include <dce/dced.h>

#include "greet_dced.h"

#include "util.h"

char invocation_instructions[] = "Usage:\n\

1. Invoke the dcecp program: dcecp\n\

dcecp>\n\

2. Start the server:\n\

dcecp> server start greeter_dced\n\

3. If dced cannot find a matching server object, create server configuration:\n\

dcecp> source greet_dced.install\n\

dcecp> server start greeter_dced\n\

4. exit dcecp.\n\

dcecp> exit";

FILE * out = NULL;

boolean32 rpc_mgmt_authorize (rpc_binding_handle_t client_bn,

unsigned32 op_no,

unsigned32 *st);

int main(

int argc,

char *argv[]

)

{

server_t *server_conf;

dce_server_register_data_t register_data[1];

dce_server_handle_t server_handle;

error_status_t status;

/* if we are a daemon stderr is missing */

out = fopen ("/tmp/srv.out" , "w");

/* otherwise just use

out = stderr;

*/

fprintf(out, "Server start\n"); fflush(out);

/********** Get the server's configuration from the local dced ***********/

fprintf(out, "dce_server_inq_server() call\n");

fflush(out);

dce_server_inq_server(&server_conf, &status);

fprintf(out, "dce_server_inq_server() return\n");

fflush(out);

if(status != error_status_ok) { /* Describe startup via dcecp and dced */

fprintf(out, "%s\n", invocation_instructions);

fflush(out);

ERROR_CHECK(status, "Cannot get server configuration structure");

}

/********** login and manage key ****************/

fprintf(out, "dce_server_sec_begin() call\n");

fflush(out);

dce_server_sec_begin(dce_server_c_login|dce_server_c_manage_key, &status);

fprintf(out, "dce_server_sec_begin() return\n");

fflush(out);

if ( status != error_status_ok) {

fprintf(out, "Failed in dce_server_sec_begin()\n");

fflush(out);

ERROR_CHECK(status, "Cannot sec_begin");

}

/********** Only the protocol sequences we want ****************/

fprintf(out, "dce_server_use_protseq() call\n");

fflush(out);

dce_server_use_protseq( NULL , (idl_char *)"ncadg_ip_udp", &status);

fprintf(out, "dce_server_use_protseq() return\en");

fflush(out);

if ( status != error_status_ok) {

fprintf(out, "Failed to specify protocol sequence\n");

fflush(out);

ERROR_CHECK(status, "Cannot specify protocol sequence");

}

/************* Fill in rest of registration data structures **************/

register_data[0].ifhandle = greet_dcedif_v1_0_s_ifspec;

register_data[0].epv = NULL; /* use the default entry point vector */

register_data[0].num_types = 0;

register_data[0].types = NULL;

/************************** Register the Server **************************/

fprintf(out, "dce_server_register() call\en"); fflush(out);

dce_server_register(

dce_server_c_ns_export, /* flag says register server with CDS */

server_conf,

register_data,

&server_handle,

&status

);

fprintf(out, "dce_server_register() return\n");

fflush(out);

if ( status != error_status_ok) {

fprintf(out, "Failed dce_server_register. Error %d\n", status);

fflush(out);

ERROR_CHECK(status, "Can't register server with DCE");

}

/******************* Listen for remote procedure calls *******************/

fprintf(out, "Listening...\n"); fflush(out);

rpc_server_listen(rpc_c_listen_max_calls_default, &status);

fprintf(out, "Returned from listening...\n");

fflush(out);

if ( status != rpc_s_ok) {

fprintf(out, "Failed rpc_server_listen\n");

fflush(out);

ERROR_CHECK(status, "Can't start listening for calls");

}

/************************ Unregister from DCE ****************************/

fprintf(out, "dce_server_unregister call\n");

fflush(out);

dce_server_unregister(&server_handle, &status);

fprintf(out, "dce_server_unregister return\n");

fflush(out);

if ( status != error_status_ok) {

fprintf(out, "Failed dce_server_unregister\en");

fflush(out);

ERROR_CHECK(status, "Can't unregister server from DCE");

}

fprintf(out, "dce_server_sec_done call\n");

fflush(out);

dce_server_sec_done(&status);

fprintf(out, "dce_server_sec_done return\n");

fflush(out);

if ( status != error_status_ok) {

fprintf(out, "Failed dce_server_sec_done\n");

fflush(out);

ERROR_CHECK(status, "Can't do sec_done");

}

}