FreeBSD/contrib/ntp/ntpd/ntp_leapsec.c
/* ------------------------------------------------------------------ */
/* load a file from a FILE pointer. Note: If hcheck is true, load
 * only after successful signature check. The stream must be seekable
 * or this will fail.
 */
load a file from a FILE pointer. Note: If hcheck is true, load
only after successful signature check. The stream must be seekable
or this will fail.
load a file from a FILE pointer . Note : If hcheck is true load only after successful signature check . The stream must be seekable or this will fail .
int
leapsec_load_stream(
	FILE       * ifp  ,
	const char * fname,
	int  logall)
{
	leap_table_t *pt;
	int           rcheck;
	if (NULL == fname)
		fname = "<unknown>";
	rcheck = leapsec_validate((leapsec_reader)getc, ifp);
	if (logall)
		switch (rcheck)
		{
		case LSVALID_GOODHASH:
			msyslog(LOG_NOTICE, "%s ('%s'): good hash signature",
				logPrefix, fname);
			break;
		case LSVALID_NOHASH:
			msyslog(LOG_ERR, "%s ('%s'): no hash signature",
				logPrefix, fname);
			break;
		case LSVALID_BADHASH:
			msyslog(LOG_ERR, "%s ('%s'): signature mismatch",
				logPrefix, fname);
			break;
		case LSVALID_BADFORMAT:
			msyslog(LOG_ERR, "%s ('%s'): malformed hash signature",
				logPrefix, fname);
			break;
		default:
			msyslog(LOG_ERR, "%s ('%s'): unknown error code %d",
				logPrefix, fname, rcheck);
			break;
		}
	if (rcheck < 0)
		return FALSE;
	rewind(ifp);
	pt = leapsec_get_table(TRUE);
	if (!leapsec_load(pt, (leapsec_reader)getc, ifp, TRUE)) {
		switch (errno) {
		case EINVAL:
			msyslog(LOG_ERR, "%s ('%s'): bad transition time",
				logPrefix, fname);
			break;
		case ERANGE:
			msyslog(LOG_ERR, "%s ('%s'): times not ascending",
				logPrefix, fname);
			break;
		default:
			msyslog(LOG_ERR, "%s ('%s'): parsing error",
				logPrefix, fname);
			break;
		}
		return FALSE;
	}
	if (pt->head.size)
		msyslog(LOG_NOTICE, "%s ('%s'): loaded, expire=%s last=%s ofs=%d",
			logPrefix, fname, lstostr(&pt->head.expire),
			lstostr(&pt->info[0].ttime), pt->info[0].taiof);
	else
		msyslog(LOG_NOTICE,
			"%s ('%s'): loaded, expire=%s ofs=%d (no entries after build date)",
			logPrefix, fname, lstostr(&pt->head.expire),
			pt->head.base_tai);
	return leapsec_set_table(pt);
}
int leapsec_load_stream ( FILE * ifp , const char * fname , int logall ) { leap_table_t * pt ; int rcheck ; if ( NULL == fname ) fname = " " ; rcheck = leapsec_validate ( ( leapsec_reader ) getc , ifp ) ; if ( logall ) switch ( rcheck ) { case LSVALID_GOODHASH : msyslog ( LOG_NOTICE , " " , logPrefix , fname ) ; break ; case LSVALID_NOHASH : msyslog ( LOG_ERR , " " , logPrefix , fname ) ; break ; case LSVALID_BADHASH : msyslog ( LOG_ERR , " " , logPrefix , fname ) ; break ; case LSVALID_BADFORMAT : msyslog ( LOG_ERR , " " , logPrefix , fname ) ; break ; default : msyslog ( LOG_ERR , " " , logPrefix , fname , rcheck ) ; break ; } if ( rcheck < 0 ) return FALSE ; rewind ( ifp ) ; pt = leapsec_get_table ( TRUE ) ; if ( ! leapsec_load ( pt , ( leapsec_reader ) getc , ifp , TRUE ) ) { switch ( errno ) { case EINVAL : msyslog ( LOG_ERR , " " , logPrefix , fname ) ; break ; case ERANGE : msyslog ( LOG_ERR , " " , logPrefix , fname ) ; break ; default : msyslog ( LOG_ERR , " " , logPrefix , fname ) ; break ; } return FALSE ; } if ( pt -> head . size ) msyslog ( LOG_NOTICE , " " , logPrefix , fname , lstostr ( & pt -> head . expire ) , lstostr ( & pt -> info [ 0 ] . ttime ) , pt -> info [ 0 ] . taiof ) ; else msyslog ( LOG_NOTICE , " " , logPrefix , fname , lstostr ( & pt -> head . expire ) , pt -> head . base_tai ) ; return leapsec_set_table ( pt ) ; }
load a file from a FILE pointer.
load a file from a FILE pointer .
/*BOOL*/ /*BOOL*/