Last active
April 16, 2018 05:39
-
-
Save frasertweedale/b336be8ae37e9ee22755c3e9b72cec07 to your computer and use it in GitHub Desktop.
DN parsing programs (NSS, openldap)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <ldap.h> | |
| int main(int argc, char **argv) { | |
| if (argc < 2) { | |
| printf("Usage!\n"); | |
| exit(1); | |
| } | |
| LDAPDN dn = NULL; | |
| if (LDAP_SUCCESS != ldap_str2dn(argv[1], &dn, LDAP_DN_FORMAT_LDAPV3)) { | |
| printf("Failed to parse DN\n"); | |
| exit(1); | |
| } | |
| for (int i = 0; dn[i] != NULL; i++) { | |
| LDAPRDN rdn = dn[i]; | |
| printf("RDN %d\n", i); | |
| for (int j = 0; rdn[j] != NULL; j++) { | |
| LDAPAVA *ava = rdn[j]; | |
| printf(" AVA %d %s=%s\n", j, ava->la_attr.bv_val, ava->la_value.bv_val); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <nss3/nss.h> | |
| #include <nss3/cert.h> | |
| int main(int argc, char **argv) { | |
| if (argc < 2) { | |
| fprintf(stderr, "must give stringified dn arg\n"); | |
| exit(1); | |
| } | |
| if (NSS_NoDB_Init(NULL) != SECSuccess) { | |
| fprintf(stderr, "failed to init nss\n"); | |
| exit(1); | |
| } | |
| CERTName *dn = CERT_AsciiToName(argv[1]); | |
| if (dn == NULL) { | |
| fprintf(stderr, "failed to parse dn\n"); | |
| exit(1); | |
| } | |
| printf("Parsed name (as stringified by NSS):\n"); | |
| printf(" %s\n", CERT_NameToAscii(dn)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment