1 /* 2 * password.h 3 * 4 * This file is part of msmtp, an SMTP client, and of mpop, a POP3 client. 5 * 6 * Copyright (C) 2019, 2020, 2021 Martin Lambers <marlam@marlam.de> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef PASSWORD_H 23 #define PASSWORD_H 24 25 typedef enum { 26 password_service_smtp, 27 password_service_pop3 28 } password_service_t; 29 30 /* 31 * password_get() 32 * 33 * This function tries to get a password for service::user@hostname. 34 * It tries to get it from the system's keychain (if available). 35 * If that fails and consult_netrc is set, it tries to read a password from .netrc. 36 * If that fails, it tries to read a password via getpass(). 37 * If getpass_only_via_tty is set, then getpass() will only be called 38 * if it reads from /dev/tty instead of stdin. 39 * This function returns NULL on failure or the password in an allocated 40 * buffer. 41 */ 42 char *password_get(const char *hostname, const char *user, 43 password_service_t service, 44 int consult_netrc, 45 int getpass_only_via_tty); 46 47 /* 48 * password_eval() 49 * 50 * Evaluates command in 'arg' and stores result in 'buf' (which is allocated). 51 * Returns non-zero if command execution failed, otherwise zero. On error, 52 * *errstr will contain an error string. 53 */ 54 int password_eval(const char *arg, char **buf, char **errstr); 55 56 #endif 57