FreeBSD/contrib/bsnmp/snmpd/main.c
/*
 * Check USM PDU header credentials against local SNMP Engine & users.
 */
Check USM PDU header credentials against local SNMP Engine & users.
Check USM PDU header credentials against local SNMP Engine & users .
static enum snmp_code
snmp_pdu_auth_user(struct snmp_pdu *pdu)
{
	uint64_t etime;
	usm_user = NULL;
	if (pdu->engine.engine_len == 0 && strlen(pdu->user.sec_name) == 0) {
		pdu->engine.engine_len = snmpd_engine.engine_len;
		memcpy(pdu->engine.engine_id, snmpd_engine.engine_id,
		    snmpd_engine.engine_len);
		pdu->engine.engine_boots = snmpd_engine.engine_boots;
		pdu->engine.engine_time = snmpd_engine.engine_time;
		pdu->flags |= SNMP_MSG_AUTODISCOVER;
		return (SNMP_CODE_OK);
	}
	if ((usm_user = usm_find_user(pdu->engine.engine_id,
	    pdu->engine.engine_len, pdu->user.sec_name)) == NULL ||
	    usm_user->status != 1 )
		return (SNMP_CODE_BADUSER);
	if (usm_user->user_engine_len != snmpd_engine.engine_len ||
	    memcmp(usm_user->user_engine_id, snmpd_engine.engine_id,
	    snmpd_engine.engine_len) != 0)
		return (SNMP_CODE_BADENGINE);
	pdu->user.priv_proto = usm_user->suser.priv_proto;
	memcpy(pdu->user.priv_key, usm_user->suser.priv_key,
	    sizeof(pdu->user.priv_key));
	if ((pdu->flags & SNMP_MSG_AUTH_FLAG) != 0) {
		etime = (get_ticks() - start_tick)  / 100ULL;
		if (etime < INT32_MAX)
			snmpd_engine.engine_time = etime;
		else {
			start_tick = get_ticks();
			set_snmpd_engine();
			snmpd_engine.engine_time = start_tick;
		}
		pdu->user.auth_proto = usm_user->suser.auth_proto;
		memcpy(pdu->user.auth_key, usm_user->suser.auth_key,
		    sizeof(pdu->user.auth_key));
		if (pdu->engine.engine_boots == 0 &&
		    pdu->engine.engine_time == 0) {
		    	pdu->flags |= SNMP_MSG_AUTODISCOVER;
			return (SNMP_CODE_OK);
		}
		if (pdu->engine.engine_boots != snmpd_engine.engine_boots ||
		    abs(pdu->engine.engine_time - snmpd_engine.engine_time) >
		    SNMP_TIME_WINDOW)
			return (SNMP_CODE_NOTINTIME);
	}
	if (((pdu->flags & SNMP_MSG_PRIV_FLAG) != 0 &&
	    (pdu->flags & SNMP_MSG_AUTH_FLAG) == 0) ||
	    ((pdu->flags & SNMP_MSG_AUTH_FLAG) == 0 &&
	    usm_user->suser.auth_proto != SNMP_AUTH_NOAUTH) ||
	    ((pdu->flags & SNMP_MSG_PRIV_FLAG) == 0 &&
	    usm_user->suser.priv_proto != SNMP_PRIV_NOPRIV))
		return (SNMP_CODE_BADSECLEVEL);
	return (SNMP_CODE_OK);
}
static enum snmp_code snmp_pdu_auth_user ( struct snmp_pdu * pdu ) { uint64_t etime ; usm_user = NULL ; if ( pdu -> engine . engine_len == 0 && strlen ( pdu -> user . sec_name ) == 0 ) { pdu -> engine . engine_len = snmpd_engine . engine_len ; memcpy ( pdu -> engine . engine_id , snmpd_engine . engine_id , snmpd_engine . engine_len ) ; pdu -> engine . engine_boots = snmpd_engine . engine_boots ; pdu -> engine . engine_time = snmpd_engine . engine_time ; pdu -> flags |= SNMP_MSG_AUTODISCOVER ; return ( SNMP_CODE_OK ) ; } if ( ( usm_user = usm_find_user ( pdu -> engine . engine_id , pdu -> engine . engine_len , pdu -> user . sec_name ) ) == NULL || usm_user -> status != 1 ) return ( SNMP_CODE_BADUSER ) ; if ( usm_user -> user_engine_len != snmpd_engine . engine_len || memcmp ( usm_user -> user_engine_id , snmpd_engine . engine_id , snmpd_engine . engine_len ) != 0 ) return ( SNMP_CODE_BADENGINE ) ; pdu -> user . priv_proto = usm_user -> suser . priv_proto ; memcpy ( pdu -> user . priv_key , usm_user -> suser . priv_key , sizeof ( pdu -> user . priv_key ) ) ; if ( ( pdu -> flags & SNMP_MSG_AUTH_FLAG ) != 0 ) { etime = ( get_ticks ( ) - start_tick ) / 100ULL ; if ( etime < INT32_MAX ) snmpd_engine . engine_time = etime ; else { start_tick = get_ticks ( ) ; set_snmpd_engine ( ) ; snmpd_engine . engine_time = start_tick ; } pdu -> user . auth_proto = usm_user -> suser . auth_proto ; memcpy ( pdu -> user . auth_key , usm_user -> suser . auth_key , sizeof ( pdu -> user . auth_key ) ) ; if ( pdu -> engine . engine_boots == 0 && pdu -> engine . engine_time == 0 ) { pdu -> flags |= SNMP_MSG_AUTODISCOVER ; return ( SNMP_CODE_OK ) ; } if ( pdu -> engine . engine_boots != snmpd_engine . engine_boots || abs ( pdu -> engine . engine_time - snmpd_engine . engine_time ) > SNMP_TIME_WINDOW ) return ( SNMP_CODE_NOTINTIME ) ; } if ( ( ( pdu -> flags & SNMP_MSG_PRIV_FLAG ) != 0 && ( pdu -> flags & SNMP_MSG_AUTH_FLAG ) == 0 ) || ( ( pdu -> flags & SNMP_MSG_AUTH_FLAG ) == 0 && usm_user -> suser . auth_proto != SNMP_AUTH_NOAUTH ) || ( ( pdu -> flags & SNMP_MSG_PRIV_FLAG ) == 0 && usm_user -> suser . priv_proto != SNMP_PRIV_NOPRIV ) ) return ( SNMP_CODE_BADSECLEVEL ) ; return ( SNMP_CODE_OK ) ; }
Check USM PDU header credentials against local SNMP Engine & users.
Check USM PDU header credentials against local SNMP Engine & users .
/* un-authenticated snmpEngineId discovery */ /* active */ /* authenticated snmpEngineId discovery */