diff options
Diffstat (limited to 'auth.c')
-rw-r--r-- | auth.c | 77 |
1 files changed, 50 insertions, 27 deletions
@@ -23,10 +23,18 @@ Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. ******************************************************************************/ +/* $XFree86: xc/programs/xsm/auth.c,v 1.7 2001/12/14 20:02:23 dawes Exp $ */ #include "xsm.h" #include <X11/ICE/ICEutil.h> +#include "auth.h" + +#ifdef HAS_MKSTEMP +#include <unistd.h> +#endif +#include <sys/types.h> +#include <sys/stat.h> static char *addAuthFile = NULL; static char *remAuthFile = NULL; @@ -40,10 +48,7 @@ static char *remAuthFile = NULL; */ Bool -HostBasedAuthProc (hostname) - -char *hostname; - +HostBasedAuthProc(char *hostname) { return (0); /* For now, we don't support host based authentication */ } @@ -56,12 +61,7 @@ char *hostname; */ static void -write_iceauth (addfp, removefp, entry) - -FILE *addfp; -FILE *removefp; -IceAuthDataEntry *entry; - +write_iceauth(FILE *addfp, FILE *removefp, IceAuthDataEntry *entry) { fprintf (addfp, "add %s \"\" %s %s ", @@ -80,13 +80,15 @@ IceAuthDataEntry *entry; +#ifndef HAS_MKSTEMP static char * -unique_filename (path, prefix) - -char *path; -char *prefix; - +unique_filename(char *path, char *prefix) +#else +static char * +unique_filename(char *path, char *prefix, int *pFd) +#endif { +#ifndef HAS_MKSTEMP #ifndef X_NOT_POSIX return ((char *) tempnam (path, prefix)); #else @@ -104,6 +106,19 @@ char *prefix; else return (NULL); #endif +#else + char tempFile[PATH_MAX]; + char *ptr; + + sprintf (tempFile, "%s/%sXXXXXX", path, prefix); + ptr = (char *)malloc(strlen(tempFile) + 1); + if (ptr != NULL) + { + strcpy(ptr, tempFile); + *pFd = mkstemp(ptr); + } + return ptr; +#endif } @@ -116,12 +131,8 @@ char *prefix; #define MAGIC_COOKIE_LEN 16 Status -SetAuthentication (count, listenObjs, authDataEntries) - -int count; -IceListenObj *listenObjs; -IceAuthDataEntry **authDataEntries; - +SetAuthentication(int count, IceListenObj *listenObjs, + IceAuthDataEntry **authDataEntries) { FILE *addfp = NULL; FILE *removefp = NULL; @@ -129,6 +140,9 @@ IceAuthDataEntry **authDataEntries; int original_umask; char command[256]; int i; +#ifdef HAS_MKSTEMP + int fd; +#endif original_umask = umask (0077); /* disallow non-owner access */ @@ -139,7 +153,7 @@ IceAuthDataEntry **authDataEntries; if (!path) path = "."; } - +#ifndef HAS_MKSTEMP if ((addAuthFile = unique_filename (path, ".xsm")) == NULL) goto bad; @@ -151,6 +165,19 @@ IceAuthDataEntry **authDataEntries; if (!(removefp = fopen (remAuthFile, "w"))) goto bad; +#else + if ((addAuthFile = unique_filename (path, ".xsm", &fd)) == NULL) + goto bad; + + if (!(addfp = fdopen(fd, "wb"))) + goto bad; + + if ((remAuthFile = unique_filename (path, ".xsm", &fd)) == NULL) + goto bad; + + if (!(removefp = fdopen(fd, "wb"))) + goto bad; +#endif if ((*authDataEntries = (IceAuthDataEntry *) XtMalloc ( count * 2 * sizeof (IceAuthDataEntry))) == NULL) @@ -225,11 +252,7 @@ IceAuthDataEntry **authDataEntries; */ void -FreeAuthenticationData (count, authDataEntries) - -int count; -IceAuthDataEntry *authDataEntries; - +FreeAuthenticationData(int count, IceAuthDataEntry *authDataEntries) { /* Each transport has entries for ICE and XSMP */ |