/
githubmirror
/
audit-userspace
Обзор
Документация
Войти
/
githubmirror
/
audit-userspace
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
audisp/plugins/ids/nvpair.c
136 строк
3 KB
Steve Grubb
Update license and copyrights
20 июл 2026, 22:56
20 июл 2026, 22:56
aad6ac2
Код
Авторство
О чём код?
/* * nvpair.c - Minimal linked list library for arg-jobue pairs * Copyright (c) 2019,2021,2025-26 Steve Grubb. * All Rights Reserved. * * This software may be freely redistributed and/or modified under the * terms of the GNU General Public License as published by the Free * Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor * Boston, MA 02110-1335, USA. * * Authors: * Steve Grubb <sgrubb@redhat.com> */ #include "config.h" #include <stdlib.h> #include "nvpair.h" void nvpair_list_create(nvlist *l) { l->head = NULL; l->cur = NULL; l->prev = NULL; l->cnt = 0; } /*nvnode *nvlist_next(nvlist *l) { if (l->cur == NULL) { l->prev = NULL; return NULL; } l->prev = l->cur; l->cur = l->cur->next; return l->cur; }*/ int nvpair_list_append(nvlist *l, nvnode *node) { nvnode *newnode = malloc(sizeof(nvnode)); nvnode *tail; if (newnode == NULL) return 1; newnode->arg = node->arg; newnode->job = node->job; newnode->expiration = node->expiration; newnode->next = NULL; // if we are at top, fix this up if (l->head == NULL) { l->head = newnode; l->prev = NULL; } else { // Add pointer to newnode and make sure we are at the end // cur is search state, so locate the tail from the list head. tail = l->head; while (tail->next) tail = tail->next; tail->next = newnode; l->prev = tail; } // make newnode current l->cur = newnode; l->cnt++; return 0; } int nvpair_list_find_job(nvlist *l, time_t t) { nvnode* node = l->head; l->prev = NULL; while (node) { if (node->expiration <= t) { l->cur = node; return 1; } else { l->prev = node; node = node->next; } } l->cur = NULL; l->prev = NULL; return 0; } void nvpair_list_delete_cur(nvlist *l) { if (l->cur == NULL) return; if (l->cur == l->head) { l->head = l->cur->next; l->prev = NULL; } else if (l->prev) l->prev->next = l->cur->next; free(l->cur->arg); free(l->cur); l->cur = NULL; l->prev = NULL; l->cnt--; } void nvpair_list_clear(nvlist* l) { nvnode* nextnode; nvnode* current; current = l->head; while (current) { nextnode=current->next; free(current->arg); free(current); current=nextnode; } l->head = NULL; l->prev = NULL; l->cur = NULL; l->cnt = 0; }