Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / Bug_2908_Regression / MessengerServer.cpp
blobe347070986f26c6fef61d459ebca00a3971ceecb
1 #include "Messenger_i.h"
2 #include "ace/Get_Opt.h"
3 #include <orbsvcs/SecurityLevel2C.h>
5 const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'o':
17 ior_output_file = get_opts.opt_arg ();
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-o <iorfile>"
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 int
34 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
36 try
38 // Initialize orb
39 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
41 if (parse_args (argc, argv) != 0)
42 return 1;
44 //Get reference to Root POA
45 CORBA::Object_var POA_obj = orb->resolve_initial_references( "RootPOA");
46 PortableServer::POA_var poa = PortableServer::POA::_narrow( POA_obj.in());
48 // Activate POA Manager
49 PortableServer::POAManager_var mgr = poa->the_POAManager();
50 mgr->activate();
52 // Create an object
53 Messenger_i messenger_servant (orb);
54 Messenger_var messenger_factory = messenger_servant._this ();
56 // In order to allow collocated invocations we need to allow unsecured
57 // collocated invocations to the object else our security manager will
58 // block the collocated invocation unless you explicitly allow it
59 CORBA::Object_var sec_man =
60 orb->resolve_initial_references ("SecurityLevel2:SecurityManager");
61 SecurityLevel2::SecurityManager_var sec2manager =
62 SecurityLevel2::SecurityManager::_narrow (sec_man.in ());
63 SecurityLevel2::AccessDecision_var ad_tmp =
64 sec2manager->access_decision ();
65 TAO::SL2::AccessDecision_var ad =
66 TAO::SL2::AccessDecision::_narrow (ad_tmp.in ());
67 // Allow unsecured collocated invocations
68 ad->default_collocated_decision (true);
70 CORBA::String_var ior =
71 orb->object_to_string (messenger_factory.in ());
73 // If the ior_output_file exists, output the ior to it
74 if (ior_output_file != 0)
76 FILE *output_file= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_output_file), "w");
77 if (output_file == 0)
78 ACE_ERROR_RETURN ((LM_ERROR,
79 "Cannot open output file for writing IOR: %s",
80 ACE_TEXT_ALWAYS_CHAR(ior_output_file)),
81 1);
82 ACE_OS::fprintf (output_file, "%s", ior.in ());
83 ACE_OS::fclose (output_file);
86 // Accept requests
87 orb->run();
89 poa->destroy (true, true);
91 orb->destroy();
93 catch (const CORBA::Exception&)
95 ACE_ERROR((LM_ERROR, "Caught a CORBA exception: "));
96 return 1;
99 return 0;