188 lines
4.7 KiB
C
188 lines
4.7 KiB
C
|
//++=======================================================================
|
||
|
// File Name: test.c
|
||
|
// Version: v1.00
|
||
|
// Author: Juan Carlos Luciani v1.0
|
||
|
//
|
||
|
// Abstract: This module tests the authentication token infrastructure.
|
||
|
//
|
||
|
// Notes:
|
||
|
//
|
||
|
// Revision History:
|
||
|
//
|
||
|
//
|
||
|
// (C) Unpublished Copyright of Novell, Inc. All Rights Reserved.
|
||
|
//
|
||
|
// No part of this file may be duplicated, revised, translated, localized,
|
||
|
// or modified in any manner or compiled, linked or uploaded or downloaded
|
||
|
// to or from any computer system without the prior written consent of
|
||
|
// Novell, Inc.
|
||
|
//=======================================================================--
|
||
|
|
||
|
|
||
|
|
||
|
//===[ Include files ]=====================================================
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <getopt.h>
|
||
|
#include <errno.h>
|
||
|
|
||
|
#include <auth_token.h>
|
||
|
|
||
|
//===[ Type definitions ]==================================================
|
||
|
|
||
|
//
|
||
|
// DbgTrace macro define
|
||
|
//
|
||
|
#define DbgTrace(LEVEL, X, Y) { \
|
||
|
if (LEVEL == 0) \
|
||
|
printf(X, Y); \
|
||
|
else if (DebugLevel >= LEVEL) \
|
||
|
printf(X, Y); \
|
||
|
}
|
||
|
|
||
|
|
||
|
//===[ Function prototypes ]===============================================
|
||
|
|
||
|
//===[ Global variables ]==================================================
|
||
|
|
||
|
// Usage string
|
||
|
char usage[] = "\ntest: usage: [-p ConnectPort] [-D DebugLevel]\n";
|
||
|
|
||
|
// Debug Level
|
||
|
int DebugLevel = 3;
|
||
|
|
||
|
|
||
|
//++=======================================================================
|
||
|
void
|
||
|
ExecuteTests(void)
|
||
|
//
|
||
|
// Arguments:
|
||
|
//
|
||
|
// Returns:
|
||
|
//
|
||
|
// Abstract:
|
||
|
//
|
||
|
// Notes:
|
||
|
//
|
||
|
// Environment:
|
||
|
//
|
||
|
//=======================================================================--
|
||
|
{
|
||
|
CasaStatus status;
|
||
|
char userName[100];
|
||
|
int userNameBufLen = sizeof(userName);
|
||
|
char token[1000];
|
||
|
int tokenBufLen = sizeof(token);
|
||
|
|
||
|
DbgTrace(1, "ExecuteTests- Start\n", 0);
|
||
|
|
||
|
status = GetAuthTokenCredentials("krb-test-service",
|
||
|
userName,
|
||
|
&userNameBufLen,
|
||
|
token,
|
||
|
&tokenBufLen);
|
||
|
if (CASA_SUCCESS(status)
|
||
|
&& CasaStatusCode(status) != CASA_STATUS_OBJECT_NOT_FOUND)
|
||
|
{
|
||
|
// We obtained authentication token credentials to authenticate
|
||
|
// to the service, now verify them.
|
||
|
printf("userName = %s\n", userName);
|
||
|
printf("userNameBufLen = %d\n", userNameBufLen);
|
||
|
printf("tokenBufLen = %d\n", tokenBufLen);
|
||
|
status = ValidateAuthTokenCredentials("krb-test-service",
|
||
|
userName,
|
||
|
strlen(userName),
|
||
|
token,
|
||
|
strlen(token));
|
||
|
if (CASA_SUCCESS(status))
|
||
|
{
|
||
|
DbgTrace(1, "ExecuteTests- ValidateAuthTokenCredentials success\n", 0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DbgTrace(0, "ExecuteTests- ValidateAuthTokenCredentials failure, status = %08X\n", status);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DbgTrace(0, "ExecuteTests- GetAuthTokenCredentials failure, status = %08X\n", status);
|
||
|
}
|
||
|
|
||
|
DbgTrace(1, "ExecuteTests- End\n", 0);
|
||
|
}
|
||
|
|
||
|
|
||
|
//++=======================================================================
|
||
|
int
|
||
|
main(
|
||
|
int argc,
|
||
|
char* argv[])
|
||
|
//
|
||
|
// Arguments:
|
||
|
//
|
||
|
// Returns:
|
||
|
//
|
||
|
// Abstract:
|
||
|
//
|
||
|
// Notes:
|
||
|
//
|
||
|
// L2
|
||
|
//=======================================================================--
|
||
|
{
|
||
|
int optionsSpecified = 0;
|
||
|
bool doneScanning = false;
|
||
|
bool invalidOption = false;
|
||
|
int option;
|
||
|
|
||
|
printf("**** auth-token-test ****\n");
|
||
|
|
||
|
// Scan through the options specified
|
||
|
while (!doneScanning)
|
||
|
{
|
||
|
opterr = 0;
|
||
|
option = getopt(argc, argv, "D");
|
||
|
|
||
|
// Proceed based on the result
|
||
|
switch (option)
|
||
|
{
|
||
|
case 'D':
|
||
|
// Set the debug level
|
||
|
DebugLevel = atoi(optarg);
|
||
|
optionsSpecified++;
|
||
|
break;
|
||
|
|
||
|
case '?':
|
||
|
// Invalid option detected
|
||
|
doneScanning = true;
|
||
|
invalidOption = true;
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
// Done scanning
|
||
|
doneScanning = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Do some sanity checking
|
||
|
if (!invalidOption)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
for (i = 0; i < 1; i++)
|
||
|
ExecuteTests();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Invalid option detected or the user failed to
|
||
|
// specify the listening port number.
|
||
|
printf(usage, argv[0]);
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
|
||
|
} /*-- main() --*/
|
||
|
|