/*
* 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>
-RCSID
- ("$Header$");
+#include <roken.h>
+
+#include <afs/kautils.h> /*MAXKTCREALMLEN*/
#include "uss_procs.h" /*Module interface */
#include "uss_common.h" /*Common defs & operations */
#include "uss_acl.h" /*ACL-related operations */
-#include <errno.h> /*Unix error codes */
-#include <pwd.h> /*Password info */
-#include <sys/stat.h> /*Stat defs */
-#include <dirent.h> /*Directory package */
-#include <sys/file.h> /*O_EXCL, O_CREAT, etc */
-#ifdef AFS_SUN5_ENV
-#include <fcntl.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-#include <afs/kautils.h> /*MAXKTCREALMLEN*/
#undef USS_PROCS_DB
#undef USS_PROCS_DB_INSTANCE
#undef USS_PROCS_DB_BUILDDIR
char temp[1000];
extern int line;
-static int Copy();
-static int Echo();
+static int Copy(char *a_from, char *a_to, int a_mode);
+static int Echo(char *a_s, char *a_f, int a_mode);
/*-----------------------------------------------------------------------
* EXPORTED uss_procs_BuildDir
*------------------------------------------------------------------------*/
afs_int32
-uss_procs_BuildDir(a_path, a_mode, a_owner, a_access)
- char *a_path;
- char *a_mode;
- char *a_owner;
- char *a_access;
-
+uss_procs_BuildDir(char *a_path, char *a_mode, char *a_owner, char *a_access)
{ /*uss_procs_BuildDir */
int m, o;
* Use our linked list to remember this directory's true ACL setting so
* we may set it correctly at the tail end of the account creation.
*/
- new_dir = (struct uss_subdir *)malloc(sizeof(struct uss_subdir));
+ new_dir = malloc(sizeof(struct uss_subdir));
new_dir->previous = uss_currentDir;
- new_dir->path = (char *)malloc(strlen(a_path) + 1);
- strcpy(new_dir->path, a_path);
- new_dir->finalACL = (char *)malloc(strlen(a_access) + 1);
- strcpy(new_dir->finalACL, a_access);
+ new_dir->path = strdup(a_path);
+ new_dir->finalACL = strdup(a_access);
uss_currentDir = new_dir;
/*
*------------------------------------------------------------------------*/
afs_int32
-uss_procs_CpFile(a_path, a_mode, a_owner, a_proto)
- char *a_path;
- char *a_mode;
- char *a_owner;
- char *a_proto;
-
+uss_procs_CpFile(char *a_path, char *a_mode, char *a_owner, char *a_proto)
{ /*uss_procs_CpFile */
int m, o;
*------------------------------------------------------------------------*/
afs_int32
-uss_procs_EchoToFile(a_path, a_mode, a_owner, a_content)
- char *a_path;
- char *a_mode;
- char *a_owner;
- char *a_content;
-
+uss_procs_EchoToFile(char *a_path, char *a_mode, char *a_owner,
+ char *a_content)
{ /*uss_procs_EchoToFile */
int m, o;
*------------------------------------------------------------------------*/
afs_int32
-uss_procs_Exec(a_command)
- char *a_command;
-
+uss_procs_Exec(char *a_command)
{ /*uss_procs_Exec */
if (uss_verbose)
*------------------------------------------------------------------------*/
afs_int32
-uss_procs_SetLink(a_path1, a_path2, a_type)
- char *a_path1;
- char *a_path2;
- char a_type;
-
+uss_procs_SetLink(char *a_path1, char *a_path2, char a_type)
{ /*uss_procs_SetLink */
struct stat stbuf;
*------------------------------------------------------------------------*/
int
-uss_procs_GetOwner(a_ownerStr)
- char *a_ownerStr;
-
+uss_procs_GetOwner(char *a_ownerStr)
{ /*uss_procs_GetOwner */
struct passwd *pw; /*Ptr to password file entry */
* static Copy
*
* Description:
- * Copies the "from" file to the "to" file and sets the mode.
+ * Copies the "from" file to the "to" file and sets the mode.
*
* Arguments:
* a_from : File to copy from.
*------------------------------------------------------------------------*/
static int
-Copy(a_from, a_to, a_mode)
- char *a_from;
- char *a_to;
- int a_mode;
-
+Copy(char *a_from, char *a_to, int a_mode)
{ /*Copy */
- register int fd1, fd2;
+ int fd1, fd2;
char buf[BUFSIZ];
- int cnt, rc;
+ int rcnt, wcnt = -1, rc;
umask(0);
fd1 = open(a_to, O_EXCL | O_CREAT | O_WRONLY, a_mode);
close(fd1);
return (1);
}
- while ((cnt = read(fd2, buf, BUFSIZ)) == BUFSIZ)
- write(fd1, buf, cnt);
-
- write(fd1, buf, cnt);
+ do {
+ rcnt = read(fd2, buf, BUFSIZ);
+ if (rcnt == -1)
+ break;
+ wcnt = write(fd1, buf, rcnt);
+ } while (rcnt == BUFSIZ && rcnt == wcnt);
+ if (rcnt == -1 || wcnt != rcnt) {
+ uss_procs_PrintErr(line, "read/write error to %s\n", a_to);
+ close(fd1);
+ close(fd2);
+ return (1);
+ }
rc = close(fd1);
if (rc) {
uss_procs_PrintErr(line, "Failed to close '%s' %s\n", a_to,
strerror(errno));
return (1);
}
- if (rc = close(fd2))
+ if ((rc = close(fd2)))
uss_procs_PrintErr(line, "Warning: Failed to close '%s': %s\n",
a_from, strerror(errno));
return (0);
*------------------------------------------------------------------------*/
static int
-Echo(a_s, a_f, a_mode)
- char *a_s;
- char *a_f;
- int a_mode;
-
+Echo(char *a_s, char *a_f, int a_mode)
{ /*Echo */
- register int fd;
+ int fd;
umask(0);
fd = open(a_f, O_EXCL | O_CREAT | O_WRONLY, a_mode);
return (1);
}
}
- write(fd, a_s, strlen(a_s));
- write(fd, "\n", 1);
+ if (write(fd, a_s, strlen(a_s)) != strlen(a_s) ||
+ write(fd, "\n", 1) != 1) {
+ uss_procs_PrintErr(line, "Short write to '%s'\n", a_f);
+ close(fd);
+ return (1);
+ }
if (close(fd)) {
uss_procs_PrintErr(line, "Failed to close '%s': %s\n", a_f,
strerror(errno));
*------------------------------------------------------------------------*/
afs_int32
-uss_procs_PickADir(path, cp)
- char *path;
- char *cp;
-
+uss_procs_PickADir(char *path, char *cp)
{ /*uss_procs_PickADir */
char cd[300]; /*Current directory for search */
- int i, count, MinIndex, mina = 10000;
+ int i, count, MinIndex = 0, mina = 10000;
struct dirent *dp;
DIR *dirp;
- char dirname[300];
+ char dirname[301];
if (uss_NumGroups == 0) {
fprintf(stderr, "%s: No choice yet given to replace $AUTO\n",
cd[1] = '\0';
}
- /*
+ /*
* We now have the current dir (cd). Search all of the given
* subdirs (by G in template), count the number of entries in
* each and pick the minimum.
*/
for (i = 0; i < uss_NumGroups; i++) {
- sprintf(dirname, "%s/%s", cd, uss_DirPool[i]);
+ snprintf(dirname, sizeof(dirname), "%s/%s", cd, uss_DirPool[i]);
if ((dirp = opendir(dirname)) == NULL) {
if (errno != ENOTDIR)
fprintf(stderr,
*------------------------------------------------------------------------*/
int
-uss_procs_AddToDirPool(a_dirToAdd)
- char *a_dirToAdd;
+uss_procs_AddToDirPool(char *a_dirToAdd)
{
if (uss_NumGroups > 99) {
return (-1);
*------------------------------------------------------------------------*/
FILE *
-uss_procs_FindAndOpen(a_fileToOpen)
- char *a_fileToOpen;
-
+uss_procs_FindAndOpen(char *a_fileToOpen)
{ /*uss_procs_FindAndOpen */
#define NUM_TPL_PATHS 3
*------------------------------------------------------------------------*/
void
-uss_procs_PrintErr(a_lineNum, a_fmt, a_1, a_2, a_3, a_4, a_5)
- int a_lineNum;
- char *a_fmt;
- char *a_1;
- char *a_2;
- char *a_3;
- char *a_4;
- char *a_5;
-
+uss_procs_PrintErr(int a_lineNum, char *a_fmt, ... )
{ /*uss_procs_PrintErr */
+ va_list ap;
+ va_start(ap, a_fmt);
uss_syntax_err++;
fprintf(stderr, "%s: Template file, line %d: ", uss_whoami, a_lineNum);
- fprintf(stderr, a_fmt, a_1, a_2, a_3, a_4, a_5);
-
+ vfprintf(stderr, a_fmt, ap);
+ va_end(ap);
} /*uss_procs_PrintErr */