Sample Code
This section lists a sample code t hat will helpy ou get started in using the ArubaOS XML API i nterface.These codes
have beent ested in a controlled environment.We recommend that you test this code in a non-production
environmentbefore using it for actual usermanagement tasks.

Using XML A PI in C Langu age

The examplescript i s written in the
C
language.The example script (auth.c) sends an authentication request from
your authentication server to the controller.
NOTE:Thi si san exampl e code and is provided fori llustration purposes.If you plan to use this code in your environment, ensure that
thecode meets your IT guidelines. Also create an error free executable to successfullyexecute the script.
Figure 357: AuthenticationSc riptList ing
##### 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");
DellPowerConnect W- Series ArubaOS 6.2 | UserGuide ExternalUser Manageme nt |784