SshClient.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. #nullable enable
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics.CodeAnalysis;
  5. using System.IO;
  6. using System.Net;
  7. using System.Text;
  8. using Renci.SshNet.Common;
  9. namespace Renci.SshNet
  10. {
  11. /// <summary>
  12. /// Provides client connection to SSH server.
  13. /// </summary>
  14. public class SshClient : BaseClient
  15. {
  16. /// <summary>
  17. /// Holds the list of forwarded ports.
  18. /// </summary>
  19. private readonly List<ForwardedPort> _forwardedPorts;
  20. /// <summary>
  21. /// Holds a value indicating whether the current instance is disposed.
  22. /// </summary>
  23. /// <value>
  24. /// <see langword="true"/> if the current instance is disposed; otherwise, <see langword="false"/>.
  25. /// </value>
  26. private bool _isDisposed;
  27. private MemoryStream? _inputStream;
  28. /// <summary>
  29. /// Gets the list of forwarded ports.
  30. /// </summary>
  31. public IEnumerable<ForwardedPort> ForwardedPorts
  32. {
  33. get
  34. {
  35. return _forwardedPorts.AsReadOnly();
  36. }
  37. }
  38. /// <summary>
  39. /// Initializes a new instance of the <see cref="SshClient" /> class.
  40. /// </summary>
  41. /// <param name="connectionInfo">The connection info.</param>
  42. /// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is <see langword="null"/>.</exception>
  43. public SshClient(ConnectionInfo connectionInfo)
  44. : this(connectionInfo, ownsConnectionInfo: false)
  45. {
  46. }
  47. /// <summary>
  48. /// Initializes a new instance of the <see cref="SshClient"/> class.
  49. /// </summary>
  50. /// <param name="host">Connection host.</param>
  51. /// <param name="port">Connection port.</param>
  52. /// <param name="username">Authentication username.</param>
  53. /// <param name="password">Authentication password.</param>
  54. /// <exception cref="ArgumentNullException"><paramref name="password"/> is <see langword="null"/>.</exception>
  55. /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
  56. /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
  57. public SshClient(string host, int port, string username, string password)
  58. #pragma warning disable CA2000 // Dispose objects before losing scope
  59. : this(new PasswordConnectionInfo(host, port, username, password), ownsConnectionInfo: true)
  60. #pragma warning restore CA2000 // Dispose objects before losing scope
  61. {
  62. }
  63. /// <summary>
  64. /// Initializes a new instance of the <see cref="SshClient"/> class.
  65. /// </summary>
  66. /// <param name="host">Connection host.</param>
  67. /// <param name="username">Authentication username.</param>
  68. /// <param name="password">Authentication password.</param>
  69. /// <exception cref="ArgumentNullException"><paramref name="password"/> is <see langword="null"/>.</exception>
  70. /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, or <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
  71. public SshClient(string host, string username, string password)
  72. : this(host, ConnectionInfo.DefaultPort, username, password)
  73. {
  74. }
  75. /// <summary>
  76. /// Initializes a new instance of the <see cref="SshClient"/> class.
  77. /// </summary>
  78. /// <param name="host">Connection host.</param>
  79. /// <param name="port">Connection port.</param>
  80. /// <param name="username">Authentication username.</param>
  81. /// <param name="keyFiles">Authentication private key file(s) .</param>
  82. /// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <see langword="null"/>.</exception>
  83. /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
  84. /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception>
  85. [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
  86. public SshClient(string host, int port, string username, params IPrivateKeySource[] keyFiles)
  87. : this(new PrivateKeyConnectionInfo(host, port, username, keyFiles), ownsConnectionInfo: true)
  88. {
  89. }
  90. /// <summary>
  91. /// Initializes a new instance of the <see cref="SshClient"/> class.
  92. /// </summary>
  93. /// <param name="host">Connection host.</param>
  94. /// <param name="username">Authentication username.</param>
  95. /// <param name="keyFiles">Authentication private key file(s) .</param>
  96. /// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <see langword="null"/>.</exception>
  97. /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <see langword="null"/> or contains only whitespace characters.</exception>
  98. public SshClient(string host, string username, params IPrivateKeySource[] keyFiles)
  99. : this(host, ConnectionInfo.DefaultPort, username, keyFiles)
  100. {
  101. }
  102. /// <summary>
  103. /// Initializes a new instance of the <see cref="SshClient"/> class.
  104. /// </summary>
  105. /// <param name="connectionInfo">The connection info.</param>
  106. /// <param name="ownsConnectionInfo">Specified whether this instance owns the connection info.</param>
  107. /// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is <see langword="null"/>.</exception>
  108. /// <remarks>
  109. /// If <paramref name="ownsConnectionInfo"/> is <see langword="true"/>, then the
  110. /// connection info will be disposed when this instance is disposed.
  111. /// </remarks>
  112. private SshClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo)
  113. : this(connectionInfo, ownsConnectionInfo, new ServiceFactory())
  114. {
  115. }
  116. /// <summary>
  117. /// Initializes a new instance of the <see cref="SshClient"/> class.
  118. /// </summary>
  119. /// <param name="connectionInfo">The connection info.</param>
  120. /// <param name="ownsConnectionInfo">Specified whether this instance owns the connection info.</param>
  121. /// <param name="serviceFactory">The factory to use for creating new services.</param>
  122. /// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is <see langword="null"/>.</exception>
  123. /// <exception cref="ArgumentNullException"><paramref name="serviceFactory"/> is <see langword="null"/>.</exception>
  124. /// <remarks>
  125. /// If <paramref name="ownsConnectionInfo"/> is <see langword="true"/>, then the
  126. /// connection info will be disposed when this instance is disposed.
  127. /// </remarks>
  128. internal SshClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, IServiceFactory serviceFactory)
  129. : base(connectionInfo, ownsConnectionInfo, serviceFactory)
  130. {
  131. _forwardedPorts = new List<ForwardedPort>();
  132. }
  133. /// <summary>
  134. /// Called when client is disconnecting from the server.
  135. /// </summary>
  136. protected override void OnDisconnecting()
  137. {
  138. base.OnDisconnecting();
  139. foreach (var port in _forwardedPorts)
  140. {
  141. port.Stop();
  142. }
  143. }
  144. /// <summary>
  145. /// Adds the forwarded port.
  146. /// </summary>
  147. /// <param name="port">The port.</param>
  148. /// <exception cref="InvalidOperationException">Forwarded port is already added to a different client.</exception>
  149. /// <exception cref="ArgumentNullException"><paramref name="port"/> is <see langword="null"/>.</exception>
  150. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  151. public void AddForwardedPort(ForwardedPort port)
  152. {
  153. ThrowHelper.ThrowIfNull(port);
  154. EnsureSessionIsOpen();
  155. AttachForwardedPort(port);
  156. _forwardedPorts.Add(port);
  157. }
  158. /// <summary>
  159. /// Stops and removes the forwarded port from the list.
  160. /// </summary>
  161. /// <param name="port">Forwarded port.</param>
  162. /// <exception cref="ArgumentNullException"><paramref name="port"/> is <see langword="null"/>.</exception>
  163. public void RemoveForwardedPort(ForwardedPort port)
  164. {
  165. ThrowHelper.ThrowIfNull(port);
  166. // Stop port forwarding before removing it
  167. port.Stop();
  168. DetachForwardedPort(port);
  169. _ = _forwardedPorts.Remove(port);
  170. }
  171. private void AttachForwardedPort(ForwardedPort port)
  172. {
  173. if (port.Session != null && port.Session != Session)
  174. {
  175. throw new InvalidOperationException("Forwarded port is already added to a different client.");
  176. }
  177. port.Session = Session;
  178. }
  179. private static void DetachForwardedPort(ForwardedPort port)
  180. {
  181. port.Session = null;
  182. }
  183. /// <summary>
  184. /// Creates the command to be executed.
  185. /// </summary>
  186. /// <param name="commandText">The command text.</param>
  187. /// <returns><see cref="SshCommand"/> object.</returns>
  188. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  189. public SshCommand CreateCommand(string commandText)
  190. {
  191. return CreateCommand(commandText, ConnectionInfo.Encoding);
  192. }
  193. /// <summary>
  194. /// Creates the command to be executed with specified encoding.
  195. /// </summary>
  196. /// <param name="commandText">The command text.</param>
  197. /// <param name="encoding">The encoding to use for results.</param>
  198. /// <returns><see cref="SshCommand"/> object which uses specified encoding.</returns>
  199. /// <remarks>This method will change current default encoding.</remarks>
  200. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  201. /// <exception cref="ArgumentNullException"><paramref name="commandText"/> or <paramref name="encoding"/> is <see langword="null"/>.</exception>
  202. public SshCommand CreateCommand(string commandText, Encoding encoding)
  203. {
  204. EnsureSessionIsOpen();
  205. ConnectionInfo.Encoding = encoding;
  206. return new SshCommand(Session!, commandText, encoding);
  207. }
  208. /// <summary>
  209. /// Creates and executes the command.
  210. /// </summary>
  211. /// <param name="commandText">The command text.</param>
  212. /// <returns>Returns an instance of <see cref="SshCommand"/> with execution results.</returns>
  213. /// <remarks>This method internally uses asynchronous calls.</remarks>
  214. /// <exception cref="ArgumentException">CommandText property is empty.</exception>
  215. /// <exception cref="SshException">Invalid Operation - An existing channel was used to execute this command.</exception>
  216. /// <exception cref="InvalidOperationException">Asynchronous operation is already in progress.</exception>
  217. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  218. /// <exception cref="ArgumentNullException"><paramref name="commandText"/> is <see langword="null"/>.</exception>
  219. public SshCommand RunCommand(string commandText)
  220. {
  221. var cmd = CreateCommand(commandText);
  222. _ = cmd.Execute();
  223. return cmd;
  224. }
  225. /// <summary>
  226. /// Creates the shell.
  227. /// </summary>
  228. /// <param name="input">The input.</param>
  229. /// <param name="output">The output.</param>
  230. /// <param name="extendedOutput">The extended output.</param>
  231. /// <param name="terminalName">Name of the terminal.</param>
  232. /// <param name="columns">The columns.</param>
  233. /// <param name="rows">The rows.</param>
  234. /// <param name="width">The width.</param>
  235. /// <param name="height">The height.</param>
  236. /// <param name="terminalModes">The terminal mode.</param>
  237. /// <param name="bufferSize">Size of the internal read buffer.</param>
  238. /// <returns>
  239. /// Returns a representation of a <see cref="Shell" /> object.
  240. /// </returns>
  241. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  242. public Shell CreateShell(Stream input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint>? terminalModes, int bufferSize)
  243. {
  244. EnsureSessionIsOpen();
  245. return new Shell(Session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize);
  246. }
  247. /// <summary>
  248. /// Creates the shell.
  249. /// </summary>
  250. /// <param name="input">The input.</param>
  251. /// <param name="output">The output.</param>
  252. /// <param name="extendedOutput">The extended output.</param>
  253. /// <param name="terminalName">Name of the terminal.</param>
  254. /// <param name="columns">The columns.</param>
  255. /// <param name="rows">The rows.</param>
  256. /// <param name="width">The width.</param>
  257. /// <param name="height">The height.</param>
  258. /// <param name="terminalModes">The terminal mode.</param>
  259. /// <returns>
  260. /// Returns a representation of a <see cref="Shell" /> object.
  261. /// </returns>
  262. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  263. public Shell CreateShell(Stream input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint> terminalModes)
  264. {
  265. return CreateShell(input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, 1024);
  266. }
  267. /// <summary>
  268. /// Creates the shell.
  269. /// </summary>
  270. /// <param name="input">The input.</param>
  271. /// <param name="output">The output.</param>
  272. /// <param name="extendedOutput">The extended output.</param>
  273. /// <returns>
  274. /// Returns a representation of a <see cref="Shell" /> object.
  275. /// </returns>
  276. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  277. public Shell CreateShell(Stream input, Stream output, Stream extendedOutput)
  278. {
  279. return CreateShell(input, output, extendedOutput, string.Empty, 0, 0, 0, 0, terminalModes: null, 1024);
  280. }
  281. /// <summary>
  282. /// Creates the shell.
  283. /// </summary>
  284. /// <param name="encoding">The encoding to use to send the input.</param>
  285. /// <param name="input">The input.</param>
  286. /// <param name="output">The output.</param>
  287. /// <param name="extendedOutput">The extended output.</param>
  288. /// <param name="terminalName">Name of the terminal.</param>
  289. /// <param name="columns">The columns.</param>
  290. /// <param name="rows">The rows.</param>
  291. /// <param name="width">The width.</param>
  292. /// <param name="height">The height.</param>
  293. /// <param name="terminalModes">The terminal mode.</param>
  294. /// <param name="bufferSize">Size of the internal read buffer.</param>
  295. /// <returns>
  296. /// Returns a representation of a <see cref="Shell" /> object.
  297. /// </returns>
  298. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  299. public Shell CreateShell(Encoding encoding, string input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint>? terminalModes, int bufferSize)
  300. {
  301. /*
  302. * TODO Issue #1224: let shell dispose of input stream when we own the stream!
  303. */
  304. _inputStream = new MemoryStream();
  305. using (var writer = new StreamWriter(_inputStream, encoding, bufferSize: 1024, leaveOpen: true))
  306. {
  307. writer.Write(input);
  308. writer.Flush();
  309. }
  310. _ = _inputStream.Seek(0, SeekOrigin.Begin);
  311. return CreateShell(_inputStream, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize);
  312. }
  313. /// <summary>
  314. /// Creates the shell.
  315. /// </summary>
  316. /// <param name="encoding">The encoding.</param>
  317. /// <param name="input">The input.</param>
  318. /// <param name="output">The output.</param>
  319. /// <param name="extendedOutput">The extended output.</param>
  320. /// <param name="terminalName">Name of the terminal.</param>
  321. /// <param name="columns">The columns.</param>
  322. /// <param name="rows">The rows.</param>
  323. /// <param name="width">The width.</param>
  324. /// <param name="height">The height.</param>
  325. /// <param name="terminalModes">The terminal modes.</param>
  326. /// <returns>
  327. /// Returns a representation of a <see cref="Shell" /> object.
  328. /// </returns>
  329. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  330. public Shell CreateShell(Encoding encoding, string input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint> terminalModes)
  331. {
  332. return CreateShell(encoding, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, 1024);
  333. }
  334. /// <summary>
  335. /// Creates the shell.
  336. /// </summary>
  337. /// <param name="encoding">The encoding.</param>
  338. /// <param name="input">The input.</param>
  339. /// <param name="output">The output.</param>
  340. /// <param name="extendedOutput">The extended output.</param>
  341. /// <returns>
  342. /// Returns a representation of a <see cref="Shell" /> object.
  343. /// </returns>
  344. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  345. public Shell CreateShell(Encoding encoding, string input, Stream output, Stream extendedOutput)
  346. {
  347. return CreateShell(encoding, input, output, extendedOutput, string.Empty, 0, 0, 0, 0, terminalModes: null, 1024);
  348. }
  349. /// <summary>
  350. /// Creates the shell without allocating a pseudo terminal,
  351. /// similar to the <c>ssh -T</c> option.
  352. /// </summary>
  353. /// <param name="input">The input.</param>
  354. /// <param name="output">The output.</param>
  355. /// <param name="extendedOutput">The extended output.</param>
  356. /// <param name="bufferSize">Size of the internal read buffer.</param>
  357. /// <returns>
  358. /// Returns a representation of a <see cref="Shell" /> object.
  359. /// </returns>
  360. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  361. public Shell CreateShellNoTerminal(Stream input, Stream output, Stream extendedOutput, int bufferSize = -1)
  362. {
  363. EnsureSessionIsOpen();
  364. return new Shell(Session, input, output, extendedOutput, bufferSize);
  365. }
  366. /// <summary>
  367. /// Creates the shell stream.
  368. /// </summary>
  369. /// <param name="terminalName">The <c>TERM</c> environment variable.</param>
  370. /// <param name="columns">The terminal width in columns.</param>
  371. /// <param name="rows">The terminal width in rows.</param>
  372. /// <param name="width">The terminal width in pixels.</param>
  373. /// <param name="height">The terminal height in pixels.</param>
  374. /// <param name="bufferSize">The size of the buffer.</param>
  375. /// <returns>
  376. /// The created <see cref="ShellStream"/> instance.
  377. /// </returns>
  378. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  379. /// <remarks>
  380. /// <para>
  381. /// The <c>TERM</c> environment variable contains an identifier for the text window's capabilities.
  382. /// You can get a detailed list of these capabilities by using the ‘infocmp’ command.
  383. /// </para>
  384. /// <para>
  385. /// The column/row dimensions override the pixel dimensions(when nonzero). Pixel dimensions refer
  386. /// to the drawable area of the window.
  387. /// </para>
  388. /// </remarks>
  389. public ShellStream CreateShellStream(string terminalName, uint columns, uint rows, uint width, uint height, int bufferSize)
  390. {
  391. return CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModeValues: null);
  392. }
  393. /// <summary>
  394. /// Creates the shell stream.
  395. /// </summary>
  396. /// <param name="terminalName">The <c>TERM</c> environment variable.</param>
  397. /// <param name="columns">The terminal width in columns.</param>
  398. /// <param name="rows">The terminal width in rows.</param>
  399. /// <param name="width">The terminal width in pixels.</param>
  400. /// <param name="height">The terminal height in pixels.</param>
  401. /// <param name="bufferSize">The size of the buffer.</param>
  402. /// <param name="terminalModeValues">The terminal mode values.</param>
  403. /// <returns>
  404. /// The created <see cref="ShellStream"/> instance.
  405. /// </returns>
  406. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  407. /// <remarks>
  408. /// <para>
  409. /// The <c>TERM</c> environment variable contains an identifier for the text window's capabilities.
  410. /// You can get a detailed list of these capabilities by using the ‘infocmp’ command.
  411. /// </para>
  412. /// <para>
  413. /// The column/row dimensions override the pixel dimensions(when non-zero). Pixel dimensions refer
  414. /// to the drawable area of the window.
  415. /// </para>
  416. /// </remarks>
  417. public ShellStream CreateShellStream(string terminalName, uint columns, uint rows, uint width, uint height, int bufferSize, IDictionary<TerminalModes, uint>? terminalModeValues)
  418. {
  419. EnsureSessionIsOpen();
  420. return ServiceFactory.CreateShellStream(Session, terminalName, columns, rows, width, height, terminalModeValues, bufferSize);
  421. }
  422. /// <summary>
  423. /// Creates the shell stream without allocating a pseudo terminal,
  424. /// similar to the <c>ssh -T</c> option.
  425. /// </summary>
  426. /// <param name="bufferSize">The size of the buffer.</param>
  427. /// <returns>
  428. /// The created <see cref="ShellStream"/> instance.
  429. /// </returns>
  430. /// <exception cref="SshConnectionException">Client is not connected.</exception>
  431. public ShellStream CreateShellStreamNoTerminal(int bufferSize = -1)
  432. {
  433. EnsureSessionIsOpen();
  434. return ServiceFactory.CreateShellStreamNoTerminal(Session, bufferSize);
  435. }
  436. /// <summary>
  437. /// Stops forwarded ports.
  438. /// </summary>
  439. protected override void OnDisconnected()
  440. {
  441. base.OnDisconnected();
  442. for (var i = _forwardedPorts.Count - 1; i >= 0; i--)
  443. {
  444. var port = _forwardedPorts[i];
  445. DetachForwardedPort(port);
  446. _forwardedPorts.RemoveAt(i);
  447. }
  448. }
  449. /// <summary>
  450. /// Releases unmanaged and - optionally - managed resources.
  451. /// </summary>
  452. /// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
  453. protected override void Dispose(bool disposing)
  454. {
  455. base.Dispose(disposing);
  456. if (_isDisposed)
  457. {
  458. return;
  459. }
  460. if (disposing)
  461. {
  462. if (_inputStream != null)
  463. {
  464. _inputStream.Dispose();
  465. _inputStream = null;
  466. }
  467. _isDisposed = true;
  468. }
  469. }
  470. private void EnsureSessionIsOpen()
  471. {
  472. if (Session is null)
  473. {
  474. throw new SshConnectionException("Client not connected.");
  475. }
  476. }
  477. }
  478. }