auth.h 3.5 KB

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