HostProcControl is a CORBA service, which provides API for remote managing of an operating system. Using HostProcControl, you can create CORBA-objects able to give:
AdministrationGuide_eng.pdf for more details).
The package is written on C++ and being distributed in the form of source code.
There are three types of HostProcControl CORBA-object:
All HostProcControl functionality is accessible via object named HostControl. Checking if client access permitted is carried out before the creation of this object. To create HostControl object, client invokes HostControlHome's getHostControl method with two parameters considering to be a complex "client ID" consisting of user name and user password. HostControlHome receives ID and seeks the same in user list. User list is the file at the host being edited by service administrator and being composed of strings like following:
John : Johnson A.E.Belyaev:265-60-43 <another_name>:<another_password>Access permits if ID corresponding has been found, and not permits otherwise.
The common rule reads as follows: client must not remember to destroy each object created by itself. Nevertheless, you can command to object such as HostControl, FileReader and FileWriter to destroy itself in the case having not been used during some timeout fixed. For this pupose every object has a set_timeout method being invoked with timeout value for the object (in seconds) as a parameter. There are next features of timeout control system now:
This HostControlHome object is created automatically when server starts. This is a "root" object of the service. Depending on server options used, an access to this object may be obtained via three (different) vays (see Administration Guide for details):
HostControlService=corbaloc::<host>:<port>/HostControlService
interface HostControlHome
{
HostControl
getHostControl(in string name, in string password)
raises(LoginIncorrect);
};
-ORBInitRef HostControlService=corbaloc::127.0.0.1:1025/HostControlServiceUsing next code presented we get accesss to HostControlHome and try to create HostControl object:
/* variables needed */
Object_var obj;
HostControl_var hostControl;
HostControlHome_var hostControlHome;
/* ORB initialization using options from the command line */
myORB = ORB_init(argc,argv);
/* getting access to HostControlHome */
obj = myORB->resolve_initial_references( "HostControlService" );
hostControlHome = HostControlHome::_narrow(obj);
/* getting client ID */
char name[]="name";
char password[]="password";
try {
/* trying to create HostControl */
hostControl = hostControlHome->getHostControl(name,password);
} catch ( const LoginIncorrect& ex ) {
/* error message may be present here */
goto quit;
}
/* using of HostControl may be present here */
/* deleting of HostControl */
hostControl->destroy();
quit:
myORB->destroy();
This HostControl object is the most powerfull object of the service. It's held the next functionality:
interface HostControl
{
ProcInfoSeq getProcsInfo() raises(HostError);
ProcInfo getProcInfoByPid(in unsigned long pid) raises(HostError);
unsigned long bornProcByName(in string name,in StringSeq args) raises(HostError);
void killProcByName(in short signal, in string name) raises(HostError);
void killProcByPid(in short signal, in unsigned long pid) raises(HostError);
FileReader createFileReader(in string path) raises(HostError);
FileWriter createFileWriter(in string path,in WriteMode mode) raises(HostError);
boolean statFile(in string path, in char arg) raises(HostError);
void rmFile(in string path) raises(HostError);
void set_timeout(in unsigned long timeout);
void destroy();
};
A. Methods to process control
struct ProcInfo
{
unsigned long pid; // the Process ID
string name; // the name of executable
unsigned long ppid; // the PID of the parent
};
typedef sequence<ProcInfo> ProcInfoSeq;
typedef sequence<string> StringSeq;
The relation between set of arg values and assumptions correcponding is shown in the tables:
for any platform:
| arg value | assumption |
| 'e' | file exists |
| 's' | file exists and is not zero size |
| 'c' | file exists and is character special |
| 'd' | file exists and is directory |
| 'f' | file exists and is'nt directory |
| 'r' | file exists and is'nt read protected |
| 'w' | file exists and is'nt write protected |
| 'x' | file exists and may be run |
for UNIX extra:
| arg value | assumption |
| 'h' | file exists and is symbolic link |
| 'b' | file exists and is block special |
| 'p' | file exists and is named pipe (fifo) |
| 'u' | file exists and can invoke setuid |
| 'g' | file exists and can invoke setgid |
All values of arg being not included in this table are not permited; using of them leads to InvalidModeArgument exception will be throwed.
enum WriteMode { enRewrite, enAppend };
Let us assume "hostControlHome" is object variable obtained as stated above and "<learner>:<test>" is string in user list;
HostControl_var hostControl;
ProcInfoSeq_var procseq;
/* create HostControl object */
try {
hostControl = hostControlHome->getHostControl("learner","test");
} catch ( const LoginIncorrect& ex ) {
/* error message: ... */
goto quit;
}
/* obtain the process list */
procseq = hostControl->getProcsInfo();
/* outtype process list */
for(int i = 0; i< procseq->length() ; i++) {
cout << procseq[i].pid << " ";
cout << procseq[i].name << " ";
cout << procseq[i].ppid << endl;
}
/* destroy the object */
hostControl->destroy();
quit:
.....
HostControl_var hostControl;
/* create HostControl object */
try {
hostControl = hostControlHome->getHostControl("learner","test");
} catch ( const LoginIncorrect& ex ) {
/* error message: ... */
goto quit;
}
if ( hostControl->statFile("garbage.txt",'f') ) {
hostControl->rmFile("garbage.txt")
}
/* destruction of the object */
hostControl->destroy();
quit:
.....
This object FileReader provides access to byte sequence type data stored in remote file being opend at the time of creating of the object by means of HostControl::createFileReader 3.2.3.
interface FileReader
{
OctSeq
read(in unsigned long nbytes, out unsigned long actual_nbytes)
raises(HostError);
boolean eof() raises(HostError);
void set_timeout(in unsigned long timeout );
void close() raises(HostError);
};
typedef sequence<octet> OctSeq;
Let us assume that "hostControl" is object variable obtained as stated above; next code copies remote file demo.txt into standard output:
/* create FileRedader object */
FileReader_var freader = hostControl->createFileRedader("demo.txt");
OctSeq_var data = new OctSeq;
const int buffer_size = 10000;
data -> length( buffer_size );
char buff[buffer_size+1];
int readed;
do {
/* read the portion of data from the file */
data = filereader->read( buffer_size, readed );
/* send data into standard output */
memcpy(buff,data->get_buffer(),readed);
buff[readed+1]='\0';
cout << buff;
} while ( readed==buffer_size ); // repeat while not eof reached
/* close file and destroy FileReader object */
freader->close();
This object FileWriter wrtes byte sequence type data into remote file being opend at the time of creating of the object by means of HostControl::createFileWriter 3.2.3.
interface FileWriter
{
void write(in unsigned long nbytes, in OctSeq bytes) raises(HostError);
void set_timeout(in unsigned long timeout);
void close() raises(HostError); \
};
typedef sequence<octet> OctSeq;
Let us assume that "hostControl" is object variable obtained as stated above; next code copies file demo.txt from client to host:
/* create FileWriter object*/
FileWriter_var filewriter = hostControl->createFileWriter( "demo.txt", UAKG_enRewrite );
/* create file to read */
FILE* file = fopen("demo.txt","rb");
const int buffer_size = 10000;
OctSeq_var buf = new OctSeq;
buf -> length( buffer_size );
int readed;
while ( !feof( file ) ) {
/* read data from the local file */
readed = fread(buf->data(),1,buffer_size,file);
/* write data to the remote file */
filewriter->write(readed,buf);
if ( ferror( file )) {
break;
}
}
/* close files and destroy FileWriter object */
fclose( file );
filewriter->close();
InvalidLogin exception arises when creating HostControl object
in the case client invoking getHostControl is not registered in the user list
(see description of HostControlHome::getHostControl method for details 3.1.3);
exception InvalidLogin {};
AccessControlFailure exception arises when creating HostControl object
in the case access rights control is found to be impossible
(for example, user list is not found)
(see description of HostControlHome::getHostControl 3.1.3 too);
exception AccessControlFailure {};
exception InvalidModeArgument {};
exception HostError
{
long os_errno; // error number according to POSIX
string errstr; // description of system error
string add_info; // reserved
};
This model client application demonstrates an order of access to HostProcControl functionality using corbaloc url. Specific rules to adapting of the server see in ORB documentation.
using namespace CORBA;
static ORB_var myORB ;
#define NAME_LEN 20
#define PASSWD_LEN 20
int main(int argc,char** argv)
{
char name[20],password[20];
myORB = ORB_init(argc,argv);
Object_var obj;
int retval=1;
try {
obj=myORB->string_to_object(
"corbaloc::x.internal.company.com:1000/HostControlService");
} catch ( const SystemException& ex ) {
cerr << argv[0] << ": Can\'t resolve HostControlService reference" << endl;
goto quit;
}
if ( is_nil(obj) ) {
cerr << "Object is NULL" << endl;
goto quit;
}
HostControlHome_var hstCntrHome = HostControlHome::_narrow(obj);
if ( is_nil(HstCntrHome) ) {
cout << "Can\'t narrow object " << endl;
goto quit;
}
cout << "Enter name :" << flush ;
cin.get_line(name,NAME_LEN);
cout << "Enter password :" << flush;
cin.get_line(password,PASSWD_LEN);
HostControl_var hostControl ;
try {
hostControl = HstCntrHome->getHostControl(name,password);
} catch (const SystemException& ex ) {
cerr << "System Exception" << endl;
goto quit;
} catch (const IncorrectLogin& ex ) {
cerr << "Login incorrect" << endl;
goto quit;
}
cout << "login succesfull" << endl;
retval=0;
//
// do you work here.
//
hostControl->destroy();
quit:
myORB->destroy();
return retval;
}
The package HostProcControl is created and supported by GradSoft company,
the home page of GradSoft is http://www.gradsoft.com.ua/.
The current release number of the project is HostProcControl-1.0.