#pragma module OESSynch "OES-Synch-1-A" /* **++ ** FACILITY: Remote URL Activator ** ** MODULE DESCRIPTION: ** ** This is a VMS-part of the "remote UTL activator", contains a code to send ** packet to remote PC with running "URL-Executor". ** ** AUTHOR: Ruslan R. Laishev ** Copyright 2009-2010, Ruslan R. Laishev ** ** This program can be built by the following procedure: ** ** $ CC/NOWARN/NODEBUG/INCL=[] OESSynch.C ** $ LINK/NODEBUG/NOTRACE OESSynch ** ** ** Control logicals: ** DEFINE OES_SYNCH_PORT 8377 - UDP port number on target PeeCee ** DEFINE OES_SYNCH_URL - eg "http://www.starlet.spb.ru", full UTL to open in browser ** DEFINE OES_SYNCH_NODE - eg "172.16.1.24", IP address/named fo target PeeCee ** ** C Binding: ** status = url_snd(); ** ** ** MODIFICATION HISTORY: ** ** 7-JUL-2009 RRL Initial coding. ** 8-JUL-2009 RRL Added some code to get "Remote Port Info" under HP TCP/IP ** 5-MAR-2010 RRL Changed name of the project to OESSynch, made changes according ** to last requirement. **-- */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define __NEW_STARLET 1 #include #define INIT_SDESC(dsc, len, ptr) {(dsc).dsc$b_dtype = DSC$K_DTYPE_T;\ (dsc).dsc$b_class = DSC$K_CLASS_S; (dsc).dsc$w_length = (short) (len);\ (dsc).dsc$a_pointer = (char *) (ptr);} #define INIT_DDESC(dsc) {(dsc).dsc$b_dtype = DSC$K_DTYPE_T;\ (dsc).dsc$b_class = DSC$K_CLASS_D;(dsc).dsc$w_length = 0;\ (dsc).dsc$a_pointer = NULL;} $DESCRIPTOR(dsc_ucxdev, "UCX$DEVICE"); $DESCRIPTOR(dsc_tcpipdev, "TCPIP$DEVICE"); $DESCRIPTOR(dsc_port, "OES_SYNCH_PORT"); $DESCRIPTOR(dsc_url, "OES_SYNCH_URL"); $DESCRIPTOR(dsc_node, "OES_SYNCH_NODE"); $DESCRIPTOR(dsc_tbl, "LNM$PROCESS_TABLE"); #define OES_SYNCH_PORT 8377 /* ** ** MACRO DEFINITIONS ** */ #define min(x,y) ((x > y)?y:x) #define max(x,y) ((x < y)?y:x) const struct { short proto; char type; char domain; } sck_parm = {INET$C_UDP,INET_PROTYP$C_DGRAM,INET$C_AF_INET}; #pragma member_alignment save #pragma nomember_alignment struct pdu { unsigned char fl, /* 'S' or standard, 'D' for debug */ cprog[8], /* Calling program name */ url[200]; /* URL */ }; #pragma member_alignment restore /* **++ ** FUNCTIONAL DESCRIPTION: ** ** Performs an authentication and authorization of the PMAS user against ** remote RADIUS server/database. ** ** FORMAL PARAMETERS: ** ** email_d: E-Mail entered by user AS IS, by descriptor ** password_d: Password string, by descriptor ** ** RETURN VALUE: ** ** VMS Condition code. ** **-- */ int oes_synch (void) { int status,len,ipaddr,pid = 0; unsigned char obuf [1024],ibuf[1024]; unsigned short buflen,port,hostlen = 0; static short chan; struct pdu *ptr = (struct pdu *)obuf; const struct sockaddr_in sock_host = {INET$C_AF_INET,0,INET$C_INADDR_ANY,0}; ILE2 loc_host = {sizeof(struct sockaddr_in),0,&sock_host}; ILE3 rem_host = {sizeof(struct sockaddr_in),0,&sock_host,&hostlen}, lnms[] = {{sizeof(ibuf),LNM$_STRING,ibuf,&buflen},{0,0,0,0}}, prcnm[] = {{sizeof(ptr->cprog),JPI$_PRCNAM,&ptr->cprog,&buflen},{0,0,0,0}}; iosb iosb; struct hostent *hp; /* ** Get parameters from logicals */ if ( !(1 & (status = sys$trnlnm (0,&dsc_tbl,&dsc_port,0,&lnms))) ) port = OES_SYNCH_PORT; else if ( !lib$cvt_dtb(buflen,ibuf,&port) ) return SS$_INSFARG; /* ** Initialize network stuff */ if ( !(1 & (status = sys$assign( &dsc_ucxdev,&chan,0,0))) ) { if ( (status != SS$_NOSUCHDEV) ) return status; if ( !(1 & (status = sys$assign( &dsc_tcpipdev,&chan,0,0))) ) return status; } /* ** Create a UDP device */ sock_host.sin_family = INET$C_AF_INET; status = sys$qiow (EFN$C_ENF,chan,IO$_SETMODE,&iosb, 0,0,&sck_parm,0,&loc_host,0,0,0); if ( !(status & 1) ) { sys$dassgn (chan); return status; } if ( !(iosb.iosb$w_status & 1) ) { sys$dassgn (chan); return iosb.iosb$w_status; } /* ** Get target node IP-address from the logical name */ if ( !(1 & (status = sys$trnlnm (0,&dsc_tbl,&dsc_node,0,&lnms))) ) return status; ibuf[buflen] = '\0'; if ( -1 != (status = inet_addr(ibuf)) ) sock_host.sin_addr.s_addr = inet_addr(ibuf); else if ( hp = gethostbyname(ibuf) ) sock_host.sin_addr.s_addr = *(int *)hp->h_addr; sock_host.sin_port = htons(port); /* ** Prepare REQUEST packet */ ptr->fl = 'S'; // ptr->fl = 'D'; len = sizeof(ptr->fl); /* ** Get process name */ if ( !(1 & (status = sys$getjpiw(EFN$C_ENF,&pid,0,prcnm,0,0,0))) ) return status; len += sizeof(ptr->cprog); /* ** Retrive an URL to sent to target node */ lnms[0].ile3$ps_bufaddr = &ptr->url; lnms[0].ile3$w_length = sizeof(ptr->url); if ( !(1 & (status = sys$trnlnm (0,&dsc_tbl,&dsc_url,0,&lnms))) ) return status; len += buflen; /* ** Queue the read request */ if ( !(1 & (status = sys$qiow (EFN$C_ENF,chan,IO$_WRITEVBLK,&iosb,0,0, ptr,len,&rem_host,0,0,0))) ) sys$dassgn (chan); return (1 & status)?iosb.iosb$w_status:status; } #if 1 int main (void) { int status; status = oes_synch (); return status; } #endif