Lines Matching +full:is +full:- +full:decoded +full:- +full:cs

2  * ntp_control.c - respond to mode 6 control messages and send async
42 #define NO_REQUEST (-1)
64 #define ctl_putsfp(tag, sfp) ctl_putdblf(tag, 0, -1, \
451 * more-or-less)
682 * is up to the trap receipient to keep resetting it to avoid being
700 * the reference clock driver doesn't set peer->sstclktype to something
823 * init_control - initialize request data
847 * ctl_error - send an error response for the current request
874 sendpkt(rmt_addr, lcl_inter, -2, (void *)&rpkt, in ctl_error()
877 sendpkt(rmt_addr, lcl_inter, -3, (void *)&rpkt, in ctl_error()
885 * daemon might run with special permissions and is remote in is_safe_filename()
890 * base plane or a '_' ([_A-Za-z0-9]), the following characters in is_safe_filename()
891 * must be from [-._+A-Za-z0-9]. in is_safe_filename()
894 * the NTP protocol makes no provisions for UTF-8 or local code in is_safe_filename()
897 * The following table is a packed bit field of 128 two-bit in is_safe_filename()
898 * groups. The LSB in each group tells us if a character is in is_safe_filename()
899 * acceptable at the first position, the MSB if the character is in is_safe_filename()
902 * This does not ensure that the file name is syntactically in is_safe_filename()
934 * save_config - Implements ntpq -c "saveconfig <filename>"
936 * changes by ntpq's :config or config-from-file
939 * processing of file names -- both cause security problems. This is bit
958 /* TALOS-CAN-0062: block directory traversal for VMS, too */ in save_config()
974 * applicable -- only Windows does this...) in save_config()
979 # elif defined(_O_EXCL) /* windows is alway very special... */ in save_config()
1004 stoa(&rbufp->recv_srcadr)); in save_config()
1016 stoa(&rbufp->recv_srcadr)); in save_config()
1022 * buffer size. If the available buffer is too short, bail out; in save_config()
1023 * likewise if there is no file spec. (The latter will not in save_config()
1027 reqlen = (size_t)(reqend - reqpt); in save_config()
1031 reqlen = (size_t)(nulpos - reqpt); in save_config()
1041 stoa(&rbufp->recv_srcadr)); in save_config()
1052 * ntpq -c "saveconfig ntp-%Y%m%d-%H%M%S.conf" in save_config()
1067 * is very likely to fail later if there are format in save_config()
1086 stoa(&rbufp->recv_srcadr)); in save_config()
1095 /* TALOS-CAN-0062: block directory traversal for VMS, too */ in save_config()
1103 stoa(&rbufp->recv_srcadr)); in save_config()
1118 stoa(&rbufp->recv_srcadr)); in save_config()
1123 if (-1 == fd) in save_config()
1128 if (NULL == fptr || -1 == dump_all_config_trees(fptr, 1)) { in save_config()
1133 stoa(&rbufp->recv_srcadr)); in save_config()
1138 fullpath, stoa(&rbufp->recv_srcadr)); in save_config()
1142 * ntpq -c "rv 0 savedconfig" in save_config()
1143 * Note: the way 'savedconfig' is defined makes overflow in save_config()
1155 "saveconfig unavailable, configured with --disable-saveconfig"); in save_config()
1162 * process_control - process an incoming control message
1184 rmt_addr = &rbufp->recv_srcadr; in process_control()
1185 lcl_inter = rbufp->dstadr; in process_control()
1186 pkt = (struct ntp_control *)&rbufp->recv_pkt; in process_control()
1189 * If the length is less than required for the header, in process_control()
1192 if (rbufp->recv_length < (int)CTL_HEADER_LEN) { in process_control()
1199 * If this packet is a response or a fragment, ignore it. in process_control()
1201 if ( (CTL_RESPONSE | CTL_MORE | CTL_ERROR) & pkt->r_m_e_op in process_control()
1202 || pkt->offset != 0) { in process_control()
1204 if (CTL_RESPONSE & pkt->r_m_e_op) in process_control()
1206 if (CTL_MORE & pkt->r_m_e_op) in process_control()
1208 if (CTL_ERROR & pkt->r_m_e_op) in process_control()
1210 if (pkt->offset != 0) in process_control()
1215 res_version = PKT_VERSION(pkt->li_vn_mode); in process_control()
1229 res_opcode = pkt->r_m_e_op; in process_control()
1230 rpkt.sequence = pkt->sequence; in process_control()
1231 rpkt.associd = pkt->associd; in process_control()
1235 res_associd = htons(pkt->associd); in process_control()
1240 req_count = (int)ntohs(pkt->count); in process_control()
1247 if ((rbufp->recv_length & 0x3) != 0) in process_control()
1249 rbufp->recv_length)); in process_control()
1255 req_data = rbufp->recv_length - CTL_HEADER_LEN; in process_control()
1256 if (req_data < req_count || rbufp->recv_length & 0x3) { in process_control()
1266 maclen = rbufp->recv_length - properlen; in process_control()
1267 if ((rbufp->recv_length & 3) == 0 && in process_control()
1274 rbufp->recv_length, properlen, res_keyid, in process_control()
1277 if (!authistrustedip(res_keyid, &rbufp->recv_srcadr)) in process_control()
1280 rbufp->recv_length - maclen, in process_control()
1293 reqpt = (char *)pkt->u.data; in process_control()
1299 for (cc = control_codes; cc->control_code != NO_REQUEST; cc++) { in process_control()
1300 if (cc->control_code == res_opcode) { in process_control()
1303 if (cc->flags == AUTH in process_control()
1309 (cc->handler)(rbufp, restrict_mask); in process_control()
1324 * ctlpeerstatus - return a status word for this peer
1333 status = p->status; in ctlpeerstatus()
1334 if (FLAG_CONFIG & p->flags) in ctlpeerstatus()
1336 if (p->keyid) in ctlpeerstatus()
1338 if (FLAG_AUTHENTIC & p->flags) in ctlpeerstatus()
1340 if (p->reach) in ctlpeerstatus()
1342 if (MDF_TXONLY_MASK & p->cast_flags) in ctlpeerstatus()
1345 return CTL_PEER_STATUS(status, p->num_events, p->last_event); in ctlpeerstatus()
1350 * ctlclkstatus - return a status word for this clock
1358 return CTL_PEER_STATUS(0, pcs->lastevent, pcs->currentstatus); in ctlclkstatus()
1364 * ctlsysstatus - return the system status word
1374 if (CTL_SST_TS_UNSPEC != sys_peer->sstclktype) in ctlsysstatus()
1375 this_clock = sys_peer->sstclktype; in ctlsysstatus()
1376 else if (sys_peer->refclktype < COUNTOF(clocktypes)) in ctlsysstatus()
1377 this_clock = clocktypes[sys_peer->refclktype]; in ctlsysstatus()
1389 * ctl_flushpkt - write out the current packet and prepare
1404 dlen = datapt - rpkt.u.data; in ctl_flushpkt()
1441 ctl_traps[i].tr_localaddr, -4, in ctl_flushpkt()
1453 * is an additional requirement that the MAC in ctl_flushpkt()
1464 sendpkt(rmt_addr, lcl_inter, -5, in ctl_flushpkt()
1467 sendpkt(rmt_addr, lcl_inter, -6, in ctl_flushpkt()
1485 /* --------------------------------------------------------------------
1486 * block transfer API -- stream string/data fragments into xmit buffer
1491 * 'buf' may only be NULL when 'len' is zero!
1498 /* put ctl data in a gather-style operation */
1503 int/*BOOL*/ bin /* set to 1 when data is binary */ in ctl_putdata_ex()
1543 cur_len = (size_t)(dataend - datapt); in ctl_putdata_ex()
1554 src_len -= cur_len; in ctl_putdata_ex()
1557 cur_len = (size_t)(dataend - datapt); in ctl_putdata_ex()
1569 * ctl_putdata - write data into the packet, fragmenting and starting
1570 * another if this one is full.
1576 int bin /* set to 1 when data is binary */ in ctl_putdata()
1587 * ctl_putstr - write a tagged string into the response packet
1592 * len is the data length excluding the NUL terminator,
1623 * ctl_putunqstr - write a tagged string into the response packet
1628 * len is the data length excluding the NUL terminator.
1655 * ctl_putdblf - write a tagged, signed double into the response packet
1676 * ctl_putuint - write a tagged unsigned integer into the response
1693 * ctl_putcal - write a decoded calendar data into the response.
1708 pcal->year, pcal->month, pcal->monthday, in ctl_putcal()
1709 pcal->hour, pcal->minute in ctl_putcal()
1717 * ctl_putfs - write a decoded filestamp into the response
1728 time_t fstamp = (time_t)uval - JAN_1970; in ctl_putfs()
1736 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, in ctl_putfs()
1737 tm->tm_hour, tm->tm_min); in ctl_putfs()
1744 * ctl_puthex - write a tagged unsigned integer, in hex, into the
1763 * ctl_putint - write a tagged signed integer into the response
1781 * ctl_putts - write a tagged timestamp, in hex, into the response
1794 (u_long)ts->l_ui, (u_long)ts->l_uf); in ctl_putts()
1801 * ctl_putadr - write an IP address into the response
1821 * ctl_putrefid - send a u_int32 refid as printable text
1847 * ctl_putarray - write a tagged eight element double array into the response
1866 i--; in ctl_putarray()
1867 rc = snprintf(cp, (size_t)(ep - cp), " %.2f", arr[i] * 1e3); in ctl_putarray()
1868 INSIST(rc >= 0 && (size_t)rc < (size_t)(ep - cp)); in ctl_putarray()
1871 ctl_putunqstr(tag, buffer, (size_t)(cp - buffer)); in ctl_putarray()
1875 * ctl_printf - put a formatted string into the data buffer
1892 strcpy(fmtbuf + sizeof(fmtbuf) - strlen(ellipsis) - 1, in ctl_printf()
1899 * ctl_putsys - output a system variable
1920 * CS_K_* variables depend on up-to-date output of ntp_adjtime() in ctl_putsys()
1976 sys_peer->associd); in ctl_putsys()
1980 if (sys_peer != NULL && sys_peer->dstadr != NULL) in ctl_putsys()
1981 ss = sptoa(&sys_peer->srcadr); in ctl_putsys()
1989 ? sys_peer->hmode in ctl_putsys()
2018 sizeof(str_processor) - 1); in ctl_putsys()
2028 sizeof(str_system) - 1); in ctl_putsys()
2058 if (strlen(sys_var[CS_VARLIST].text) > (sizeof(buf) - 4)) in ctl_putsys()
2064 for (k = sys_var; !(k->flags & EOV); k++) { in ctl_putsys()
2065 if (k->flags & PADDING) in ctl_putsys()
2067 len = strlen(k->text); in ctl_putsys()
2068 if (len + 1 >= buffend - buffp) in ctl_putsys()
2074 memcpy(buffp, k->text, len); in ctl_putsys()
2078 for (k = ext_sys_var; k && !(k->flags & EOV); k++) { in ctl_putsys()
2079 if (k->flags & PADDING) in ctl_putsys()
2081 if (NULL == k->text) in ctl_putsys()
2083 ss1 = strchr(k->text, '='); in ctl_putsys()
2085 len = strlen(k->text); in ctl_putsys()
2087 len = ss1 - k->text; in ctl_putsys()
2088 if (len + 1 >= buffend - buffp) in ctl_putsys()
2094 memcpy(buffp, k->text,(unsigned)len); in ctl_putsys()
2097 if (2 >= buffend - buffp) in ctl_putsys()
2103 ctl_putdata(buf, (unsigned)( buffp - buf ), 0); in ctl_putsys()
2158 if (kb - u >= 0.5) in ctl_putsys()
2182 if (kb - u >= 0.5) in ctl_putsys()
2193 current_time - sys_stattime); in ctl_putsys()
2287 current_time - auth_timereset); in ctl_putsys()
2291 * CTL_IF_KERNLOOP() puts a zero if the kernel loop is in ctl_putsys()
2304 * loop is unavailable, or kernel hard PPS is not in ctl_putsys()
2321 (sys_var[varid].text, 0, -1, in ctl_putsys()
2439 current_time - io_timereset); in ctl_putsys()
2488 current_time - timer_timereset); in ctl_putsys()
2546 for (cp = cinfo; cp != NULL; cp = cp->link) { in ctl_putsys()
2548 cp->subject, cp->issuer, cp->flags); in ctl_putsys()
2551 ctl_putcal(sys_var[CS_REVTIME].text, &(cp->last)); in ctl_putsys()
2569 * ctl_putpeer - output a peer variable
2593 !(FLAG_PREEMPT & p->flags)); in ctl_putpeer()
2597 ctl_putuint(peer_var[id].text, !(p->keyid)); in ctl_putpeer()
2602 !!(FLAG_AUTHENTIC & p->flags)); in ctl_putpeer()
2606 ctl_putadr(peer_var[id].text, 0, &p->srcadr); in ctl_putpeer()
2610 ctl_putuint(peer_var[id].text, SRCPORT(&p->srcadr)); in ctl_putpeer()
2614 if (p->hostname != NULL) in ctl_putpeer()
2615 ctl_putstr(peer_var[id].text, p->hostname, in ctl_putpeer()
2616 strlen(p->hostname)); in ctl_putpeer()
2621 (p->dstadr != NULL) in ctl_putpeer()
2622 ? &p->dstadr->sin in ctl_putpeer()
2628 (p->dstadr != NULL) in ctl_putpeer()
2629 ? SRCPORT(&p->dstadr->sin) in ctl_putpeer()
2634 if (p->r21 > 0.) in ctl_putpeer()
2635 ctl_putdbl(peer_var[id].text, p->r21 / 1e3); in ctl_putpeer()
2639 if (p->r34 > 0.) in ctl_putpeer()
2640 ctl_putdbl(peer_var[id].text, p->r34 / 1e3); in ctl_putpeer()
2644 ctl_putuint(peer_var[id].text, p->throttle); in ctl_putpeer()
2648 ctl_putuint(peer_var[id].text, p->leap); in ctl_putpeer()
2652 ctl_putuint(peer_var[id].text, p->hmode); in ctl_putpeer()
2656 ctl_putuint(peer_var[id].text, p->stratum); in ctl_putpeer()
2660 ctl_putuint(peer_var[id].text, p->ppoll); in ctl_putpeer()
2664 ctl_putuint(peer_var[id].text, p->hpoll); in ctl_putpeer()
2668 ctl_putint(peer_var[id].text, p->precision); in ctl_putpeer()
2672 ctl_putdbl(peer_var[id].text, p->rootdelay * 1e3); in ctl_putpeer()
2676 ctl_putdbl(peer_var[id].text, p->rootdisp * 1e3); in ctl_putpeer()
2681 if (p->flags & FLAG_REFCLOCK) { in ctl_putpeer()
2682 ctl_putrefid(peer_var[id].text, p->refid); in ctl_putpeer()
2686 if (REFID_ISTEXT(p->stratum)) in ctl_putpeer()
2687 ctl_putrefid(peer_var[id].text, p->refid); in ctl_putpeer()
2689 ctl_putadr(peer_var[id].text, p->refid, NULL); in ctl_putpeer()
2693 ctl_putts(peer_var[id].text, &p->reftime); in ctl_putpeer()
2697 ctl_putts(peer_var[id].text, &p->aorg); in ctl_putpeer()
2701 ctl_putts(peer_var[id].text, &p->dst); in ctl_putpeer()
2705 if (p->xleave) in ctl_putpeer()
2706 ctl_putdbl(peer_var[id].text, p->xleave * 1e3); in ctl_putpeer()
2710 if (p->bias != 0.) in ctl_putpeer()
2711 ctl_putdbl(peer_var[id].text, p->bias * 1e3); in ctl_putpeer()
2715 ctl_puthex(peer_var[id].text, p->reach); in ctl_putpeer()
2719 ctl_puthex(peer_var[id].text, p->flash); in ctl_putpeer()
2724 if (p->flags & FLAG_REFCLOCK) { in ctl_putpeer()
2725 ctl_putuint(peer_var[id].text, p->ttl); in ctl_putpeer()
2729 if (p->ttl > 0 && p->ttl < COUNTOF(sys_ttl)) in ctl_putpeer()
2731 sys_ttl[p->ttl]); in ctl_putpeer()
2735 ctl_putuint(peer_var[id].text, p->unreach); in ctl_putpeer()
2740 p->nextdate - current_time); in ctl_putpeer()
2744 ctl_putdbl(peer_var[id].text, p->delay * 1e3); in ctl_putpeer()
2748 ctl_putdbl(peer_var[id].text, p->offset * 1e3); in ctl_putpeer()
2752 ctl_putdbl(peer_var[id].text, p->jitter * 1e3); in ctl_putpeer()
2756 ctl_putdbl(peer_var[id].text, p->disp * 1e3); in ctl_putpeer()
2760 if (p->keyid > NTP_MAXKEY) in ctl_putpeer()
2761 ctl_puthex(peer_var[id].text, p->keyid); in ctl_putpeer()
2763 ctl_putuint(peer_var[id].text, p->keyid); in ctl_putpeer()
2767 ctl_putarray(peer_var[id].text, p->filter_delay, in ctl_putpeer()
2768 p->filter_nextpt); in ctl_putpeer()
2772 ctl_putarray(peer_var[id].text, p->filter_offset, in ctl_putpeer()
2773 p->filter_nextpt); in ctl_putpeer()
2777 ctl_putarray(peer_var[id].text, p->filter_disp, in ctl_putpeer()
2778 p->filter_nextpt); in ctl_putpeer()
2782 ctl_putuint(peer_var[id].text, p->pmode); in ctl_putpeer()
2786 ctl_putuint(peer_var[id].text, p->received); in ctl_putpeer()
2790 ctl_putuint(peer_var[id].text, p->sent); in ctl_putpeer()
2802 for (k = peer_var; !(EOV & k->flags); k++) { in ctl_putpeer()
2803 if (PADDING & k->flags) in ctl_putpeer()
2805 i = strlen(k->text); in ctl_putpeer()
2810 memcpy(s, k->text, i); in ctl_putpeer()
2816 ctl_putdata(buf, (u_int)(s - buf), 0); in ctl_putpeer()
2822 current_time - p->timereceived); in ctl_putpeer()
2827 current_time - p->timereachable); in ctl_putpeer()
2831 ctl_putuint(peer_var[id].text, p->badauth); in ctl_putpeer()
2835 ctl_putuint(peer_var[id].text, p->bogusorg); in ctl_putpeer()
2839 ctl_putuint(peer_var[id].text, p->oldpkt); in ctl_putpeer()
2843 ctl_putuint(peer_var[id].text, p->seldisptoolarge); in ctl_putpeer()
2847 ctl_putuint(peer_var[id].text, p->selbroken); in ctl_putpeer()
2851 ctl_putuint(peer_var[id].text, p->status); in ctl_putpeer()
2855 if (p->crypto) in ctl_putpeer()
2856 ctl_puthex(peer_var[id].text, p->crypto); in ctl_putpeer()
2860 if (p->crypto) { in ctl_putpeer()
2861 dp = EVP_get_digestbynid(p->crypto >> 16); in ctl_putpeer()
2868 if (p->subject != NULL) in ctl_putpeer()
2869 ctl_putstr(peer_var[id].text, p->subject, in ctl_putpeer()
2870 strlen(p->subject)); in ctl_putpeer()
2877 if (NULL == (ap = p->recval.ptr)) in ctl_putpeer()
2880 ctl_putint(peer_var[CP_INITSEQ].text, ap->seq); in ctl_putpeer()
2881 ctl_puthex(peer_var[CP_INITKEY].text, ap->key); in ctl_putpeer()
2883 ntohl(p->recval.tstamp)); in ctl_putpeer()
2887 if (p->ident != NULL) in ctl_putpeer()
2888 ctl_putstr(peer_var[id].text, p->ident, in ctl_putpeer()
2889 strlen(p->ident)); in ctl_putpeer()
2900 * ctl_putclock - output clock variables
2918 if (mustput || pcs->clockdesc == NULL in ctl_putclock()
2919 || *(pcs->clockdesc) == '\0') { in ctl_putclock()
2920 ctl_putuint(clock_var[id].text, pcs->type); in ctl_putclock()
2925 pcs->p_lastcode, in ctl_putclock()
2926 (unsigned)pcs->lencode); in ctl_putclock()
2930 ctl_putuint(clock_var[id].text, pcs->polls); in ctl_putclock()
2935 pcs->noresponse); in ctl_putclock()
2940 pcs->badformat); in ctl_putclock()
2945 pcs->baddata); in ctl_putclock()
2949 if (mustput || (pcs->haveflags & CLK_HAVETIME1)) in ctl_putclock()
2951 pcs->fudgetime1 * 1e3); in ctl_putclock()
2955 if (mustput || (pcs->haveflags & CLK_HAVETIME2)) in ctl_putclock()
2957 pcs->fudgetime2 * 1e3); in ctl_putclock()
2961 if (mustput || (pcs->haveflags & CLK_HAVEVAL1)) in ctl_putclock()
2963 pcs->fudgeval1); in ctl_putclock()
2967 /* RefID of clocks are always text even if stratum is fudged */ in ctl_putclock()
2968 if (mustput || (pcs->haveflags & CLK_HAVEVAL2)) in ctl_putclock()
2969 ctl_putrefid(clock_var[id].text, pcs->fudgeval2); in ctl_putclock()
2973 ctl_putuint(clock_var[id].text, pcs->flags); in ctl_putclock()
2977 if (pcs->clockdesc == NULL || in ctl_putclock()
2978 *(pcs->clockdesc) == '\0') { in ctl_putclock()
2984 pcs->clockdesc, in ctl_putclock()
2985 strlen(pcs->clockdesc)); in ctl_putclock()
3001 for (k = clock_var; !(EOV & k->flags); k++) { in ctl_putclock()
3002 if (PADDING & k->flags) in ctl_putclock()
3005 i = strlen(k->text); in ctl_putclock()
3011 memcpy(s, k->text, i); in ctl_putclock()
3015 for (k = pcs->kv_list; k && !(EOV & k->flags); k++) { in ctl_putclock()
3016 if (PADDING & k->flags) in ctl_putclock()
3019 ss = k->text; in ctl_putclock()
3025 i = ss - k->text; in ctl_putclock()
3031 memcpy(s, k->text, (unsigned)i); in ctl_putclock()
3040 ctl_putdata(buf, (unsigned)(s - buf), 0); in ctl_putclock()
3044 if (mustput || (pcs->haveflags & CLK_HAVEMINJIT)) in ctl_putclock()
3046 pcs->fudgeminjitter * 1e3); in ctl_putclock()
3059 * ctl_getitem - get the next data item from the incoming packet
3069 * the result is NULL once, it will never be EOV again for this in ctl_getitem()
3071 * variable is found and processed in a given 'var_list'. (That in ctl_getitem()
3072 * is, a result is returned that is neither NULL nor EOV). in ctl_getitem()
3111 while (plhead != pltail && isspace((u_char)pltail[-1])) in ctl_getitem()
3112 --pltail; in ctl_getitem()
3115 plsize = (size_t)(pltail - plhead); in ctl_getitem()
3124 /* no payload, current end --> current name termination */ in ctl_getitem()
3130 * Now we're sure that the packet data itself is sane. Scan the in ctl_getitem()
3131 * list now. Make sure a NULL list is properly treated by in ctl_getitem()
3132 * returning a synthetic End-Of-Values record. We must not in ctl_getitem()
3142 for (v = var_list; !(EOV & v->flags); ++v) in ctl_getitem()
3143 if (!(PADDING & v->flags)) { in ctl_getitem()
3145 * name is bracketed by [reqpt..tp] and not NUL in ctl_getitem()
3147 * lookup value IS NUL-terminated but might in ctl_getitem()
3152 const char *sp2 = v->text; in ctl_getitem()
3168 if (EOV & v->flags) in ctl_getitem()
3190 * control_unspec - response to an unspecified op-code
3202 * What is an appropriate response to an unspecified op-code? in control_unspec()
3220 * read_status - return either a list of associd's, or a particular
3241 * Two choices here. If the specified association ID is in read_status()
3253 peer->num_events = 0; in read_status()
3265 for (peer = peer_list; peer != NULL; peer = peer->p_link) { in read_status()
3266 a_st[n++] = htons(peer->associd); in read_status()
3282 * read_peervars - half of read_variables() implementation
3306 peer->num_events = 0; in read_peervars()
3310 if (v->flags & EOV) { in read_peervars()
3314 INSIST(v->code < COUNTOF(wants)); in read_peervars()
3315 wants[v->code] = 1; in read_peervars()
3330 * read_sysvars - half of read_variables() implementation
3339 const u_char *cs; in read_sysvars() local
3356 if (!(EOV & v->flags)) { in read_sysvars()
3357 INSIST(v->code < wants_count); in read_sysvars()
3358 wants[v->code] = 1; in read_sysvars()
3367 if (EOV & v->flags) { in read_sysvars()
3372 n = v->code + CS_MAXCODE + 1; in read_sysvars()
3388 for (cs = def_sys_var; *cs != 0; cs++) in read_sysvars()
3389 ctl_putsys((int)*cs); in read_sysvars()
3390 for (kv = ext_sys_var; kv && !(EOV & kv->flags); kv++) in read_sysvars()
3391 if (DEF & kv->flags) in read_sysvars()
3392 ctl_putdata(kv->text, strlen(kv->text), in read_sysvars()
3401 * read_variables - return the variables the caller asks for
3418 * write_variables - write into variables. We only allow leap bit
3457 if (v->flags & EOV) { in write_variables()
3460 if (v->flags & EOV) { in write_variables()
3469 if (!(v->flags & CAN_WRITE)) { in write_variables()
3492 octets = strlen(v->text) + strlen(valuep) + 2; in write_variables()
3495 t = v->text; in write_variables()
3500 set_sys_var(vareqv, 1 + strlen(vareqv), v->flags); in write_variables()
3524 * configure() processes ntpq :config/config-from-file, allowing
3536 * Hence check if the association id is 0 in configure()
3553 stoa(&rbufp->recv_srcadr)); in configure()
3561 if (data_count > sizeof(remote_config.buffer) - 2) { in configure()
3570 stoa(&rbufp->recv_srcadr)); in configure()
3573 /* Bug 2853 -- check if all characters were acceptable */ in configure()
3574 if (data_count != (size_t)(reqend - reqpt)) { in configure()
3583 stoa(&rbufp->recv_srcadr), in configure()
3597 stoa(&rbufp->recv_srcadr), in configure()
3600 /* Now we have to make sure there is a NL/NUL sequence at the in configure()
3608 config_remotely(&rbufp->recv_srcadr); in configure()
3631 stoa(&rbufp->recv_srcadr)); in configure()
3636 * derive_nonce - generate 32-bit nonce value derived from the client
3637 * address and a request-specific timestamp.
3639 * This uses MD5 for a non-authentication purpose -- the nonce is used
3640 * analogous to the TCP 3-way handshake to confirm the UDP client can
3641 * receive traffic from which it claims to originate, that is, to
3658 while (!salt[0] || current_time - last_salt_update >= 3600) { in derive_nonce()
3684 * generate_nonce - generate client-address-specific nonce string.
3694 derived = derive_nonce(&rbufp->recv_srcadr, in generate_nonce()
3695 rbufp->recv_time.l_ui, in generate_nonce()
3696 rbufp->recv_time.l_uf); in generate_nonce()
3698 rbufp->recv_time.l_ui, rbufp->recv_time.l_uf, derived); in generate_nonce()
3703 * validate_nonce - validate client-address-specific nonce string.
3706 * client-provided value and the timestamp is recent enough.
3725 derived = derive_nonce(&rbufp->recv_srcadr, ts.l_ui, ts.l_uf); in validate_nonce()
3734 * send_random_tag_value - send a randomly-generated three character
3740 * with randomly-generated tag names with correct .# index. Make it
3741 * three characters knowing that none of the currently-used subscripted
3761 snprintf(&buf[4], sizeof(buf) - 4, "%d", indx); in send_random_tag_value()
3767 * Send a MRU list entry in response to a "ntpq -c mrulist" operation.
3772 * the order is random.
3804 pch = sptoa(&mon->rmtadr); in send_mru_entry()
3810 ctl_putts(tag, &mon->last); in send_mru_entry()
3815 ctl_putts(tag, &mon->first); in send_mru_entry()
3820 ctl_putint(tag, mon->count); in send_mru_entry()
3825 ctl_putuint(tag, mon->vn_mode); in send_mru_entry()
3830 ctl_puthex(tag, mon->flags); in send_mru_entry()
3834 remaining--; in send_mru_entry()
3840 * read_mru_list - supports ntpq's mrulist command.
3842 * The challenge here is to match ntpdc's monlist functionality without
3850 * packets lost. The entries are retrieved oldest-first, taking into
3855 * response was sent by ntpd. The only difference is it may be longer,
3862 * after the first request is supplied as a series of last seen
3866 * Otherwise, the request is failed and it is up to ntpq to back up and
3879 * limit=1 is a special case: Instead of fetching
3884 * address. When limit is not one and frags= is
3888 * address given. No port specification is needed,
3889 * and any supplied is ignored.
3890 * resall= 0x-prefixed hex restrict bits which must all be
3893 * resany= 0x-prefixed hex restrict bits, at least one of
3896 * last.0= 0x-prefixed hex l_fp timestamp of newest entry
3908 * followup request. Following the nonce is the next newer entry than
3940 * on all *.0 values preceding any *.1 values, that is all values for
3943 * The end of the response list is noted with one or two tag=value
3946 * now= 0x-prefixed l_fp timestamp at the server marking
3949 * If any entries were returned, now= is followed by:
4002 stoa(&rbufp->recv_srcadr)); in read_mru_list()
4042 !(EOV & v->flags)) { in read_mru_list()
4048 if (!strcmp(nonce_text, v->text)) { in read_mru_list()
4051 } else if (!strcmp(frags_text, v->text)) { in read_mru_list()
4054 } else if (!strcmp(limit_text, v->text)) { in read_mru_list()
4057 } else if (!strcmp(mincount_text, v->text)) { in read_mru_list()
4062 } else if (!strcmp(resall_text, v->text)) { in read_mru_list()
4065 } else if (!strcmp(resany_text, v->text)) { in read_mru_list()
4068 } else if (!strcmp(maxlstint_text, v->text)) { in read_mru_list()
4071 } else if (!strcmp(laddr_text, v->text)) { in read_mru_list()
4075 } else if (1 == sscanf(v->text, last_fmt, &si) && in read_mru_list()
4083 } else if (1 == sscanf(v->text, addr_fmt, &si) && in read_mru_list()
4091 v->text)); in read_mru_list()
4096 v->text, val)); in read_mru_list()
4105 /* return no responses until the nonce is validated */ in read_mru_list()
4121 * If either frags or limit is not given, use the max. in read_mru_list()
4136 mon = mon->hash_next) in read_mru_list()
4137 if (ADDR_PORT_EQ(&mon->rmtadr, &addr[i])) in read_mru_list()
4140 if (L_ISEQU(&mon->last, &last[i])) in read_mru_list()
4155 ctl_putts("last.older", &mon->last); in read_mru_list()
4156 pch = sptoa(&mon->rmtadr); in read_mru_list()
4181 if (mon->count < mincount) in read_mru_list()
4183 if (resall && resall != (resall & mon->flags)) in read_mru_list()
4185 if (resany && !(resany & mon->flags)) in read_mru_list()
4187 if (maxlstint > 0 && now.l_ui - mon->last.l_ui > in read_mru_list()
4190 if (lcladr != NULL && mon->lcladr != lcladr) in read_mru_list()
4206 send_random_tag_value(count - 1); in read_mru_list()
4210 ctl_putts("last.newest", &prior_mon->last); in read_mru_list()
4217 * Send a ifstats entry in response to a "ntpq -c ifstats" request.
4222 * the order is random.
4261 noisebits -= 4; in send_ifstats_entry()
4270 pch = sptoa(&la->sin); in send_ifstats_entry()
4276 if (INT_BCASTOPEN & la->flags) in send_ifstats_entry()
4277 pch = sptoa(&la->bcast); in send_ifstats_entry()
4285 ctl_putint(tag, !la->ignore_packets); in send_ifstats_entry()
4290 ctl_putstr(tag, la->name, strlen(la->name)); in send_ifstats_entry()
4295 ctl_puthex(tag, (u_int)la->flags); in send_ifstats_entry()
4300 ctl_putint(tag, la->last_ttl); in send_ifstats_entry()
4305 ctl_putint(tag, la->num_mcast); in send_ifstats_entry()
4310 ctl_putint(tag, la->received); in send_ifstats_entry()
4315 ctl_putint(tag, la->sent); in send_ifstats_entry()
4320 ctl_putint(tag, la->notsent); in send_ifstats_entry()
4325 ctl_putuint(tag, la->peercnt); in send_ifstats_entry()
4330 ctl_putuint(tag, current_time - la->starttime); in send_ifstats_entry()
4334 remaining--; in send_ifstats_entry()
4341 * read_ifstats - send statistics for each local address, exposed by
4342 * ntpq -c ifstats
4357 for (la = ep_list; la != NULL; la = la->elink) in read_ifstats()
4358 if (ifidx == la->ifnum) in read_ifstats()
4379 psaA->sa.sa_family = AF_INET; in sockaddrs_from_restrict_u()
4380 psaA->sa4.sin_addr.s_addr = htonl(pres->u.v4.addr); in sockaddrs_from_restrict_u()
4381 psaM->sa.sa_family = AF_INET; in sockaddrs_from_restrict_u()
4382 psaM->sa4.sin_addr.s_addr = htonl(pres->u.v4.mask); in sockaddrs_from_restrict_u()
4384 psaA->sa.sa_family = AF_INET6; in sockaddrs_from_restrict_u()
4385 memcpy(&psaA->sa6.sin6_addr, &pres->u.v6.addr, in sockaddrs_from_restrict_u()
4386 sizeof(psaA->sa6.sin6_addr)); in sockaddrs_from_restrict_u()
4387 psaM->sa.sa_family = AF_INET6; in sockaddrs_from_restrict_u()
4388 memcpy(&psaM->sa6.sin6_addr, &pres->u.v6.mask, in sockaddrs_from_restrict_u()
4389 sizeof(psaA->sa6.sin6_addr)); in sockaddrs_from_restrict_u()
4395 * Send a restrict entry in response to a "ntpq -c reslist" request.
4400 * the order is random.
4438 noisebits -= 2; in send_restrict_entry()
4460 ctl_putuint(tag, pres->count); in send_restrict_entry()
4465 match_str = res_match_flags(pres->mflags); in send_restrict_entry()
4466 access_str = res_access_flags(pres->rflags); in send_restrict_entry()
4479 remaining--; in send_restrict_entry()
4492 for ( ; pres != NULL; pres = pres->link) { in send_restrict_list()
4500 * read_addr_restrictions - returns IPv4 and IPv6 access control lists
4517 * read_ordlist - CTL_OP_READ_ORDLIST_A for ntpq -c ifstats & reslist
4526 const size_t ifstats_chars = COUNTOF(ifstats_s) - 1; in read_ordlist()
4528 const size_t a_r_chars = COUNTOF(addr_rst_s) - 1; in read_ordlist()
4534 * used only for ntpq -c ifstats. With the addition of reslist in read_ordlist()
4536 * which require authentication. The request data is empty or in read_ordlist()
4538 * addresses and associated stats. It is "addr_restrictions" in read_ordlist()
4543 cpkt = (struct ntp_control *)&rbufp->recv_pkt; in read_ordlist()
4544 qdata_octets = ntohs(cpkt->count); in read_ordlist()
4546 !memcmp(ifstats_s, cpkt->u.data, ifstats_chars))) { in read_ordlist()
4551 !memcmp(addr_rst_s, cpkt->u.data, a_r_chars)) { in read_ordlist()
4560 * req_nonce - CTL_OP_REQ_NONCE for ntpq -c mrulist prerequisite.
4576 * read_clockstatus - return clock radio status
4600 struct refclockstat cs; in read_clockstatus()
4607 * is a clock use it, else search peer_list for one. in read_clockstatus()
4610 sys_peer->flags)) in read_clockstatus()
4615 peer = peer->p_link) in read_clockstatus()
4616 if (FLAG_REFCLOCK & peer->flags) in read_clockstatus()
4619 if (NULL == peer || !(FLAG_REFCLOCK & peer->flags)) { in read_clockstatus()
4624 * If we got here we have a peer which is a clock. Get his in read_clockstatus()
4627 cs.kv_list = NULL; in read_clockstatus()
4628 refclock_control(&peer->srcadr, NULL, &cs); in read_clockstatus()
4629 kv = cs.kv_list; in read_clockstatus()
4633 rpkt.status = htons(ctlclkstatus(&cs)); in read_clockstatus()
4638 if (!(EOV & v->flags)) { in read_clockstatus()
4639 wants[v->code] = TRUE; in read_clockstatus()
4646 free_varlist(cs.kv_list); in read_clockstatus()
4649 if (EOV & v->flags) { in read_clockstatus()
4652 free_varlist(cs.kv_list); in read_clockstatus()
4655 wants[CC_MAXCODE + 1 + v->code] = TRUE; in read_clockstatus()
4663 ctl_putclock(i, &cs, TRUE); in read_clockstatus()
4672 ctl_putclock((int)*cc, &cs, FALSE); in read_clockstatus()
4673 for ( ; kv != NULL && !(EOV & kv->flags); kv++) in read_clockstatus()
4674 if (DEF & kv->flags) in read_clockstatus()
4675 ctl_putdata(kv->text, strlen(kv->text), in read_clockstatus()
4680 free_varlist(cs.kv_list); in read_clockstatus()
4688 * write_clockstatus - we don't do this
4706 * set_trap - set a trap in response to a control message
4717 * See if this guy is allowed in set_trap()
4735 if (!ctlsettrap(&rbufp->recv_srcadr, rbufp->dstadr, traptype, in set_trap()
4743 * unset_trap - unset a trap in response to a control message
4755 * trap is configured. Note we also must be aware of the in unset_trap()
4766 if (!ctlclrtrap(&rbufp->recv_srcadr, rbufp->dstadr, traptype)) in unset_trap()
4773 * ctlsettrap - called to set a trap
4795 tp->tr_flags = TRAP_INUSE|TRAP_CONFIGURED; in ctlsettrap()
4799 if (tp->tr_flags & TRAP_CONFIGURED) in ctlsettrap()
4801 tp->tr_flags = TRAP_INUSE; in ctlsettrap()
4805 if (tp->tr_flags & TRAP_CONFIGURED) in ctlsettrap()
4807 tp->tr_flags = TRAP_INUSE|TRAP_NONPRIO; in ctlsettrap()
4810 tp->tr_settime = current_time; in ctlsettrap()
4811 tp->tr_resets++; in ctlsettrap()
4823 if ((TRAP_INUSE & tp->tr_flags) && in ctlsettrap()
4824 !(TRAP_CONFIGURED & tp->tr_flags) && in ctlsettrap()
4825 ((tp->tr_settime + CTL_TRAPTIME) > current_time)) { in ctlsettrap()
4826 tp->tr_flags = 0; in ctlsettrap()
4827 num_ctl_traps--; in ctlsettrap()
4829 if (!(TRAP_INUSE & tp->tr_flags)) { in ctlsettrap()
4831 } else if (!(TRAP_CONFIGURED & tp->tr_flags)) { in ctlsettrap()
4839 if ((TRAP_NONPRIO & tptouse->tr_flags) && in ctlsettrap()
4840 !(TRAP_NONPRIO & tp->tr_flags)) in ctlsettrap()
4843 if (!(TRAP_NONPRIO & tptouse->tr_flags) in ctlsettrap()
4844 && (TRAP_NONPRIO & tp->tr_flags)) { in ctlsettrap()
4848 if (tptouse->tr_origtime < in ctlsettrap()
4849 tp->tr_origtime) in ctlsettrap()
4854 if ( TRAP_NONPRIO & tp->tr_flags) { in ctlsettrap()
4857 tptouse->tr_flags) && in ctlsettrap()
4858 tptouse->tr_origtime < in ctlsettrap()
4859 tp->tr_origtime)) in ctlsettrap()
4879 tptouse->tr_settime = tptouse->tr_origtime = current_time; in ctlsettrap()
4880 tptouse->tr_count = tptouse->tr_resets = 0; in ctlsettrap()
4881 tptouse->tr_sequence = 1; in ctlsettrap()
4882 tptouse->tr_addr = *raddr; in ctlsettrap()
4883 tptouse->tr_localaddr = linter; in ctlsettrap()
4884 tptouse->tr_version = (u_char) version; in ctlsettrap()
4885 tptouse->tr_flags = TRAP_INUSE; in ctlsettrap()
4887 tptouse->tr_flags |= TRAP_CONFIGURED; in ctlsettrap()
4889 tptouse->tr_flags |= TRAP_NONPRIO; in ctlsettrap()
4896 * ctlclrtrap - called to clear a trap
4910 if (tp->tr_flags & TRAP_CONFIGURED in ctlclrtrap()
4914 tp->tr_flags = 0; in ctlclrtrap()
4915 num_ctl_traps--; in ctlclrtrap()
4921 * ctlfindtrap - find a trap given the remote and local addresses
4942 * report_event - report an event to the trappers
4977 snprintf(statstr + len, sizeof(statstr) - len, in report_event()
4992 if (peer->last_event != errlast) in report_event()
4993 peer->num_events = 0; in report_event()
4994 if (peer->num_events >= CTL_PEER_MAXEVENTS) in report_event()
4997 peer->last_event = errlast; in report_event()
4998 peer->num_events++; in report_event()
4999 if (ISREFCLOCKADR(&peer->srcadr)) in report_event()
5000 src = refnumtoa(&peer->srcadr); in report_event()
5002 src = stoa(&peer->srcadr); in report_event()
5009 snprintf(statstr + len, sizeof(statstr) - len, in report_event()
5028 * Peer Events should be associated with a peer -- hence the in report_event()
5029 * name. But there are instances where this function is called in report_event()
5031 * CryptoNAK, or when a leap second alarm is going off while in report_event()
5037 * and this is probably not the best of all options. in report_event()
5038 * -*-perlinger@ntp.org-*- in report_event()
5059 } else if (NULL != peer) { /* paranoia -- skip output */ in report_event()
5060 rpkt.associd = htons(peer->associd); in report_event()
5072 struct refclockstat cs; in report_event() local
5075 cs.kv_list = NULL; in report_event()
5076 refclock_control(&peer->srcadr, NULL, &cs); in report_event()
5079 ctlclkstatus(&cs)); in report_event()
5082 ctl_putclock(i, &cs, FALSE); in report_event()
5083 for (kv = cs.kv_list; in report_event()
5084 kv != NULL && !(EOV & kv->flags); in report_event()
5086 if (DEF & kv->flags) in report_event()
5087 ctl_putdata(kv->text, in report_event()
5088 strlen(kv->text), in report_event()
5090 free_varlist(cs.kv_list); in report_event()
5103 * mprintf_event - printf-style varargs variant of report_event()
5127 * ctl_clr_stats - clear stat counters
5161 while (!(EOV & (k++)->flags)) in count_var()
5213 while (!(EOV & k->flags)) { in set_var()
5214 if (NULL == k->text) { in set_var()
5217 k->text = td; in set_var()
5218 k->flags = def; in set_var()
5222 t = k->text; in set_var()
5228 td = erealloc((void *)(intptr_t)k->text, size); in set_var()
5230 k->text = td; in set_var()
5231 k->flags = def; in set_var()
5255 * get_ext_sys_var() retrieves the value of a user-defined variable or
5267 for (v = ext_sys_var; !(EOV & v->flags); v++) { in get_ext_sys_var()
5268 if (NULL != v->text && !memcmp(tag, v->text, c)) { in get_ext_sys_var()
5269 if ('=' == v->text[c]) { in get_ext_sys_var()
5270 val = v->text + c + 1; in get_ext_sys_var()
5272 } else if ('\0' == v->text[c]) { in get_ext_sys_var()
5290 for (k = kv; !(k->flags & EOV); k++) in free_varlist()
5291 free((void *)(intptr_t)k->text); in free_varlist()