libssh
0.10.90
The SSH library
|
Functions | |
int | ssh_getpass (const char *prompt, char *buf, size_t len, int echo, int verify) |
Get a password from the console. | |
int | ssh_get_random (void *where, int len, int strong) |
Get random bytes. | |
char * | ssh_get_user_home_dir (void) |
int | ssh_file_readaccess_ok (const char *file) |
int | ssh_dir_writeable (const char *path) |
Check if the given path is an existing directory and that is accessible for writing. | |
char * | ssh_get_local_username (void) |
int | ssh_is_ipaddr_v4 (const char *str) |
int | ssh_is_ipaddr (const char *str) |
char * | ssh_lowercase (const char *str) |
char * | ssh_hostport (const char *host, int port) |
char * | ssh_get_hexa (const unsigned char *what, size_t len) |
Convert a buffer into a colon separated hex string. The caller has to free the memory. | |
void | ssh_print_hexa (const char *descr, const unsigned char *what, size_t len) |
void | ssh_log_hexdump (const char *descr, const unsigned char *what, size_t len) |
Log the content of a buffer in hexadecimal format, similar to the output of 'hexdump -C' command. | |
const char * | ssh_version (int req_version) |
Check if libssh is the required version or get the version string. | |
struct ssh_list * | ssh_list_new (void) |
void | ssh_list_free (struct ssh_list *list) |
struct ssh_iterator * | ssh_list_get_iterator (const struct ssh_list *list) |
struct ssh_iterator * | ssh_list_find (const struct ssh_list *list, void *value) |
size_t | ssh_list_count (const struct ssh_list *list) |
Get the number of elements in the list. | |
int | ssh_list_append (struct ssh_list *list, const void *data) |
int | ssh_list_prepend (struct ssh_list *list, const void *data) |
void | ssh_list_remove (struct ssh_list *list, struct ssh_iterator *iterator) |
const void * | _ssh_list_pop_head (struct ssh_list *list) |
char * | ssh_dirname (const char *path) |
Parse directory component. | |
char * | ssh_basename (const char *path) |
basename - parse filename component. | |
int | ssh_mkdir (const char *pathname, mode_t mode) |
Attempts to create a directory with the given pathname. | |
int | ssh_mkdirs (const char *pathname, mode_t mode) |
Attempts to create a directory with the given pathname. The missing directories in the given pathname are created recursively. | |
char * | ssh_path_expand_tilde (const char *d) |
Expand a directory starting with a tilde '~'. | |
char * | ssh_path_expand_escape (ssh_session session, const char *s) |
int | ssh_analyze_banner (ssh_session session, int server) |
void | ssh_timestamp_init (struct ssh_timestamp *ts) |
int | ssh_make_milliseconds (unsigned long sec, unsigned long usec) |
int | ssh_timeout_elapsed (struct ssh_timestamp *ts, int timeout) |
int | ssh_timeout_update (struct ssh_timestamp *ts, int timeout) |
updates a timeout value so it reflects the remaining time | |
int | ssh_match_group (const char *group, const char *object) |
void | explicit_bzero (void *s, size_t n) |
char * | strndup (const char *s, size_t n) |
void | uint64_inc (unsigned char *counter) |
int | ssh_quote_file_name (const char *file_name, char *buf, size_t buf_len) |
int | ssh_newline_vis (const char *string, char *buf, size_t buf_len) |
int | ssh_tmpname (char *name) |
char * | ssh_strreplace (const char *src, const char *pattern, const char *replace) |
char * | ssh_strerror (int err_num, char *buf, size_t buflen) |
ssize_t | ssh_readn (int fd, void *buf, size_t nbytes) |
Read the requested number of bytes from a local file. | |
ssize_t | ssh_writen (int fd, const void *buf, size_t nbytes) |
Write the requested number of bytes to a local file. | |
int | ssh_check_hostname_syntax (const char *hostname) |
Checks syntax of a domain name. | |
int | ssh_check_username_syntax (const char *username) |
Checks syntax of a username. | |
Different helper functions used in the SSH Library.
char * ssh_basename | ( | const char * | path | ) |
basename - parse filename component.
basename breaks a null-terminated pathname string into a filename component. ssh_basename() returns the component following the final '/'. Trailing '/' characters are not counted as part of the pathname.
[in] | path | The path to parse. |
int ssh_check_hostname_syntax | ( | const char * | hostname | ) |
Checks syntax of a domain name.
The check is made based on the RFC1035 section 2.3.1 Allowed characters are: hyphen, period, digits (0-9) and letters (a-zA-Z)
The label should be no longer than 63 characters The label should start with a letter and end with a letter or number The label in this implementation can start with a number to allow virtual URLs to pass. Note that this will make IPv4 addresses to pass this check too.
hostname | The domain name to be checked, has to be null terminated |
int ssh_check_username_syntax | ( | const char * | username | ) |
Checks syntax of a username.
This check disallows metacharacters in the username
username | The username to be checked, has to be null terminated |
int ssh_dir_writeable | ( | const char * | path | ) |
Check if the given path is an existing directory and that is accessible for writing.
[in] | path | Path to the directory to be checked |
char * ssh_dirname | ( | const char * | path | ) |
Parse directory component.
dirname breaks a null-terminated pathname string into a directory component. In the usual case, ssh_dirname() returns the string up to, but not including, the final '/'. Trailing '/' characters are not counted as part of the pathname. The caller must free the memory using ssh_string_free_char().
[in] | path | The path to parse. |
char * ssh_get_hexa | ( | const unsigned char * | what, |
size_t | len ) |
Convert a buffer into a colon separated hex string. The caller has to free the memory.
[in] | what | What should be converted to a hex string. |
[in] | len | Length of the buffer to convert. |
int ssh_get_random | ( | void * | where, |
int | len, | ||
int | strong ) |
Get random bytes.
Make sure to always check the return code of this function!
[in] | where | The buffer to fill with random bytes |
[in] | len | The size of the buffer to fill. |
[in] | strong | Use a strong or private RNG source. |
int ssh_getpass | ( | const char * | prompt, |
char * | buf, | ||
size_t | len, | ||
int | echo, | ||
int | verify ) |
Get a password from the console.
You should make sure that the buffer is an empty string!
You can also use this function to ask for a username. Then you can fill the buffer with the username and it is shows to the users. If the users just presses enter the buffer will be untouched.
The prompt will look like this:
Username: [john]
If you press enter then john is used as the username, or you can type it in to change it.
[in] | prompt | The prompt to show to ask for the password. |
[out] | buf | The buffer the password should be stored. It NEEDS to be empty or filled out. |
[in] | len | The length of the buffer. |
[in] | echo | Should we echo what you type. |
[in] | verify | Should we ask for the password twice. |
size_t ssh_list_count | ( | const struct ssh_list * | list | ) |
Get the number of elements in the list.
[in] | list | The list to count. |
void ssh_log_hexdump | ( | const char * | descr, |
const unsigned char * | what, | ||
size_t | len ) |
Log the content of a buffer in hexadecimal format, similar to the output of 'hexdump -C' command.
The first logged line is the given description followed by the length. Then the content of the buffer is logged 16 bytes per line in the following format:
(offset) (first 8 bytes) (last 8 bytes) (the 16 bytes as ASCII char values)
The output for a 16 bytes array containing values from 0x00 to 0x0f would be:
"Example (16 bytes):" " 00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................"
The value for each byte as corresponding ASCII character is printed at the end if the value is printable. Otherwise, it is replaced with '.'.
[in] | descr | A description for the content to be logged |
[in] | what | The buffer to be logged |
[in] | len | The length of the buffer given in what |
int ssh_mkdir | ( | const char * | pathname, |
mode_t | mode ) |
Attempts to create a directory with the given pathname.
This is the portable version of mkdir, mode is ignored on Windows systems.
[in] | pathname | The path name to create the directory. |
[in] | mode | The permissions to use. |
int ssh_mkdirs | ( | const char * | pathname, |
mode_t | mode ) |
Attempts to create a directory with the given pathname. The missing directories in the given pathname are created recursively.
[in] | pathname | The path name to create the directory. |
[in] | mode | The permissions to use. |
char * ssh_path_expand_tilde | ( | const char * | d | ) |
Expand a directory starting with a tilde '~'.
[in] | d | The directory to expand. |
void ssh_print_hexa | ( | const char * | descr, |
const unsigned char * | what, | ||
size_t | len ) |
ssize_t ssh_readn | ( | int | fd, |
void * | buf, | ||
size_t | nbytes ) |
Read the requested number of bytes from a local file.
A call to read() may perform a short read even when sufficient data is present in the file. This function can be used to avoid such short reads.
This function tries to read the requested number of bytes from the file until one of the following occurs :
On encountering an error due to an interrupt, this function ignores that error and continues trying to read the data.
[in] | fd | The file descriptor of the local file to read from. |
[out] | buf | Pointer to a buffer in which read data will be stored. |
[in] | nbytes | Number of bytes to read. |
int ssh_timeout_update | ( | struct ssh_timestamp * | ts, |
int | timeout ) |
updates a timeout value so it reflects the remaining time
[in] | ts | pointer to an existing timestamp |
[in] | timeout | timeout in milliseconds. Negative values mean infinite timeout |
const char * ssh_version | ( | int | req_version | ) |
Check if libssh is the required version or get the version string.
[in] | req_version | The version required. |
Example:
ssize_t ssh_writen | ( | int | fd, |
const void * | buf, | ||
size_t | nbytes ) |
Write the requested number of bytes to a local file.
A call to write() may perform a short write on a local file. This function can be used to avoid short writes.
This function tries to write the requested number of bytes until those many bytes are written or some error occurs.
On encountering an error due to an interrupt, this function ignores that error and continues trying to write the data.
[in] | fd | The file descriptor of the local file to write to. |
[in] | buf | Pointer to a buffer in which data to write is stored. |
[in] | nbytes | Number of bytes to write. |