int main (void) { KLStatus err; KLPrincipal principal; char *principalName; char *cacheName; printf ("Testing KLAcquireNewTickets (nil)...\n"); err = KLAcquireNewTickets (nil, &principal, &cacheName); if (err == klNoErr) { err = KLGetStringFromPrincipal (principal, kerberosVersion_V5, &principalName); if (err == klNoErr) { printf ("Got tickets for '%s' in cache '%s'\n", principalName, cacheName); KLDisposeString (principalName); } else { printf ("KLGetStringFromPrincipal() returned (err = %ld)\n", err); } KLDisposeString (cacheName); printf ("Testing KLChangePassword (principal)...\n"); err = KLChangePassword (principal); if (err != klNoErr) { printf ("KLChangePassword() returned (err = %ld)\n", err); } KLDisposePrincipal (principal); } else { printf ("KLAcquireNewTickets() returned (err = %ld)\n", err); } printf ("All done testing!\n"); return 0; }
void TestHighLevelAPI (void) { KLStatus err; KLPrincipal inPrincipal, outPrincipal, outPrincipal2; char *outCredCacheName, *outCredCacheName2; KLTime expirationTime; char* principalString; char timeString[256]; KLBoolean valid; err = KLCreatePrincipalFromTriplet ("grail", "", "TESTV5-KERBEROS-1.3.1", &inPrincipal); printf ("KLCreatePrincipalFromTriplet([email protected]) (err = %d)\n", err); if (err == klNoErr) { err = KLAcquireNewInitialTicketsWithPassword (inPrincipal, NULL, "liarg", &outCredCacheName); if (err != klNoErr) { printf ("KLAcquireNewInitialTicketsWithPassword() returned err = %d\n", err); } else { printf ("KLAcquireNewInitialTicketsWithPassword() returned '%s'\n", outCredCacheName); KLDisposeString (outCredCacheName); } KLDisposePrincipal (inPrincipal); } err = KLCreatePrincipalFromTriplet ("nobody", "", "TEST-KERBEROS-1.3.1", &inPrincipal); printf ("KLCreatePrincipalFromTriplet([email protected]) (err = %d)\n", err); if (err == klNoErr) { err = KLAcquireNewInitialTicketsWithPassword (inPrincipal, NULL, "ydobon", &outCredCacheName); if (err != klNoErr) { printf ("KLAcquireNewInitialTicketsWithPassword() returned err = %d\n", err); } else { printf ("KLAcquireNewInitialTicketsWithPassword() returned '%s'\n", outCredCacheName); KLDisposeString (outCredCacheName); } KLDisposePrincipal (inPrincipal); } err = KLAcquireNewInitialTickets (NULL, NULL, &inPrincipal, &outCredCacheName); printf ("KLAcquireNewInitialTickets() (err = %d)\n", err); if (err == klNoErr) { KLDisposeString (outCredCacheName); err = KLAcquireInitialTickets (inPrincipal, NULL, &outPrincipal, &outCredCacheName); printf ("KLAcquireInitialTickets() (err = %d)\n", err); if (err == klNoErr) { KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } KLDisposePrincipal (inPrincipal); } err = KLSetDefaultLoginOption (loginOption_LoginName, "testname", 3); printf ("KLSetDefaultLoginOption(loginOption_LoginName) to testname (err = %d)\n", err); if (err == klNoErr) { err = KLSetDefaultLoginOption (loginOption_LoginInstance, "testinstance", 6); printf ("KLSetDefaultLoginOption(loginOption_LoginInstance) to testinstance (err = %d)\n", err); } err = KLAcquireNewInitialTickets (NULL, NULL, &inPrincipal, &outCredCacheName); printf ("KLAcquireNewInitialTickets() (err = %d)\n", err); if (err == klNoErr) { KLDisposeString (outCredCacheName); KLDisposePrincipal (inPrincipal); } // Principal == NULL while (KLAcquireNewInitialTickets (NULL, NULL, &outPrincipal, &outCredCacheName) == klNoErr) { err = KLTicketExpirationTime (outPrincipal, kerberosVersion_All, &expirationTime); err = KLCacheHasValidTickets (outPrincipal, kerberosVersion_All, &valid, &outPrincipal2, &outCredCacheName2); if (err == klNoErr) { err = KLGetStringFromPrincipal (outPrincipal2, kerberosVersion_V4, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal returned string '%s'\n", principalString); KLDisposeString (principalString); } KLDisposePrincipal (outPrincipal2); KLDisposeString (outCredCacheName2); err = KLCacheHasValidTickets (outPrincipal, kerberosVersion_All, &valid, NULL, NULL); if (err != klNoErr) { printf ("KLCacheHasValidTickets returned error = %d\n", err); } } err = KLCacheHasValidTickets (outPrincipal, kerberosVersion_All, &valid, NULL, NULL); KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } err = KLAcquireNewInitialTickets (NULL, NULL, &outPrincipal, &outCredCacheName); if (err == klNoErr) { KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } err = KLCreatePrincipalFromTriplet ("nobody", "", "TEST-KERBEROS-1.3.1", &inPrincipal); printf ("KLCreatePrincipalFromTriplet([email protected]) (err = %d)\n", err); if (err == klNoErr) { err = KLAcquireNewInitialTickets (inPrincipal, NULL, &outPrincipal, &outCredCacheName); printf ("KLAcquireNewInitialTickets([email protected]) (err = %d)\n", err); if (err == klNoErr) { KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } err = KLDestroyTickets (inPrincipal); KLDisposePrincipal (inPrincipal); } err = KLCreatePrincipalFromTriplet ("nobody", "", "TEST-KERBEROS-1.3.1", &inPrincipal); printf ("KLCreatePrincipalFromTriplet([email protected]) (err = %d)\n", err); if (err == klNoErr) { err = KLAcquireInitialTickets (inPrincipal, NULL, &outPrincipal, &outCredCacheName); printf ("KLAcquireInitialTickets([email protected]) (err = %d)\n", err); if (err == klNoErr) { KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } err = KLAcquireNewInitialTickets (inPrincipal, NULL, &outPrincipal, &outCredCacheName); if (err == klNoErr) { err = KLGetStringFromPrincipal (outPrincipal, kerberosVersion_V5, &principalString); if (err == klNoErr) { err = KLTicketExpirationTime (outPrincipal, kerberosVersion_All, &expirationTime); printf ("Tickets for principal '%s' expire on %s\n", principalString, TimeToString(timeString, expirationTime)); KLDisposeString (principalString); } KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } err = KLChangePassword (inPrincipal); printf ("KLChangePassword() (err = %d)\n", err); err = KLDestroyTickets (inPrincipal); printf ("KLDestroyTickets() (err = %d)\n", err); KLDisposePrincipal (inPrincipal); } }
void TestKLPrincipal (void) { KLStatus err = klNoErr; KLPrincipal extraLongPrincipal = NULL; KLPrincipal principal = NULL; KLPrincipal adminPrincipal = NULL; KLPrincipal adminPrincipalV4 = NULL; KLPrincipal adminPrincipalV5 = NULL; char *principalString = NULL; char *user = NULL; char *instance = NULL; char *realm = NULL; printf ("Entering TestKLPrincipal()\n"); printf ("----------------------------------------------------------------\n"); err = KLCreatePrincipalFromString ("thisprincipalnameislongerthanissupportedbyKerberos4@TEST-KERBEROS-1.3.1", kerberosVersion_V5, &extraLongPrincipal); printf ("KLCreatePrincipalFromString " "('thisprincipalnameislongerthanissupportedbyKerberos4@TEST-KERBEROS-1.3.1') " "(err = %s)\n", error_message(err)); printf ("----------------------------------------------------------------\n"); err = KLCreatePrincipalFromTriplet ("nobody", "", "TEST-KERBEROS-1.3.1", &principal); printf ("KLCreatePrincipalFromTriplet ('nobody' '' 'TEST-KERBEROS-1.3.1') (err = %s)\n", error_message(err)); if (err == klNoErr) { err = KLGetStringFromPrincipal (principal, kerberosVersion_V5, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal ([email protected], v5) returned string '%s'\n", principalString); KLDisposeString (principalString); } else { printf ("KLGetStringFromPrincipal([email protected], v5) returned (err = %s)\n", error_message(err)); } err = KLGetStringFromPrincipal (principal, kerberosVersion_V4, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal ([email protected], v4) returned string '%s'\n", principalString); KLDisposeString (principalString); } else { printf ("KLGetStringFromPrincipal([email protected], v4) returned (err = %s)\n", error_message(err)); } err = KLGetTripletFromPrincipal (principal, &user, &instance, &realm); if (err == klNoErr) { printf ("KLGetTripletFromPrincipal ([email protected]) returned triplet %s' '%s' '%s'\n", user, instance, realm); KLDisposeString (user); KLDisposeString (instance); KLDisposeString (realm); } else { printf ("KLGetTripletFromPrincipal([email protected]) returned (err = %s)\n", error_message(err)); } } printf ("----------------------------------------------------------------\n"); err = KLCreatePrincipalFromTriplet ("nobody", "admin", "TEST-KERBEROS-1.3.1", &adminPrincipal); printf ("KLCreatePrincipalFromTriplet ('nobody' 'admin' 'TEST-KERBEROS-1.3.1') (err = %d)\n", err); if (err == klNoErr) { err = KLGetStringFromPrincipal (adminPrincipal, kerberosVersion_V5, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal (nobody/[email protected], v5) returned string '%s'\n", principalString); KLDisposeString (principalString); } else { printf ("KLGetStringFromPrincipal(nobody/[email protected], v5) returned (err = %d)\n", err); } err = KLGetStringFromPrincipal (adminPrincipal, kerberosVersion_V4, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal (nobody/[email protected], v4) returned string '%s'\n", principalString); KLDisposeString (principalString); } else { printf ("KLGetStringFromPrincipal(nobody/[email protected], v4) returned (err = %d)\n", err); } err = KLGetTripletFromPrincipal (adminPrincipal, &user, &instance, &realm); if (err == klNoErr) { printf ("KLGetTripletFromPrincipal (nobody/[email protected]) returned triplet %s' '%s' '%s'\n", user, instance, realm); KLDisposeString (user); KLDisposeString (instance); KLDisposeString (realm); } else { printf ("KLGetTripletFromPrincipal(lxs/[email protected]) returned (err = %d)\n", err); } } printf ("----------------------------------------------------------------\n"); err = KLCreatePrincipalFromString ("nobody/[email protected]", kerberosVersion_V5, &adminPrincipalV5); printf ("KLCreatePrincipalFromString ('nobody/[email protected]', v5) (err = %d)\n", err); if (err == klNoErr) { err = KLGetStringFromPrincipal (adminPrincipalV5, kerberosVersion_V5, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal (nobody/[email protected], v5) returned string '%s'\n", principalString); KLDisposeString (principalString); } else { printf ("KLGetStringFromPrincipal(nobody/[email protected], v5) returned (err = %d)\n", err); } err = KLGetStringFromPrincipal (adminPrincipalV5, kerberosVersion_V4, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal (nobody/[email protected], v4) returned string '%s'\n", principalString); KLDisposeString (principalString); } else { printf ("KLGetStringFromPrincipal(nobody/[email protected], v4) returned (err = %d)\n", err); } err = KLGetTripletFromPrincipal (adminPrincipalV5, &user, &instance, &realm); if (err == klNoErr) { printf ("KLGetTripletFromPrincipal (nobody/[email protected]) returned triplet %s' '%s' '%s'\n", user, instance, realm); KLDisposeString (user); KLDisposeString (instance); KLDisposeString (realm); } else { printf ("KLGetTripletFromPrincipal(nobody/[email protected]) returned (err = %d)\n", err); } } printf ("----------------------------------------------------------------\n"); err = KLCreatePrincipalFromString ("[email protected]", kerberosVersion_V4, &adminPrincipalV4); printf ("KLCreatePrincipalFromString ('[email protected]') (err = %d)\n", err); if (err == klNoErr) { err = KLGetStringFromPrincipal (adminPrincipalV4, kerberosVersion_V5, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal ([email protected], v5) returned string '%s'\n", principalString); KLDisposeString (principalString); } else { printf ("KLGetStringFromPrincipal([email protected], v5) returned (err = %d)\n", err); } err = KLGetStringFromPrincipal (adminPrincipalV4, kerberosVersion_V4, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal ([email protected], v4) returned string '%s'\n", principalString); KLDisposeString (principalString); } else { printf ("KLGetStringFromPrincipal([email protected], v4) returned (err = %d)\n", err); } err = KLGetTripletFromPrincipal (adminPrincipalV4, &user, &instance, &realm); if (err == klNoErr) { printf ("KLGetTripletFromPrincipal ([email protected]) returned triplet %s' '%s' '%s'\n", user, instance, realm); KLDisposeString (user); KLDisposeString (instance); KLDisposeString (realm); } else { printf ("KLGetTripletFromPrincipal([email protected]) returned (err = %d)\n", err); } } printf ("----------------------------------------------------------------\n"); if (adminPrincipalV4 != NULL && adminPrincipalV5 != NULL) { KLBoolean equivalent; err = KLComparePrincipal (adminPrincipalV5, adminPrincipalV4, &equivalent); if (err == klNoErr) { printf ("KLComparePrincipal %s comparing nobody/[email protected] and [email protected]\n", equivalent ? "passed" : "FAILED"); } else { printf ("KLComparePrincipal returned (err = %d)\n", err); } } if (principal != NULL && adminPrincipalV5 != NULL) { KLBoolean equivalent; err = KLComparePrincipal (principal, adminPrincipalV4, &equivalent); if (err == klNoErr) { printf ("KLComparePrincipal %s comparing [email protected] and [email protected]\n", equivalent ? "FAILED" : "passed"); } else { printf ("KLComparePrincipal returned (err = %d)\n", err); } } if (principal != NULL && adminPrincipalV5 != NULL) { KLBoolean equivalent; err = KLComparePrincipal (principal, adminPrincipalV5, &equivalent); if (err == klNoErr) { printf ("KLComparePrincipal %s comparing [email protected] and nobody/[email protected]\n", equivalent ? "FAILED" : "passed"); } else { printf ("KLComparePrincipal returned (err = %d)\n", err); } } if (adminPrincipal != NULL && adminPrincipalV5 != NULL) { KLBoolean equivalent; err = KLComparePrincipal (adminPrincipalV5, principal, &equivalent); if (err == klNoErr) { printf ("KLComparePrincipal %s comparing nobody/[email protected] and [email protected]\n", equivalent ? "FAILED" : "passed"); } else { printf ("KLComparePrincipal returned (err = %d)\n", err); } } printf ("----------------------------------------------------------------\n\n"); if (extraLongPrincipal != NULL) KLDisposePrincipal (extraLongPrincipal); if (adminPrincipalV5 != NULL) KLDisposePrincipal (adminPrincipalV5); if (adminPrincipalV4 != NULL) KLDisposePrincipal (adminPrincipalV4); if (adminPrincipal != NULL) KLDisposePrincipal (adminPrincipal); if (principal != NULL) KLDisposePrincipal (principal); }