Help! I can't get the following code to work. I'm trying to fetch a
user's PTS group memberships. The basic idea is:
setpag();
ka_UserAuthenticateGeneral( user, passwd);
pr_ListMembers( user, &groups);
ktc_ForgetAllTokens();
I get the user's token OK, but then pr_ListMembers() always fails saying
there's no such user (UNOENT). So do calls to pr_SNameToId() or
pr_IDListMembers().
But pr_SNameToId() works if I call it before ka_UserAuthenticateGeneral().
And pr_ListMembers() and pr_IDListMembers() both also work if I comment
out ka_UserAuthenticateGeneral() and setpag(), and get a token before I
run the program. There seems to be something about how I get the token
that prevents the pts calls from working. I've tried it without setpag()
and without KA_USERAUTH_DOSETPAG. I've tried using a different library
link order. I've tried 3 different ways of declaring pruclient.
I've tried this on Solaris 2.51 and Solaris 2.6 using the following
libraries:
cc -I/usr/afsws/include -g afs-auth.c
-L/usr/afsws/lib -L/usr/afsws/lib/afs
-lkauth -lprot -lubik -lauth -lrxkad -lsys -ldes -lrx -llwp
-lcom_err -laudit /usr/afsws/lib/afs/util.a
/lib/libsocket.a /usr/ucblib/libucb.a /lib/libnsl.a /lib/libintl.a
/lib/libdl.so -o afs-auth
I've also tried on AIX 3.2.5, with slightly different libs.
Any ideas???
-----
Jim C. LeBay - Michigan State University - Computer Laboratory
(517) 355-4500 x143 - [EMAIL PROTECTED]
--------------------------------------------------------
#include <afs/stds.h>
#include <afs/ptclient.h>
#include <afs/pterror.h>
#include <afs/kautils.h>
#include <stdio.h>
extern struct ubik_client *pruclient;
/*******************/
initialize()
{
int rc;
setpag();
pruclient = (struct ubik_client *)0;
rc = pr_Initialize(1L, "/usr/vice/etc", "msu.edu");
if (rc != 0) {
printf("pr_Init failed: %d\n", rc);
exit();
}
}
/*******************/
pts_membership(char *user, char *passwd)
{
namelist groups;
int id;
char *reason;
int rc, i;
/* this call works, returning the correct id for "user" */
rc = pr_SNameToId(user, &id);
if (rc != 0) {
printf("failed to get id for user %s: %d\n", user, rc);
return;
} else {
printf("User=%s ID=%d\n", user, id);
}
/* and I can get a token for "user" */
rc = ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION +
KA_USERAUTH_DOSETPAG,
user, "", "", passwd, 1, 0, 0, &reason);
if (rc != 0) {
printf("failed to get a token for %s: %d: %s\n", user, rc,
reason);
return;
}
groups.namelist_len = 0;
groups.namelist_val = NULL;
/* but this call always returns 5382 (UNOENT) */
/* rc = pr_ListMembers(user, &groups); */
rc = pr_IDListMembers(id, &groups);
if (rc != 0) {
printf("failed to list groups for %d: %d\n", id, rc);
return;
}
printf("Groups for %s: %d:\n", user, id);
for (i=0; i < groups.namelist_len; i++) {
printf("\t %s\n", groups.namelist_val[i]);
}
ktc_ForgetAllTokens();
}
/*******************/
main()
{
char user[20], passwd[20];
initialize();
for (;;) {
printf("\n Enter username: ");
scanf("%s", user);
printf(" Enter password: ");
scanf("%s", passwd);
pts_membership(user, passwd);
ktc_ForgetAllTokens();
}
}