auth.h 3.9 KB

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