authdial.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <authsrv.h>
  12. #include <bio.h>
  13. #include <ndb.h>
  14. int
  15. authdial(char *netroot, char *dom)
  16. {
  17. char *p;
  18. int rv;
  19. if(dom == nil)
  20. /* look for one relative to my machine */
  21. return dial(netmkaddr("$auth", netroot, "ticket"), 0, 0, 0);
  22. /* look up an auth server in an authentication domain */
  23. p = csgetvalue(netroot, "authdom", dom, "auth", nil);
  24. /* if that didn't work, just try the IP domain */
  25. if(p == nil)
  26. p = csgetvalue(netroot, "dom", dom, "auth", nil);
  27. /*
  28. * if that didn't work, try p9auth.$dom. this is very helpful if
  29. * you can't edit /lib/ndb.
  30. */
  31. if(p == nil)
  32. p = smprint("p9auth.%s", dom);
  33. if(p == nil){ /* should no longer ever happen */
  34. werrstr("no auth server found for %s", dom);
  35. return -1;
  36. }
  37. rv = dial(netmkaddr(p, netroot, "ticket"), 0, 0, 0);
  38. free(p);
  39. return rv;
  40. }