#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
void printAuthenticationAppMenu()
{
printf("Usage: authentication_example <test#> <arg1> <arg2> ... \n");
printf("Test 1: Create authentication list name: authentication_example 1 <access-level> <list-name> \n");
printf("Test 2: Add methods to authentication list: authentication_example 2 <access-level> <list-name> <method1> <method2> <method3> .... \n");
printf("Test 3: Get authentication list names and configured methods of an access type: authentication_example 3 <access-level>\n");
printf("Test 4: Set authentication list to an access line: authentication_example 4 <access-line> <access-level> <list-name> \n");
printf("Test 5: Get authentication list name applied to access line: authentication_example 5 <access-line> <access-level> \n");
printf("Test 6: Delete authentication list applied to the access-line: authentication_example 6 <access-line> <access-level> \n");
printf("Test 7: Delete authentication list created: authentication_example 7 <access-level> <list-name> \n");
printf("Test 8: Authentication OpEN APIs sanity: authentication_example 8 \n");
return;
}
{
char str[100];
memset(str, 0, sizeof(str));
strncpy(str, listName, (sizeof(str) - 1));
buffDesc.
size = strlen(str)+1;
{
{
printf("Bad return code trying to create authentication list name for access level %d. (result = %d) \n", accessLevel, result);
}
else
{
printf("Authentication list name created successfully. \n");
}
}
else
{
printf("Authentication list name is too long or contains invalid characters. \n");
}
return;
}
{
char str[100];
memset(str, 0, sizeof(str));
strncpy(str, listName, (sizeof(str) - 1));
buffDesc.pstart = str;
buffDesc.size = strlen(str)+1;
{
printf("Bad return code trying to add methods to authentication list for access level %d. (result = %d) \n", accessLevel, result);
}
else
{
printf("Methods added to authentication list successfully. \n");
}
return;
}
{
uint32_t authListNameSize;
uint32_t maxAuthMethods;
uint32_t i = 0;
char *str;
char *methodStr;
{
printf("Bad return code trying to get authentication list name size. (result = %d)", result);
return;
}
{
printf("Bad return code trying to get maximum authentication methods supported. (result = %d) \n", result);
return;
}
if ((str = (char *)malloc(authListNameSize)) == NULL)
{
printf("Could not allocate memory.\n");
return;
}
if ((methodStr = (char *)malloc(maxAuthMethods)) == NULL)
{
printf("Could not allocate memory.\n");
free(str);
return;
}
memset(str, 0, authListNameSize);
listName.pstart = str;
listName.size = authListNameSize;
memset(methodStr, 0, maxAuthMethods);
methodList.pstart = methodStr;
methodList.size = maxAuthMethods;
printf("Getting the first authentication list name. \n");
{
printf("Bad return code trying to get first authentication list name for access level: %d (result = %d) \n", accessLevel, result);
free(methodStr);
free(str);
return;
}
printf("Auth_list_name Methods\n");
do
{
printf("%-15s ", str);
{
for (i = 0; i < methodList.size; i++)
{
switch ((methodStr[i]-'0'))
{
printf("Enable ");
break;
printf("Line ");
break;
printf("Local ");
break;
printf("None ");
break;
printf("Radius ");
break;
printf("Tacacs ");
break;
printf("Deny ");
break;
default:
break;
}
}
}
else
{
printf("Method list get failed. (result = %d) \n", result);
}
listName.size = authListNameSize;
methodList.size = maxAuthMethods;
printf("\n");
free(str);
free(methodStr);
return;
}
{
char str[100];
memset(str, 0, sizeof(str));
strncpy(str, listName, (sizeof(str) - 1));
buffDesc.pstart = str;
buffDesc.size = strlen(str)+1;
{
printf("Bad return code trying to apply the authentication list name to access line %d. (result = %d) \n", accessLine, result);
}
else
{
printf("Authentication list name applied to access line successfully \n");
}
return;
}
{
char *str;
uint32_t authListNameSize;
{
printf("Bad return code trying to get authentication list name size. (result = %d)", result);
return;
}
if ((str = (char *)malloc(authListNameSize)) == NULL)
{
printf("Could not allocate memory.\n");
return;
}
memset(str, 0, authListNameSize);
listName.pstart = str;
listName.size = authListNameSize;
printf(" Getting the authentication list name applied to access line %d\n", accessLine);
{
printf("Bad return code while getting authentication list name applied to access line. (result = %d) \n", result);
}
else
{
printf("Authentication list name: %s \n", str);
}
free(str);
return;
}
{
printf("Deleting authentication list applied to access line %d. \n", accessLine);
{
printf("Bad return code trying to delete authentication list name applied to access line. (result = %d) \n", result);
}
else
{
printf("Deleted the authentication list name from the access line %d. \n", accessLine);
}
return;
}
char *listName)
{
char str[100];
memset(str, 0, sizeof(str));
strncpy(str, listName, (sizeof(str) - 1));
buffDesc.pstart = str;
buffDesc.size = strlen(str)+1;
printf("Deleting the authentication list %s \n", listName);
{
printf("Bad return code trying to delete authentication list. (result = %d) \n", result);
}
else
{
printf("Authentication list %s deleted successfully. \n", (char *) buffDesc.pstart);
}
return;
}
{
uint32_t authListNameSize = 0, maxAuthMethods =0;
char *str, *str1;
printf("Testing authentication OpEN APIs sanity.\n");
{
printf("Bad return code trying to get authentication name size. (result = %d) \n", result);
return;
}
{
printf("Bad return code trying to get maximum authentication methods supported. (result = %d) \n", result);
return;
}
if ((str = (char *)malloc(authListNameSize)) == NULL)
{
printf("Could not allocate memory\n");
return;
}
memset(str, 0, authListNameSize);
buffDesc1.pstart = str;
buffDesc1.size = authListNameSize;
if ((str1 = (char *)malloc(maxAuthMethods)) == NULL)
{
printf("Could not allocate memory\n");
free(str);
return;
}
memset(str1, 0, maxAuthMethods);
buffDesc2.pstart = str1;
buffDesc2.size = maxAuthMethods;
printf("\nTesting openapiAuthenticationListNameSizeGet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("NULL string length. (result = %d)\n", result);
printf("openapiAuthenticationListNameSizeGet() sanity successful.\n");
printf("\nTesting openapiAuthenticationMethodsMaxGet(): \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Maximum methods parameter NULL. (result = %d)\n", result);
printf("openapiAuthenticationMethodsMaxGet() sanity successful.\n");
printf("\nTesting openapiAuthenticationListCreate() \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access level. (result = %d)\n", result);
printf("NULL authentication list name buff descriptor. (result = %d)\n", result);
printf("openapiAuthenticationListCreate() sanity successful.\n");
printf("\nTesting openapiAuthenticationMethodsAdd() \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access level. (result = %d)\n", result);
printf("NULL authentication list name buff descriptor. (result = %d)\n", result);
printf("NULL methods buff descriptor. (result = %d)\n", result);
printf("openapiAuthenticationMethodsAdd() sanity successful.\n");
printf("\nTesting openapiAuthenticationMethodListGet() \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access level. (result = %d)\n", result);
printf("NULL buff descriptor to authentication list name. (result = %d)\n", result);
printf("NULL buff descriptor to method list. (result = %d)\n", result);
printf("openapiAuthenticationMethodListGet() sanity successful.\n");
printf("\nTesting openapiAuthenticationListFirstGet() \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access level. (result = %d)\n", result);
printf("NULL buff descriptor to authentication list name. (result = %d)\n", result);
printf("openapiAuthenticationListFirstGet() sanity successful.\n");
printf("\nTesting openapiAuthenticationListNextGet() \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access level. (result = %d)\n", result);
printf("NULL buff descriptor to previous authentication list name. (result = %d)\n", result);
printf("NULL buff descriptor to next authentication list name. (result = %d)\n", result);
printf("openapiAuthenticationListNextGet() sanity successful.\n");
printf("\nTesting openapiAuthenticationListDelete() \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access level. (result = %d)\n", result);
printf("NULL buff descriptor to authentication list name. (result = %d)\n", result);
printf("openapiAuthenticationListDelete() sanity successful.\n");
printf("\nTesting openapiAuthenticationListLineSet() \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access line (result = %d)\n", result);
printf("Invalid access level. (result = %d)\n", result);
printf("NULL buff descriptor to authentication list name. (result = %d)\n", result);
printf("openapiAuthenticationListLineSet() sanity successful.\n");
printf("\nTesting openapiAuthenticationListLineGet() \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access line (result = %d)\n", result);
printf("Invalid access level. (result = %d)\n", result);
printf("NULL buff descriptor to authentication list name. (result = %d)\n", result);
printf("openapiAuthenticationListLineGet() sanity successful.\n");
printf("\nTesting openapiAuthenticationListLineDelete() \n");
printf("NULL Client Handle. (result = %d)\n", result);
printf("Invalid access line (result = %d)\n", result);
printf("Invalid access level. (result = %d)\n", result);
printf("openapiAuthenticationListLineDelete() sanity successful.\n");
free(str);
free(str1);
return;
}
int main(int argc, char **argv)
{
uint32_t testNum, arg1, arg2;
char switch_os_revision_string[100];
char str[100];
uint32_t i = 0;
if (argc < 2)
{
printAuthenticationAppMenu();
exit(1);
}
testNum = atoi(argv[1]);
l7proc_crashlog_register();
{
printf("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n", result);
exit(2);
}
{
sleep(1);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Starting Authentication API example application");
printf("\n");
switch_os_revision.pstart = switch_os_revision_string;
switch_os_revision.size = sizeof(switch_os_revision_string);
printf("Network OS version = %s\n", switch_os_revision_string);
else
printf("Network OS version retrieve error\n");
printf("\n");
switch (testNum)
{
case 1:
if (argc != 4)
{
printAuthenticationAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
authenticationListCreate(&clientHandle, arg1, argv[3]);
break;
case 2:
if (argc < 5)
{
printAuthenticationAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
memset(str, 0, sizeof(str));
for (i = 4; i < argc; i++)
{
strncat(str, argv[i], strlen(argv[i]));
}
authMethods.pstart = str;
authMethods.size = strlen(str)+1;
authenticationMethodsAdd(&clientHandle, arg1, argv[3], &authMethods);
break;
case 3:
if (argc != 3)
{
printAuthenticationAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
authenticationInfoGet(&clientHandle, arg1);
break;
case 4:
if (argc != 5)
{
printAuthenticationAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
authenticationListLineApply(&clientHandle, arg1, arg2, argv[4]);
break;
case 5:
if (argc != 4)
{
printAuthenticationAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
authenticationListLineGet(&clientHandle, arg1, arg2);
break;
case 6:
if (argc != 4)
{
printAuthenticationAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
arg2 = atoi(argv[3]);
authenticationListLineDelete(&clientHandle, arg1, arg2);
break;
case 7:
if (argc != 4)
{
printAuthenticationAppMenu();
exit(1);
}
arg1 = atoi(argv[2]);
authenticationListDelete(&clientHandle, arg1, argv[3]);
break;
case 8:
if (argc != 2)
{
printAuthenticationAppMenu();
exit(1);
}
authenticationOpENAPIsSanity(&clientHandle);
break;
default:
printAuthenticationAppMenu();
break;
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping Authentication API example application");
return 0;
}