/* eurephia_admin_common.c -- Common functions used for the admin API * * GPLv2 - Copyright (C) 2008 David Sommerseth * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; version 2 * of the License. * * 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; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include #include #include #include #include #include #define EUREPHIA_ADMIN_COMMON_C #include "eurephia_admin_struct.h" #include "eurephia_admin_common.h" eurephiaUSERINFO *eAdminPopulateUSERINFO(int uid, const char *uname, const char *pwd, const char *activated, const char *deactivd, const char *lastacc) { eurephiaUSERINFO *newrec = NULL; newrec = (eurephiaUSERINFO *) malloc(sizeof(eurephiaUSERINFO)+2); assert( newrec != NULL ); memset(newrec, 0, sizeof(eurephiaUSERINFO)+2); newrec->uid = uid; newrec->username = strdup_nullsafe(uname); newrec->password = (pwd == NULL ? NULL : passwdhash(pwd)); newrec->activated = strdup_nullsafe(activated); newrec->deactivated = strdup_nullsafe(deactivd); newrec->last_accessed = strdup_nullsafe(lastacc); newrec->next = NULL; return newrec; } void _eAdminFreeUSERINFO_func(eurephiaUSERINFO *p) { if( p == NULL ) { return; } eAdminFreeCERTLIST(p->certlist); eAdminFreeUSERINFO(p->next); free_nullsafe(p->username); free_nullsafe(p->password); free_nullsafe(p->activated); free_nullsafe(p->deactivated); free_nullsafe(p->last_accessed); p->next = NULL; free(p); } void _eAdminFreeUSERLIST_func(eurephiaUSERLIST *p) { if( p == NULL ) { return; } eAdminFreeUSERINFO(p->users); free(p); } eurephiaCERTLIST *eAdminCreateCERTLIST() { eurephiaCERTLIST *lst = NULL; lst = (eurephiaCERTLIST *) malloc(sizeof(eurephiaCERTLIST)+2); memset(lst, 0, sizeof(eurephiaCERTLIST)+2); lst->num_certs = 0; return lst; } eurephiaCERTINFO *eAdminPopulateCERTINFO(int certid, int depth, const char *digest, const char *cname, const char *org, const char *email, const char *reg) { eurephiaCERTINFO *newrec = NULL; newrec = (eurephiaCERTINFO *) malloc(sizeof(eurephiaCERTINFO)+2); assert( newrec != NULL ); memset(newrec, 0, sizeof(eurephiaCERTINFO)+2); newrec->certid = certid; newrec->depth = depth; newrec->digest = strdup_nullsafe(digest); newrec->common_name = strdup_nullsafe(cname); newrec->organisation = strdup_nullsafe(org); newrec->email = strdup_nullsafe(email); newrec->registered = strdup_nullsafe(reg); newrec->next = NULL; return newrec; } void eAdminInsertCERTINFO(eurephiaCERTLIST *list, eurephiaCERTINFO *cert) { assert( list != NULL ); if( list->certs != NULL ) { cert->next = list->certs; list->certs = cert; list->num_certs++; } else { list->certs = cert; list->num_certs = 1; } } void _eAdminFreeCERTINFO_func(eurephiaCERTINFO *p) { if( p == NULL ) { return; } eAdminFreeCERTINFO(p->next); free_nullsafe(p->digest); free_nullsafe(p->common_name); free_nullsafe(p->organisation); free_nullsafe(p->email); free_nullsafe(p->registered); p->access = NULL; p->next = NULL; free(p); } void _eAdminFreeCERTLIST_func(eurephiaCERTLIST *p) { #ifdef FIREWALL eurephiaACCESSLIST *aclst = NULL; #endif if( p == NULL ) { return; } #ifdef FIREWALL aclst = ((p->certs != NULL) && (p->certs->access != NULL)) ? p->certs->access->_head : NULL; eAdminFreeACCESSLIST(aclst); #endif eAdminFreeCERTINFO(p->certs); free(p); } #ifdef FIREWALL eurephiaACCESSINFO *eAdminRegisterACCESSINFO(eurephiaACCESSLIST *aclst, int accprofid, const char *fwprofile, const char *accdescr) { eurephiaACCESSINFO *ptr = NULL; assert( aclst != NULL ); for( ptr = aclst->profiles; ptr != NULL; ptr = ptr->next) { if( ptr->accessprofile == accprofid ) { return ptr; } } // If no record was found, register it automatically if( ptr == NULL ) { ptr = (eurephiaACCESSINFO *) malloc(sizeof(eurephiaACCESSINFO)+2); assert(ptr != NULL); memset(ptr, 0, sizeof(eurephiaACCESSINFO)+2); ptr->accessprofile = accprofid; ptr->fwprofile = strdup_nullsafe(fwprofile); ptr->access_descr = strdup_nullsafe(accdescr); ptr->_head = aclst; if( aclst->profiles == NULL ) { aclst->profiles = ptr; aclst->num_profiles = 1; } else { ptr->next = aclst->profiles; aclst->profiles = ptr; aclst->num_profiles++; } } return ptr; } eurephiaACCESSLIST *eAdminCreateACCESSLIST() { eurephiaACCESSLIST *ptr = NULL; ptr = (eurephiaACCESSLIST *) malloc(sizeof(eurephiaACCESSLIST)+2); assert(ptr != NULL); memset(ptr, 0, sizeof(eurephiaACCESSLIST)+2); return ptr; } void _eAdminFreeACCESSINFO_func(eurephiaACCESSINFO *p) { if( p == NULL ) { return; } eAdminFreeACCESSINFO(p->next); free_nullsafe(p->access_descr); free_nullsafe(p->fwprofile); p->_head = NULL; p->accessprofile = 0; free(p); } void _eAdminFreeACCESSLIST_func(eurephiaACCESSLIST *p) { if( p == NULL ) { return; } eAdminFreeACCESSINFO(p->profiles); p->num_profiles = 0; free(p); } #endif // FIREWALL