/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
#include <afsconfig.h>
#include <afs/param.h>
+#include <afs/stds.h>
+#include <afs/procmgmt.h>
+#include <roken.h>
+#include <afs/opr.h>
-#include <afs/stds.h>
-#ifdef AFS_AIX32_ENV
-#include <signal.h>
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
#ifdef AFS_NT40_ENV
-#include <fcntl.h>
-#include <winsock2.h>
#include <WINNT/afsevent.h>
#include <sys/utime.h>
-#include <afs/dirent.h>
#include <direct.h>
-#include <process.h>
-#include <io.h>
-#include <afs/procmgmt.h>
-#else
-#include <sys/file.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include <dirent.h>
#endif
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+
+#ifdef AFS_AIX_ENV
+#include <sys/statfs.h>
#endif
-#include <stdio.h>
-#include <errno.h>
+
#include <rx/xdr.h>
#include <rx/rx.h>
#include <rx/rxkad.h>
#include <afs/cellconfig.h>
#include <afs/afsutil.h>
#include <afs/fileutil.h>
-#ifdef AFS_AIX_ENV
-#include <sys/statfs.h>
-#endif
+
#include "update.h"
#include "global.h"
#include "update_internal.h"
afs_int32
GetServer(char *aname)
{
- register struct hostent *th;
+ struct hostent *th;
afs_int32 addr;
th = gethostbyname(aname);
afs_uint32 mode;
int error;
- char hostname[MAXSIZE];
+ char hostname[MAXFNSIZE];
FILE *stream;
afs_int32 time, length, atime;
struct filestr *df;
int a, cnt;
rxkad_level level;
- char dirbuf[MAXSIZE], filename[MAXSIZE];
+ char dirbuf[MAXFNSIZE], filename[MAXFNSIZE];
struct filestr *dirname, *ModFiles, *okhostfiles;
#ifdef AFS_AIX32_ENV
/*
- * The following signal action for AIX is necessary so that in case of a
- * crash (i.e. core is generated) we can include the user's data section
+ * The following signal action for AIX is necessary so that in case of a
+ * crash (i.e. core is generated) we can include the user's data section
* in the core dump. Unfortunately, by default, only a partial core is
* generated which, in many cases, isn't too useful.
*/
("Usage: upclient <hostname> [-crypt] [-clear] [-t <retry time>] [-verbose]* <dir>+ [-help]\n");
exit(1);
}
- } else if (strlen(hostname) == 0)
- strcpy(hostname, argv[a]);
- else {
- strcpy(filename, argv[a]);
+ } else if (strlen(hostname) == 0) {
+ if (strlcpy(hostname, argv[a], sizeof(hostname))
+ >= sizeof(hostname)) {
+ fprintf(stderr, "Supplied hostname is too long\n");
+ exit(1);
+ }
+ } else {
+ if (strlcpy(filename, argv[a], sizeof(filename))
+ >= sizeof(filename)) {
+ fprintf(stderr, "Supplied filename is too long\n");
+ exit(1);
+ }
FilepathNormalize(filename);
AddToList(&dirname, filename);
}
if (verbose >= 3)
printf(" checking %s\n", filename);
if (!IsCompatible(filename, time, length)) {
- /* if the file info has changed , record all the
+ /* if the file info has changed , record all the
*changed files in the ModFiles array*/
if (verbose >= 2)
printf(" getting %s\n", filename);
AddToList(&ModFiles, filename);
- /* now get the file from the server. The received
+ /* now get the file from the server. The received
* file is created under the name filename.NEW */
errcode =
GetFileFromUpServer(conn, filename, uid, gid, mode,
{ /*delete all the redundant files on the client */
DIR *dirp;
struct dirent *dp;
- char filename[MAXSIZE];
+ char filename[MAXFNSIZE];
dirp = opendir(curDir);
if (dirp == 0) {
free(curDir);
} /* end for each dir loop */
/*delete the file with info on files in directory df->name */
- IOMGR_Sleep(interval);
+ sleep(interval);
continue;
fail_dirbuf:
fclose(stream);
unlink(dirbuf);
fail:
- IOMGR_Sleep(retrytime);
+ sleep(retrytime);
if (cnt > 10) {
rx_DestroyConnection(conn);
goto again;
/* returns 1 if the file is upto date else returns 0*/
/*check the dir case more carefully */
int
-IsCompatible(char *filename, afs_int32 time, afs_int32 length)
+IsCompatible(char *filename, afs_int32 time, afs_int32 length)
{
struct stat status;
afs_int32 error;
int
-update_ReceiveFile(register int fd, register struct rx_call *call, register struct stat *status)
+update_ReceiveFile(int fd, struct rx_call *call, struct stat *status)
{
- register char *buffer = (char *)0;
+ char *buffer = (char *)0;
afs_int32 length;
- register int blockSize;
+ int blockSize;
afs_int32 error = 0, len;
#ifdef AFS_AIX_ENV
struct statfs tstatfs;
#else
blockSize = status->st_blksize;
#endif
- buffer = (char *)malloc(blockSize);
+ buffer = malloc(blockSize);
if (!buffer) {
printf("malloc failed\n");
return UPDATE_ERROR;
}
while (!error && length) {
- register int nbytes = (length > blockSize ? blockSize : length);
+ int nbytes = (length > blockSize ? blockSize : length);
nbytes = rx_Read(call, buffer, nbytes);
if (!nbytes)
error = UPDATE_ERROR;
/*
* PathsAreEquivalent() -- determine if paths are equivalent
+ * Returns 1 if yes, 0 if no, -1 on error.
*/
static int
PathsAreEquivalent(char *path1, char *path2)
{
- int areEq = 0;
- char pathNorm1[AFSDIR_PATH_MAX], pathNorm2[AFSDIR_PATH_MAX];
+ int areEq = 0, code;
+ char *pathNorm1, *pathNorm2;
#ifdef AFS_NT40_ENV
/* case-insensitive comparison of normalized, same-flavor (short) paths */
DWORD status;
+ pathNorm1 = malloc(AFSDIR_PATH_MAX);
+ if (pathNorm1 == NULL)
+ return -1;
status = GetShortPathName(path1, pathNorm1, AFSDIR_PATH_MAX);
if (status == 0 || status > AFSDIR_PATH_MAX) {
/* can't convert path to short version; just use long version */
- strcpy(pathNorm1, path1);
+ free(pathNorm1);
+ pathNorm1 = strdup(path1);
+ if (pathNorm1 == NULL)
+ return -1;
}
FilepathNormalize(pathNorm1);
+ pathNorm2 = malloc(AFSDIR_PATH_MAX);
+ if (pathNorm2 == NULL) {
+ code = -1;
+ goto out;
+ }
status = GetShortPathName(path2, pathNorm2, AFSDIR_PATH_MAX);
if (status == 0 || status > AFSDIR_PATH_MAX) {
/* can't convert path to short version; just use long version */
- strcpy(pathNorm2, path2);
+ free(pathNorm2);
+ pathNorm2 = strdup(path2);
+ if (pathNorm2 == NULL) {
+ code = -1;
+ goto out;
+ }
}
FilepathNormalize(pathNorm2);
}
#else
/* case-sensitive comparison of normalized paths */
- strcpy(pathNorm1, path1);
+ pathNorm1 = strdup(path1);
+ if (pathNorm1 == NULL)
+ return -1;
FilepathNormalize(pathNorm1);
- strcpy(pathNorm2, path2);
+ pathNorm2 = strdup(path2);
+ if (pathNorm2 == NULL) {
+ code = -1;
+ goto out;
+ }
FilepathNormalize(pathNorm2);
if (strcmp(pathNorm1, pathNorm2) == 0) {
areEq = 1;
}
#endif /* AFS_NT40_ENV */
- return areEq;
+ code = 0;
+out:
+ free(pathNorm1);
+ free(pathNorm2);
+ return (code != 0) ? code : areEq;
}
afs_com_err(whoami, rc, "Unable to construct local path");
return -1;
}
- if (PathsAreEquivalent(hostfile, filename)) {
- free(hostfile);
- return 0;
- }
+ rc = PathsAreEquivalent(hostfile, filename);
free(hostfile);
+ if (rc < 0)
+ return -1;
+ if (rc)
+ return 0;
}
return 1;
}
static int
RenameNewFiles(struct filestr *modFiles)
{
- char newname[MAXSIZE];
+ char newname[MAXFNSIZE];
char *fname;
int errcode = 0;
struct filestr *tf;
strcat(newname, ".NEW");
if (verbose >= 2)
printf(" renaming %s\n", newname);
- errcode = renamefile(newname, fname);
+ errcode = rk_rename(newname, fname);
if (errcode) {
printf("could not rename %s to %s\n", newname, fname);
afs_com_err(whoami, errno, "could not rename %s to %s", newname,
/* GetFileFromUpServer() - Makes the FetchFile() call and gets the
- * file from the upserver.
+ * file from the upserver.
* Return Values:
* 0 - Alls well
* -1 - Serious error. Quit right away.
- * 1 - Error, but keep trying for the other files
- *
+ * 1 - Error, but keep trying for the other files
+ *
* The file obtained is written to the localized version of the filename.NEW
* and the uid, gid, file mode, access and modification times will be set to
* the passed in values.
#else
struct timeval tvp[2];
#endif
- char newfile[MAXSIZE];
+ char newfile[MAXFNSIZE];
/* construct local path from canonical (wire-format) path */
errcode = ConstructLocalPath(filename, "/", &lfile);