int decode_negTokenInit(unsigned char *security_blob, int length, struct TCP_Server_Info *server) { struct asn1_ctx ctx; unsigned char *end; unsigned char *sequence_end; unsigned long *oid = NULL; unsigned int cls, con, tag, oidlen, rc; /* cifs_dump_mem(" Received SecBlob ", security_blob, length); */ asn1_open(&ctx, security_blob, length); /* GSSAPI header */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding negTokenInit header"); return 0; } else if ((cls != ASN1_APL) || (con != ASN1_CON) || (tag != ASN1_EOC)) { cFYI(1, "cls = %d con = %d tag = %d", cls, con, tag); return 0; } /* Check for SPNEGO OID -- remember to free obj->oid */ rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); if (rc) { if ((tag == ASN1_OJI) && (con == ASN1_PRI) && (cls == ASN1_UNI)) { rc = asn1_oid_decode(&ctx, end, &oid, &oidlen); if (rc) { rc = compare_oid(oid, oidlen, SPNEGO_OID, SPNEGO_OID_LEN); kfree(oid); } } else rc = 0; } /* SPNEGO OID not present or garbled -- bail out */ if (!rc) { cFYI(1, "Error decoding negTokenInit header"); return 0; } /* SPNEGO */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding negTokenInit"); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON) || (tag != ASN1_EOC)) { cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0", cls, con, tag, end, *end); return 0; } /* negTokenInit */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding negTokenInit"); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_CON) || (tag != ASN1_SEQ)) { cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1", cls, con, tag, end, *end); return 0; } /* sequence */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding 2nd part of negTokenInit"); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON) || (tag != ASN1_EOC)) { cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0", cls, con, tag, end, *end); return 0; } /* sequence of */ if (asn1_header_decode (&ctx, &sequence_end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding 2nd part of negTokenInit"); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_CON) || (tag != ASN1_SEQ)) { cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1", cls, con, tag, end, *end); return 0; } /* list of security mechanisms */ while (!asn1_eoc_decode(&ctx, sequence_end)) { rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); if (!rc) { cFYI(1, "Error decoding negTokenInit hdr exit2"); return 0; } if ((tag == ASN1_OJI) && (con == ASN1_PRI)) { if (asn1_oid_decode(&ctx, end, &oid, &oidlen)) { cFYI(1, "OID len = %d oid = 0x%lx 0x%lx " "0x%lx 0x%lx", oidlen, *oid, *(oid + 1), *(oid + 2), *(oid + 3)); if (compare_oid(oid, oidlen, MSKRB5_OID, MSKRB5_OID_LEN)) server->sec_mskerberos = true; else if (compare_oid(oid, oidlen, KRB5U2U_OID, KRB5U2U_OID_LEN)) server->sec_kerberosu2u = true; else if (compare_oid(oid, oidlen, KRB5_OID, KRB5_OID_LEN)) server->sec_kerberos = true; else if (compare_oid(oid, oidlen, NTLMSSP_OID, NTLMSSP_OID_LEN)) server->sec_ntlmssp = true; kfree(oid); } } else { cFYI(1, "Should be an oid what is going on?"); } } <<<<<<< HEAD
int decode_negTokenInit(unsigned char *security_blob, int length, enum securityEnum *secType) { struct asn1_ctx ctx; unsigned char *end; unsigned char *sequence_end; unsigned long *oid = NULL; unsigned int cls, con, tag, oidlen, rc; bool use_ntlmssp = false; bool use_kerberos = false; bool use_mskerberos = false; *secType = NTLM; /* BB eventually make Kerberos or NLTMSSP the default*/ /* cifs_dump_mem(" Received SecBlob ", security_blob, length); */ asn1_open(&ctx, security_blob, length); /* GSSAPI header */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, ("Error decoding negTokenInit header")); return 0; } else if ((cls != ASN1_APL) || (con != ASN1_CON) || (tag != ASN1_EOC)) { cFYI(1, ("cls = %d con = %d tag = %d", cls, con, tag)); return 0; } /* Check for SPNEGO OID -- remember to free obj->oid */ rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); if (rc) { if ((tag == ASN1_OJI) && (con == ASN1_PRI) && (cls == ASN1_UNI)) { rc = asn1_oid_decode(&ctx, end, &oid, &oidlen); if (rc) { rc = compare_oid(oid, oidlen, SPNEGO_OID, SPNEGO_OID_LEN); kfree(oid); } } else rc = 0; } /* SPNEGO OID not present or garbled -- bail out */ if (!rc) { cFYI(1, ("Error decoding negTokenInit header")); return 0; } if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, ("Error decoding negTokenInit")); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON) || (tag != ASN1_EOC)) { cFYI(1, ("cls = %d con = %d tag = %d end = %p (%d) exit 0", cls, con, tag, end, *end)); return 0; } if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, ("Error decoding negTokenInit")); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_CON) || (tag != ASN1_SEQ)) { cFYI(1, ("cls = %d con = %d tag = %d end = %p (%d) exit 1", cls, con, tag, end, *end)); return 0; } if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, ("Error decoding 2nd part of negTokenInit")); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON) || (tag != ASN1_EOC)) { cFYI(1, ("cls = %d con = %d tag = %d end = %p (%d) exit 0", cls, con, tag, end, *end)); return 0; } if (asn1_header_decode (&ctx, &sequence_end, &cls, &con, &tag) == 0) { cFYI(1, ("Error decoding 2nd part of negTokenInit")); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_CON) || (tag != ASN1_SEQ)) { cFYI(1, ("cls = %d con = %d tag = %d end = %p (%d) exit 1", cls, con, tag, end, *end)); return 0; } while (!asn1_eoc_decode(&ctx, sequence_end)) { rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); if (!rc) { cFYI(1, ("Error decoding negTokenInit hdr exit2")); return 0; } if ((tag == ASN1_OJI) && (con == ASN1_PRI)) { if (asn1_oid_decode(&ctx, end, &oid, &oidlen)) { cFYI(1, ("OID len = %d oid = 0x%lx 0x%lx " "0x%lx 0x%lx", oidlen, *oid, *(oid + 1), *(oid + 2), *(oid + 3))); if (compare_oid(oid, oidlen, MSKRB5_OID, MSKRB5_OID_LEN) && !use_kerberos) use_mskerberos = true; else if (compare_oid(oid, oidlen, KRB5_OID, KRB5_OID_LEN) && !use_mskerberos) use_kerberos = true; else if (compare_oid(oid, oidlen, NTLMSSP_OID, NTLMSSP_OID_LEN)) use_ntlmssp = true; kfree(oid); } } else { cFYI(1, ("Should be an oid what is going on?")); } } if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, ("Error decoding last part negTokenInit exit3")); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { /* tag = 3 indicating mechListMIC */ cFYI(1, ("Exit 4 cls = %d con = %d tag = %d end = %p (%d)", cls, con, tag, end, *end)); return 0; } if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, ("Error decoding last part negTokenInit exit5")); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_CON) || (tag != ASN1_SEQ)) { cFYI(1, ("cls = %d con = %d tag = %d end = %p (%d)", cls, con, tag, end, *end)); } if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, ("Error decoding last part negTokenInit exit 7")); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { cFYI(1, ("Exit 8 cls = %d con = %d tag = %d end = %p (%d)", cls, con, tag, end, *end)); return 0; } if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, ("Error decoding last part negTokenInit exit9")); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_PRI) || (tag != ASN1_GENSTR)) { cFYI(1, ("Exit10 cls = %d con = %d tag = %d end = %p (%d)", cls, con, tag, end, *end)); return 0; } cFYI(1, ("Need to call asn1_octets_decode() function for %s", ctx.pointer)); /* is this UTF-8 or ASCII? */ if (use_kerberos) *secType = Kerberos; else if (use_mskerberos) *secType = MSKerberos; else if (use_ntlmssp) *secType = NTLMSSP; return 1; }
BOOL CtronEtherIndexs(char *server, int port, char *community, int rdelay, int timeout, char *cpath, CString &strBuffer) { int s; struct sockaddr_in serv; int nEther = 0; int nEthers[256] = {0}; struct oid nEtherDs[256]; int nIfIndex[256] = {0}; char IfDescr[256][64] = {0}; BOOL bResult = TRUE; int i = 0; struct oid *poid = NULL, *proid = NULL; struct snval *psnval = NULL; strBuffer = _T(""); if(MakeSocket(server, port, s, serv) < 0) { return FALSE; } poid = (struct oid *)malloc(sizeof(struct oid)); proid = (struct oid *)malloc(sizeof(struct oid)); psnval = (struct snval *)malloc(sizeof(struct snval)); if(poid == NULL || proid == NULL || psnval == NULL) { bResult = FALSE; goto err; } memcpy(poid, ðerStatsTable, sizeof(struct oid)); memset(proid, 0, sizeof(struct oid)); memset(psnval, 0, sizeof(struct snval)); // Get Rmon Index while(SN_NEXT_VALUE(s, serv, community, 1, poid, proid, psnval) == 0) { if(compare_oid(*proid, etherStatsIndex) || psnval->sv_type != ASN1_INT) { break; } nEthers[nEther ++] = psnval->sv_val.sv_int; if(nEther >= 256) { break; } memcpy(poid, proid, sizeof(struct oid)); memset(proid, 0, sizeof(struct oid)); memset(psnval, 0, sizeof(struct snval)); } if(nEther == 0) { bResult = FALSE; goto err; } // Get Rmon Data Source for(i = 0;i < nEther;i ++) { struct oid ds = etherStatsDataSource; ds.id[ds.len ++] = nEthers[i]; memset(psnval, 0, sizeof(struct snval)); if(SN_VALUE(s, serv, community, 1, &ds, psnval) < 0) { bResult = FALSE; goto err; } if(psnval->sv_type != ASN1_OBJID) { bResult = FALSE; goto err; } nEtherDs[i] = psnval->sv_val.sv_oid; } // Get Interface Index for(i = 0;i < nEther;i ++) { memset(psnval, 0, sizeof(struct snval)); if(SN_VALUE(s, serv, community, 1, &nEtherDs[i], psnval) < 0) { bResult = FALSE; goto err; } if(psnval->sv_type != ASN1_INT) { bResult = FALSE; goto err; } nIfIndex[i] = psnval->sv_val.sv_int; } // Get Interface Description for(i = 0;i < nEther;i ++) { struct oid descr = ifDescr; descr.id[descr.len ++] = nIfIndex[i]; memset(psnval, 0, sizeof(struct snval)); if(SN_VALUE(s, serv, community, 1, &descr, psnval) < 0) { bResult = FALSE; goto err; } if(psnval->sv_type != ASN1_OCTSTR) { bResult = FALSE; goto err; } strncpy(IfDescr[i], psnval->sv_val.sv_str.sv_str, psnval->sv_val.sv_str.sv_len); } // Organize Output for(i = 0;i < nEther;i ++) { char szBuffer[1024] = {0}; sprintf(szBuffer, "%s%d###%s###$$$", szBuffer, nEthers[i], IfDescr[i]); strBuffer += szBuffer; } err: if(poid) { free(poid); poid = NULL; } if(proid) { free(proid); proid = NULL; } if(psnval) { free(psnval); psnval = NULL; } return bResult; }
BOOL CTRONSSRCPU_MONITOR(char *server, int port, char *community, int rdelay, int timeout, char *cpath, char *szReturn) { int s; struct sockaddr_in serv; int ret = 0; BOOL bResult = TRUE; struct oid *poid = NULL, *proid = NULL; struct snval *psnval = NULL; *szReturn = 0; if((ret = MakeSocket(server, port, s, serv)) < 0) { if(ret == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CheckPoint_1%>"));//<%IDS_CheckPoint_1%> else if(ret == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CheckPoint_2%>"));//<%IDS_CheckPoint_2%> else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CheckPoint_3%>"));//<%IDS_CheckPoint_3%> return FALSE; } poid = (struct oid *)malloc(sizeof(struct oid)); proid = (struct oid *)malloc(sizeof(struct oid)); psnval = (struct snval *)malloc(sizeof(struct snval)); if(poid == NULL || proid == NULL || psnval == NULL) { bResult = FALSE; sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CTRON_01%>")); // 内存溢出错误 goto err; } memset(poid, 0, sizeof(struct oid)); memset(proid, 0, sizeof(struct oid)); memset(psnval, 0, sizeof(struct snval)); memcpy(poid, &capCPUTable, sizeof(struct oid)); while(SN_NEXT_VALUE(s, serv, community, 1, poid, proid, psnval) == 0) { if(compare_oid(*proid, capCPUCurrentUtilization) || psnval->sv_type != ASN1_INT || psnval->sv_val.sv_int > 100 || psnval->sv_val.sv_int < 0) { break; } sprintf(szReturn, "%sUtilization=%d$", szReturn, psnval->sv_val.sv_int); memcpy(poid, proid, sizeof(struct oid)); memset(proid, 0, sizeof(struct oid)); memset(psnval, 0, sizeof(struct snval)); } if(!*szReturn) { bResult = FALSE; sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_CTRON_02%>")); // 设备无此性能参数 } err: if(poid) { free(poid); poid = NULL; } if(proid) { free(proid); proid = NULL; } if(psnval) { free(psnval); psnval = NULL; } return bResult; }
int decode_negTokenInit(unsigned char *security_blob, int length, struct TCP_Server_Info *server) { struct asn1_ctx ctx; unsigned char *end; unsigned char *sequence_end; unsigned long *oid = NULL; unsigned int cls, con, tag, oidlen, rc; /* */ asn1_open(&ctx, security_blob, length); /* */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding negTokenInit header"); return 0; } else if ((cls != ASN1_APL) || (con != ASN1_CON) || (tag != ASN1_EOC)) { cFYI(1, "cls = %d con = %d tag = %d", cls, con, tag); return 0; } /* */ rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); if (rc) { if ((tag == ASN1_OJI) && (con == ASN1_PRI) && (cls == ASN1_UNI)) { rc = asn1_oid_decode(&ctx, end, &oid, &oidlen); if (rc) { rc = compare_oid(oid, oidlen, SPNEGO_OID, SPNEGO_OID_LEN); kfree(oid); } } else rc = 0; } /* */ if (!rc) { cFYI(1, "Error decoding negTokenInit header"); return 0; } /* */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding negTokenInit"); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON) || (tag != ASN1_EOC)) { cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0", cls, con, tag, end, *end); return 0; } /* */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding negTokenInit"); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_CON) || (tag != ASN1_SEQ)) { cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1", cls, con, tag, end, *end); return 0; } /* */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding 2nd part of negTokenInit"); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON) || (tag != ASN1_EOC)) { cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0", cls, con, tag, end, *end); return 0; } /* */ if (asn1_header_decode (&ctx, &sequence_end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding 2nd part of negTokenInit"); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_CON) || (tag != ASN1_SEQ)) { cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1", cls, con, tag, end, *end); return 0; } /* */ while (!asn1_eoc_decode(&ctx, sequence_end)) { rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); if (!rc) { cFYI(1, "Error decoding negTokenInit hdr exit2"); return 0; } if ((tag == ASN1_OJI) && (con == ASN1_PRI)) { if (asn1_oid_decode(&ctx, end, &oid, &oidlen)) { cFYI(1, "OID len = %d oid = 0x%lx 0x%lx " "0x%lx 0x%lx", oidlen, *oid, *(oid + 1), *(oid + 2), *(oid + 3)); if (compare_oid(oid, oidlen, MSKRB5_OID, MSKRB5_OID_LEN)) server->sec_mskerberos = true; else if (compare_oid(oid, oidlen, KRB5U2U_OID, KRB5U2U_OID_LEN)) server->sec_kerberosu2u = true; else if (compare_oid(oid, oidlen, KRB5_OID, KRB5_OID_LEN)) server->sec_kerberos = true; else if (compare_oid(oid, oidlen, NTLMSSP_OID, NTLMSSP_OID_LEN)) server->sec_ntlmssp = true; kfree(oid); } } else { cFYI(1, "Should be an oid what is going on?"); } } /* */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { /* */ if (ctx.error == ASN1_ERR_DEC_EMPTY) goto decode_negtoken_exit; cFYI(1, "Error decoding last part negTokenInit exit3"); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { /* */ cFYI(1, "Exit 4 cls = %d con = %d tag = %d end = %p (%d)", cls, con, tag, end, *end); return 0; } /* */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding last part negTokenInit exit5"); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_CON) || (tag != ASN1_SEQ)) { cFYI(1, "cls = %d con = %d tag = %d end = %p (%d)", cls, con, tag, end, *end); } /* */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding last part negTokenInit exit 7"); return 0; } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { cFYI(1, "Exit 8 cls = %d con = %d tag = %d end = %p (%d)", cls, con, tag, end, *end); return 0; } /* */ if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { cFYI(1, "Error decoding last part negTokenInit exit9"); return 0; } else if ((cls != ASN1_UNI) || (con != ASN1_PRI) || (tag != ASN1_GENSTR)) { cFYI(1, "Exit10 cls = %d con = %d tag = %d end = %p (%d)", cls, con, tag, end, *end); return 0; } cFYI(1, "Need to call asn1_octets_decode() function for %s", ctx.pointer); /* */ decode_negtoken_exit: return 1; }