473,382 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to fool getpass()

I want to override getpass() mechanisms of getting password from the
keyboard. I opened a new pseudoterminal: /dev/ptmx and the other side
of it and tried to redirect it to standard ftp client (what i want to
do is to make my program enter the password automatically) I looked
into ftp sources and know that ftp uses getpass() function to acquire
password. Although i'm using pseudoterminal (not pipes) it seems to
work exactly the same as with pipes. Ftp ignores my program and waits
for user to enter password from the keyboard, dunno what to do.
thx for any help.

Marek
here is my code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <malloc.h>
#include <fcntl.h>
#include <pty.h>
#include <utmp.h>

#define CS_NOT_CONNECTED 0
#define CS_CONNECTED 1

#define RC_ERROR_PROCESS_SPAWN 35
#define RC_GEN_FAIL 1
#define RC_ERROR_OPEN_FILE 2
#define RC_GEN_SUCCESS 0

#define D_BUFSIZE 500
#define D_PATH_MAX 256

int main(int argc, char **argv, char **envp)
{
int forkRes1 = 0;
int forkRes2 = 0;
int telnetInPipe[2],
telnetOutPipe[2];
int ftpMasterFd,
ftpSlaveFd;

int readData = -1;
char buffer[D_BUFSIZE + 1];
char cmdToRun[D_BUFSIZE];
int connectionStatus = CS_NOT_CONNECTED;
int i = 0;
char *tmp;
char name[D_PATH_MAX];
struct termios stermios;
memset(buffer, '\0', sizeof(buffer));

pipe(telnetInPipe);
pipe(telnetOutPipe);

ftpMasterFd = open("/dev/ptmx", O_RDWR | O_NOCTTY);
grantpt(ftpMasterFd);
unlockpt(ftpMasterFd);
tmp = (char *)ptsname(ftpMasterFd);

ftpSlaveFd = open(tmp, O_RDWR | O_NOCTTY);

/* openpty(&ftpMasterFd, &ftpSlaveFd, name, NULL, NULL); */
printf("master: %d, slave: %d, name: %s\n",
ftpMasterFd,
ftpSlaveFd,
tmp);
if (argc<2)
{
printf("Too few parameters.\nUsage:\n\n");
return 0;
}

forkRes1 = fork();
if (0 == forkRes1)
{
/* child1 part */
close(ftpMasterFd);
dup2(ftpSlaveFd, 0);
dup2(ftpSlaveFd, 1);
dup2(ftpSlaveFd, 2);
/*tcgetattr(0, &stermios);

stermios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
stermios.c_lflag |= ICANON;
stermios.c_lflag &= ~(ONLCR);

tcsetattr(0, TCSANOW, &stermios); */
execlp("ftp","ftp","-v", "-n",argv[1], 0);
return RC_ERROR_PROCESS_SPAWN;
}
else
{
/* parent part */
close(ftpSlaveFd);
while (1)
{
do
{
memset(buffer, 0, sizeof(buffer));
readData = read(ftpMasterFd, buffer,D_BUFSIZE);
buffer[readData]='\0';
if (connectionStatus == 3)
{
write(ftpMasterFd, "password\n", 10);
connectionStatus++;
}
printf("%s",
buffer);
processFtpBuffer(buffer,
ftpMasterFd,
&connectionStatus);

fflush(stdout);
}
while (readData==D_BUFSIZE);
fflush(stdout);
}
}

return 0;

}

int processFtpBuffer(char *buffer,
int ftpMasterFd,
int *connectionStatus)
{
int status = RC_GEN_SUCCESS;
char *relativePtr = 0;
int i;
char cmdToRun[300];
FILE *tty;
memset(cmdToRun, 0, sizeof(cmdToRun));
if (0 != strstr(buffer, "220"))
{
write(ftpMasterFd, "user root\n", 10);
}
else if (0 != strstr(buffer, "331"))
{
*connectionStatus = 3;
}
return status;

Aug 15 '06 #1
2 2877
marek...@gmail.com wrote:
I want to override getpass() mechanisms of getting password from the
keyboard. I opened a new pseudoterminal: /dev/ptmx and the other side
of it and tried to redirect it to standard ftp client (what i want to
do is to make my program enter the password automatically) I looked
into ftp sources and know that ftp uses getpass() function to acquire
password. Although i'm using pseudoterminal (not pipes) it seems to
work exactly the same as with pipes. Ftp ignores my program and waits
for user to enter password from the keyboard, dunno what to do.
thx for any help.
[snip]

We only discuss Standard C here which doesn't include pseudoterminals,
getpass(), pipes, etc. Try comp.unix.programmer.

Robert Gamble

Aug 15 '06 #2
ma******@gmail.com wrote:
Although i'm using pseudoterminal (not pipes) it seems to
work exactly the same as with pipes. Ftp ignores my program and waits
for user to enter password from the keyboard, dunno what to do.
This may be a job for expect. (or libexpect, to use in a C program).

See comp.unix.questions FAQ 3.9
Aug 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lucas Raab | last post by:
Could someone please demo the "getpass" module? I would like to use this, but have problems with it. Also, is there a way to have usernames other than through "pwd" (which I don't have because I...
1
by: gibber | last post by:
Ok, so I'm new to Python, so I'm clearly missing something, but where is the documentation? For example, take xml.dom.pulldown. I've found...
1
by: John Lowe | last post by:
Hi Folks, Our data raid (/data) got nearly full. Due to design limitation, it is already at max, no more room to expand. We like to replace /data with a new and bigger raid and still call it...
6
by: John Salerno | last post by:
I'm guessing this might have something to do with my particular system? Warning: Problem with getpass. Passwords may be echoed. Password: hello 'hello'
9
by: raylopez99 | last post by:
After refering to the below thread, I take it for C# Forms 2.0, there a way to draw a 1 pixel by 1 pixel rectangle, which I was able to do just now successfully. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.