Пример #1
0
static int
S_stress_start(int argc, char * argv[])
{
    CFDictionaryRef	dict = NULL;
    int			i;
    char *		ifname = argv[0];
    int 		result;
    SCDynamicStoreRef	store;

    if (access(argv[1], R_OK) != 0) {
	fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
	return (errno);
    }
    dict = (CFDictionaryRef)my_CFPropertyListCreateFromFile(argv[1]);
    if (isA_CFDictionary(dict) == NULL) {
	fprintf(stderr, "contents of file %s invalid\n", argv[1]);
	my_CFRelease(&dict);
	return (EINVAL);
    }
    store = config_session_start(NULL, NULL, ifname);
    if (store == NULL) {
	CFRelease(dict);
	return (EINVAL);
    }

    for (i = 0; TRUE; i++) {
	result = EAPOLControlStart(ifname, dict);
	if (result != 0) {
	    fprintf(stderr, "EAPOLControlStart(%s) returned %d (%s)\n",
		    ifname, result, strerror(result));
	    break;
	}
	result = S_wait_for_state(ifname, store, 
				  kEAPOLControlStateRunning,
				  kEAPOLControlStateStarting);
	if (result != 0) {
	    fprintf(stderr, "Waiting for Running failed\n");
	    break;
	}
	result = EAPOLControlStop(ifname);
	if (result != 0) {
	    fprintf(stderr, "EAPOLControlStop(%s) returned %d (%s)\n",
		    ifname, result, strerror(result));
	    break;
	}
	(void)S_wait_for_state(ifname, store, 
			       kEAPOLControlStateIdle,
			       kEAPOLControlStateStopping);
    }
    fprintf(stderr, "Failed at iteration %d\n", i + 1);
    my_CFRelease(&dict);
    return (result);
}
STATIC bool
load_DUID_info(void)
{
    CFDataRef		duid;
    CFDictionaryRef	duid_ia;
    CFDataRef		host_uuid;
    CFArrayRef		ia_list;

    duid_ia = my_CFPropertyListCreateFromFile(DUID_IA_FILE);
    if (isA_CFDictionary(duid_ia) == NULL) {
	goto done;
    }
    duid = CFDictionaryGetValue(duid_ia, kDUIDKey);
    if (isA_CFData(duid) == NULL) {
	goto done;
    }
    ia_list = CFDictionaryGetValue(duid_ia, kIAIDListKey);
    ia_list = isA_CFArray(ia_list);
    if (ia_list != NULL) {
	int		count;
	int		i;

	count = CFArrayGetCount(ia_list);
	for (i = 0; i < count; i++) {
	    CFStringRef	name = CFArrayGetValueAtIndex(ia_list, i);
	    if (isA_CFString(name) == NULL) {
		/* invalid property */
		ia_list = NULL;
		break;
	    }
	}
    }
    host_uuid = CFDictionaryGetValue(duid_ia, kHostUUIDKey);
    if (isA_CFData(host_uuid) != NULL 
	&& CFDataGetLength(host_uuid) == sizeof(uuid_t)) {
	CFDataRef	our_UUID;

	our_UUID = HostUUIDGet();
	if (our_UUID != NULL && CFEqual(host_uuid, our_UUID) == FALSE) {
	    syslog(LOG_NOTICE,
		   "DHCPDUID: ignoring DUID - host UUID doesn't match");
	    goto done;
	}
    }
    S_DUID = CFRetain(duid);
    if (ia_list != NULL) {
	S_IAIDList = CFArrayCreateMutableCopy(NULL, 0, ia_list);
    }

 done:
    my_CFRelease(&duid_ia);
    return (S_DUID != NULL);
}
Пример #3
0
static int
S_update(int argc, char * argv[])
{
    CFDictionaryRef	dict = NULL;
    int 		result;

    if (access(argv[1], R_OK) != 0) {
	fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
	return (errno);
    }
    dict = (CFDictionaryRef)my_CFPropertyListCreateFromFile(argv[1]);
    if (isA_CFDictionary(dict) == NULL) {
	fprintf(stderr, "contents of file %s invalid\n", argv[1]);
	my_CFRelease(&dict);
	return (EINVAL);
    }
    result = EAPOLControlUpdate(argv[0], dict);
    fprintf(stderr, "EAPOLControlUpdate returned %d\n", result);
    my_CFRelease(&dict);
    return (result);
}
Пример #4
0
/* 
 * Function: DHCPLeaseListRead
 *
 * Purpose:
 *   Read the single DHCP lease for the given interface/client_id into a
 *   DHCPLeaseList structure.  This lease is marked as "tentative" because
 *   we have no idea whether the lease is still good or not, since another
 *   version of the OS (or another OS) could have had additional communication
 *   with the DHCP server, invalidating our notion of the lease.  It also
 *   affords a simple, self-cleansing mechanism to clear out the set of
 *   leases we keep track of.
 */
