static int test_heim_oid_format_same(const char *str, const heim_oid *oid) { int ret; char *p; heim_oid o2; ret = der_print_heim_oid(oid, ' ', &p); if (ret) { printf("fail to print oid: %s\n", str); return 1; } ret = strcmp(p, str); if (ret) { printf("oid %s != formated oid %s\n", str, p); free(p); return ret; } ret = der_parse_heim_oid(p, " ", &o2); if (ret) { printf("failed to parse %s\n", p); free(p); return ret; } free(p); ret = der_heim_oid_cmp(&o2, oid); der_free_oid(&o2); return ret; }
static int stringtooid(const char *name, size_t len, heim_oid *oid) { int i, ret; char *s; memset(oid, 0, sizeof(*oid)); for (i = 0; i < sizeof(no)/sizeof(no[0]); i++) { if (strncasecmp(no[i].n, name, len) == 0) return der_copy_oid((*no[i].o)(), oid); } s = malloc(len + 1); if (s == NULL) return ENOMEM; memcpy(s, name, len); s[len] = '\0'; ret = der_parse_heim_oid(s, ".", oid); free(s); return ret; }
static int readConfMechOid(int argc, const char **argv, gss_OID *mech) { int i; OM_uint32 major, minor; const char *oidstr = NULL; #ifndef __APPLE__ size_t oidstrLen; gss_buffer_desc oidBuf; char *p; #endif for (i = 0; i < argc; i++) { if (strncmp(argv[i], "mech=", 5) != 0) continue; oidstr = &argv[i][5]; break; } if (oidstr == NULL) return PAM_SUCCESS; #ifdef __APPLE__ char mechbuf[64]; size_t mech_len; heim_oid heimOid; int ret; if (der_parse_heim_oid(oidstr, " .", &heimOid)) return PAM_SERVICE_ERR; ret = der_put_oid((unsigned char *)mechbuf + sizeof(mechbuf) - 1, sizeof(mechbuf), &heimOid, &mech_len); if (ret) { der_free_oid(&heimOid); return PAM_SERVICE_ERR; } *mech = (gss_OID)malloc(sizeof(gss_OID_desc)); if (*mech == NULL) { der_free_oid(&heimOid); return PAM_BUF_ERR; } (*mech)->elements = malloc(mech_len); if ((*mech)->elements == NULL) { der_free_oid(&heimOid); free(*mech); *mech = NULL; return PAM_BUF_ERR; } (*mech)->length = mech_len; memcpy((*mech)->elements, mechbuf + sizeof(mechbuf) - mech_len, mech_len); der_free_oid(&heimOid); major = GSS_S_COMPLETE; minor = 0; #else oidstrLen = strlen(oidstr); oidBuf.length = 2 + oidstrLen + 2; oidBuf.value = malloc(oidBuf.length + 1); if (oidBuf.value == NULL) return PAM_BUF_ERR; p = (char *)oidBuf.value; *p++ = '{'; *p++ = ' '; for (i = 0; i < oidstrLen; i++) *p++ = oidstr[i] == '.' ? ' ' : oidstr[i]; *p++ = ' '; *p++ = '}'; *p = '\0'; assert(oidBuf.length == p - (char *)oidBuf.value); major = gss_str_to_oid(&minor, &oidBuf, mech); free(oidBuf.value); #endif return pamGssMapStatus(major, minor); }