authsasllogin.c
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:2k
源码类别:

WEB邮件程序

开发平台:

C/C++

  1. /* $Id: authsasllogin.c,v 1.1 1999/12/13 03:34:28 mrsam Exp $ */
  2. /*
  3. ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
  4. ** distribution information.
  5. */
  6. #include "config.h"
  7. #include "random128/random128.h"
  8. #include "authsasl.h"
  9. #include "authmod.h"
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #if HAVE_UNISTD_H
  13. #include <unistd.h>
  14. #endif
  15. #include <ctype.h>
  16. #include <stdio.h>
  17. #include <errno.h>
  18. int authsasl_login(const char *method, const char *initresponse,
  19. char *(*getresp)(const char *),
  20. char **authtype,
  21. char **authdata)
  22. {
  23. char *uid;
  24. char *pw;
  25. char *p;
  26. int n;
  27. if (initresponse)
  28. {
  29. uid=malloc(strlen(initresponse)+1);
  30. if (!uid)
  31. {
  32. perror("malloc");
  33. return (AUTHSASL_ERROR);
  34. }
  35. strcpy(uid, initresponse);
  36. }
  37. else
  38. {
  39. p=authsasl_tobase64("Username:", -1);
  40. if (!p)
  41. {
  42. perror("malloc");
  43. return (AUTHSASL_ERROR);
  44. }
  45. uid=getresp(p);
  46. free(p);
  47. if (!uid)
  48. {
  49. perror("malloc");
  50. return (AUTHSASL_ERROR);
  51. }
  52. if (*uid == '*')
  53. {
  54. free(uid);
  55. return (AUTHSASL_ABORTED);
  56. }
  57. }
  58. p=authsasl_tobase64("Password:", -1);
  59. if (!p)
  60. {
  61. free(uid);
  62. perror("malloc");
  63. return (AUTHSASL_ERROR);
  64. }
  65. pw=getresp(p);
  66. free(p);
  67. if (!pw)
  68. {
  69. free(uid);
  70. perror("malloc");
  71. return (AUTHSASL_ERROR);
  72. }
  73. if (*pw == '*')
  74. {
  75. free(pw);
  76. free(uid);
  77. return (AUTHSASL_ABORTED);
  78. }
  79. if ((n=authsasl_frombase64(uid)) < 0 ||
  80. (uid[n]=0, n=authsasl_frombase64(pw)) < 0)
  81. {
  82. free(uid);
  83. free(pw);
  84. return (AUTHSASL_ABORTED);
  85. }
  86. pw[n]=0;
  87. if ( (*authtype=malloc(sizeof(AUTHTYPE_LOGIN))) == 0)
  88. {
  89. free(uid);
  90. free(pw);
  91. perror("malloc");
  92. return (AUTHSASL_ERROR);
  93. }
  94. strcpy( *authtype, AUTHTYPE_LOGIN);
  95. if ( (*authdata=malloc(strlen(uid)+strlen(pw)+3)) == 0)
  96. {
  97. free( *authtype );
  98. free(uid);
  99. free(pw);
  100. perror("malloc");
  101. return (AUTHSASL_ERROR);
  102. }
  103. strcat(strcat(strcat(strcpy(*authdata, uid), "n"), pw), "n");
  104. return (AUTHSASL_OK);
  105. }