/* **************************************************************** Copyright (c) 1992, Carnegie Mellon University All Rights Reserved Permission is hereby granted to use, copy, modify, and distribute this software provided that the above copyright notice appears in all copies and that any distribution be for noncommercial purposes. Carnegie Mellon University disclaims all warranties with regard to this software. In no event shall Carnegie Mellon University be liable for any special, indirect, or consequential damages or any damages whatsoever resulting from loss of use, data, or profits arising out of or in connection with the use or performance of this software. **************************************************************** */ /* * RDATE - A program to synchronise time using CMU-OpenVMS/IP * * AUTHOR * Mark Prior, * University Computing Services * University of Adelaide * GPO Box 498 * Adelaide SA 5113 * Australia * * E-mail: mrp@sirius.ua.oz[.au] * * SYNOPSIS * This program uses CMU-OpenVMS/IP to synchronise date/time on a VMS Vax * with a Unix system on the LAN. This emulates the rdate function * available under BSD Unix but uses the formatted port rather than the * binary one. This enables the VMS machines to automatically change * to/from Daylight saving (providing the Unix system has got it right). * * We synchronise all our VMS hosts to a single Unix host once a week (on * a Sunday morning at 4am). * * BUGS/FEATURES * Should check that the time difference is not outrageous. * Should handle more Unix date formats. */ #include #include #include #include #include #include #include #define DAYTIME 13 int SYS$ASSIGN(),SYS$BINTIM(),SYS$QIOW(),SYS$SETIME(),SYS$SNDOPR(); Do_Rdate(HostNm) char *HostNm; { char *p,*host,*strchr(); char date[26],rdate[26],buffer[BUFSIZ],month[4],now[24]; long time_buffer,timadr[2]; int status,day,year,hour,minute,second; short channel; struct { short status,count; long xstatus; } iosb; union { struct OPC opc; char msg[BUFSIZ+8]; } opcmsg; $DESCRIPTOR(ip,"INET$DEVICE"); $DESCRIPTOR(timbuf,now); $DESCRIPTOR(opc,opcmsg.msg); time(&time_buffer); strcpy(date,ctime(&time_buffer)); *strchr(date,'\n') = '\0'; /* * Make a connection to the daytime socket on the Unix machine */ if ((status = SYS$ASSIGN(&ip,&channel,0,0)) != SS$_NORMAL) exit(status); if ((status = SYS$QIOW(0,channel,IO$_CREATE,&iosb,0,0,HostNm,DAYTIME,0,1,0,600)) != SS$_NORMAL) exit(status); if (iosb.status == SS$_ABORT) exit(iosb.xstatus); else if (iosb.status != SS$_NORMAL) exit(iosb.status); /* * Read the time, don't bother to close the channel we will only get * an abort message so why confuse the issue. */ if ((status = SYS$QIOW(0,channel,IO$_READVBLK,&iosb,0,0,rdate,26,0,0,0,0)) != SS$_NORMAL) exit(status); if (iosb.status == SS$_ABORT) exit(iosb.xstatus); else if (iosb.status != SS$_NORMAL) exit(iosb.status); /* * BEWARE: This format is used by 4.3BSD and SunOS 4.0 but is different * on Ultrix V2. Change the format if your Unix host uses another format */ if (sscanf(rdate,"%*s %s %d %d:%d:%d %d\n",month,&day,&hour,&minute,&second,&year) != 6) { fprintf(stderr,"Date returned from %s is of incompatible format\n",HostNm); exit(1); } *strchr(rdate,'\n') = '\0'; for (p = month;*p;p++) *p = toupper(*p); /* * Now change the format to VMS style date/time */ sprintf(now,"%2d-%s-%d %02d:%02d:%02d.00",day,month,year,hour,minute,second); timbuf.dsc$w_length = strlen(now); if ((status = SYS$BINTIM(&timbuf,&timadr)) != SS$_NORMAL) exit(status); if ((status = SYS$SETIME(&timadr)) != SS$_NORMAL) exit(status); sprintf(buffer,"RDATE: Time synchronised with %s.\r\nTime changed from %s to %s.",HostNm,date,rdate); /* * All has gone well so make an operator log that we have modified * the time. */ opcmsg.opc.opc$b_ms_type = OPC$_RQ_RQST; opcmsg.opc.opc$b_ms_target = OPC$M_NM_CENTRL; opcmsg.opc.opc$l_ms_rqstid = 0; strcpy(&opcmsg.msg[8],buffer); opc.dsc$w_length = strlen(buffer)+8; if ((status = SYS$SNDOPR(&opc,0)) != SS$_NORMAL) exit(status); }