static void clean_up (harglst *a, harg *data, hargkey_t *key, unsigned len) { /* last step, delete descriptor */ if (data == 0) { if (a == 0) return ; if (a->sorter != 0) XFREE (a->sorter) ; XFREE (a) ; return ; } /* recursively delete sublist */ if (is_harglst_type (data->type) && a != 0 && (a->destroy_mode & H_sRECURSE)) harg_close_any (data->d.d.ptr [0], a->destroy_mode); # ifdef ARG_ARGLIST else switch (data->type) { case HARG_ARGLIST: case HARG_PARGLIST: /* recursively delete sublist */ if (a != 0 && (a->destroy_mode & H_sRECURSE)) arg_free_all (data->d.d.ptr [0]); default: break; } # endif XFREE (data); }
struct arglist * store_plugin(struct arglist * plugin, char * file) { char desc_file[PATH_MAX+1]; char path[PATH_MAX+1]; struct plugin plug; struct pprefs pp[MAX_PREFS+1]; char * str; char * dir; struct arglist * arglist, * ret, *prefs; int e; int fd; int num_plugin_prefs = 0; if( current_mode == MODE_SYS ) dir = sys_store_dir; else dir = usr_store_dir; if(strlen(file) + 2 > sizeof(path)) return NULL; strncpy(path, dir, sizeof(path) - 2 - strlen(file)); str = strrchr(path, '/'); if(str != NULL) { str[0] = '\0'; } strcat(path, "/"); strcat(path, file); snprintf(desc_file, sizeof(desc_file), "%s/%s", dir, file); str = strrchr(desc_file, '.'); if( str != NULL ) { str[0] = '\0'; if(strlen(desc_file) + 6 < sizeof(desc_file) ) strcat(desc_file, ".desc"); } bzero(&plug, sizeof(plug)); bzero(pp, sizeof(pp)); plug.magic = MAGIC; plug.id = _plug_get_id(plugin); e = safe_copy(path, plug.path, sizeof(plug.path), path, "path"); if(e < 0)return NULL; plug.timeout = _plug_get_timeout(plugin); plug.category = _plug_get_category(plugin); str = _plug_get_name(plugin); e = safe_copy(str, plug.name, sizeof(plug.name), path, "name"); if(e < 0)return NULL; str = _plug_get_version(plugin); e = safe_copy(str, plug.version, sizeof(plug.version), path, "version"); if(e < 0)return NULL; str = _plug_get_summary(plugin); e = safe_copy(str, plug.summary, sizeof(plug.summary), path, "summary"); if(e < 0)return NULL; str = _plug_get_description(plugin); e = safe_copy(str, plug.description, sizeof(plug.description), path, "description"); if(e < 0)return NULL; str = _plug_get_copyright(plugin); e = safe_copy(str, plug.copyright, sizeof(plug.copyright), path, "copyright"); if(e < 0)return NULL; str = _plug_get_family(plugin); e = safe_copy(str, plug.family, sizeof(plug.family), path, "family"); if(e < 0)return NULL; str = _plug_get_cve_id(plugin); #ifdef DEBUG_STORE if ( str != NULL && strlen(str) > OLD_CVE_SZ ) fprintf(stderr, "WARNING! CVE size will be too long for older versions of Nessus!\n"); #endif e = safe_copy(str, plug.cve_id, sizeof(plug.cve_id), path, "cve_id"); if(e < 0)return NULL; str = _plug_get_bugtraq_id(plugin); #ifdef DEBUG_STORE if ( str != NULL && strlen(str) > OLD_BID_SZ) fprintf(stderr, "WARNING! BID size will be too long for older versions of Nessus!\n"); #endif e = safe_copy(str, plug.bid, sizeof(plug.bid), path, "bugtraq id"); if(e < 0)return NULL; str = _plug_get_xref(plugin); #ifdef DEBUG_STORE if ( str != NULL && strlen(str) > OLD_XREF_SZ) fprintf(stderr, "WARNING! BID size will be too long for older versions of Nessus!\n"); #endif e = safe_copy(str, plug.xref, sizeof(plug.xref), path, "xref id"); if(e < 0)return NULL; arglist = _plug_get_deps(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.dependencies, sizeof(plug.dependencies), path, "dependencies"); efree(&str); if(e < 0)return NULL; arglist = _plug_get_required_keys(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.required_keys, sizeof(plug.required_keys), path, "required keys"); efree(&str); if(e < 0)return NULL; arglist = _plug_get_excluded_keys(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.excluded_keys, sizeof(plug.excluded_keys), path, "excluded_keys"); efree(&str); if(e < 0)return NULL; arglist = _plug_get_required_ports(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.required_ports, sizeof(plug.required_ports), path, "required ports"); efree(&str); if(e < 0)return NULL; arglist = _plug_get_required_udp_ports(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.required_udp_ports, sizeof(plug.required_udp_ports), path, "required udp ports"); efree(&str); if(e < 0)return NULL; prefs = arg_get_value(plugin, "preferences"); arglist = arg_get_value(plugin, "PLUGIN_PREFS"); if( arglist != NULL ) { char * p_name = _plug_get_name(plugin); while(arglist->next != NULL) { char * name = arglist->name; char * dfl = arglist->value; char * type, * str; type = arglist->name; str = strchr(type, '/'); str[0] = '\0'; name = str + 1; e = safe_copy(type, pp[num_plugin_prefs].type, sizeof(pp[num_plugin_prefs].type), path, "preference-type"); if(e < 0)return NULL; e = safe_copy(name, pp[num_plugin_prefs].name, sizeof(pp[num_plugin_prefs].name), path, "preference-name"); if(e < 0)return NULL; e = safe_copy(dfl, pp[num_plugin_prefs].dfl, sizeof(pp[num_plugin_prefs].dfl), path, "preference-default"); if(e < 0)return NULL; num_plugin_prefs ++; if(num_plugin_prefs >= MAX_PREFS) { fprintf(stderr, "%s: too many preferences\n", path); return NULL; } _add_plugin_preference(prefs, p_name, name, type, dfl); str[0] = '/'; arglist = arglist->next; } } if(num_plugin_prefs > 0) plug.has_prefs = 1; fd = open(desc_file, O_RDWR|O_CREAT|O_TRUNC, 0644); if(fd < 0) { return NULL; } if(write(fd, &plug, sizeof(plug)) < 0) { perror("write "); } if(num_plugin_prefs > 0) { write(fd, pp, sizeof(pp)); } close(fd); arg_set_value(plugin, "preferences", -1, NULL); arg_free_all(plugin); return NULL; }