~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/CTest/Curl/getpass.c

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2005-03-02 09:22:44 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050302092244-y6o9j8wr27vqcqvx
Tags: 2.0.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================================
 
2
 * Copyright (C) 1998 - 2002, Daniel Stenberg, <daniel@haxx.se>, et al.
 
3
 *
 
4
 * Redistribution and use are freely permitted provided that:
 
5
 *
 
6
 *   1) This header remain in tact.
 
7
 *   2) The prototypes for getpass and getpass_r are not changed from:
 
8
 *         char *getpass(const char *prompt)
 
9
 *         char *getpass_r(const char *prompt, char* buffer, int buflen)
 
10
 *   3) This source code is not used outside of this(getpass.c) file.
 
11
 *   4) Any changes to this(getpass.c) source code are made publicly available.
 
12
 *
 
13
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
 
14
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 
15
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
 
16
 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 
17
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
18
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
19
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
20
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
21
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
22
 * POSSIBILITY OF SUCH DAMAGE.
 
23
 * ============================================================================
 
24
 *
 
25
 * $Id: getpass.c,v 1.5 2003/05/06 15:26:42 andy Exp $
 
26
 *
 
27
 * The spirit of this license is to allow use of this source code in any
 
28
 * project be it open or closed but still encourage the use of the open,
 
29
 * library based equivilents.
 
30
 *
 
31
 * Author(s):
 
32
 *   Angus Mackay <amackay@gus.ml.org>
 
33
 *
 
34
 * Contributor(s):
 
35
 *   Daniel Stenberg <daniel@haxx.se>
 
36
 */
 
37
 
 
38
#include "setup.h" /* setup.h is required for read() prototype */
 
39
 
 
40
#ifndef HAVE_GETPASS_R
 
41
 
 
42
#ifndef WIN32
 
43
#ifdef  VMS
 
44
#include <stdio.h>
 
45
#include <string.h>
 
46
#include descrip
 
47
#include starlet
 
48
#include iodef
 
49
#include iosbdef
 
50
char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 
51
{
 
52
        long sts;
 
53
        short chan;
 
54
        struct _iosb iosb;
 
55
        /* VMS does not work because of warnings on icc */
 
56
        /* $DESCRIPTOR(ttdesc, "TT");                   
 
57
 
 
58
        buffer[0]='\0';
 
59
        if ((sts = sys$assign(&ttdesc, &chan,0,0)) & 1) {
 
60
                if (((sts = sys$qiow(0, chan, IO$_READPROMPT | IO$M_NOECHO, &iosb, 0, 0, buffer, buflen, 0, 0, prompt, strlen(prompt))) & 1) && (iosb.iosb$w_status&1)) {
 
61
                        buffer[iosb.iosb$w_bcnt] = '\0';
 
62
                } 
 
63
                sts = sys$dassgn(chan);
 
64
        }
 
65
        */
 
66
        return buffer; /* we always return success */
 
67
}
 
68
#else /* VMS */
 
69
#ifdef HAVE_TERMIOS_H
 
70
#  if !defined(HAVE_TCGETATTR) && !defined(HAVE_TCSETATTR) 
 
71
#    undef HAVE_TERMIOS_H
 
72
#  endif
 
73
#endif
 
74
 
 
75
#ifndef RETSIGTYPE
 
76
#  define RETSIGTYPE void
 
77
#endif
 
78
 
 
79
#ifdef HAVE_UNISTD_H
 
80
#include <unistd.h>
 
81
#endif
 
82
#include <stdio.h>
 
83
#include <signal.h>
 
84
#ifdef HAVE_TERMIOS_H
 
85
#  include <termios.h>
 
86
#else
 
87
#  ifdef HAVE_TERMIO_H
 
88
#  include <termio.h>
 
89
#  else
 
90
#  endif
 
91
#endif
 
92
 
 
93
/* The last #include file should be: */
 
94
#ifdef MALLOCDEBUG
 
95
#include "memdebug.h"
 
96
#endif
 
