]> andersk Git - openssh.git/blame - openbsd-compat/bsd-misc.c
- (djm) Fix return value checks for RAND_bytes. Report from
[openssh.git] / openbsd-compat / bsd-misc.c
CommitLineData
8efc0c15 1/*
bfc9a610 2 * Copyright (c) 1999-2000 Damien Miller. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
bfc9a610 12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
8efc0c15 24
416ed5a7 25#include "includes.h"
d0104542 26#include "xmalloc.h"
8efc0c15 27
0b202697 28RCSID("$Id$");
29
d0104542 30/*
31 * NB. duplicate __progname in case it is an alias for argv[0]
32 * Otherwise it may get clobbered by setproctitle()
33 */
260d427b 34char *get_progname(char *argv0)
35{
36#ifdef HAVE___PROGNAME
37 extern char *__progname;
38
d0104542 39 return xstrdup(__progname);
260d427b 40#else
41 char *p;
42
43 if (argv0 == NULL)
44 return "unknown"; /* XXX */
45 p = strrchr(argv0, '/');
46 if (p == NULL)
47 p = argv0;
48 else
49 p++;
d0104542 50
51 return xstrdup(p);
260d427b 52#endif
53}
54
a5c9cd31 55#ifndef HAVE_SETLOGIN
56int setlogin(const char *name)
57{
58 return(0);
59}
60#endif /* !HAVE_SETLOGIN */
61
62#ifndef HAVE_INNETGR
63int innetgr(const char *netgroup, const char *host,
64 const char *user, const char *domain)
65{
66 return(0);
67}
68#endif /* HAVE_INNETGR */
69
70#if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
71int seteuid(uid_t euid)
72{
73 return(setreuid(-1,euid));
74}
75#endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
819b676f 76
febd3f8e 77#if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID)
78int setegid(uid_t egid)
79{
80 return(setresgid(-1,egid,-1));
81}
82#endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
83
416ed5a7 84#if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR)
85const char *strerror(int e)
819b676f 86{
416ed5a7 87 extern int sys_nerr;
88 extern char *sys_errlist[];
89
e2bccbcd 90 if ((e >= 0) && (e < sys_nerr))
416ed5a7 91 return(sys_errlist[e]);
e2bccbcd 92 else
93 return("unlisted error");
819b676f 94}
416ed5a7 95#endif
89c7e31c 96
97#ifndef HAVE_UTIMES
98int utimes(char *filename, struct timeval *tvp)
99{
100 struct utimbuf ub;
101
6c266dc3 102 ub.actime = tvp[0].tv_sec;
103 ub.modtime = tvp[1].tv_sec;
89c7e31c 104
105 return(utime(filename, &ub));
106}
107#endif
f25cd32c 108
109#ifndef HAVE_TRUNCATE
110int truncate (const char *path, off_t length)
111{
112 int fd, ret, saverrno;
113
114 fd = open(path, O_WRONLY);
115 if (fd < 0)
116 return -1;
117
118 ret = ftruncate(fd, length);
119 saverrno = errno;
120 (void) close (fd);
121 if (ret == -1)
122 errno = saverrno;
123 return(ret);
124}
125#endif /* HAVE_TRUNCATE */
126
246446cd 127#if !defined(HAVE_SETGROUPS) && defined(SETGROUPS_NOOP)
128/*
129 * Cygwin setgroups should be a noop.
130 */
131int
f2d02e44 132setgroups(size_t size, const gid_t *list)
246446cd 133{
134 return 0;
135}
136#endif
137
This page took 0.479902 seconds and 5 git commands to generate.