/* * Function: AFPUser_set_random_password * Purpose: * Set a random password for the user and returns it in passwd. * Do not change the password again until AFPUSER_PASSWORD_CHANGE_INTERVAL * has elapsed. This overcomes the problem where every client * request packet is duplicated. In that case, the client tries to use * a password that subsequently gets changed when the duplicate arrives. */ Boolean AFPUser_set_random_password(AFPUserRef user, char * passwd, size_t passwd_len) { CFDateRef last_set; Boolean ok = TRUE; CFDateRef now; CFStringRef pw; ODRecordRef record; now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()); pw = CFDictionaryGetValue(user, kAFPUserPassword); last_set = CFDictionaryGetValue(user, kAFPUserDatePasswordLastSet); if (pw != NULL && last_set != NULL && (CFDateGetTimeIntervalSinceDate(now, last_set) < AFPUSER_PASSWORD_CHANGE_INTERVAL)) { /* return what we have */ #ifdef TEST_AFPUSERS printf("No need to change the password %d < %d\n", (int)CFDateGetTimeIntervalSinceDate(now, last_set), AFPUSER_PASSWORD_CHANGE_INTERVAL); #endif /* TEST_AFPUSERS */ (void)_SC_cfstring_to_cstring(pw, passwd, passwd_len, kCFStringEncodingASCII); CFDictionarySetValue(user, kAFPUserDatePasswordLastSet, now); } else { generate_random_password(passwd, passwd_len); record = (ODRecordRef)CFDictionaryGetValue(user, kAFPUserODRecord); pw = CFStringCreateWithCString(NULL, passwd, kCFStringEncodingASCII); ok = ODRecordChangePassword(record, NULL, pw, NULL); if (ok) { CFDictionarySetValue(user, kAFPUserPassword, pw); CFDictionarySetValue(user, kAFPUserDatePasswordLastSet, now); } else { my_log(LOG_NOTICE, "AFPUser_set_random_password:"******" ODRecordChangePassword() failed"); CFDictionaryRemoveValue(user, kAFPUserPassword); CFDictionaryRemoveValue(user, kAFPUserDatePasswordLastSet); } CFRelease(pw); } CFRelease(now); return ok; }
// Executes a linear mouse movement animation. It can be a simple cursor // move or a drag depending on what is passed to `type`. static void mouse_animate( CGEventType type, CGMouseButton button, CGPoint start_point, CGPoint end_point, double duration ) { CFDateRef current_time = NULL; CGPoint current_point = start_point; double xstep = (end_point.x - start_point.x) / (duration * FPS); double ystep = (end_point.y - start_point.y) / (duration * FPS); CFDateRef start = NOW; double remaining = 0.0; while (!CLOSE_ENOUGH(current_point, end_point)) { remaining = end_point.x - current_point.x; current_point.x += abs(xstep) > abs(remaining) ? remaining : xstep; remaining = end_point.y - current_point.y; current_point.y += abs(ystep) > abs(remaining) ? remaining : ystep; POSTRELEASE(NEW_EVENT(type, current_point, button)); mouse_sleep(1); current_time = NOW; // this is a safety if (CFDateGetTimeIntervalSinceDate(NOW, start) > (duration + 1)) break; RELEASE(current_time); current_time = NULL; current_point = mouse_current_position(); } RELEASE(start); if (current_time) RELEASE(current_time); }
STATIC bool linklocal_modifier_has_expired(CFDictionaryRef dict, CFDateRef now) { bool has_expired = TRUE; CFDataRef modifier; uint8_t security_level; modifier = CGAModifierDictGetModifier(dict, &security_level); if (modifier != NULL) { CFDateRef creation_date; creation_date = CFDictionaryGetValue(dict, kCreationDate); if (isA_CFDate(creation_date) != NULL && (CFDateGetTimeIntervalSinceDate(now, creation_date) < LINKLOCAL_MODIFIER_EXPIRATION_SECONDS)) { has_expired = FALSE; } } return (has_expired); }