~ubuntu-branches/ubuntu/precise/libssh/precise

« back to all changes in this revision

Viewing changes to libssh/init.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-06-15 15:48:07 UTC
  • mfrom: (1.1.10 upstream) (4.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110615154807-3muklcqfftr1vtch
Tags: 0.5.0-2
* debian/patches/0002-Check-for-NULL-pointers-in-string-c.patch:
  Consolidate patch (Should fix previous REJECT)
* Support multiarch spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * init.c - initialization and finalization of the library
3
 
 *
4
 
 * This file is part of the SSH Library
5
 
 *
6
 
 * Copyright (c) 2003-2009 by Aris Adamantiadis
7
 
 *
8
 
 * The SSH Library is free software; you can redistribute it and/or modify
9
 
 * it under the terms of the GNU Lesser General Public License as published by
10
 
 * the Free Software Foundation; either version 2.1 of the License, or (at your
11
 
 * option) any later version.
12
 
 *
13
 
 * The SSH Library is distributed in the hope that it will be useful, but
14
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
 
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16
 
 * License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU Lesser General Public License
19
 
 * along with the SSH Library; see the file COPYING.  If not, write to
20
 
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21
 
 * MA 02111-1307, USA.
22
 
 */
23
 
 
24
 
#include "config.h"
25
 
#include "libssh/priv.h"
26
 
#include "libssh/socket.h"
27
 
#include "libssh/dh.h"
28
 
 
29
 
#ifdef _WIN32
30
 
#include <winsock2.h>
31
 
#endif
32
 
 
33
 
/**
34
 
 * \addtogroup ssh_session
35
 
 * @{
36
 
 */
37
 
 
38
 
/**
39
 
 * @brief initialize global cryptographic data structures.
40
 
 *
41
 
 * This function should only be called once, at the beginning of the program, in
42
 
 * the main thread. It may be omitted if your program is not multithreaded.
43
 
 *
44
 
 * @returns 0
45
 
 */
46
 
int ssh_init(void) {
47
 
  if(ssh_crypto_init())
48
 
    return -1;
49
 
  if(ssh_socket_init())
50
 
    return -1;
51
 
  if(ssh_regex_init())
52
 
    return -1;
53
 
  return 0;
54
 
}
55
 
 
56
 
 
57
 
/**
58
 
 * @brief Finalize and cleanup all libssh and cryptographic data structures.
59
 
 *
60
 
 * This function should only be called once, at the end of the program!
61
 
 *
62
 
 * @returns -1 in case of error
63
 
   @returns 0 otherwise
64
 
 */
65
 
int ssh_finalize(void) {
66
 
  ssh_regex_finalize();
67
 
  ssh_crypto_finalize();
68
 
  ssh_socket_cleanup();
69
 
#ifdef HAVE_LIBGCRYPT
70
 
  gcry_control(GCRYCTL_TERM_SECMEM);
71
 
#elif defined HAVE_LIBCRYPTO
72
 
  EVP_cleanup();
73
 
#endif
74
 
#ifdef _WIN32
75
 
  WSACleanup();
76
 
#endif
77
 
  return 0;
78
 
}
79
 
 
80
 
/**
81
 
 * @}
82
 
 */
83
 
/* vim: set ts=2 sw=2 et cindent: */