1 | //sshaskpass.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2012 |
---|
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 |
---|
21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
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 | |
---|
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 | |
---|
52 | int roar_sshaskpass_getpass (char ** pw, char * desc) { |
---|
53 | #if defined(_ASKPASS) && defined(ROAR_SUPPORT_PASSWORD_API) && defined(ROAR_HAVE_POPEN) && defined(ROAR_HAVE_PCLOSE) |
---|
54 | FILE * cpipe; |
---|
55 | char buf[1024]; |
---|
56 | int pos; |
---|
57 | int i; |
---|
58 | |
---|
59 | if ( pw == NULL ) |
---|
60 | return -1; |
---|
61 | |
---|
62 | if ( (cpipe = popen(_ASKPASS, "r")) == NULL ) { |
---|
63 | return -1; |
---|
64 | } |
---|
65 | |
---|
66 | if ( fgets(buf, 1024, cpipe) == NULL ) { |
---|
67 | fclose(cpipe); |
---|
68 | return -1; |
---|
69 | } |
---|
70 | |
---|
71 | pclose(cpipe); |
---|
72 | |
---|
73 | pos = strlen(buf); |
---|
74 | |
---|
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); |
---|
82 | |
---|
83 | if ( pos == 0 ) |
---|
84 | return -1; |
---|
85 | |
---|
86 | *pw = roar_mm_strdup(buf); |
---|
87 | |
---|
88 | return 0; |
---|
89 | #else |
---|
90 | roar_err_set(ROAR_ERROR_NOSYS); |
---|
91 | return -1; |
---|
92 | #endif |
---|
93 | } |
---|
94 | |
---|
95 | //ll |
---|