97
 
 
98
char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 
99
{
 
100
  FILE *infp;
 
101
  char infp_fclose = 0;
 
102
  FILE *outfp;
 
103
  RETSIGTYPE (*sigint)();
 
104
#ifndef __EMX__
 
105
  RETSIGTYPE (*sigtstp)();
 
106
#endif
 
107
  size_t bytes_read;
 
108
  int infd;
 
109
  int outfd;
 
110
#ifdef HAVE_TERMIOS_H
 
111
  struct termios orig;
 
112
  struct termios noecho;
 
113
#else
 
114
#  ifdef HAVE_TERMIO_H
 
115
  struct termio orig;
 
116
  struct termio noecho;  
 
117
#  else
 
118
#  endif
 
119
#endif
 
120
 
 
121
  sigint = signal(SIGINT, SIG_IGN);
 
122
  /* 20000318 mgs
 
123
   * this is needed by the emx system, SIGTSTP is not a supported signal */
 
124
#ifndef __EMX__
 
125
  sigtstp = signal(SIGTSTP, SIG_IGN);
 
126
#endif
 
127
 
 
128
  infp=fopen("/dev/tty", "r");
 
129
  if( NULL == infp )
 
130
    infp = stdin;
 
131
  else
 
132
    infp_fclose = 1;
 
133
 
 
134
  outfp = stderr;
 
135
 
 
136
  infd = fileno(infp);
 
137
  outfd = fileno(outfp);
 
138
 
 
139
  /* dissable echo */
 
140
#ifdef HAVE_TERMIOS_H
 
141
  tcgetattr(outfd, &orig);
 
142
 
 
143
  noecho = orig;
 
144
  noecho.c_lflag &= ~ECHO;
 
145
  tcsetattr(outfd, TCSANOW, &noecho);
 
146
#else
 
147
#  ifdef HAVE_TERMIO_H
 
148
  ioctl(outfd, TCGETA, &orig);
 
149
  noecho = orig;
 
150
  noecho.c_lflag &= ~ECHO;
 
151
  ioctl(outfd, TCSETA, &noecho);
 
152
#  else
 
153
#  endif
 
154
#endif
 
155
 
 
156
  fputs(prompt, outfp);
 
157
  fflush(outfp);
 
158
 
 
159
  bytes_read=read(infd, buffer, buflen);
 
160
  buffer[bytes_read > 0 ? (bytes_read -1) : 0] = '\0';
 
161
 
 
162
  /* print a new line if needed */
 
163
#ifdef HAVE_TERMIOS_H
 
164
  fputs("\n", outfp);
 
165
#else
 
166
#  ifdef HAVE_TERMIO_H
 
167
  fputs("\n", outfp);
 
168
#  else
 
169
#  endif
 
170
#endif
 
171
 
 
172
  /*
 
173
   * reset term charectaristics, use TCSAFLUSH incase the
 
174
   * user types more than buflen
 
175
   */
 
176
#ifdef HAVE_TERMIOS_H
 
177
  tcsetattr(outfd, TCSAFLUSH, &orig);
 
178
#else
 
179
#  ifdef HAVE_TERMIO_H
 
180
  ioctl(outfd, TCSETA, &orig);
 
181
#  else
 
182
#  endif
 
183
#endif
 
184
  
 
185
  signal(SIGINT, sigint);
 
186
#ifndef __EMX__
 
187
  signal(SIGTSTP, sigtstp);
 
188
#endif
 
189
 
 
190
  if(infp_fclose)
 
191
    fclose(infp);
 
192
 
 
193
  return buffer; /* we always return success */
 
194
}
 
195
#endif /* VMS */
 
196
#else /* WIN32 */
 
197
#include <stdio.h>
 
198
#include <conio.h>
 
199
char *getpass_r(const char *prompt, char *buffer, int buflen)
 
200
{
 
201
  int i;
 
202
  printf("%s", prompt);
 
203
 
 
204
  for(i=0; i<buflen; i++) {
 
205
    buffer[i] = (char)getch();
 
206
    if ( buffer[i] == '\r' ) {
 
207
      buffer[i] = 0;
 
208
      break;
 
209
    }
 
210
  }
 
211
  /* if user didn't hit ENTER, terminate buffer */
 
212
  if (i==buflen)
 
213
    buffer[buflen-1]=0;
 
214
 
 
215
  return buffer; /* we always return success */
 
216
}
 
217
#endif
 
218
 
 
219
#endif /* ifndef HAVE_GETPASS_R */
 
220
 
 
221
#if 0
 
222
/* for consistensy, here's the old-style function: */
 
223
char *getpass(const char *prompt)
 
224
{
 
225
  static char buf[256];
 
226
  return getpass_r(prompt, buf, sizeof(buf));
 
227
}
 
228
#endif
 
229
 
 
230
/*
 
231
 * local variables:
 
232
 * eval: (load-file "../curl-mode.el")
 
233
 * end:
 
234
 * vim600: fdm=marker
 
235
 * vim: et sw=2 ts=2 sts=2 tw=78
 
236
 */