@ -45,11 +45,23 @@ static uint64_t member_read64(const uint8_t* p) {
return n ;
return n ;
}
}
int member_sync_build_owner_msg ( uint64_t node_id , const char * tags , uint8_t * out , size_t capacity ) {
size_t len = tags ? strlen ( tags ) : 0 ;
if ( ! tags | | ! out | | len > MS_ADM_TAGS_MAX | | capacity < len + 8 ) {
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: invalid owner message node=%016llx bytes=%zu capacity=%zu max=%d " ,
MS_ID , ( unsigned long long ) node_id , len , capacity , MS_ADM_TAGS_MAX ) ;
return - 1 ;
}
memcpy ( out , tags , len ) ;
memcpy ( out + len , & node_id , 8 ) ;
return ( int ) len + 8 ;
}
static int _compute_member_hash ( uint64_t node_id , const uint8_t * x25519 , const uint8_t * ed25519 ,
static int _compute_member_hash ( uint64_t node_id , const uint8_t * x25519 , const uint8_t * ed25519 ,
const uint8_t * join_sig , uint64_t join_ts , const uint8_t * update_sig , uint64_t update_ts ,
const uint8_t * join_sig , uint64_t join_ts , const uint8_t * update_sig , uint64_t update_ts ,
const char * userinfo , const char * adm_tags , const uint8_t * adm_tags_sig ,
const char * userinfo , const char * adm_tags , const uint8_t * adm_tags_sig ,
uint64_t signed_by , const uint8_t * signature , uint8_t hash_out [ MT_HASH_SIZE ] ) {
uint64_t signed_by , const uint8_t * signature , uint8_t hash_out [ MT_HASH_SIZE ] ) {
uint8_t data [ 1024 ] ;
uint8_t data [ MS_ADM_TAGS_MAX + 1024 ] ;
size_t off = 0 ;
size_t off = 0 ;
member_write64 ( data + off , node_id ) ; off + = 8 ;
member_write64 ( data + off , node_id ) ; off + = 8 ;
memcpy ( data + off , x25519 , 32 ) ; off + = 32 ;
memcpy ( data + off , x25519 , 32 ) ; off + = 32 ;
@ -59,13 +71,13 @@ static int _compute_member_hash(uint64_t node_id, const uint8_t* x25519, const u
if ( update_sig ) memcpy ( data + off , update_sig , 64 ) ; else memset ( data + off , 0 , 64 ) ;
if ( update_sig ) memcpy ( data + off , update_sig , 64 ) ; else memset ( data + off , 0 , 64 ) ;
off + = 64 ; member_write64 ( data + off , update_ts ) ; off + = 8 ;
off + = 64 ; member_write64 ( data + off , update_ts ) ; off + = 8 ;
size_t ul = userinfo ? strlen ( userinfo ) : 0 , atl = adm_tags ? strlen ( adm_tags ) : 0 ;
size_t ul = userinfo ? strlen ( userinfo ) : 0 , atl = adm_tags ? strlen ( adm_tags ) : 0 ;
if ( ul > 255 | | atl > 255 ) {
if ( ul > 255 | | atl > MS_ADM_TAGS_MAX ) {
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: member strings exceed wire limits node=%016llx " , MS_ID , ( unsigned long long ) node_id ) ;
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: member strings exceed wire limits node=%016llx " , MS_ID , ( unsigned long long ) node_id ) ;
return - 1 ;
return - 1 ;
}
}
data [ off + + ] = ( uint8_t ) ul ;
data [ off + + ] = ( uint8_t ) ul ;
if ( ul ) { memcpy ( data + off , userinfo , ul ) ; off + = ul ; }
if ( ul ) { memcpy ( data + off , userinfo , ul ) ; off + = ul ; }
data [ off + + ] = ( uint8_t ) atl ;
data [ off + + ] = ( uint8_t ) ( atl > > 8 ) ; data [ off + + ] = ( uint8_t ) atl ;
if ( atl ) { memcpy ( data + off , adm_tags , atl ) ; off + = atl ; }
if ( atl ) { memcpy ( data + off , adm_tags , atl ) ; off + = atl ; }
if ( adm_tags_sig ) memcpy ( data + off , adm_tags_sig , 64 ) ; else memset ( data + off , 0 , 64 ) ;
if ( adm_tags_sig ) memcpy ( data + off , adm_tags_sig , 64 ) ; else memset ( data + off , 0 , 64 ) ;
off + = 64 ; member_write64 ( data + off , signed_by ) ; off + = 8 ;
off + = 64 ; member_write64 ( data + off , signed_by ) ; off + = 8 ;
@ -237,15 +249,15 @@ static int _member_get_page(void* ctx, const char* ns, uint64_t prefix, int afte
if ( src ! = 0 ) continue ;
if ( src ! = 0 ) continue ;
if ( ! member_blob ( stmt , 1 , 32 , 0 ) | | ! member_blob ( stmt , 2 , 32 , 0 ) | | ! member_blob ( stmt , 3 , 64 , 1 )
if ( ! member_blob ( stmt , 1 , 32 , 0 ) | | ! member_blob ( stmt , 2 , 32 , 0 ) | | ! member_blob ( stmt , 3 , 64 , 1 )
| | ! member_blob ( stmt , 5 , 64 , 1 ) | | ! member_blob ( stmt , 9 , 64 , 1 ) | | ! member_blob ( stmt , 11 , 64 , 1 )
| | ! member_blob ( stmt , 5 , 64 , 1 ) | | ! member_blob ( stmt , 9 , 64 , 1 ) | | ! member_blob ( stmt , 11 , 64 , 1 )
| | ( nm & & strlen ( nm ) > 255 ) | | ( atags & & strlen ( atags ) > 255 ) ) {
| | ( nm & & strlen ( nm ) > 255 ) | | ( atags & & strlen ( atags ) > MS_ADM_TAGS_MAX ) ) {
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: invalid page record ns=%s node=%016llx " , MS_ID , ns , ( unsigned long long ) nid ) ;
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: invalid page record ns=%s node=%016llx " , MS_ID , ns , ( unsigned long long ) nid ) ;
sqlite3_finalize ( stmt ) ; return - 1 ;
sqlite3_finalize ( stmt ) ; return - 1 ;
}
}
uint8_t nl = nm ? ( uint8_t ) strnlen ( nm , 255 ) : 0 ;
uint8_t nl = nm ? ( uint8_t ) strnlen ( nm , 255 ) : 0 ;
uint8 _t atl = atags ? ( uint8_t ) strn len ( atags , 255 ) : 0 ;
size _t atl = atags ? strlen ( atags ) : 0 ;
uint8_t flags = ( sig & & jts ) ? PEERS_FLAG_HAS_JOIN : 0 ;
uint8_t flags = ( sig & & jts ) ? PEERS_FLAG_HAS_JOIN : 0 ;
size_t need = 8 + 32 + 32 + 1 + ( flags ? 72ULL : 0ULL ) + 64 + 8 + 1 + ( size_t ) nl + 1 + ( size_t ) atl + 64 + 8 + 64 ;
size_t need = 8 + 32 + 32 + 1 + ( flags ? 72ULL : 0ULL ) + 64 + 8 + 1 + ( size_t ) nl + 2 + atl + 64 + 8 + 64 ;
if ( off + need > * len ) {
if ( off + need > * len ) {
if ( ! cnt ) { DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: record exceeds page capacity ns=%s " , MS_ID , ns ) ; sqlite3_finalize ( stmt ) ; return - 1 ; }
if ( ! cnt ) { DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: record exceeds page capacity ns=%s " , MS_ID , ns ) ; sqlite3_finalize ( stmt ) ; return - 1 ; }
* more = 1 ;
* more = 1 ;
@ -268,7 +280,7 @@ static int _member_get_page(void* ctx, const char* ns, uint64_t prefix, int afte
}
}
buf [ off + + ] = nl ;
buf [ off + + ] = nl ;
if ( nl ) { memcpy ( buf + off , nm , nl ) ; off + = nl ; }
if ( nl ) { memcpy ( buf + off , nm , nl ) ; off + = nl ; }
buf [ off + + ] = atl ;
buf [ off + + ] = ( uint8_t ) ( atl > > 8 ) ; buf [ off + + ] = ( uint8_t ) atl ;
if ( atl ) { memcpy ( buf + off , atags , atl ) ; off + = atl ; }
if ( atl ) { memcpy ( buf + off , atags , atl ) ; off + = atl ; }
if ( atsig & & sqlite3_column_bytes ( stmt , 9 ) > = 64 ) { memcpy ( buf + off , atsig , 64 ) ; off + = 64 ; }
if ( atsig & & sqlite3_column_bytes ( stmt , 9 ) > = 64 ) { memcpy ( buf + off , atsig , 64 ) ; off + = 64 ; }
else { memset ( buf + off , 0 , 64 ) ; off + = 64 ; }
else { memset ( buf + off , 0 , 64 ) ; off + = 64 ; }
@ -364,7 +376,7 @@ static void _ms_on_bgp_node(struct TOPO_GROUP* group, uint64_t node_id, int even
/* REMOVE не удаляет member (удаление — только битая подпись при верификации) */
/* REMOVE не удаляет member (удаление — только битая подпись при верификации) */
char tags [ 256 ] = " " ;
char tags [ MS_ADM_TAGS_MAX + 1 ] = " " ;
char peers_tbl [ 128 ] ; _peers_table ( group - > channel_id , peers_tbl , sizeof ( peers_tbl ) ) ;
char peers_tbl [ 128 ] ; _peers_table ( group - > channel_id , peers_tbl , sizeof ( peers_tbl ) ) ;
sqlite3_stmt * st = NULL ;
sqlite3_stmt * st = NULL ;
char sql [ 256 ] ; snprintf ( sql , sizeof ( sql ) , " SELECT COALESCE(adm_tags,'') FROM \" %s \" WHERE node_id=? " , peers_tbl ) ;
char sql [ 256 ] ; snprintf ( sql , sizeof ( sql ) , " SELECT COALESCE(adm_tags,'') FROM \" %s \" WHERE node_id=? " , peers_tbl ) ;
@ -377,8 +389,8 @@ static void _ms_on_bgp_node(struct TOPO_GROUP* group, uint64_t node_id, int even
sqlite3_finalize ( st ) ;
sqlite3_finalize ( st ) ;
}
}
DEBUG_DEBUG ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: bgp_node ev=%d nid=0x%016llx tags=%s " ,
DEBUG_DEBUG ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: bgp_node ev=%d nid=0x%016llx tags_bytes=%zu " ,
MS_ID , event , ( unsigned long long ) node_id , tags ) ;
MS_ID , event , ( unsigned long long ) node_id , strlen ( tags ) ) ;
_fire_props_changed ( inst , node_id , tags [ 0 ] ? tags : NULL , group - > channel_id ) ;
_fire_props_changed ( inst , node_id , tags [ 0 ] ? tags : NULL , group - > channel_id ) ;
}
}
@ -475,9 +487,9 @@ static int member_apply_record(struct UTUN_INSTANCE* inst, const char* ch_id,
sqlite3 * db = _db ( inst ) ; if ( ! db ) { DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: apply_record — db is NULL " , MS_ID ) ; return - 1 ; }
sqlite3 * db = _db ( inst ) ; if ( ! db ) { DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: apply_record — db is NULL " , MS_ID ) ; return - 1 ; }
int stale = 0 , changed = 0 ;
int stale = 0 , changed = 0 ;
DEBUG_TRACE ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: apply_record ch=%s nid=%016llx uts=%llu tags=%s " ,
DEBUG_TRACE ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: apply_record ch=%s nid=%016llx uts=%llu tags_bytes=%zu " ,
MS_ID , ch_id , ( unsigned long long ) m - > node_id , ( unsigned long long ) m - > update_ts ,
MS_ID , ch_id , ( unsigned long long ) m - > node_id , ( unsigned long long ) m - > update_ts ,
m - > adm_tags ? m - > adm_tags : " " ) ;
m - > adm_tags ? strlen ( m - > adm_tags ) : 0 ) ;
char peers_tbl [ 128 ] ; _peers_table ( ch_id , peers_tbl , sizeof ( peers_tbl ) ) ;
char peers_tbl [ 128 ] ; _peers_table ( ch_id , peers_tbl , sizeof ( peers_tbl ) ) ;
@ -485,7 +497,7 @@ static int member_apply_record(struct UTUN_INSTANCE* inst, const char* ch_id,
int has_local = 0 ;
int has_local = 0 ;
uint8_t local_join_sig [ 64 ] = { 0 } ; uint64_t local_join_ts = 0 ;
uint8_t local_join_sig [ 64 ] = { 0 } ; uint64_t local_join_ts = 0 ;
uint64_t local_update_ts = 0 ;
uint64_t local_update_ts = 0 ;
char local_tags [ 256 ] = " " ;
char local_tags [ MS_ADM_TAGS_MAX + 1 ] = " " ;
uint64_t local_signed_by = 0 ;
uint64_t local_signed_by = 0 ;
uint8_t local_signature [ 64 ] = { 0 } ;
uint8_t local_signature [ 64 ] = { 0 } ;
int local_src = 0 ;
int local_src = 0 ;
@ -601,18 +613,16 @@ static int member_apply_record(struct UTUN_INSTANCE* inst, const char* ch_id,
adm_storage = ( json_flat_get ( m - > adm_tags , " storage " , ver_str , sizeof ( ver_str ) ) = = 0 & & strcmp ( ver_str , " yes " ) = = 0 ) ? 1 : 0 ;
adm_storage = ( json_flat_get ( m - > adm_tags , " storage " , ver_str , sizeof ( ver_str ) ) = = 0 & & strcmp ( ver_str , " yes " ) = = 0 ) ? 1 : 0 ;
uint8_t ch_ed_pub [ 32 ] = { 0 } ;
uint8_t ch_ed_pub [ 32 ] = { 0 } ;
if ( topo_node_sqlite_channel_get ( db , ch_id , NULL , 0 , NULL , NULL , ch_ed_pub , NULL ) = = 0 ) {
if ( topo_node_sqlite_channel_get ( db , ch_id , NULL , 0 , NULL , NULL , ch_ed_pub , NULL ) = = 0 ) {
uint8_t amsg [ 264 ] ; size_t aoff = 0 ;
uint8_t amsg [ MS_ADM_TAGS_MAX + 8 ] ;
size_t atl2 = strlen ( m - > adm_tags ) ;
int aoff = member_sync_build_owner_msg ( m - > node_id , m - > adm_tags , amsg , sizeof ( amsg ) ) ;
if ( atl2 > 191 ) atl2 = 191 ;
if ( aoff < 0 ) return MT_ERR_DATA ;
memcpy ( amsg + aoff , m - > adm_tags , atl2 ) ; aoff + = atl2 ;
memcpy ( amsg + aoff , & m - > node_id , 8 ) ; aoff + = 8 ;
EVP_PKEY * pkey = EVP_PKEY_new_raw_public_key ( EVP_PKEY_ED25519 , NULL , ch_ed_pub , 32 ) ;
EVP_PKEY * pkey = EVP_PKEY_new_raw_public_key ( EVP_PKEY_ED25519 , NULL , ch_ed_pub , 32 ) ;
if ( pkey ) {
if ( pkey ) {
EVP_MD_CTX * vctx = EVP_MD_CTX_new ( ) ;
EVP_MD_CTX * vctx = EVP_MD_CTX_new ( ) ;
if ( vctx ) {
if ( vctx ) {
int ok = ( EVP_DigestVerifyInit ( vctx , NULL , NULL , NULL , pkey ) = = 1 )
int ok = ( EVP_DigestVerifyInit ( vctx , NULL , NULL , NULL , pkey ) = = 1 )
& & ( EVP_DigestVerify ( vctx , m - > adm_tags_sig , 64 , amsg , aoff ) = = 1 ) ;
& & ( EVP_DigestVerify ( vctx , m - > adm_tags_sig , 64 , amsg , aoff ) = = 1 ) ;
if ( ! ok ) DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: apply_record invalid adm_tags_sig node=0x%016llx ns=%s tags=%s " , MS_ID , ( unsigned long long ) m - > node_id , ch_id , m - > adm_tags ) ;
if ( ! ok ) DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: apply_record invalid adm_tags_sig node=0x%016llx ns=%s bytes=%zu " , MS_ID , ( unsigned long long ) m - > node_id , ch_id , strlen ( m - > adm_tags ) ) ;
else block_b_ok = 1 ;
else block_b_ok = 1 ;
EVP_MD_CTX_free ( vctx ) ;
EVP_MD_CTX_free ( vctx ) ;
}
}
@ -635,7 +645,7 @@ static int member_apply_record(struct UTUN_INSTANCE* inst, const char* ch_id,
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: adm_tags change on placeholder member (source=%d) — ignored by merkle, won't propagate nid=0x%016llx ns=%s " ,
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: adm_tags change on placeholder member (source=%d) — ignored by merkle, won't propagate nid=0x%016llx ns=%s " ,
MS_ID , local_src , ( unsigned long long ) m - > node_id , ch_id ) ;
MS_ID , local_src , ( unsigned long long ) m - > node_id , ch_id ) ;
if ( ! identity_ok | | ! block_a_ok | | ( ! is_local & & m - > adm_tags & & m - > adm_tags [ 0 ] & & ! block_b_ok ) ) {
if ( ! identity_ok | | ! block_a_ok | | ( m - > adm_tags & & m - > adm_tags [ 0 ] & & ! block_b_ok ) ) {
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: rejected record ns=%s node=%016llx identity=%d member=%d owner=%d " ,
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: rejected record ns=%s node=%016llx identity=%d member=%d owner=%d " ,
MS_ID , ch_id , ( unsigned long long ) m - > node_id , identity_ok , block_a_ok , block_b_ok ) ;
MS_ID , ch_id , ( unsigned long long ) m - > node_id , identity_ok , block_a_ok , block_b_ok ) ;
return MT_ERR_DATA ;
return MT_ERR_DATA ;
@ -762,11 +772,9 @@ int member_sync_verify_local_record(struct sqlite3* db, const char* ch_id, const
uint8_t ch_ed_pub [ 32 ] = { 0 } ;
uint8_t ch_ed_pub [ 32 ] = { 0 } ;
if ( topo_node_sqlite_channel_get ( db , ch_id , NULL , 0 , NULL , NULL , ch_ed_pub , NULL ) ! = 0 )
if ( topo_node_sqlite_channel_get ( db , ch_id , NULL , 0 , NULL , NULL , ch_ed_pub , NULL ) ! = 0 )
return 1 ; /* нет канального ключа — не можем проверить, не удаляем */
return 1 ; /* нет канального ключа — не можем проверить, не удаляем */
uint8_t amsg [ 264 ] ; size_t aoff = 0 ;
uint8_t amsg [ MS_ADM_TAGS_MAX + 8 ] ;
size_t atl2 = strlen ( m - > adm_tags ) ;
int aoff = member_sync_build_owner_msg ( m - > node_id , m - > adm_tags , amsg , sizeof ( amsg ) ) ;
if ( atl2 > 191 ) atl2 = 191 ;
if ( aoff < 0 ) return 0 ;
memcpy ( amsg + aoff , m - > adm_tags , atl2 ) ; aoff + = atl2 ;
memcpy ( amsg + aoff , & m - > node_id , 8 ) ; aoff + = 8 ;
EVP_PKEY * pkey = EVP_PKEY_new_raw_public_key ( EVP_PKEY_ED25519 , NULL , ch_ed_pub , 32 ) ;
EVP_PKEY * pkey = EVP_PKEY_new_raw_public_key ( EVP_PKEY_ED25519 , NULL , ch_ed_pub , 32 ) ;
if ( ! pkey ) return 1 ;
if ( ! pkey ) return 1 ;
EVP_MD_CTX * vctx = EVP_MD_CTX_new ( ) ;
EVP_MD_CTX * vctx = EVP_MD_CTX_new ( ) ;
@ -775,8 +783,8 @@ int member_sync_verify_local_record(struct sqlite3* db, const char* ch_id, const
if ( vctx ) EVP_MD_CTX_free ( vctx ) ;
if ( vctx ) EVP_MD_CTX_free ( vctx ) ;
EVP_PKEY_free ( pkey ) ;
EVP_PKEY_free ( pkey ) ;
if ( ! ok ) {
if ( ! ok ) {
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: verify_local — invalid adm_tags_sig nid=0x%016llx ns=%s tags=%s " ,
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: verify_local — invalid adm_tags_sig nid=0x%016llx ns=%s bytes=%zu " ,
MS_ID , ( unsigned long long ) m - > node_id , ch_id , m - > adm_tags ) ;
MS_ID , ( unsigned long long ) m - > node_id , ch_id , strlen ( m - > adm_tags ) ) ;
return 0 ;
return 0 ;
}
}
}
}
@ -877,7 +885,7 @@ void member_sync_verify_and_purge_all(struct UTUN_INSTANCE* inst) {
struct member_wire {
struct member_wire {
struct ms_member_rec rec ;
struct ms_member_rec rec ;
char userinfo [ 256 ] , tags [ 256 ] ;
char userinfo [ 256 ] , tags [ MS_ADM_TAGS_MAX + 1 ] ;
uint8_t local_join [ 64 ] ;
uint8_t local_join [ 64 ] ;
} ;
} ;
@ -898,11 +906,11 @@ static int member_decode(const uint8_t* p, size_t len, struct member_wire* w, si
if ( len - off < 73 ) return - 1 ;
if ( len - off < 73 ) return - 1 ;
m - > update_sig = p + off ; off + = 64 ; m - > update_ts = member_read64 ( p + off ) ; off + = 8 ;
m - > update_sig = p + off ; off + = 64 ; m - > update_ts = member_read64 ( p + off ) ; off + = 8 ;
uint8_t n = p [ off + + ] ;
uint8_t n = p [ off + + ] ;
if ( len - off < ( size_t ) n + 1 | | memchr ( p + off , 0 , n ) ) return - 1 ;
if ( len - off < ( size_t ) n + 2 | | memchr ( p + off , 0 , n ) ) return - 1 ;
memcpy ( w - > userinfo , p + off , n ) ; off + = n ;
memcpy ( w - > userinfo , p + off , n ) ; off + = n ;
n = p [ off + + ] ;
size_t tags_le n = ( ( size_t ) p [ off ] < < 8 ) | p [ off + 1 ] ; off + = 2 ;
if ( len - off < ( size_t ) n + 136 | | memchr ( p + off , 0 , n ) ) return - 1 ;
if ( tags_len > MS_ADM_TAGS_MAX | | len - off < tags_le n + 136 | | memchr ( p + off , 0 , tags_le n) ) return - 1 ;
memcpy ( w - > tags , p + off , n ) ; off + = n ;
memcpy ( w - > tags , p + off , tags_le n) ; off + = tags_le n;
m - > adm_tags_sig = p + off ; off + = 64 ;
m - > adm_tags_sig = p + off ; off + = 64 ;
m - > signed_by = member_read64 ( p + off ) ; off + = 8 ;
m - > signed_by = member_read64 ( p + off ) ; off + = 8 ;
m - > signature = p + off ; off + = 64 ;
m - > signature = p + off ; off + = 64 ;
@ -918,7 +926,7 @@ static int _member_apply_items(void* ctx, const char* ns, uint64_t from_peer, co
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: invalid member page ns=%s bytes=%zu " , MS_ID , ns , len ) ; return MT_ERR_DATA ;
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: invalid member page ns=%s bytes=%zu " , MS_ID , ns , len ) ; return MT_ERR_DATA ;
}
}
uint16_t count = ( ( uint16_t ) data [ 0 ] < < 8 ) | data [ 1 ] ;
uint16_t count = ( ( uint16_t ) data [ 0 ] < < 8 ) | data [ 1 ] ;
if ( count > ( len - 2 ) / 283 ) {
if ( count > ( len - 2 ) / 284 ) {
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: impossible page count=%u bytes=%zu " , MS_ID , count , len ) ; return MT_ERR_DATA ;
DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: impossible page count=%u bytes=%zu " , MS_ID , count , len ) ; return MT_ERR_DATA ;
}
}
size_t off = 2 ;
size_t off = 2 ;
@ -1134,7 +1142,8 @@ int member_sync_put(struct UTUN_INSTANCE* inst, const char* ch_id,
const char * adm_tags , const uint8_t * adm_tags_sig , int storage ,
const char * adm_tags , const uint8_t * adm_tags_sig , int storage ,
uint64_t signed_by , const uint8_t * signature ) {
uint64_t signed_by , const uint8_t * signature ) {
if ( ! inst | | ! ch_id ) { DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: put — inst=%p ch_id=%s " , MS_ID , ( void * ) inst , ch_id ? ch_id : " (null) " ) ; return - 1 ; }
if ( ! inst | | ! ch_id ) { DEBUG_ERROR ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: put — inst=%p ch_id=%s " , MS_ID , ( void * ) inst , ch_id ? ch_id : " (null) " ) ; return - 1 ; }
DEBUG_TRACE ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: put ch=%s nid=%016llx userinfo=%s adm_tags=%s storage=%d signed_by=%016llx " , MS_ID , ch_id , ( unsigned long long ) member_id , userinfo ? userinfo : " " , adm_tags ? adm_tags : " " , storage , ( unsigned long long ) signed_by ) ;
DEBUG_TRACE ( DEBUG_CATEGORY_MEMBER_SYNC , " %s: put ch=%s nid=%016llx tags_bytes=%zu storage=%d signed_by=%016llx " ,
MS_ID , ch_id , ( unsigned long long ) member_id , adm_tags ? strlen ( adm_tags ) : 0 , storage , ( unsigned long long ) signed_by ) ;
struct ms_member_rec m ;
struct ms_member_rec m ;
memset ( & m , 0 , sizeof ( m ) ) ;
memset ( & m , 0 , sizeof ( m ) ) ;