1 /* keys.c Functions for managing keys stored in files.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi 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
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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * shishi_keys_for_serverrealm_in_file
26 * @handle: Shishi library handle create by shishi_init().
27 * @filename: file to read keys from.
28 * @server: server name to get key for.
29 * @realm: realm of server to get key for.
31 * Return value: Returns the key for specific server and realm, read
32 * from the indicated file, or NULL if no key could be found or an
36 shishi_keys_for_serverrealm_in_file (Shishi
* handle
,
38 const char *server
, const char *realm
)
40 Shishi_key
*key
= NULL
;
44 fh
= fopen (filename
, "r");
51 res
= shishi_key_parse (handle
, fh
, &key
);
52 if (res
!= SHISHI_OK
|| key
== NULL
)
55 if (VERBOSENOICE (handle
))
57 printf ("Read key:\n");
58 shishi_key_print (handle
, stdout
, key
);
61 if (server
== NULL
&& realm
== NULL
)
65 shishi_key_principal (key
) &&
66 strcmp (server
, shishi_key_principal (key
)) == 0)
70 shishi_key_realm (key
) &&
71 strcmp (server
, shishi_key_principal (key
)) == 0)
74 shishi_key_done (key
);
85 * shishi_keys_for_server_in_file
86 * @handle: Shishi library handle create by shishi_init().
87 * @filename: file to read keys from.
88 * @server: server name to get key for.
90 * Return value: Returns the key for specific server, read from the
91 * indicated file, or NULL if no key could be found or an error
95 shishi_keys_for_server_in_file (Shishi
* handle
,
96 const char *filename
, const char *server
)
98 return shishi_keys_for_serverrealm_in_file (handle
, filename
, server
, NULL
);
102 * shishi_keys_for_localservice_in_file
103 * @handle: Shishi library handle create by shishi_init().
104 * @filename: file to read keys from.
105 * @service: service to get key for.
106 * @realm: realm of server to get key for, or NULL for default realm.
108 * Return value: Returns the key for the server
109 * "SERVICE/HOSTNAME@REALM" (where HOSTNAME is the current system's
110 * hostname), read from the default host keys file (see
111 * shishi_hostkeys_default_file()), or NULL if no key could be found
112 * or an error encountered.
115 shishi_keys_for_localservicerealm_in_file (Shishi
* handle
,
116 const char *filename
,
120 char server
[HOST_NAME_MAX
];
123 strcpy (server
, service
);
124 strcat (server
, "/");
126 ret
= gethostname (&server
[strlen (service
) + 1],
127 sizeof (server
) - strlen (service
) - 1);
128 server
[sizeof (server
) - 1] = '\0';
131 strcpy (&server
[strlen (service
) + 1], "localhost");
133 return shishi_keys_for_serverrealm_in_file (handle
, filename
, server
,