source: roaraudio/libroar/sshaskpass.c @ 5878:3b92b0d6ef9b

Last change on this file since 5878:3b92b0d6ef9b was 5823:f9f70dbaa376, checked in by phi, 11 years ago

updated copyright

File size: 2.6 KB
RevLine 
[1288]1//sshaskpass.c:
2
3/*
[5823]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2013
[1288]5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[1288]23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
[5379]38#ifdef _ASKPASS
39#undef _ASKPASS
40#endif
41
42#ifdef ROAR_HAVE_BIN_SSH_ASKPASS
43#define _ASKPASS ROAR_HAVE_BIN_SSH_ASKPASS
44#elif defined(ROAR_HAVE_BIN_GTK_LED_ASKPASS)
45#define _ASKPASS ROAR_HAVE_BIN_GTK_LED_ASKPASS
46#elif defined(ROAR_HAVE_BIN_X11_SSH_ASKPASS)
47#define _ASKPASS ROAR_HAVE_BIN_X11_SSH_ASKPASS
48#elif defined(ROAR_HAVE_BIN_GNOME_SSH_ASKPASS)
49#define _ASKPASS ROAR_HAVE_BIN_GNOME_SSH_ASKPASS
50#endif
51
[1288]52int roar_sshaskpass_getpass   (char ** pw, char * desc) {
[5379]53#if defined(_ASKPASS) && defined(ROAR_SUPPORT_PASSWORD_API) && defined(ROAR_HAVE_POPEN) && defined(ROAR_HAVE_PCLOSE)
[1289]54 FILE * cpipe;
55 char   buf[1024];
56 int    pos;
[4464]57 int    i;
[1288]58
[1289]59 if ( pw == NULL )
60  return -1;
61
[5379]62 if ( (cpipe = popen(_ASKPASS, "r")) == NULL ) {
[1288]63  return -1;
64 }
65
[1289]66 if ( fgets(buf, 1024, cpipe) == NULL ) {
67  fclose(cpipe);
68  return -1;
69 }
70
[3899]71 pclose(cpipe);
[1289]72
73 pos = strlen(buf);
74
[4464]75 ROAR_DBG("roar_sshaskpass_getpass(pw=%p, desc='%s'): pos=%i", pw, desc, pos);
76
77 for (i = pos - 1; i >= 0 && (buf[i] == '\r' || buf[i] == '\n'); i--, pos--) {
78  buf[i] = 0;
79 }
80
81 ROAR_DBG("roar_sshaskpass_getpass(pw=%p, desc='%s'): pos=%i", pw, desc, pos);
[1289]82
83 if ( pos == 0 )
84  return -1;
85
[4463]86 *pw = roar_mm_strdup(buf);
[1289]87
88 return 0;
[1288]89#else
[5379]90 roar_err_set(ROAR_ERROR_NOSYS);
[1288]91 return -1;
92#endif
93}
94
95//ll
Note: See TracBrowser for help on using the repository browser.