authutil.c | authutil.c | |||
---|---|---|---|---|
skipping to change at line 37 | skipping to change at line 37 | |||
#ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H | |||
#include <config.h> | #include <config.h> | |||
#endif | #endif | |||
#include <X11/ICE/ICElib.h> | #include <X11/ICE/ICElib.h> | |||
#include "ICElibint.h" | #include "ICElibint.h" | |||
#include <X11/ICE/ICEutil.h> | #include <X11/ICE/ICEutil.h> | |||
#include <X11/Xos.h> | #include <X11/Xos.h> | |||
#include <sys/stat.h> | #include <sys/stat.h> | |||
#include <errno.h> | #include <errno.h> | |||
#include <limits.h> | ||||
#include <time.h> | #include <time.h> | |||
#define Time_t time_t | #define Time_t time_t | |||
#ifdef __UNIXOS2__ | ||||
extern char* getenv(const char*); | ||||
#define link rename | ||||
#endif | ||||
#ifndef X_NOT_POSIX | #ifndef X_NOT_POSIX | |||
#include <unistd.h> | #include <unistd.h> | |||
#else | #else | |||
#ifndef WIN32 | #ifndef WIN32 | |||
extern unsigned sleep (); | extern unsigned sleep (); | |||
#else | #else | |||
#define link rename | #define link rename | |||
#endif | #endif | |||
#endif | #endif | |||
static Status read_short (FILE *file, unsigned short *shortp); | static Status read_short (FILE *file, unsigned short *shortp); | |||
static Status read_string (FILE *file, char **stringp); | static Status read_string (FILE *file, char **stringp); | |||
static Status read_counted_string (FILE *file, unsigned short *countp, char **stringp); | static Status read_counted_string (FILE *file, unsigned short *countp, char **stringp); | |||
static Status write_short (FILE *file, unsigned short s); | static Status write_short (FILE *file, unsigned short s); | |||
static Status write_string (FILE *file, char *string); | static Status write_string (FILE *file, const char *string); | |||
static Status write_counted_string (FILE *file, unsigned short count, char | static Status write_counted_string (FILE *file, unsigned short count, const | |||
*string); | char *string); | |||
/* | /* | |||
* The following routines are for manipulating the .ICEauthority file | * The following routines are for manipulating the .ICEauthority file | |||
* These are utility functions - they are not part of the standard | * These are utility functions - they are not part of the standard | |||
* ICE library specification. | * ICE library specification. | |||
*/ | */ | |||
char * | char * | |||
IceAuthFileName (void) | IceAuthFileName (void) | |||
{ | { | |||
static char slashDotICEauthority[] = "/.ICEauthority"; | static char slashDotICEauthority[] = "/.ICEauthority"; | |||
char *name; | char *name; | |||
static char *buf; | static char *buf; | |||
static int bsize; | static size_t bsize; | |||
int size; | size_t size; | |||
#if defined(WIN32) || defined(__UNIXOS2__) | #ifdef WIN32 | |||
#ifndef PATH_MAX | #ifndef PATH_MAX | |||
#define PATH_MAX 512 | #define PATH_MAX 512 | |||
#endif | #endif | |||
char dir[PATH_MAX]; | char dir[PATH_MAX]; | |||
#endif | #endif | |||
if ((name = getenv ("ICEAUTHORITY"))) | if ((name = getenv ("ICEAUTHORITY"))) | |||
return (name); | return (name); | |||
name = getenv ("HOME"); | name = getenv ("HOME"); | |||
skipping to change at line 101 | skipping to change at line 98 | |||
int len1 = 0, len2 = 0; | int len1 = 0, len2 = 0; | |||
if ((ptr1 = getenv("HOMEDRIVE")) && (ptr2 = getenv("HOMEDIR"))) { | if ((ptr1 = getenv("HOMEDRIVE")) && (ptr2 = getenv("HOMEDIR"))) { | |||
len1 = strlen (ptr1); | len1 = strlen (ptr1); | |||
len2 = strlen (ptr2); | len2 = strlen (ptr2); | |||
} else if ((ptr2 = getenv("USERNAME"))) { | } else if ((ptr2 = getenv("USERNAME"))) { | |||
len1 = strlen (ptr1 = "/users/"); | len1 = strlen (ptr1 = "/users/"); | |||
len2 = strlen (ptr2); | len2 = strlen (ptr2); | |||
} | } | |||
if ((len1 + len2 + 1) < PATH_MAX) { | if ((len1 + len2 + 1) < PATH_MAX) { | |||
sprintf (dir, "%s%s", ptr1, (ptr2) ? ptr2 : ""); | snprintf (dir, sizeof(dir), "%s%s", ptr1, (ptr2) ? ptr2 : ""); | |||
name = dir; | name = dir; | |||
} | } | |||
if (!name) | if (!name) | |||
#endif | #endif | |||
#ifdef __UNIXOS2__ | ||||
strcpy (dir,"c:"); | ||||
name = dir; | ||||
if (!name) | ||||
#endif | ||||
return (NULL); | return (NULL); | |||
} | } | |||
size = strlen (name) + strlen (&slashDotICEauthority[1]) + 2; | size = strlen (name) + strlen (&slashDotICEauthority[1]) + 2; | |||
if (size > bsize) | if (size > bsize) | |||
{ | { | |||
if (buf) | if (buf) | |||
free (buf); | free (buf); | |||
buf = malloc ((unsigned) size); | buf = malloc (size); | |||
if (!buf) | if (!buf) | |||
return (NULL); | return (NULL); | |||
bsize = size; | bsize = size; | |||
} | } | |||
strcpy (buf, name); | snprintf (buf, bsize, "%s%s", name, | |||
strcat (buf, slashDotICEauthority + (name[1] == '\0' ? 1 : 0)); | slashDotICEauthority + (name[1] == '\0' ? 1 : 0)); | |||
return (buf); | return (buf); | |||
} | } | |||
int | int | |||
IceLockAuthFile ( | IceLockAuthFile ( | |||
char *file_name, | const char *file_name, | |||
int retries, | int retries, | |||
int timeout, | int timeout, | |||
long dead | long dead | |||
) | ) | |||
{ | { | |||
char creat_name[1025], link_name[1025]; | char creat_name[1025], link_name[1025]; | |||
struct stat statb; | struct stat statb; | |||
Time_t now; | Time_t now; | |||
int creat_fd = -1; | int creat_fd = -1; | |||
if ((int) strlen (file_name) > 1022) | if ((int) strlen (file_name) > 1022) | |||
return (IceAuthLockError); | return (IceAuthLockError); | |||
strcpy (creat_name, file_name); | snprintf (creat_name, sizeof(creat_name), "%s-c", file_name); | |||
strcat (creat_name, "-c"); | snprintf (link_name, sizeof(link_name), "%s-l", file_name); | |||
strcpy (link_name, file_name); | ||||
strcat (link_name, "-l"); | ||||
if (stat (creat_name, &statb) != -1) | if (stat (creat_name, &statb) != -1) | |||
{ | { | |||
now = time ((Time_t *) 0); | now = time ((Time_t *) 0); | |||
/* | /* | |||
* NFS may cause ctime to be before now, special | * NFS may cause ctime to be before now, special | |||
* case a 0 deadtime to force lock removal | * case a 0 deadtime to force lock removal | |||
*/ | */ | |||
skipping to change at line 206 | skipping to change at line 196 | |||
} | } | |||
sleep ((unsigned) timeout); | sleep ((unsigned) timeout); | |||
--retries; | --retries; | |||
} | } | |||
return (IceAuthLockTimeout); | return (IceAuthLockTimeout); | |||
} | } | |||
void | void | |||
IceUnlockAuthFile ( | IceUnlockAuthFile ( | |||
char *file_name | const char *file_name | |||
) | ) | |||
{ | { | |||
#ifndef WIN32 | #ifndef WIN32 | |||
char creat_name[1025]; | char creat_name[1025]; | |||
#endif | #endif | |||
char link_name[1025]; | char link_name[1025]; | |||
if ((int) strlen (file_name) > 1022) | if ((int) strlen (file_name) > 1022) | |||
return; | return; | |||
#ifndef WIN32 | #ifndef WIN32 | |||
strcpy (creat_name, file_name); | snprintf (creat_name, sizeof(creat_name), "%s-c", file_name); | |||
strcat (creat_name, "-c"); | ||||
#endif | ||||
strcpy (link_name, file_name); | ||||
strcat (link_name, "-l"); | ||||
#ifndef WIN32 | ||||
unlink (creat_name); | unlink (creat_name); | |||
#endif | #endif | |||
snprintf (link_name, sizeof(link_name), "%s-l", file_name); | ||||
unlink (link_name); | unlink (link_name); | |||
} | } | |||
IceAuthFileEntry * | IceAuthFileEntry * | |||
IceReadAuthFileEntry ( | IceReadAuthFileEntry ( | |||
FILE *auth_file | FILE *auth_file | |||
) | ) | |||
{ | { | |||
IceAuthFileEntry local; | IceAuthFileEntry local; | |||
IceAuthFileEntry *ret; | IceAuthFileEntry *ret; | |||
skipping to change at line 260 | skipping to change at line 245 | |||
if (!read_string (auth_file, &local.network_id)) | if (!read_string (auth_file, &local.network_id)) | |||
goto bad; | goto bad; | |||
if (!read_string (auth_file, &local.auth_name)) | if (!read_string (auth_file, &local.auth_name)) | |||
goto bad; | goto bad; | |||
if (!read_counted_string (auth_file, | if (!read_counted_string (auth_file, | |||
&local.auth_data_length, &local.auth_data)) | &local.auth_data_length, &local.auth_data)) | |||
goto bad; | goto bad; | |||
if (!(ret = (IceAuthFileEntry *) malloc (sizeof (IceAuthFileEntry)))) | if (!(ret = malloc (sizeof (IceAuthFileEntry)))) | |||
goto bad; | goto bad; | |||
*ret = local; | *ret = local; | |||
return (ret); | return (ret); | |||
bad: | bad: | |||
if (local.protocol_name) free (local.protocol_name); | if (local.protocol_name) free (local.protocol_name); | |||
if (local.protocol_data) free (local.protocol_data); | if (local.protocol_data) free (local.protocol_data); | |||
skipping to change at line 289 | skipping to change at line 274 | |||
IceAuthFileEntry *auth | IceAuthFileEntry *auth | |||
) | ) | |||
{ | { | |||
if (auth) | if (auth) | |||
{ | { | |||
if (auth->protocol_name) free (auth->protocol_name); | if (auth->protocol_name) free (auth->protocol_name); | |||
if (auth->protocol_data) free (auth->protocol_data); | if (auth->protocol_data) free (auth->protocol_data); | |||
if (auth->network_id) free (auth->network_id); | if (auth->network_id) free (auth->network_id); | |||
if (auth->auth_name) free (auth->auth_name); | if (auth->auth_name) free (auth->auth_name); | |||
if (auth->auth_data) free (auth->auth_data); | if (auth->auth_data) free (auth->auth_data); | |||
free ((char *) auth); | free (auth); | |||
} | } | |||
} | } | |||
Status | Status | |||
IceWriteAuthFileEntry ( | IceWriteAuthFileEntry ( | |||
FILE *auth_file, | FILE *auth_file, | |||
IceAuthFileEntry *auth | IceAuthFileEntry *auth | |||
) | ) | |||
{ | { | |||
if (!write_string (auth_file, auth->protocol_name)) | if (!write_string (auth_file, auth->protocol_name)) | |||
return (0); | return (0); | |||
skipping to change at line 365 | skipping to change at line 350 | |||
} | } | |||
/* | /* | |||
* local routines | * local routines | |||
*/ | */ | |||
static Status | static Status | |||
read_short (FILE *file, unsigned short *shortp) | read_short (FILE *file, unsigned short *shortp) | |||
{ | { | |||
unsigned char file_short[2]; | unsigned char file_short[2]; | |||
if (fread ((char *) file_short, (int) sizeof (file_short), 1, file) != 1) | if (fread (file_short, sizeof (file_short), 1, file) != 1) | |||
return (0); | return (0); | |||
*shortp = file_short[0] * 256 + file_short[1]; | *shortp = file_short[0] * 256 + file_short[1]; | |||
return (1); | return (1); | |||
} | } | |||
static Status | static Status | |||
read_string (FILE *file, char **stringp) | read_string (FILE *file, char **stringp) | |||
{ | { | |||
skipping to change at line 389 | skipping to change at line 374 | |||
if (!read_short (file, &len)) | if (!read_short (file, &len)) | |||
return (0); | return (0); | |||
data = malloc ((unsigned) len + 1); | data = malloc ((unsigned) len + 1); | |||
if (!data) | if (!data) | |||
return (0); | return (0); | |||
if (len != 0) | if (len != 0) | |||
{ | { | |||
if (fread (data, (int) sizeof (char), (int) len, file) != len) | if (fread (data, sizeof (char), len, file) != len) | |||
{ | { | |||
free (data); | free (data); | |||
return (0); | return (0); | |||
} | } | |||
} | } | |||
data[len] = '\0'; | data[len] = '\0'; | |||
*stringp = data; | *stringp = data; | |||
skipping to change at line 423 | skipping to change at line 408 | |||
{ | { | |||
data = NULL; | data = NULL; | |||
} | } | |||
else | else | |||
{ | { | |||
data = malloc ((unsigned) len); | data = malloc ((unsigned) len); | |||
if (!data) | if (!data) | |||
return (0); | return (0); | |||
if (fread (data, (int) sizeof (char), (int) len, file) != len) | if (fread (data, sizeof (char), len, file) != len) | |||
{ | { | |||
free (data); | free (data); | |||
return (0); | return (0); | |||
} | } | |||
} | } | |||
*stringp = data; | *stringp = data; | |||
*countp = len; | *countp = len; | |||
return (1); | return (1); | |||
} | } | |||
static Status | static Status | |||
write_short (FILE *file, unsigned short s) | write_short (FILE *file, unsigned short s) | |||
{ | { | |||
unsigned char file_short[2]; | unsigned char file_short[2]; | |||
file_short[0] = (s & (unsigned) 0xff00) >> 8; | file_short[0] = (s & (unsigned) 0xff00) >> 8; | |||
file_short[1] = s & 0xff; | file_short[1] = s & 0xff; | |||
if (fwrite ((char *) file_short, (int) sizeof (file_short), 1, file) != 1) | if (fwrite (file_short, sizeof (file_short), 1, file) != 1) | |||
return (0); | return (0); | |||
return (1); | return (1); | |||
} | } | |||
static Status | static Status | |||
write_string (FILE *file, char *string) | write_string (FILE *file, const char *string) | |||
{ | { | |||
unsigned short count = strlen (string); | size_t count = strlen (string); | |||
if (!write_short (file, count)) | ||||
return (0); | ||||
if (fwrite (string, (int) sizeof (char), (int) count, file) != count) | if (count > USHRT_MAX) | |||
return (0); | return (0); | |||
return (1); | return write_counted_string (file, (unsigned short) count, string); | |||
} | } | |||
static Status | static Status | |||
write_counted_string (FILE *file, unsigned short count, char *string) | write_counted_string (FILE *file, unsigned short count, const char *string) | |||
{ | { | |||
if (!write_short (file, count)) | if (!write_short (file, count)) | |||
return (0); | return (0); | |||
if (fwrite (string, (int) sizeof (char), (int) count, file) != count) | if (fwrite (string, sizeof (char), count, file) != count) | |||
return (0); | return (0); | |||
return (1); | return (1); | |||
} | } | |||
End of changes. 25 change blocks. | ||||
47 lines changed or deleted | 29 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |