mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
style: make includes and examples code style strict
make travis and the makefile rule verify them too Closes #334
This commit is contained in:
@ -49,9 +49,11 @@ int main(int argc, char *argv[])
|
||||
struct sockaddr_in sin;
|
||||
const char *fingerprint;
|
||||
LIBSSH2_SESSION *session;
|
||||
const char *username="username";
|
||||
const char *password="password";
|
||||
const char *sftppath="/tmp/secretdir";
|
||||
const char *username = "username";
|
||||
const char *password = "password";
|
||||
const char *sftppath = "/tmp/secretdir";
|
||||
const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
int rc;
|
||||
LIBSSH2_SFTP *sftp_session;
|
||||
LIBSSH2_SFTP_HANDLE *sftp_handle;
|
||||
@ -60,16 +62,17 @@ int main(int argc, char *argv[])
|
||||
WSADATA wsadata;
|
||||
int err;
|
||||
|
||||
err = WSAStartup(MAKEWORD(2,0), &wsadata);
|
||||
if (err != 0) {
|
||||
err = WSAStartup(MAKEWORD(2, 0), &wsadata);
|
||||
if(err != 0) {
|
||||
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (argc > 1) {
|
||||
if(argc > 1) {
|
||||
hostaddr = inet_addr(argv[1]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
hostaddr = htonl(0x7F000001);
|
||||
}
|
||||
|
||||
@ -83,9 +86,9 @@ int main(int argc, char *argv[])
|
||||
sftppath = argv[4];
|
||||
}
|
||||
|
||||
rc = libssh2_init (0);
|
||||
if (rc != 0) {
|
||||
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
|
||||
rc = libssh2_init(0);
|
||||
if(rc != 0) {
|
||||
fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -98,8 +101,8 @@ int main(int argc, char *argv[])
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(22);
|
||||
sin.sin_addr.s_addr = hostaddr;
|
||||
if (connect(sock, (struct sockaddr*)(&sin),
|
||||
sizeof(struct sockaddr_in)) != 0) {
|
||||
if(connect(sock, (struct sockaddr*)(&sin),
|
||||
sizeof(struct sockaddr_in)) != 0) {
|
||||
fprintf(stderr, "failed to connect!\n");
|
||||
return -1;
|
||||
}
|
||||
@ -116,8 +119,8 @@ int main(int argc, char *argv[])
|
||||
/* ... start it up. This will trade welcome banners, exchange keys,
|
||||
* and setup crypto, compression, and MAC layers
|
||||
*/
|
||||
while ((rc = libssh2_session_handshake(session, sock)) ==
|
||||
LIBSSH2_ERROR_EAGAIN);
|
||||
while((rc = libssh2_session_handshake(session, sock)) ==
|
||||
LIBSSH2_ERROR_EAGAIN);
|
||||
if(rc) {
|
||||
fprintf(stderr, "Failure establishing SSH session: %d\n", rc);
|
||||
return -1;
|
||||
@ -135,21 +138,22 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
if (auth_pw) {
|
||||
if(auth_pw) {
|
||||
/* We could authenticate via password */
|
||||
while ((rc = libssh2_userauth_password(session, username, password)) ==
|
||||
LIBSSH2_ERROR_EAGAIN);
|
||||
if (rc) {
|
||||
while((rc = libssh2_userauth_password(session, username, password)) ==
|
||||
LIBSSH2_ERROR_EAGAIN);
|
||||
if(rc) {
|
||||
fprintf(stderr, "Authentication by password failed.\n");
|
||||
goto shutdown;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* Or by public key */
|
||||
while ((rc = libssh2_userauth_publickey_fromfile(session, username,
|
||||
"/home/username/.ssh/id_rsa.pub",
|
||||
"/home/username/.ssh/id_rsa",
|
||||
password)) == LIBSSH2_ERROR_EAGAIN);
|
||||
if (rc) {
|
||||
while((rc = libssh2_userauth_publickey_fromfile(session, username,
|
||||
pubkey, privkey,
|
||||
password)) ==
|
||||
LIBSSH2_ERROR_EAGAIN);
|
||||
if(rc) {
|
||||
fprintf(stderr, "\tAuthentication by public key failed\n");
|
||||
goto shutdown;
|
||||
}
|
||||
@ -159,24 +163,24 @@ int main(int argc, char *argv[])
|
||||
do {
|
||||
sftp_session = libssh2_sftp_init(session);
|
||||
|
||||
if ((!sftp_session) && (libssh2_session_last_errno(session) !=
|
||||
LIBSSH2_ERROR_EAGAIN)) {
|
||||
if((!sftp_session) && (libssh2_session_last_errno(session) !=
|
||||
LIBSSH2_ERROR_EAGAIN)) {
|
||||
fprintf(stderr, "Unable to init SFTP session\n");
|
||||
goto shutdown;
|
||||
}
|
||||
} while (!sftp_session);
|
||||
} while(!sftp_session);
|
||||
|
||||
fprintf(stderr, "libssh2_sftp_opendir()!\n");
|
||||
/* Request a dir listing via SFTP */
|
||||
do {
|
||||
sftp_handle = libssh2_sftp_opendir(sftp_session, sftppath);
|
||||
|
||||
if ((!sftp_handle) && (libssh2_session_last_errno(session) !=
|
||||
LIBSSH2_ERROR_EAGAIN)) {
|
||||
if((!sftp_handle) && (libssh2_session_last_errno(session) !=
|
||||
LIBSSH2_ERROR_EAGAIN)) {
|
||||
fprintf(stderr, "Unable to open dir with SFTP\n");
|
||||
goto shutdown;
|
||||
}
|
||||
} while (!sftp_handle);
|
||||
} while(!sftp_handle);
|
||||
|
||||
fprintf(stderr, "libssh2_sftp_opendir() is done, now receive listing!\n");
|
||||
do {
|
||||
@ -184,8 +188,8 @@ int main(int argc, char *argv[])
|
||||
LIBSSH2_SFTP_ATTRIBUTES attrs;
|
||||
|
||||
/* loop until we fail */
|
||||
while ((rc = libssh2_sftp_readdir(sftp_handle, mem, sizeof(mem),
|
||||
&attrs)) == LIBSSH2_ERROR_EAGAIN) {
|
||||
while((rc = libssh2_sftp_readdir(sftp_handle, mem, sizeof(mem),
|
||||
&attrs)) == LIBSSH2_ERROR_EAGAIN) {
|
||||
;
|
||||
}
|
||||
if(rc > 0) {
|
||||
@ -196,13 +200,15 @@ int main(int argc, char *argv[])
|
||||
/* this should check what permissions it
|
||||
is and print the output accordingly */
|
||||
printf("--fix----- ");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf("---------- ");
|
||||
}
|
||||
|
||||
if(attrs.flags & LIBSSH2_SFTP_ATTR_UIDGID) {
|
||||
printf("%4d %4d ", (int) attrs.uid, (int) attrs.gid);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf(" - - ");
|
||||
}
|
||||
|
||||
@ -212,21 +218,22 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("%s\n", mem);
|
||||
}
|
||||
else if (rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
else if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
/* blocking */
|
||||
fprintf(stderr, "Blocking\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
|
||||
} while (1);
|
||||
} while(1);
|
||||
|
||||
libssh2_sftp_closedir(sftp_handle);
|
||||
libssh2_sftp_shutdown(sftp_session);
|
||||
|
||||
shutdown:
|
||||
|
||||
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing");
|
||||
libssh2_session_disconnect(session, "Normal Shutdown");
|
||||
libssh2_session_free(session);
|
||||
|
||||
#ifdef WIN32
|
||||
|
Reference in New Issue
Block a user