int add_to_trusted_mac_list(const char possiblemac[]) { char *mac = NULL; t_MAC *p = NULL; /* check for valid format */ if (!check_mac_format(possiblemac)) { debug(LOG_NOTICE, "[%s] not a valid MAC address to trust", possiblemac); return -1; } mac = safe_malloc(18); sscanf(possiblemac, "%17[A-Fa-f0-9:]", mac); /* See if MAC is already on the list; don't add duplicates */ for (p = config.trustedmaclist; p != NULL; p = p->next) { if (!strcasecmp(p->mac,mac)) { debug(LOG_INFO, "MAC address [%s] already on trusted list", mac); free(mac); return 1; } } /* Add MAC to head of list */ p = safe_malloc(sizeof(t_MAC)); p->mac = safe_strdup(mac); p->next = config.trustedmaclist; config.trustedmaclist = p; debug(LOG_INFO, "Added MAC address [%s] to trusted list", mac); free(mac); return 0; }
/* Remove given MAC address from the config's allowed mac list. * Return 0 on success, nonzero on failure */ int remove_from_allowed_mac_list(char *possiblemac) { char *mac = NULL; t_MAC **p = NULL; t_MAC *del = NULL; int found = 0; /* check for valid format */ if (!check_mac_format(possiblemac)) { debug(LOG_NOTICE, "[%s] not a valid MAC address", possiblemac); return -1; } /* abort if not using ALLOW mechanism */ if (MAC_ALLOW != config.macmechanism) { debug(LOG_NOTICE, "Attempt to access allowed MAC list but control mechanism != allow"); return -1; } mac = safe_malloc(18); sscanf(possiblemac, "%17[A-Fa-f0-9:]", mac); /* If empty list, nothing to do */ if (config.allowedmaclist == NULL) { debug(LOG_INFO, "MAC address [%s] not on empty allowed list", mac); free(mac); return -1; } /* Find MAC on the list, remove it */ for (p = &(config.allowedmaclist); *p != NULL; p = &((*p)->next)) { if (!strcasecmp((*p)->mac,mac)) { /* found it */ del = *p; *p = del->next; debug(LOG_INFO, "Removed MAC address [%s] from allowed list", mac); free(del); free(mac); return 0; } } /* MAC was not on list */ debug(LOG_INFO, "MAC address [%s] not on allowed list", mac); free(mac); return -1; }
/* Remove given MAC address from the config's trusted mac list. * Return 0 on success, nonzero on failure */ int remove_from_trusted_mac_list(char *possiblemac) { char *mac = NULL; t_MAC **p = NULL; t_MAC *del = NULL; int found = 0; /* check for valid format */ if (!check_mac_format(possiblemac)) { debug(LOG_NOTICE, "[%s] not a valid MAC address", possiblemac); return -1; } mac = safe_malloc(18); sscanf(possiblemac, "%17[A-Fa-f0-9:]", mac); /* If empty list, nothing to do */ if (config.trustedmaclist == NULL) { debug(LOG_INFO, "MAC address [%s] not on empty trusted list", mac); free(mac); return -1; } /* Find MAC on the list, remove it */ for (p = &(config.trustedmaclist); *p != NULL; p = &((*p)->next)) { if (!strcasecmp((*p)->mac,mac)) { /* found it */ del = *p; *p = del->next; debug(LOG_INFO, "Removed MAC address [%s] from trusted list", mac); free(del); free(mac); return 0; } } /* MAC was not on list */ debug(LOG_INFO, "MAC address [%s] not on trusted list", mac); free(mac); return -1; }
/* Add given MAC address to the config's allowed mac list. * Return 0 on success, nonzero on failure */ int add_to_allowed_mac_list(const char possiblemac[]) { char *mac = NULL; t_MAC *p = NULL; /* check for valid format */ if (!check_mac_format(possiblemac)) { debug(LOG_NOTICE, "[%s] not a valid MAC address to allow", possiblemac); return -1; } /* abort if not using ALLOW mechanism */ if (MAC_ALLOW != config.macmechanism) { debug(LOG_NOTICE, "Attempt to access allowed MAC list but control mechanism != allow"); return -1; } mac = safe_malloc(18); sscanf(possiblemac, "%17[A-Fa-f0-9:]", mac); /* See if MAC is already on the list; don't add duplicates */ for (p = config.allowedmaclist; p != NULL; p = p->next) { if (!strcasecmp(p->mac,mac)) { debug(LOG_INFO, "MAC address [%s] already on allowed list", mac); free(mac); return 1; } } /* Add MAC to head of list */ p = safe_malloc(sizeof(t_MAC)); p->mac = safe_strdup(mac); p->next = config.allowedmaclist; config.allowedmaclist = p; debug(LOG_INFO, "Added MAC address [%s] to allowed list", mac); free(mac); return 0; }