X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cde%2Fprograms%2Fdtlogin%2Fgenauth.c;h=ae2ed2196404f70d441bd83c366ce62aaeae5bac;hb=89e76b2e9bfe4375ecbedf8464906f08b4493b56;hp=6fc12fd512417f9832fc4a4b90e363ed1f2b8097;hpb=83b6996daa2c5ae22fc2b69093814cb08314954a;p=oweals%2Fcde.git diff --git a/cde/programs/dtlogin/genauth.c b/cde/programs/dtlogin/genauth.c index 6fc12fd5..ae2ed219 100644 --- a/cde/programs/dtlogin/genauth.c +++ b/cde/programs/dtlogin/genauth.c @@ -1,3 +1,25 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these librararies and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ /* $TOG: genauth.c /main/6 1997/03/25 12:33:13 barstow $ */ /* (c) Copyright 1997, The Open Group */ /* * @@ -201,6 +223,52 @@ char bytes[64]; # define FILE_LIMIT 1024 /* no more than this many buffers */ +/* for linux/csrg we use a simpler method to get 2 random longs from + * the OS's random number device. + */ + +#if defined(linux) || defined(CSRG_BASED) +#define READ_LIMIT (sizeof (long) * 2) + +static sumFile (char *name, long sum[2]) +{ + long buf[2]; + int fd; + int ret_status = 0; + + if ( (fd = open (name, 0)) < 0 ) + { + LogError((unsigned char *) "Cannot open randomFile \"%s\", errno = %d\n", + name, errno); + return 0; + } + + sum[0] = 0; + sum[1] = 0; + + if (read(fd, (char *)buf, READ_LIMIT) != READ_LIMIT) + { + LogError((unsigned char *) "Could not read %d bytes from '%s'\n", + READ_LIMIT, name); + /* cheap fallback */ + sum[0] = (long)time((Time_t *) 0); + sum[1] = sum[0]; + } + else + { + sum[0] = buf[0]; + sum[1] = buf[1]; + ret_status = 1; + } + + close(fd); + return ret_status; +} + +#undef READ_LIMIT + +#else /* linux || CSRG_BASED */ + static sumFile (name, sum) char *name; @@ -238,7 +306,7 @@ long sum[2]; close (fd); return ret_status; } - +#endif /* linux || CSRG_BASED */ GenerateAuthData (auth, len) char *auth; @@ -373,8 +441,17 @@ static int cryptoInited = 0; int InitCryptoKey( void ) { +#if defined(linux) + /* non-blocking */ + char *key_file = "/dev/urandom"; +#elif defined(CSRG_BASED) + /* non-blocking */ + char *key_file = "/dev/random"; +#else +# warning "Using /dev/mem for random bits." + /* JET - this seems like a really bad idea. */ char *key_file = "/dev/mem"; - +#endif if (cryptoInited) return;