* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-keysign.c,v 1.10 2003/03/13 11:42:19 markus Exp $");
+RCSID("$OpenBSD: ssh-keysign.c,v 1.18 2004/08/23 14:29:23 dtucker Exp $");
#include <openssl/evp.h>
#include <openssl/rand.h>
#include "canohost.h"
#include "pathnames.h"
#include "readconf.h"
+#include "uidswap.h"
-uid_t original_real_uid; /* XXX readconf.c needs this */
+/* XXX readconf.c needs these */
+uid_t original_real_uid;
-#ifdef HAVE___PROGNAME
extern char *__progname;
-#else
-char *__progname;
-#endif
static int
valid_request(struct passwd *pw, char *host, Key **ret, u_char *data,
u_int datalen)
{
Buffer b;
- Key *key;
+ Key *key = NULL;
u_char *pkblob;
u_int blen, len;
char *pkalg, *p;
/* end of message */
if (buffer_len(&b) != 0)
fail++;
+ buffer_free(&b);
debug3("valid_request: fail %d", fail);
key_fd[0] = open(_PATH_HOST_RSA_KEY_FILE, O_RDONLY);
key_fd[1] = open(_PATH_HOST_DSA_KEY_FILE, O_RDONLY);
- seteuid(getuid());
- setuid(getuid());
+ original_real_uid = getuid(); /* XXX readconf.c needs this */
+ if ((pw = getpwuid(original_real_uid)) == NULL)
+ fatal("getpwuid failed");
+ pw = pwcopy(pw);
+
+ permanently_set_uid(pw);
init_rng();
seed_rng();
#endif
/* verify that ssh-keysign is enabled by the admin */
- original_real_uid = getuid(); /* XXX readconf.c needs this */
initialize_options(&options);
- (void)read_config_file(_PATH_HOST_CONFIG_FILE, "", &options);
+ (void)read_config_file(_PATH_HOST_CONFIG_FILE, "", &options, 0);
fill_default_options(&options);
if (options.enable_ssh_keysign != 1)
fatal("ssh-keysign not enabled in %s",
if (key_fd[0] == -1 && key_fd[1] == -1)
fatal("could not open any host key");
- if ((pw = getpwuid(getuid())) == NULL)
- fatal("getpwuid failed");
- pw = pwcopy(pw);
-
SSLeay_add_all_algorithms();
for (i = 0; i < 256; i++)
rnd[i] = arc4random();
/* send reply */
buffer_clear(&b);
buffer_put_string(&b, signature, slen);
- ssh_msg_send(STDOUT_FILENO, version, &b);
+ if (ssh_msg_send(STDOUT_FILENO, version, &b) == -1)
+ fatal("ssh_msg_send failed");
return (0);
}