static tree_cell * nasl_hmac (lex_ctxt * lexic, int algorithm) { char *data = get_str_local_var_by_name (lexic, "data"); char *key = get_str_local_var_by_name (lexic, "key"); int data_len = get_local_var_size_by_name (lexic, "data"); int key_len = get_local_var_size_by_name (lexic, "key"); return nasl_gcrypt_hash (lexic, algorithm, data, data_len, key, key_len); }
static tree_cell * security_something(lex_ctxt * lexic, proto_post_something_t proto_post_func, post_something_t post_func) { struct arglist * script_infos = lexic->script_infos; char* proto = get_str_local_var_by_name(lexic, "protocol"); char* data = get_str_local_var_by_name(lexic, "data"); int port = get_int_local_var_by_name(lexic, "port", -1); char * dup = NULL; if(data != NULL) { int len = get_local_var_size_by_name(lexic, "data"); int i; dup = nasl_strndup(data, len); for(i=0;i<len;i++) if(dup[i] == 0)dup[i]=' '; } /*if((arg_get_value(script_infos, "standalone")) != NULL) { if( data != NULL ) fprintf(stdout, "%s\n", dup); else fprintf(stdout, "Success\n"); }*/ if(proto == NULL) proto = get_str_local_var_by_name(lexic, "proto"); if(port < 0) port = get_int_var_by_num(lexic, 0, -1); if(dup != NULL) { if(proto == NULL) post_func(script_infos, port, dup); else proto_post_func(script_infos, port, proto, dup); efree(&dup); return FAKE_CELL; } if(proto == NULL) post_func(script_infos, port, NULL); else proto_post_func(script_infos, port, proto, NULL); return FAKE_CELL; }
tree_cell* nasl_str_replace(lex_ctxt * lexic) { char *a, *b, *r, *s, *c; int sz_a, sz_b, sz_r, count; int i1, i2, sz2, n, l; tree_cell *retc = NULL; a = get_str_local_var_by_name(lexic, "string"); b = get_str_local_var_by_name(lexic, "find"); r = get_str_local_var_by_name(lexic, "replace"); sz_a = get_local_var_size_by_name(lexic, "string"); sz_b = get_local_var_size_by_name(lexic, "find"); sz_r = get_local_var_size_by_name(lexic, "replace"); count = get_int_local_var_by_name(lexic, "count", 0); if (a == NULL || b == NULL) { nasl_perror(lexic, "Missing argument: str_replace(string: s, find: f, replace: r [,count: c])\n"); return NULL; } if (sz_b == 0) { nasl_perror(lexic, "str_replace: illegal 'find' argument value\n"); return NULL; } if (r == NULL) { r = ""; sz_r = 0; } retc = alloc_typed_cell(CONST_DATA); s = emalloc(1); sz2 = 0; n = 0; for (i1 = i2 = 0; i1 < sz_a - sz_b; ) { c = (char*)memmem(a + i1, sz_a - i1, b, sz_b); if(c == NULL) break; l = (c - a) - i1; sz2 += sz_r + l; s = erealloc(s, sz2+1); s[sz2] = '\0'; if (c - a > i1) { memcpy(s + i2, a + i1, l); i2 += l; } if (sz_r > 0) { memcpy(s + i2, r, sz_r); i2 += sz_r; } i1 += l + sz_b; n ++; if (count > 0 && n >= count) break; } if (i1 < sz_a) { sz2 += (sz_a - i1); s = erealloc(s, sz2+1); s[sz2] = '\0'; memcpy(s + i2, a + i1, sz_a - i1); } retc->x.str_val = s; retc->size = sz2; return retc; }