1 /* sysutils.c - system helpers
2 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG 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 * GnuPG 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 this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
30 #if defined(__linux__) && defined(__alpha__) && __GLIBC__ < 2
31 #include <asm/sysinfo.h>
32 #include <asm/unistd.h>
37 #include <sys/resource.h>
44 #if defined(__linux__) && defined(__alpha__) && __GLIBC__ < 2
45 #warning using trap_unaligned
47 setsysinfo(unsigned long op
, void *buffer
, unsigned long size
,
48 int *start
, void *arg
, unsigned long flag
)
50 return syscall(__NR_osf_setsysinfo
, op
, buffer
, size
, start
, arg
, flag
);
58 buf
[0] = SSIN_UACPROC
;
59 buf
[1] = UAC_SIGBUS
| UAC_NOPRINT
;
60 setsysinfo(SSI_NVPAIRS
, buf
, 1, 0, 0, 0);
71 disable_core_dumps (void)
73 #ifdef HAVE_DOSISH_SYSTEM
81 if( !setrlimit( RLIMIT_CORE
, &limit
) )
83 if( errno
!= EINVAL
&& errno
!= ENOSYS
)
84 log_fatal (_("can't disable core dumps: %s\n"), strerror(errno
) );
92 /* Return a string which is used as a kind of process ID */
94 get_session_marker( size_t *rlen
)
96 static byte marker
[SIZEOF_UNSIGNED_LONG
*2];
97 static int initialized
;
100 volatile ulong aa
, bb
; /* we really want the uninitialized value */
104 /* also this marker is guessable it is not easy to use this
105 * for a faked control packet because an attacker does not
106 * have enough control about the time the verification does
107 * take place. Of course, we can add just more random but
108 * than we need the random generator even for verification
109 * tasks - which does not make sense. */
110 a
= aa
^ (ulong
)getpid();
111 b
= bb
^ (ulong
)time(NULL
);
112 memcpy( marker
, &a
, SIZEOF_UNSIGNED_LONG
);
113 memcpy( marker
+SIZEOF_UNSIGNED_LONG
, &b
, SIZEOF_UNSIGNED_LONG
);
115 *rlen
= sizeof(marker
);
120 #if 0 /* not yet needed */
122 check_permissions(const char *path
,int extension
,int checkonly
)
124 #if defined(HAVE_STAT) && !defined(HAVE_DOSISH_SYSTEM)
133 if(extension
&& path
[0]!=DIRSEP_C
)
135 if(strchr(path
,DIRSEP_C
))
136 tmppath
=make_filename(path
,NULL
);
138 tmppath
=make_filename(GNUPG_LIBDIR
,path
,NULL
);
141 tmppath
=m_strdup(path
);
143 /* It's okay if the file doesn't exist */
144 if(stat(tmppath
,&statbuf
)!=0)
150 isdir
=S_ISDIR(statbuf
.st_mode
);
152 /* Per-user files must be owned by the user. Extensions must be
153 owned by the user or root. */
154 if((!extension
&& statbuf
.st_uid
!= getuid()) ||
155 (extension
&& statbuf
.st_uid
!=0 && statbuf
.st_uid
!=getuid()))
158 log_info(_("Warning: unsafe ownership on %s \"%s\"\n"),
159 isdir
?"directory":extension
?"extension":"file",path
);
163 /* This works for both directories and files - basically, we don't
164 care what the owner permissions are, so long as the group and
165 other permissions are 0 for per-user files, and non-writable for
167 if((extension
&& (statbuf
.st_mode
& (S_IWGRP
|S_IWOTH
)) !=0) ||
168 (!extension
&& (statbuf
.st_mode
& (S_IRWXG
|S_IRWXO
)) != 0))
172 /* However, if the directory the directory/file is in is owned
173 by the user and is 700, then this is not a problem.
174 Theoretically, we could walk this test up to the root
175 directory /, but for the sake of sanity, I'm stopping at one
178 dir
= make_dirname (tmppath
);
179 if(stat(dir
,&statbuf
)==0 && statbuf
.st_uid
==getuid() &&
180 S_ISDIR(statbuf
.st_mode
) && (statbuf
.st_mode
& (S_IRWXG
|S_IRWXO
))==0)
190 log_info(_("Warning: unsafe permissions on %s \"%s\"\n"),
191 isdir
?"directory":extension
?"extension":"file",path
);
202 #endif /* HAVE_STAT && !HAVE_DOSISH_SYSTEM */