libssh 0.12.0
The SSH library
Loading...
Searching...
No Matches
misc.h
1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2009 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef MISC_H_
22#define MISC_H_
23
24#include "config.h"
25
26#ifdef _WIN32
27# ifdef _MSC_VER
28# ifndef _SSIZE_T_DEFINED
29# undef ssize_t
30# include <BaseTsd.h>
31 typedef _W64 SSIZE_T ssize_t;
32# define _SSIZE_T_DEFINED
33# endif /* _SSIZE_T_DEFINED */
34# endif /* _MSC_VER */
35#else
36#include <sys/types.h>
37#include <stdbool.h>
38#endif /* _WIN32 */
39#include <stdio.h>
40
41#include "libssh/libssh.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/* in misc.c */
48/* gets the user home dir. */
49char *ssh_get_user_home_dir(ssh_session session);
50char *ssh_get_local_username(void);
51char *ssh_get_local_hostname(void);
52int ssh_file_readaccess_ok(const char *file);
53int ssh_dir_writeable(const char *path);
54
55char *ssh_path_expand_tilde(const char *d);
56/* Expand a string using session option values. */
57char *ssh_path_expand_escape(ssh_session session, const char *s);
58/* Expand HostName tokens. */
59char *ssh_path_expand_hostname(ssh_session session, const char *s);
60int ssh_analyze_banner(ssh_session session, int server);
61int ssh_is_ipaddr_v4(const char *str);
62int ssh_is_ipaddr(const char *str);
63int ssh_normalize_loose_ip(const char *host, char **result);
64
65/* list processing */
66
67struct ssh_list {
68 struct ssh_iterator *root;
69 struct ssh_iterator *end;
70};
71
72struct ssh_iterator {
73 struct ssh_iterator *next;
74 const void *data;
75};
76
82 char *hostname;
84 char *username;
86 int port;
87};
88
89struct ssh_timestamp {
90 long seconds;
91 long useconds;
92};
93
94enum ssh_quote_state_e {
95 NO_QUOTE,
96 SINGLE_QUOTE,
97 DOUBLE_QUOTE
98};
99
100struct ssh_list *ssh_list_new(void);
101void ssh_list_free(struct ssh_list *list);
102struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
103struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value);
104size_t ssh_list_count(const struct ssh_list *list);
105int ssh_list_append(struct ssh_list *list, const void *data);
106int ssh_list_prepend(struct ssh_list *list, const void *data);
107void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
108char *ssh_lowercase(const char* str);
109char *ssh_hostport(const char *host, int port);
110
111const void *_ssh_list_pop_head(struct ssh_list *list);
112
113#define ssh_iterator_value(type, iterator)\
114 ((type)((iterator)->data))
115
121#define ssh_list_pop_head(type, ssh_list)\
122 ((type)_ssh_list_pop_head(ssh_list))
123
124#define SSH_LIST_FREE(x) \
125 do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
126
127int ssh_make_milliseconds(unsigned long sec, unsigned long usec);
128void ssh_timestamp_init(struct ssh_timestamp *ts);
129int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
130int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
131
132void uint64_inc(unsigned char *counter);
133
134void ssh_log_hexdump(const char *descr, const unsigned char *what, size_t len);
135
136int ssh_mkdirs(const char *pathname, mode_t mode);
137
138int ssh_quote_file_name(const char *file_name, char *buf, size_t buf_len);
139int ssh_newline_vis(const char *string, char *buf, size_t buf_len);
140int ssh_tmpname(char *name);
141
142char *ssh_strreplace(const char *src, const char *pattern, const char *repl);
143
144ssize_t ssh_readn(int fd, void *buf, size_t nbytes);
145ssize_t ssh_writen(int fd, const void *buf, size_t nbytes);
146
147int ssh_check_hostname_syntax(const char *hostname);
148int ssh_check_username_syntax(const char *username);
149
150void ssh_proxyjumps_free(struct ssh_list *proxy_jump_list);
151bool ssh_libssh_proxy_jumps(void);
152
153FILE *ssh_strict_fopen(const char *filename, size_t max_file_size);
154
155#ifdef __cplusplus
156}
157#endif
158
159#endif /* MISC_H_ */
bool ssh_libssh_proxy_jumps(void)
Check if libssh proxy jumps is enabled.
Definition misc.c:2661
ssize_t ssh_writen(int fd, const void *buf, size_t nbytes)
Write the requested number of bytes to a local file.
Definition misc.c:2500
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.
Definition misc.c:664
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...
Definition misc.c:1245
ssize_t ssh_readn(int fd, void *buf, size_t nbytes)
Read the requested number of bytes from a local file.
Definition misc.c:2444
size_t ssh_list_count(const struct ssh_list *list)
Get the number of elements in the list.
Definition misc.c:934
void ssh_proxyjumps_free(struct ssh_list *proxy_jump_list)
Free proxy jump list.
Definition misc.c:2636
char * ssh_path_expand_hostname(ssh_session session, const char *s)
Expand HostName tokens.
Definition misc.c:1716
int ssh_check_hostname_syntax(const char *hostname)
Checks syntax of a domain name.
Definition misc.c:2546
char * ssh_path_expand_escape(ssh_session session, const char *s)
Expand a string using session option values.
Definition misc.c:1698
char * ssh_path_expand_tilde(const char *d)
Expand a directory starting with a tilde '~'.
Definition misc.c:1308
int ssh_check_username_syntax(const char *username)
Checks syntax of a username.
Definition misc.c:2605
int ssh_timeout_update(struct ssh_timestamp *ts, int timeout)
updates a timeout value so it reflects the remaining time
Definition misc.c:1965
int ssh_normalize_loose_ip(const char *host, char **result)
Normalizes a loose IPv4 string (e.g. "0", "127.1") to dotted-quad format.
Definition misc.c:2796
int ssh_dir_writeable(const char *path)
Check if the given path is an existing directory and that is accessible for writing.
Definition misc.c:375
Holds connection details for an SSH proxyjump host.
Definition misc.h:80
int port
Definition misc.h:86
char * username
Definition misc.h:84
char * hostname
Definition misc.h:82