诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

257 rivejä
6.3 KiB

  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "tool_setup.h"
  23. #ifndef HAVE_GETPASS_R
  24. /* this file is only for systems without getpass_r() */
  25. #ifdef HAVE_FCNTL_H
  26. # include <fcntl.h>
  27. #endif
  28. #ifdef HAVE_TERMIOS_H
  29. # include <termios.h>
  30. #elif defined(HAVE_TERMIO_H)
  31. # include <termio.h>
  32. #endif
  33. #ifdef __VMS
  34. # include descrip
  35. # include starlet
  36. # include iodef
  37. #endif
  38. #ifdef WIN32
  39. # include <conio.h>
  40. #endif
  41. #ifdef NETWARE
  42. # ifdef __NOVELL_LIBC__
  43. # include <screen.h>
  44. # else
  45. # include <nwconio.h>
  46. # endif
  47. #endif
  48. #define _MPRINTF_REPLACE
  49. #include <curl/mprintf.h>
  50. #include "tool_getpass.h"
  51. #include "memdebug.h" /* keep this as LAST include */
  52. #ifdef __VMS
  53. /* VMS implementation */
  54. char *getpass_r(const char *prompt, char *buffer, size_t buflen)
  55. {
  56. long sts;
  57. short chan;
  58. /* MSK, 23-JAN-2004, iosbdef.h wasn't in VAX V7.2 or CC 6.4 */
  59. /* distribution so I created this. May revert back later to */
  60. /* struct _iosb iosb; */
  61. struct _iosb
  62. {
  63. short int iosb$w_status; /* status */
  64. short int iosb$w_bcnt; /* byte count */
  65. int unused; /* unused */
  66. } iosb;
  67. $DESCRIPTOR(ttdesc, "TT");
  68. buffer[0] = '\0';
  69. sts = sys$assign(&ttdesc, &chan, 0, 0);
  70. if(sts & 1) {
  71. sts = sys$qiow(0, chan,
  72. IO$_READPROMPT | IO$M_NOECHO,
  73. &iosb, 0, 0, buffer, buflen, 0, 0,
  74. prompt, strlen(prompt));
  75. if((sts & 1) && (iosb.iosb$w_status & 1))
  76. buffer[iosb.iosb$w_bcnt] = '\0';
  77. sts = sys$dassgn(chan);
  78. }
  79. return buffer; /* we always return success */
  80. }
  81. #define DONE
  82. #endif /* __VMS */
  83. #ifdef __SYMBIAN32__
  84. # define getch() getchar()
  85. #endif
  86. #if defined(WIN32) || defined(__SYMBIAN32__)
  87. char *getpass_r(const char *prompt, char *buffer, size_t buflen)
  88. {
  89. size_t i;
  90. fputs(prompt, stderr);
  91. for(i = 0; i < buflen; i++) {
  92. buffer[i] = (char)getch();
  93. if(buffer[i] == '\r' || buffer[i] == '\n') {
  94. buffer[i] = '\0';
  95. break;
  96. }
  97. else
  98. if(buffer[i] == '\b')
  99. /* remove this letter and if this is not the first key, remove the
  100. previous one as well */
  101. i = i - (i >= 1) ? 2 : 1;
  102. }
  103. #ifndef __SYMBIAN32__
  104. /* since echo is disabled, print a newline */
  105. fputs("\n", stderr);
  106. #endif
  107. /* if user didn't hit ENTER, terminate buffer */
  108. if(i == buflen)
  109. buffer[buflen-1] = '\0';
  110. return buffer; /* we always return success */
  111. }
  112. #define DONE
  113. #endif /* WIN32 || __SYMBIAN32__ */
  114. #ifdef NETWARE
  115. /* NetWare implementation */
  116. #ifdef __NOVELL_LIBC__
  117. char *getpass_r(const char *prompt, char *buffer, size_t buflen)
  118. {
  119. return getpassword(prompt, buffer, buflen);
  120. }
  121. #else
  122. char *getpass_r(const char *prompt, char *buffer, size_t buflen)
  123. {
  124. size_t i = 0;
  125. printf("%s", prompt);
  126. do {
  127. buffer[i++] = getch();
  128. if(buffer[i-1] == '\b') {
  129. /* remove this letter and if this is not the first key,
  130. remove the previous one as well */
  131. if(i > 1) {
  132. printf("\b \b");
  133. i = i - 2;
  134. }
  135. else {
  136. RingTheBell();
  137. i = i - 1;
  138. }
  139. }
  140. else if(buffer[i-1] != 13)
  141. putchar('*');
  142. } while((buffer[i-1] != 13) && (i < buflen));
  143. buffer[i-1] = '\0';
  144. printf("\r\n");
  145. return buffer;
  146. }
  147. #endif /* __NOVELL_LIBC__ */
  148. #define DONE
  149. #endif /* NETWARE */
  150. #ifndef DONE /* not previously provided */
  151. #ifdef HAVE_TERMIOS_H
  152. # define struct_term struct termios
  153. #elif defined(HAVE_TERMIO_H)
  154. # define struct_term struct termio
  155. #else
  156. # undef struct_term
  157. #endif
  158. static bool ttyecho(bool enable, int fd)
  159. {
  160. #ifdef struct_term
  161. static struct_term withecho;
  162. static struct_term noecho;
  163. #endif
  164. if(!enable) {
  165. /* disable echo by extracting the current 'withecho' mode and remove the
  166. ECHO bit and set back the struct */
  167. #ifdef HAVE_TERMIOS_H
  168. tcgetattr(fd, &withecho);
  169. noecho = withecho;
  170. noecho.c_lflag &= ~ECHO;
  171. tcsetattr(fd, TCSANOW, &noecho);
  172. #elif defined(HAVE_TERMIO_H)
  173. ioctl(fd, TCGETA, &withecho);
  174. noecho = withecho;
  175. noecho.c_lflag &= ~ECHO;
  176. ioctl(fd, TCSETA, &noecho);
  177. #else
  178. /* neither HAVE_TERMIO_H nor HAVE_TERMIOS_H, we can't disable echo! */
  179. (void)fd;
  180. return FALSE; /* not disabled */
  181. #endif
  182. return TRUE; /* disabled */
  183. }
  184. else {
  185. /* re-enable echo, assumes we disabled it before (and set the structs we
  186. now use to reset the terminal status) */
  187. #ifdef HAVE_TERMIOS_H
  188. tcsetattr(fd, TCSAFLUSH, &withecho);
  189. #elif defined(HAVE_TERMIO_H)
  190. ioctl(fd, TCSETA, &withecho);
  191. #else
  192. return FALSE; /* not enabled */
  193. #endif
  194. return TRUE; /* enabled */
  195. }
  196. }
  197. char *getpass_r(const char *prompt, /* prompt to display */
  198. char *password, /* buffer to store password in */
  199. size_t buflen) /* size of buffer to store password in */
  200. {
  201. ssize_t nread;
  202. bool disabled;
  203. int fd = open("/dev/tty", O_RDONLY);
  204. if(-1 == fd)
  205. fd = 1; /* use stdin if the tty couldn't be used */
  206. disabled = ttyecho(FALSE, fd); /* disable terminal echo */
  207. fputs(prompt, stderr);
  208. nread = read(fd, password, buflen);
  209. if(nread > 0)
  210. password[--nread] = '\0'; /* zero terminate where enter is stored */
  211. else
  212. password[0] = '\0'; /* got nothing */
  213. if(disabled) {
  214. /* if echo actually was disabled, add a newline */
  215. fputs("\n", stderr);
  216. (void)ttyecho(TRUE, fd); /* enable echo */
  217. }
  218. if(1 != fd)
  219. close(fd);
  220. return password; /* return pointer to buffer */
  221. }
  222. #endif /* DONE */
  223. #endif /* HAVE_GETPASS_R */