29.06.2013 Views

Qshell Interpreter (qsh) - FTP Directory Listing - IBM

Qshell Interpreter (qsh) - FTP Directory Listing - IBM

Qshell Interpreter (qsh) - FTP Directory Listing - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

132 <strong>Qshell</strong> <strong>Interpreter</strong> (<strong>qsh</strong>)<br />

char *systag, *logtag;<br />

int logflag = 0, pwdflag = 0;<br />

FILE *netrc;<br />

struct passwd *pwdbuf;<br />

int rc=0;<br />

/* Get user's home directory. */<br />

pwdbuf = getpwuid(getuid());<br />

/* Does user have a .netrc file in their home directory? */<br />

strcat(strcpy(buffer, pwdbuf->pw_dir), “/.netrc”);<br />

if ((netrc = fopen(buffer, “r”)) == NULL) {<br />

perror(“<strong>qsh</strong>c: open() failed for x/.netrc file”);<br />

return -1;<br />

}<br />

while (!(logflag || pwdflag) && fgets(buffer, BUFSIZE, netrc) != NULL) {<br />

/* Find system name in x/.netrc. */<br />

if ((systag = (char*)strtok(buffer, “ \t\n”)) != NULL &&<br />

!strncmp(systag, “machine”, 7)) {<br />

systag = (char *)strtok(NULL, “ \t\n”);<br />

if (!strcmp(systag, sysname)) {<br />

/* Find login and password. */<br />

while (!logflag || !pwdflag) {<br />

if ((logtag = (char *)strtok(NULL, “ \t\n”)) == NULL) {<br />

/* Nothing else on that line... get another. */<br />

while (!logtag) {<br />

fgets(buffer, BUFSIZE, netrc);<br />

logtag = (char *)strtok(buffer, “ \t\n”);<br />

}<br />

}<br />

if (!strncmp(logtag, “login”, 5)) {<br />

strcpy(logname, strtok(NULL, “ \n\t”));<br />

++logflag;<br />

}<br />

else if (!strncmp(logtag, “password”, 8)) {<br />

strcpy(password, strtok(NULL, “ \n\t”));<br />

++pwdflag;<br />

}<br />

else<br />

;<br />

} /* while flags not set */<br />

} /* if found login and passwd in .netrc */<br />

} /* if machine in .netrc */<br />

} /* while fgets */<br />

fclose(netrc);<br />

/* Login and password not found for system. */<br />

if (!(logflag && pwdflag)) {<br />

rc = -1;<br />

}<br />

return rc;<br />

} /* End of GetPassword() */<br />

#ifndef USE_ICONV<br />

/*<br />

* Translate bytes using the specified translation table.<br />

*/<br />

int<br />

Translate(uchar *ip, size_t ilen, uchar *op, uchar *table)<br />

{<br />

int index;<br />

for (index = 0; index < ilen; ++index) {<br />

*op = table[*ip];<br />

ip++;<br />

op++;<br />

}<br />

return 0;<br />

} /* End of Translate() */<br />

#endif<br />

/*<br />

* Signal handler.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!