<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.3.1"/> <title>libssh: The SSH helper functions.</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">libssh  <span id="projectnumber">0.5.5</span> </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.3.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> </ul> </div> </div><!-- top --> <div class="header"> <div class="summary"> <a href="#func-members">Functions</a> </div> <div class="headertitle"> <div class="title">The SSH helper functions.<div class="ingroups"><a class="el" href="group__libssh.html">The libssh API</a></div></div> </div> </div><!--header--> <div class="contents"> <p>Different helper functions used in the SSH Library. <a href="#details">More...</a></p> <table class="memberdecls"> <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a> Functions</h2></td></tr> <tr class="memitem:ga83b053a8bdf80eea5ebc662e5098a52b"><td class="memItemLeft" align="right" valign="top">char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__libssh__misc.html#ga83b053a8bdf80eea5ebc662e5098a52b">ssh_basename</a> (const char *path)</td></tr> <tr class="memdesc:ga83b053a8bdf80eea5ebc662e5098a52b"><td class="mdescLeft"> </td><td class="mdescRight">basename - parse filename component. <a href="#ga83b053a8bdf80eea5ebc662e5098a52b">More...</a><br/></td></tr> <tr class="separator:ga83b053a8bdf80eea5ebc662e5098a52b"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:gad36f0f8dbde59aefedd385dff76384fa"><td class="memItemLeft" align="right" valign="top">char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__libssh__misc.html#gad36f0f8dbde59aefedd385dff76384fa">ssh_dirname</a> (const char *path)</td></tr> <tr class="memdesc:gad36f0f8dbde59aefedd385dff76384fa"><td class="mdescLeft"> </td><td class="mdescRight">Parse directory component. <a href="#gad36f0f8dbde59aefedd385dff76384fa">More...</a><br/></td></tr> <tr class="separator:gad36f0f8dbde59aefedd385dff76384fa"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:gad6effc9fcc3529ae5d7301fb096aa71c"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__libssh__misc.html#gad6effc9fcc3529ae5d7301fb096aa71c">ssh_getpass</a> (const char *prompt, char *buf, size_t len, int echo, int verify)</td></tr> <tr class="memdesc:gad6effc9fcc3529ae5d7301fb096aa71c"><td class="mdescLeft"> </td><td class="mdescRight">Get a password from the console. <a href="#gad6effc9fcc3529ae5d7301fb096aa71c">More...</a><br/></td></tr> <tr class="separator:gad6effc9fcc3529ae5d7301fb096aa71c"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:ga5e15e93beecaef3af67d02b7ba55309f"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__libssh__misc.html#ga5e15e93beecaef3af67d02b7ba55309f">ssh_mkdir</a> (const char *pathname, mode_t mode)</td></tr> <tr class="memdesc:ga5e15e93beecaef3af67d02b7ba55309f"><td class="mdescLeft"> </td><td class="mdescRight">Attempts to create a directory with the given pathname. <a href="#ga5e15e93beecaef3af67d02b7ba55309f">More...</a><br/></td></tr> <tr class="separator:ga5e15e93beecaef3af67d02b7ba55309f"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:ga85622306848fd7e735d5843747f6eb28"><td class="memItemLeft" align="right" valign="top">char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__libssh__misc.html#ga85622306848fd7e735d5843747f6eb28">ssh_path_expand_tilde</a> (const char *d)</td></tr> <tr class="memdesc:ga85622306848fd7e735d5843747f6eb28"><td class="mdescLeft"> </td><td class="mdescRight">Expand a directory starting with a tilde '~'. <a href="#ga85622306848fd7e735d5843747f6eb28">More...</a><br/></td></tr> <tr class="separator:ga85622306848fd7e735d5843747f6eb28"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:gad1c4b29e2421eb8f9ca111d98b0c2976"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__libssh__misc.html#gad1c4b29e2421eb8f9ca111d98b0c2976">ssh_timeout_update</a> (struct ssh_timestamp *ts, int timeout)</td></tr> <tr class="memdesc:gad1c4b29e2421eb8f9ca111d98b0c2976"><td class="mdescLeft"> </td><td class="mdescRight">updates a timeout value so it reflects the remaining time <a href="#gad1c4b29e2421eb8f9ca111d98b0c2976">More...</a><br/></td></tr> <tr class="separator:gad1c4b29e2421eb8f9ca111d98b0c2976"><td class="memSeparator" colspan="2"> </td></tr> <tr class="memitem:gaeda71ed34a62fa332762f25b14dac6eb"><td class="memItemLeft" align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__libssh__misc.html#gaeda71ed34a62fa332762f25b14dac6eb">ssh_version</a> (int req_version)</td></tr> <tr class="memdesc:gaeda71ed34a62fa332762f25b14dac6eb"><td class="mdescLeft"> </td><td class="mdescRight">Check if libssh is the required version or get the version string. <a href="#gaeda71ed34a62fa332762f25b14dac6eb">More...</a><br/></td></tr> <tr class="separator:gaeda71ed34a62fa332762f25b14dac6eb"><td class="memSeparator" colspan="2"> </td></tr> </table> <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2> <p>Different helper functions used in the SSH Library. </p> <h2 class="groupheader">Function Documentation</h2> <a class="anchor" id="ga83b053a8bdf80eea5ebc662e5098a52b"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">char* ssh_basename </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>path</em></td><td>)</td> <td></td> </tr> </table> </div><div class="memdoc"> <p>basename - parse filename component. </p> <p>basename breaks a null-terminated pathname string into a filename component. <a class="el" href="group__libssh__misc.html#ga83b053a8bdf80eea5ebc662e5098a52b" title="basename - parse filename component.">ssh_basename()</a> returns the component following the final '/'. Trailing '/' characters are not counted as part of the pathname.</p> <dl class="params"><dt>Parameters</dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">path</td><td>The path to parse.</td></tr> </table> </dd> </dl> <dl class="section return"><dt>Returns</dt><dd>The filename of path or NULL if we can't allocate memory. If path is a the string "/", basename returns the string "/". If path is NULL or an empty string, "." is returned. </dd></dl> <p>Referenced by <a class="el" href="group__libssh__scp.html#gaa584f03d4e3d582ac10a3a19818ec56d">ssh_scp_push_directory()</a>, and <a class="el" href="group__libssh__scp.html#ga544f4b9c525071910110ada94148adc6">ssh_scp_push_file()</a>.</p> </div> </div> <a class="anchor" id="gad36f0f8dbde59aefedd385dff76384fa"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">char* ssh_dirname </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>path</em></td><td>)</td> <td></td> </tr> </table> </div><div class="memdoc"> <p>Parse directory component. </p> <p>dirname breaks a null-terminated pathname string into a directory component. In the usual case, <a class="el" href="group__libssh__misc.html#gad36f0f8dbde59aefedd385dff76384fa" title="Parse directory component.">ssh_dirname()</a> 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.</p> <dl class="params"><dt>Parameters</dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">path</td><td>The path to parse.</td></tr> </table> </dd> </dl> <dl class="section return"><dt>Returns</dt><dd>The dirname of path or NULL if we can't allocate memory. If path does not contain a slash, c_dirname() returns the string ".". If path is the string "/", it returns the string "/". If path is NULL or an empty string, "." is returned. </dd></dl> <p>Referenced by <a class="el" href="group__libssh__session.html#gaf61a9cfdc40c76ffce9f9a8543755d36">ssh_write_knownhost()</a>.</p> </div> </div> <a class="anchor" id="gad6effc9fcc3529ae5d7301fb096aa71c"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int ssh_getpass </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>prompt</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">char * </td> <td class="paramname"><em>buf</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">size_t </td> <td class="paramname"><em>len</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>echo</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>verify</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div><div class="memdoc"> <p>Get a password from the console. </p> <p>You should make sure that the buffer is an empty string!</p> <p>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.</p> <div class="fragment"><div class="line"><span class="keywordtype">char</span> username[128];</div> <div class="line"></div> <div class="line">snprintf(username, <span class="keyword">sizeof</span>(username), <span class="stringliteral">"john"</span>);</div> <div class="line"></div> <div class="line"><a class="code" href="group__libssh__misc.html#gad6effc9fcc3529ae5d7301fb096aa71c" title="Get a password from the console.">ssh_getpass</a>(<span class="stringliteral">"Username:"</span>, username, <span class="keyword">sizeof</span>(username), 1, 0);</div> </div><!-- fragment --><p>The prompt will look like this:</p> <p>Username: [john]</p> <p>If you press enter then john is used as the username, or you can type it in to change it.</p> <dl class="params"><dt>Parameters</dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">prompt</td><td>The prompt to show to ask for the password.</td></tr> <tr><td class="paramdir">[out]</td><td class="paramname">buf</td><td>The buffer the password should be stored. It NEEDS to be empty or filled out.</td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">len</td><td>The length of the buffer.</td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">echo</td><td>Should we echo what you type.</td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">verify</td><td>Should we ask for the password twice.</td></tr> </table> </dd> </dl> <dl class="section return"><dt>Returns</dt><dd>0 on success, -1 on error. </dd></dl> </div> </div> <a class="anchor" id="ga5e15e93beecaef3af67d02b7ba55309f"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int ssh_mkdir </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>pathname</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">mode_t </td> <td class="paramname"><em>mode</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div><div class="memdoc"> <p>Attempts to create a directory with the given pathname. </p> <p>This is the portable version of mkdir, mode is ignored on Windows systems.</p> <dl class="params"><dt>Parameters</dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">pathname</td><td>The path name to create the directory.</td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">mode</td><td>The permissions to use.</td></tr> </table> </dd> </dl> <dl class="section return"><dt>Returns</dt><dd>0 on success, < 0 on error with errno set. </dd></dl> <p>Referenced by <a class="el" href="group__libssh__session.html#gaf61a9cfdc40c76ffce9f9a8543755d36">ssh_write_knownhost()</a>.</p> </div> </div> <a class="anchor" id="ga85622306848fd7e735d5843747f6eb28"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">char* ssh_path_expand_tilde </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>d</em></td><td>)</td> <td></td> </tr> </table> </div><div class="memdoc"> <p>Expand a directory starting with a tilde '~'. </p> <dl class="params"><dt>Parameters</dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">d</td><td>The directory to expand.</td></tr> </table> </dd> </dl> <dl class="section return"><dt>Returns</dt><dd>The expanded directory, NULL on error. </dd></dl> <p>Referenced by <a class="el" href="group__libssh__session.html#ga7a801b85800baa3f4e16f5b47db0a73d">ssh_options_set()</a>.</p> </div> </div> <a class="anchor" id="gad1c4b29e2421eb8f9ca111d98b0c2976"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int ssh_timeout_update </td> <td>(</td> <td class="paramtype">struct ssh_timestamp * </td> <td class="paramname"><em>ts</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>timeout</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div><div class="memdoc"> <p>updates a timeout value so it reflects the remaining time </p> <dl class="params"><dt>Parameters</dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">ts</td><td>pointer to an existing timestamp </td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">timeout</td><td>timeout in milliseconds. Negative values mean infinite timeout </td></tr> </table> </dd> </dl> <dl class="section return"><dt>Returns</dt><dd>remaining time in milliseconds, 0 if elapsed, -1 if never, -2 if option-set-timeout. </dd></dl> </div> </div> <a class="anchor" id="gaeda71ed34a62fa332762f25b14dac6eb"></a> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">const char* ssh_version </td> <td>(</td> <td class="paramtype">int </td> <td class="paramname"><em>req_version</em></td><td>)</td> <td></td> </tr> </table> </div><div class="memdoc"> <p>Check if libssh is the required version or get the version string. </p> <dl class="params"><dt>Parameters</dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">req_version</td><td>The version required.</td></tr> </table> </dd> </dl> <dl class="section return"><dt>Returns</dt><dd>If the version of libssh is newer than the version required it will return a version string. NULL if the version is older.</dd></dl> <p>Example:</p> <div class="fragment"><div class="line"><span class="keywordflow">if</span> (<a class="code" href="group__libssh__misc.html#gaeda71ed34a62fa332762f25b14dac6eb" title="Check if libssh is the required version or get the version string.">ssh_version</a>(SSH_VERSION_INT(0,2,1)) == NULL) {</div> <div class="line"> fprintf(stderr, <span class="stringliteral">"libssh version is too old!\n"</span>);</div> <div class="line"> exit(1);</div> <div class="line">}</div> <div class="line"></div> <div class="line"><span class="keywordflow">if</span> (debug) {</div> <div class="line"> printf(<span class="stringliteral">"libssh %s\n"</span>, <a class="code" href="group__libssh__misc.html#gaeda71ed34a62fa332762f25b14dac6eb" title="Check if libssh is the required version or get the version string.">ssh_version</a>(0));</div> <div class="line">}</div> </div><!-- fragment --> </div> </div> </div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.3.1 </small></address> </body> </html>