1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/* RADIUS client test program using the generic interface */
#include <pwdb/pwdb_public.h>
#include <stdio.h>
#define USERNAME "bob"
#define PASSWORD "testing"
#define NEWPASSWORD "NEWpassWORD"
int main(void) {
const struct pwdb * pw = NULL;
/* struct pwdb_entry * ent = NULL; */
int retval;
pwdb_type tlist[2];
tlist[0] = PWDB_RADIUS;
tlist[1] = _PWDB_MAX_TYPES;
pwdb_start();
/* LOCATE CODE */
retval = pwdb_new(&pw, 0);
printf("pwdb new call: %s, pw=%p\n", pwdb_strerror(retval),pw);
/* try first locate */
retval=pwdb_locate("user", tlist, USERNAME, PWDB_ID_UNKNOWN, &pw);
printf("locate returned: %s\n", pwdb_strerror(retval));
if (retval == PWDB_PASS_PHRASE_REQD) {
pwdb_set_entry(pw,"pass_phrase",PASSWORD, 1+strlen(PASSWORD)
, NULL, NULL, 0);
} else {
pwdb_delete(&pw);
pwdb_end();
printf("Don't know how to handle this error. Exit.\n");
exit(-1);
}
/* try a second locate */
pwdb_print_pwdb_struct(pw);
retval=pwdb_locate("user", tlist, USERNAME, PWDB_ID_UNKNOWN, &pw);
printf("locate returned: %s\n", pwdb_strerror(retval));
if (retval != PWDB_SUCCESS) {
pwdb_delete(&pw);
pwdb_end();
printf("Don't know how to handle this error. Exit.\n");
exit(-1);
}
pwdb_print_pwdb_struct(pw);
pwdb_delete(&pw);
/* UPDATING CODE */
retval = pwdb_new(&pw, 0);
printf("pwdb new call: %s, pw=%p\n", pwdb_strerror(retval),pw);
pwdb_print_pwdb_struct(pw);
/* the old password */
pwdb_set_entry(pw,"pass_phrase",PASSWORD, 1+strlen(PASSWORD),
NULL, NULL, 0);
pwdb_print_pwdb_struct(pw);
/* The new password */
pwdb_set_entry(pw,"passwd",NEWPASSWORD, 1+strlen(PASSWORD),
NULL, NULL, 0);
pwdb_print_pwdb_struct(pw);
/* tell other modules that RADIUS is taking care of this */
pwdb_set_entry(pw,"defer_pass","R",2, NULL, NULL, 0);
pwdb_print_pwdb_struct(pw);
/* Now perform an update on passwd */
retval = pwdb_replace("user", tlist, USERNAME, PWDB_ID_UNKNOWN, &pw);
printf("replace returned: %s\n",pwdb_strerror(retval));
if (retval != PWDB_SUCCESS) {
pwdb_delete(&pw);
pwdb_end();
printf("Don't know how to handle this error. Exit.\n");
exit(-1);
}
pwdb_print_pwdb_struct(pw);
/* Now change back the passwd */
pwdb_set_entry(pw,"pass_phrase",NEWPASSWORD, 1+strlen(PASSWORD),
NULL, NULL, 0);
/* The new password */
pwdb_set_entry(pw,"passwd",PASSWORD, 1+strlen(PASSWORD),
NULL, NULL, 0);
/* tell other modules that RADIUS is taking care of this */
pwdb_set_entry(pw,"defer_pass","R",2, NULL, NULL, 0);
/* Now perform an update on passwd */
retval = pwdb_replace("user", tlist, USERNAME, PWDB_ID_UNKNOWN, &pw);
printf("replace returned: %s\n",pwdb_strerror(retval));
if (retval != PWDB_SUCCESS) {
pwdb_delete(&pw);
pwdb_end();
printf("Don't know how to handle this error. Exit.\n");
exit(-1);
}
pwdb_print_pwdb_struct(pw);
pwdb_delete(&pw);
pwdb_end();
return 0;
}
|