1
0

auth.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. /*
  10. * Interface for typical callers.
  11. */
  12. typedef struct AuthInfo AuthInfo;
  13. typedef struct Chalstate Chalstate;
  14. typedef struct Chapreply Chapreply;
  15. typedef struct MSchapreply MSchapreply;
  16. typedef struct UserPasswd UserPasswd;
  17. typedef struct AuthRpc AuthRpc;
  18. enum
  19. {
  20. MAXCHLEN= 256, /* max challenge length */
  21. MAXNAMELEN= 256, /* maximum name length */
  22. MD5LEN= 16,
  23. ARok = 0, /* rpc return values */
  24. ARdone,
  25. ARerror,
  26. ARneedkey,
  27. ARbadkey,
  28. ARwritenext,
  29. ARtoosmall,
  30. ARtoobig,
  31. ARrpcfailure,
  32. ARphase,
  33. AuthRpcMax = 4096,
  34. };
  35. struct AuthRpc
  36. {
  37. int afd;
  38. char ibuf[AuthRpcMax+1]; /* +1 for NUL in auth_rpc.c */
  39. char obuf[AuthRpcMax];
  40. char *arg;
  41. uint narg;
  42. };
  43. struct AuthInfo
  44. {
  45. char *cuid; /* caller id */
  46. char *suid; /* server id */
  47. char *cap; /* capability (only valid on server side) */
  48. int nsecret; /* length of secret */
  49. uint8_t *secret; /* secret */
  50. };
  51. struct Chalstate
  52. {
  53. char *user;
  54. char chal[MAXCHLEN];
  55. int nchal;
  56. void *resp;
  57. int nresp;
  58. /* for implementation only */
  59. int afd; /* to factotum */
  60. AuthRpc *rpc; /* to factotum */
  61. char userbuf[MAXNAMELEN]; /* temp space if needed */
  62. int userinchal; /* user was sent to obtain challenge */
  63. };
  64. struct Chapreply /* for protocol "chap" */
  65. {
  66. uint8_t id;
  67. char resp[MD5LEN];
  68. };
  69. struct MSchapreply /* for protocol "mschap" */
  70. {
  71. char LMresp[24]; /* Lan Manager response */
  72. char NTresp[24]; /* NT response */
  73. };
  74. struct UserPasswd
  75. {
  76. char *user;
  77. char *passwd;
  78. };
  79. extern int newns(char*, char*);
  80. extern int addns(char*, char*);
  81. extern int noworld(char*);
  82. extern int amount(int, char*, int, char*);
  83. /* these two may get generalized away -rsc */
  84. extern int login(char*, char*, char*);
  85. extern int httpauth(char*, char*);
  86. typedef struct Attr Attr;
  87. enum {
  88. AttrNameval, /* name=val -- when matching, must have name=val */
  89. AttrQuery, /* name? -- when matching, must be present */
  90. AttrDefault, /* name:=val -- when matching, if present must match INTERNAL */
  91. };
  92. struct Attr
  93. {
  94. int type;
  95. Attr *next;
  96. char *name;
  97. char *val;
  98. };
  99. typedef int AuthGetkey(char*);
  100. int _attrfmt(Fmt*);
  101. Attr *_copyattr(Attr*);
  102. Attr *_delattr(Attr*, char*);
  103. Attr *_findattr(Attr*, char*);
  104. void _freeattr(Attr*);
  105. Attr *_mkattr(int, char*, char*, Attr*);
  106. Attr *_parseattr(char*);
  107. char *_strfindattr(Attr*, char*);
  108. extern AuthInfo* fauth_proxy(int, AuthRpc *rpc, AuthGetkey *getkey,
  109. char *params);
  110. extern AuthInfo* auth_proxy(int fd, AuthGetkey *getkey, char *fmt,
  111. ...);
  112. extern int auth_getkey(char*);
  113. extern int (*amount_getkey)(char*);
  114. extern void auth_freeAI(AuthInfo *ai);
  115. extern int auth_chuid(AuthInfo *ai, char *ns);
  116. extern Chalstate *auth_challenge(char*, ...);
  117. extern AuthInfo* auth_response(Chalstate*);
  118. extern int auth_respond(void*, uint, char*, uint, void*,
  119. uint, AuthGetkey *getkey, char*,
  120. ...);
  121. extern void auth_freechal(Chalstate*);
  122. extern AuthInfo* auth_userpasswd(char *user, char *passwd);
  123. extern UserPasswd* auth_getuserpasswd(AuthGetkey *getkey, char*,
  124. ...);
  125. extern AuthInfo* auth_getinfo(AuthRpc *rpc);
  126. extern AuthRpc* auth_allocrpc(int afd);
  127. extern Attr* auth_attr(AuthRpc *rpc);
  128. extern void auth_freerpc(AuthRpc *rpc);
  129. extern uint auth_rpc(AuthRpc *rpc, char *verb, void *a,
  130. int n);
  131. extern int auth_wep(char*, char*, ...);