Dell 6.2 Server User Manual


 
Sample Code
This section lists a sample code that will help you get started in using the ArubaOS XML API interface. These codes
have been tested in a controlled environment. We recommend that you test this code in a non-production
environment before using it for actual user management tasks.
Using XML API in C Language
The example script is written in the
C
language. The example script (auth.c) sends an authentication request from
your authentication server to the controller.
NOTE: This is an example code and is provided for illustration purposes. If you plan to use this code in your environment, ensure that
the code meets your IT guidelines. Also create an error free executable to successfully execute the script.
Figure 357: Authentication Script Listing
##### auth.c listing
##### Authentication Script Example -- Start --
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <getopt.h>
char *command, *ipaddr, *macaddr;
char *name, *password, *role;
char *tout, *secret;
char *auth, *key, enchashbuf[41];
unsigned char hashbuf[20];
char *version;
char post[4096], cmdbuf[512], encbuf[1024];
#define DEBUG
#ifdef DEBUG
#define debug(x...) fprintf(stderr, x)
#else
#define debug(x...)
#endif
extern int cgi_escape_url(char *t, int tl, char *s, int sl, int b_newline);
static void encode_message_digest (unsigned char *md, int mdlen, char *output);
static void usage (void)
{
fprintf(stderr, "Usage: ecp [options] <switch> <command> [<secret>]\n");
fprintf(stderr, " \n");
fprintf(stderr, " <switch> Switch IP address.\n");
fprintf(stderr, " <command> One of add, del, or authenticate.\n");
fprintf(stderr, " <secret> Shared secret.\n");
fprintf(stderr, " \n");
fprintf(stderr, " -i ipaddr User IP address in A.B.C.D format.\n");
fprintf(stderr, " -m macaddr User MAC address in aa:bb:cc:dd:ee:ff format.\n");
fprintf(stderr, " -n name User name.\n");
fprintf(stderr, " -p passwd User password.\n");
fprintf(stderr, " -r role User role.\n");
fprintf(stderr, " -t timeout User session timeout.\n");
fprintf(stderr, " -v version API version number. Default is 1.0\n");
DellPowerConnectW-SeriesArubaOS6.2 | User Guide ExternalUser Management | 784