int cbcreate(struct bsdconv_instance *ins, struct bsdconv_hash_entry *arg){ struct my_s *r=THIS_CODEC(ins)->priv=malloc(sizeof(struct my_s)); int i; r->min_len=1; r->after=NULL; r->before=NULL; char *filter="PRINT"; char *after="010A"; char *before=NULL; while(arg){ if(strcasecmp(arg->key, "FOR")==0){ filter=arg->ptr; }else if(strcasecmp(arg->key, "MIN-LEN")==0 && sscanf(arg->ptr, "%d", &i)==1){ r->min_len=i; }else if(strcasecmp(arg->key, "AFTER")==0){ after=arg->ptr; }else if(strcasecmp(arg->key, "BEFORE")==0){ before=arg->ptr; }else{ free(r); return EINVAL; } arg=arg->next; } r->filter=load_filter(filter); if(r->filter==NULL){ free(r); return EOPNOTSUPP; } if(after){ r->after=str2data(after, &i, ins); if(i){ if(r->after) DATA_FREE(ins, r->after); free(r); return i; } } if(before){ r->before=str2data(before, &i, ins); if(i){ if(r->after) DATA_FREE(ins, r->after); if(r->before) DATA_FREE(ins, r->before); free(r); return i; } } DATA_MALLOC(ins, r->qh); r->qh->flags=0; r->qh->next=NULL; return 0; }
void opcode_chain_serialize(opcode_chain_t oc, opcode_dict_t od, program_t p, void* dl_handle) { slist_node_t sn; opcode_chain_node_t ocn; word_t ofs = program_get_code_size(p), backup=ofs, code_sz=0, data_sz=0; /* * 1st pass : compute labels addresses and init data segment */ sn = list_head(oc); while(sn!=NULL) { ocn = node_value(opcode_chain_node_t,sn); switch(ocn->type) { case NodeLabel: ocn->lofs=ofs; program_add_label(p,ofs,ocn->name); break; case NodeData: data_sz+= 2*atoi(ocn->arg); /*vm_printf("data rep %i\n",atoi(ocn->arg));*/ break; case NodeOpcode: ofs+=2; /* two words per instruction */ code_sz+=2; break; case NodeLangPlug: case NodeLangDef: default:; }; sn=sn->next; } /* reserve segments sizes */ program_reserve_code(p, code_sz); program_reserve_data(p, data_sz?2+data_sz:0); /* * 2nd pass : serialize opcodes */ ofs=backup; sn = list_head(oc); while(sn!=NULL) { ocn = node_value(opcode_chain_node_t,sn); if(ocn->type==NodeOpcode) { opcode_serialize(od,oc,ofs,ocn,p,dl_handle); ofs+=2; } else if(ocn->type==NodeData) { long rep = atoi(ocn->arg); word_t dat = str2data(p,(vm_data_type_t)ocn->arg_type,ocn->name); dynarray_t data_seg = &p->data; while(rep>0) { dynarray_set(data_seg,dynarray_size(data_seg), ocn->arg_type); dynarray_set(data_seg,dynarray_size(data_seg), dat); rep-=1; } } sn=sn->next; } }
static krb5_error_code process_reply (krb5_context context, krb5_auth_context auth_context, int is_stream, int sock, int *result_code, krb5_data *result_code_string, krb5_data *result_string, const char *host) { krb5_error_code ret; u_char reply[1024 * 3]; ssize_t len; u_int16_t pkt_len, pkt_ver; krb5_data ap_rep_data; int save_errno; len = 0; if (is_stream) { while (len < sizeof(reply)) { unsigned long size; ret = recvfrom (sock, reply + len, sizeof(reply) - len, 0, NULL, NULL); if (ret < 0) { save_errno = errno; krb5_set_error_string(context, "recvfrom %s: %s", host, strerror(save_errno)); return save_errno; } else if (ret == 0) { krb5_set_error_string(context, "recvfrom timeout %s", host); return 1; } len += ret; if (len < 4) continue; _krb5_get_int(reply, &size, 4); if (size + 4 < len) continue; memmove(reply, reply + 4, size); len = size; break; } if (len == sizeof(reply)) { krb5_set_error_string(context, "message too large from %s", host); return ENOMEM; } } else { ret = recvfrom (sock, reply, sizeof(reply), 0, NULL, NULL); if (ret < 0) { save_errno = errno; krb5_set_error_string(context, "recvfrom %s: %s", host, strerror(save_errno)); return save_errno; } len = ret; } if (len < 6) { str2data (result_string, "server %s sent to too short message " "(%ld bytes)", host, (long)len); *result_code = KRB5_KPASSWD_MALFORMED; return 0; } pkt_len = (reply[0] << 8) | (reply[1]); pkt_ver = (reply[2] << 8) | (reply[3]); if ((pkt_len != len) || (reply[1] == 0x7e || reply[1] == 0x5e)) { KRB_ERROR error; size_t size; u_char *p; memset(&error, 0, sizeof(error)); ret = decode_KRB_ERROR(reply, len, &error, &size); if (ret) return ret; if (error.e_data->length < 2) { str2data(result_string, "server %s sent too short " "e_data to print anything usable", host); free_KRB_ERROR(&error); *result_code = KRB5_KPASSWD_MALFORMED; return 0; } p = error.e_data->data; *result_code = (p[0] << 8) | p[1]; if (error.e_data->length == 2) str2data(result_string, "server only sent error code"); else krb5_data_copy (result_string, p + 2, error.e_data->length - 2); free_KRB_ERROR(&error); return 0; } if (pkt_len != len) { str2data (result_string, "client: wrong len in reply"); *result_code = KRB5_KPASSWD_MALFORMED; return 0; } if (pkt_ver != KRB5_KPASSWD_VERS_CHANGEPW) { str2data (result_string, "client: wrong version number (%d)", pkt_ver); *result_code = KRB5_KPASSWD_MALFORMED; return 0; } ap_rep_data.data = reply + 6; ap_rep_data.length = (reply[4] << 8) | (reply[5]); if (reply + len < (u_char *)ap_rep_data.data + ap_rep_data.length) { str2data (result_string, "client: wrong AP len in reply"); *result_code = KRB5_KPASSWD_MALFORMED; return 0; } if (ap_rep_data.length) { krb5_ap_rep_enc_part *ap_rep; krb5_data priv_data; u_char *p; priv_data.data = (u_char*)ap_rep_data.data + ap_rep_data.length; priv_data.length = len - ap_rep_data.length - 6; ret = krb5_rd_rep (context, auth_context, &ap_rep_data, &ap_rep); if (ret) return ret; krb5_free_ap_rep_enc_part (context, ap_rep); ret = krb5_rd_priv (context, auth_context, &priv_data, result_code_string, NULL); if (ret) { krb5_data_free (result_code_string); return ret; } if (result_code_string->length < 2) { *result_code = KRB5_KPASSWD_MALFORMED; str2data (result_string, "client: bad length in result"); return 0; } p = result_code_string->data; *result_code = (p[0] << 8) | p[1]; krb5_data_copy (result_string, (unsigned char*)result_code_string->data + 2, result_code_string->length - 2); return 0; } else { KRB_ERROR error; size_t size; u_char *p; ret = decode_KRB_ERROR(reply + 6, len - 6, &error, &size); if (ret) { return ret; } if (error.e_data->length < 2) { krb5_warnx (context, "too short e_data to print anything usable"); return 1; /* XXX */ } p = error.e_data->data; *result_code = (p[0] << 8) | p[1]; krb5_data_copy (result_string, p + 2, error.e_data->length - 2); return 0; } }