void print_if_has_user(user_list* list, servant_user user) { if (has_user(list, user.username)) { printf("User %s is registered.\n"); } else { printf("User %s is not registered.\n"); } }
void print_if_has_user_by_username(user_list* list, char* username) { if (has_user(list, username)) { printf("User %s is registred.\n"); } else { printf("User %s is not registered.\n"); } }
void IpVerify::PrintAuthTable(int dprintf_level) { struct in6_addr host; UserPerm_t * ptable; PermHashTable->startIterations(); while (PermHashTable->iterate(host, ptable)) { MyString userid; perm_mask_t mask; ptable->startIterations(); while( ptable->iterate(userid,mask) ) { // Call has_user() to get the full mask has_user(ptable, userid.Value(), mask); MyString auth_entry_str; AuthEntryToString(host,userid.Value(),mask, auth_entry_str); dprintf(dprintf_level,"%s\n", auth_entry_str.Value()); } } dprintf(dprintf_level,"Authorizations yet to be resolved:\n"); DCpermission perm; for ( perm=FIRST_PERM; perm < LAST_PERM; perm=NEXT_PERM(perm) ) { PermTypeEntry* pentry = PermTypeArray[perm]; ASSERT( pentry ); MyString allow_users,deny_users; if( pentry->allow_users ) { UserHashToString(pentry->allow_users,allow_users); } if( pentry->deny_users ) { UserHashToString(pentry->deny_users,deny_users); } if( allow_users.Length() ) { dprintf(dprintf_level,"allow %s: %s\n", PermString(perm), allow_users.Value()); } if( deny_users.Length() ) { dprintf(dprintf_level,"deny %s: %s\n", PermString(perm), deny_users.Value()); } } }
int Clusters::operator()(int user, bool tryAgain) { int ireturn = 0; float max_distance = -1e6; int i; int avoid_i = -1; float distance_limit = 1e6; // remember what cluster we started in if needs be... if(tryAgain && cluster_lookup.find(user) != cluster_lookup.end()) { cout << "\t\x1b[35mTrying again -- avoiding "; avoid_i = cluster_lookup[user]; distance_limit = dist(&(*mods)[user], ¢roids[avoid_i]); cout << avoid_i << " with dist " << distance_limit << endl; } else if(has_user(user)) return cluster_lookup[user]; if(tryAgain) cout << "{ "; for(i = 0; i < nclusters; i++) { float m = dist(&(*mods)[user], ¢roids[i]); // best to ignore bins which are orthogonal to the user... if(!m) continue; if(tryAgain) cout << "(" << i << ", " << m << ") "; // remember the minimum distance only, provided we aren't trying // to avoid one of the indices if((i > avoid_i && m == distance_limit && max_distance != distance_limit) || (m > max_distance && m < distance_limit)) { max_distance = m; ireturn= i; } } if(tryAgain) cout << "}"; if(tryAgain) { cout << "\t --> (" << ireturn << ", " << max_distance << ")\x1b[0m" << endl; } return ireturn; }
bool IpVerify::LookupCachedVerifyResult( DCpermission perm, const struct in6_addr &sin6, const char * user, perm_mask_t & mask) { UserPerm_t * ptable = NULL; if( PermHashTable->lookup(sin6, ptable) != -1 ) { if (has_user(ptable, user, mask)) { // We do not want to return true unless there is // a cached result for this specific perm level. if( mask & (allow_mask(perm)|deny_mask(perm)) ) { return true; } } } return false; }
int IpVerify::add_hash_entry(const struct in6_addr & sin6_addr, const char * user, perm_mask_t new_mask) { UserPerm_t * perm = NULL; perm_mask_t old_mask = 0; // must init old_mask to zero!!! MyString user_key = user; // assert(PermHashTable); if ( PermHashTable->lookup(sin6_addr, perm) != -1 ) { // found an existing entry. if (has_user(perm, user, old_mask)) { // remove it because we are going to edit the mask below // and re-insert it. perm->remove(user_key); } } else { perm = new UserPerm_t(42, compute_host_hash); if (PermHashTable->insert(sin6_addr, perm) != 0) { delete perm; return FALSE; } } perm->insert(user_key, old_mask | new_mask); if( IsFulldebug(D_FULLDEBUG) || IsDebugLevel(D_SECURITY) ) { MyString auth_str; AuthEntryToString(sin6_addr,user,new_mask, auth_str); dprintf(D_FULLDEBUG|D_SECURITY, "Adding to resolved authorization table: %s\n", auth_str.Value()); } return TRUE; }