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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

while (1) {<br />

if ((cfd = accept(sfd, NULL, 0)) < 0) {<br />

LogError(“accept() failed, errno=%d\n”, errno);<br />

close(sfd);<br />

exit(1);<br />

}<br />

/* Read the user profile and password from the client. The client<br />

sends two null-terminated strings - the first one is the user<br />

profile and the second one is the password. */<br />

if (GetString(cfd, profile, 11) != 0) {<br />

getpeername(cfd, (struct sockaddr *)&client_addr, &client_addr_len);<br />

LogError(“Could not read profile from client at %s, port %hu\n”,<br />

inet_ntoa(client_addr.sin_addr), client_addr.sin_port);<br />

close(cfd);<br />

continue;<br />

}<br />

if (GetString(cfd, password, 11) != 0) {<br />

getpeername(cfd, (struct sockaddr *)&client_addr, &client_addr_len);<br />

LogError(“Could not read password from client at %s, port %hu\n”,<br />

inet_ntoa(client_addr.sin_addr), client_addr.sin_port);<br />

close(cfd);<br />

continue;<br />

}<br />

/* QSYGETPH() requires that the profile and password be exactly ten<br />

characters, left-justified in the field, and padded with blanks. */<br />

strtoupper(profile);<br />

strtoupper(password);<br />

sprintf(sy_profile, “%-10.10s”, profile);<br />

sprintf(sy_password, “%-10.10s”, password);<br />

/* Get the profile handle for the client's user profile. */<br />

QSYGETPH(sy_profile, sy_password, client_ph, &error);<br />

if (error.Bytes_Available != 0) {<br />

LogError(“Could not get profile handle for profile %s, ”<br />

“QSYGETPH() failed with exception %7.7s\n”,<br />

sy_profile, error.Exception_Id);<br />

SendError(cfd, “Could not get profile handle for profile %s\n”,<br />

sy_profile);<br />

close(cfd);<br />

continue;<br />

}<br />

/* Switch to client's user profile. */<br />

QWTSETP(client_ph, &error);<br />

if (error.Bytes_Available != 0) {<br />

LogError(“Could not switch to profile %s, ”<br />

“QWTSETP() failed with exception %7.7s\n”,<br />

sy_profile, error.Exception_Id);<br />

SendError(cfd, “Could not switch to profile %s\n”, sy_profile);<br />

QSYRLSPH(client_ph, NULL);<br />

close(cfd);<br />

continue;<br />

}<br />

/* Get the info for this user profile. */<br />

if ((cpw = getpwnam(profile)) == NULL) {<br />

/* Log error. */<br />

LogError(“Could not retrieve information for profile %s, ”<br />

“getpwnam() failed with errno=%d\n”,<br />

profile, errno);<br />

SendError(cfd, “Could not retrieve information for profile %s\n”,<br />

profile);<br />

/* Switch back to the server's user profile. */<br />

QWTSETP(server_ph, &error);<br />

if (error.Bytes_Available != 0) {<br />

LogError(“Could not switch back to server's profile, ”<br />

“QWTSETP() failed with exception %7.7s\n”,<br />

error.Exception_Id);<br />

break;<br />

}

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

Saved successfully!

Ooh no, something went wrong!