On Sun, Jul 18, 2004 at 10:06:03AM +0200, Andreas Aardal Hanssen wrote:
> >Or is there a netinfo-aware drop-in for checkpassword?
> 
> It seems you're out of luck on this one; nobody answered so I guess it's
> hard to come around a netinfo aware checkpassword.

I toyed with this a little and have made a patch for checkpassword.c
that looks up the user's password in the NetInfo database.


> But I know that there are several here that use Mac OS X, perhaps
> they could shed some light on this problem?

I don't use it but I'm learning it nevertheless, the more systems
one knows the better. :)

getpwnam() and friends seem to query NetInfo as expected, so I don't
think the patch is of that much use generally.

I assume get*() asks lookupd, which in turns has "agents" for the
various directories/databases available to the system. One is NetInfo
and it is included by default in the search order that lookupd uses.
It's possible to change that search order, and I guess that could
make the patch useful. Seems like quite the corner case, though..

Attached is a program I first made to experiment with NetInfo. I
suggest to use it to test if there is any usable passwords at all
in NetInfo - for my account on the system I developed this on, there
isn't. My passwd value is just ********. (I may not have a password
set now that I think about it, though.)

Compile with gcc -o ni ni.c, then run with ./ni <username> to show
the passwd entry from NetInfo for that user.

If it turns out you actually need checkpassword to talk NetInfo,
I'll be happy to give away the patch.


//Peter
/*
 * This work is hereby placed in the public domain.
 * Written by Peter Stuge, [EMAIL PROTECTED]
 */

#include <stdio.h>
#include <netinfo/ni.h>

int main(const int argc,const char **argv) {
  int ret=1;
  const char *s;
  ni_status i;
  void *h;
  ni_id dir;
  ni_namelist val;
  char sr[1024];

  if(argc<2) {
    fprintf(stderr,"syntax: %s <username>\n",*argv);
    goto xit;
  }

  if((i=ni_open(NULL,"/",&h))!=0) {
    fprintf(stderr,"ni_open()=%d, %s\n",i,ni_error(i));
    goto xit;
  }

  snprintf(sr,sizeof(sr),"/users/%s",argv[1]);
  if((i=ni_pathsearch(h,&dir,sr))!=0) {
    fprintf(stderr,"ni_pathsearch()=%d, %s\n",i,ni_error(i));
    goto freexit;
  }

  NI_INIT(&val);
  if((i=ni_lookupprop(h,&dir,"passwd",&val))!=0) {
    fprintf(stderr,"ni_lookupprop()=%d, %s\n",i,ni_error(i));
    goto freexit;
  }

  printf("got %d values\n",val.ni_namelist_len);
  for(i=0;i<val.ni_namelist_len;i++)
    printf("%s\n",val.ni_namelist_val[i]);

  ret=0;

freexit:
  ni_free(h);
xit:
  return ret;
}

Reply via email to