You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libsxmp/tools/misc.c

73 lines
1.8 KiB
C

/*
* Secure X Message Passing Library tools.
*
* (c) Alexander Vdolainen 2016 <avdolainen@zoho.com>
*
* libsxmp is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libsxmp is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
*
* support functions for sxmp tools
*/
#include <stdio.h>
#include <dirent.h>
#define __USE_GNU
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include <unistd.h>
#include <execinfo.h>
#include <getopt.h>
#include <string.h>
#include <errno.h>
#include <termios.h>
#include <sxt/errno.h>
#include <sxt/safebuf.h>
#include <ndbuf/ndbuf.h>
#include <sxt/sxtkey.h>
#include <sxt/socket.h>
#include <sxt/sxt.h>
int passkey_promt(char *passbuf, size_t p_len, int cnf, void *priv)
{
char *promt = (char *)priv;
int sym, len = 0;
struct termios tio;
/* print promt */
fprintf(stdout, "%s", promt);
fflush(stdout);
tcgetattr(STDIN_FILENO, &tio);
/* disable echo */
tio.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &tio);
while((sym = fgetc(stdin)) != '\n') {
passbuf[len] = sym;
if(len + 1 == p_len) break;
else len++;
}
/* enable again */
tio.c_lflag |= (ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &tio);
fprintf(stdout, "\n");
return SXT_SUCCESS;
}