auth.h 3.4 KB

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