1 /* hostkeys.c --- Functions for managing hostkeys stored in files.
2 * Copyright (C) 2002, 2003, 2004, 2007 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, see http://www.gnu.org/licenses or write
18 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 * Floor, Boston, MA 02110-1301, USA
26 * shishi_hostkeys_default_file:
27 * @handle: Shishi library handle create by shishi_init().
29 * Get file name of default host key file.
31 * Return value: Returns the default host key filename used in the
32 * library. (Not a copy of it, so don't modify or deallocate it.)
35 shishi_hostkeys_default_file (Shishi
* handle
)
39 envfile
= getenv ("SHISHI_KEYS");
41 shishi_hostkeys_default_file_set (handle
, envfile
);
43 if (!handle
->hostkeysdefaultfile
)
44 handle
->hostkeysdefaultfile
= xstrdup (HOSTKEYSFILE
);
46 return handle
->hostkeysdefaultfile
;
50 * shishi_hostkeys_default_file_set:
51 * @handle: Shishi library handle create by shishi_init().
52 * @hostkeysfile: string with new default hostkeys file name, or
53 * NULL to reset to default.
55 * Set the default host key filename used in the library. The
56 * string is copied into the library, so you can dispose of the
57 * variable immediately after calling this function.
60 shishi_hostkeys_default_file_set (Shishi
* handle
, const char *hostkeysfile
)
62 if (handle
->hostkeysdefaultfile
)
63 free (handle
->hostkeysdefaultfile
);
65 handle
->hostkeysdefaultfile
= xstrdup (hostkeysfile
);
67 handle
->hostkeysdefaultfile
= NULL
;
71 * shishi_hostkeys_for_server
72 * @handle: Shishi library handle create by shishi_init().
73 * @server: server name to get key for
75 * Get host key for @server.
77 * Return value: Returns the key for specific server, read from the
78 * default host keys file (see shishi_hostkeys_default_file()), or
79 * NULL if no key could be found or an error encountered.
82 shishi_hostkeys_for_server (Shishi
* handle
, const char *server
)
84 return shishi_keys_for_server_in_file (handle
,
85 shishi_hostkeys_default_file
90 * shishi_hostkeys_for_serverrealm
91 * @handle: Shishi library handle create by shishi_init().
92 * @server: server name to get key for
93 * @realm: realm of server to get key for.
95 * Get host key for @server in @realm.
97 * Return value: Returns the key for specific server and realm, read
98 * from the default host keys file (see
99 * shishi_hostkeys_default_file()), or NULL if no key could be found
100 * or an error encountered.
103 shishi_hostkeys_for_serverrealm (Shishi
* handle
,
104 const char *server
, const char *realm
)
106 return shishi_keys_for_serverrealm_in_file
107 (handle
, shishi_hostkeys_default_file (handle
), server
, realm
);
111 * shishi_hostkeys_for_localservicerealm
112 * @handle: Shishi library handle create by shishi_init().
113 * @service: service to get key for.
114 * @realm: realm of server to get key for, or NULL for default realm.
116 * Get host key for @service on current host in @realm.
118 * Return value: Returns the key for the server
119 * "SERVICE/HOSTNAME@REALM" (where HOSTNAME is the current system's
120 * hostname), read from the default host keys file (see
121 * shishi_hostkeys_default_file()), or NULL if no key could be found
122 * or an error encountered.
125 shishi_hostkeys_for_localservicerealm (Shishi
* handle
,
126 const char *service
, const char *realm
)
128 return shishi_keys_for_localservicerealm_in_file
129 (handle
, shishi_hostkeys_default_file (handle
), service
, realm
);
133 * shishi_hostkeys_for_localservice
134 * @handle: Shishi library handle create by shishi_init().
135 * @service: service to get key for.
137 * Get host key for @service on current host in default realm.
139 * Return value: Returns the key for the server "SERVICE/HOSTNAME"
140 * (where HOSTNAME is the current system's hostname), read from the
141 * default host keys file (see shishi_hostkeys_default_file()), or
142 * NULL if no key could be found or an error encountered.
145 shishi_hostkeys_for_localservice (Shishi
* handle
, const char *service
)
147 return shishi_hostkeys_for_localservicerealm (handle
, service
, NULL
);