void
DHCPLeaseListRead(DHCPLeaseListRef list_p,
		  const char * ifname, bool is_wifi,
		  uint8_t cid_type, const void * cid, int cid_length)
{
    char			filename[PATH_MAX];
    CFDictionaryRef		lease_dict = NULL;
    DHCPLeaseRef		lease_p;
    struct in_addr		lease_ip;

    DHCPLeaseListInit(list_p);
    if (DHCPLeaseListGetPath(ifname, cid_type, cid, cid_length,
			     filename, sizeof(filename)) == FALSE) {
	goto done;
    }
    lease_dict = my_CFPropertyListCreateFromFile(filename);
    if (isA_CFDictionary(lease_dict) == NULL) {
	goto done;
    }
    lease_p = DHCPLeaseCreateWithDictionary(lease_dict, is_wifi);
    if (lease_p == NULL) {
	goto done;
    }
    lease_p->tentative = TRUE;
    dynarray_add(list_p, lease_p);
    if (G_IPConfiguration_verbose) {
	DHCPLeaseListLog(list_p);
    }
    lease_ip = lease_p->our_ip;
    DHCPLeaseListRemoveStaleLeases(list_p);
    if (DHCPLeaseListCount(list_p) == 0) {
	remove_unused_ip(ifname, lease_ip);
    }

 done:
    my_CFRelease(&lease_dict);
    return;
}
Пример #5
0
STATIC bool
CGAParametersLoad(CFDataRef host_uuid)
{
    CFDictionaryRef	keys_info = NULL;
    CFDictionaryRef	global_modifier = NULL;
    CFDictionaryRef	linklocal_modifiers = NULL;
    CFDictionaryRef	parameters = NULL;
    CFDataRef		modifier = NULL;
    CFDataRef		plist_host_uuid;
    CFDataRef		priv;
    CFDataRef		pub;
    uint8_t		security_level;

    /* load CGA persistent information */
    parameters = my_CFPropertyListCreateFromFile(CGA_FILE);
    if (isA_CFDictionary(parameters) == NULL) {
	if (parameters != NULL) {
	    my_log_fl(LOG_NOTICE, "%s is not a dictionary", CGA_FILE);
	}
	goto done;
    }

    /* make sure that HostUUID matches */
    plist_host_uuid = CFDictionaryGetValue(parameters, kHostUUID);
    if (isA_CFData(plist_host_uuid) == NULL
	|| !CFEqual(plist_host_uuid, host_uuid)) {
	my_log_fl(LOG_NOTICE, "%@ missing/invalid", kHostUUID);
	goto done;
    }

    /* global modifier */
    global_modifier = CFDictionaryGetValue(parameters, kGlobalModifier);
    if (global_modifier != NULL) {
	modifier = CGAModifierDictGetModifier(global_modifier,
					      &security_level);
    }
    if (modifier == NULL) {
	global_modifier = NULL;
	my_log_fl(LOG_NOTICE, "%@ missing/invalid", kGlobalModifier);
	goto done;
    }

    /* load CGA keys */
    keys_info = my_CFPropertyListCreateFromFile(CGA_KEYS_FILE);
    if (isA_CFDictionary(keys_info) == NULL) {
	if (keys_info != NULL) {
	    my_log_fl(LOG_NOTICE, "%s is not a dictionary", CGA_KEYS_FILE);
	}
	goto done;
    }

    /* private key */
    priv = CFDictionaryGetValue(keys_info, kPrivateKey);
    if (isA_CFData(priv) == NULL) {
	my_log_fl(LOG_NOTICE, "%@ missing/invalid", kPrivateKey);
	goto done;
    }

    /* public key */
    pub = CFDictionaryGetValue(keys_info, kPublicKey);
    if (isA_CFData(pub) == NULL) {
	my_log_fl(LOG_NOTICE, "%@ missing/invalid", kPublicKey);
	goto done;
    }

    /* set CGA parameters in the kernel */
    if (cga_parameters_set(priv, pub, modifier, security_level) == FALSE) {
	my_log_fl(LOG_NOTICE, "cga_parameters_set failed");
	goto failed;
    }

    /* linklocal modifiers */
    linklocal_modifiers
	= CFDictionaryGetValue(parameters, kLinkLocalModifiers);
    if (linklocal_modifiers != NULL
	&& isA_CFDictionary(linklocal_modifiers) == NULL) {
	my_log_fl(LOG_NOTICE, "%s is not a dictionary", kLinkLocalModifiers);
	linklocal_modifiers = NULL;
    }

 done:
    if (global_modifier != NULL) {
	S_GlobalModifier = CFRetain(global_modifier);
    }
    else {
	global_modifier = CGAParametersCreate(host_uuid);
	if (global_modifier == NULL) {
	    goto failed;
	}
	S_GlobalModifier = global_modifier;
    }
    if (linklocal_modifiers != NULL) {
	/* make a copy of the existing one */
	S_LinkLocalModifiers 
	    = CFDictionaryCreateMutableCopy(NULL, 0, linklocal_modifiers);
	remove_old_linklocal_modifiers(S_LinkLocalModifiers);
    }
    else {
	/* create an empty modifiers dictionary */
	S_LinkLocalModifiers 
	    = CFDictionaryCreateMutable(NULL, 0,
					&kCFTypeDictionaryKeyCallBacks,
					&kCFTypeDictionaryValueCallBacks);
    }

 failed:
    my_CFRelease(&keys_info);
    my_CFRelease(&parameters);
    return (S_GlobalModifier != NULL);
}