diff options
author | Garrett D'Amore <garrett@nexenta.com> | 2010-11-15 20:03:27 -0800 |
---|---|---|
committer | Garrett D'Amore <garrett@nexenta.com> | 2010-11-15 20:03:27 -0800 |
commit | 4656d4747c8743290bfbe910c64cd75eb4e4af8d (patch) | |
tree | 241d8b3f0b8796e33937c6a27c670eba002f8f04 /usr/src/lib/libadm/common | |
parent | 60bec29ea42d65ac648c69b0fb189273e286ca57 (diff) | |
download | illumos-joyent-4656d4747c8743290bfbe910c64cd75eb4e4af8d.tar.gz |
420 remove patch (sparse package) support from svr4 pkg
421 libpkg and libadm need to be lint clean
Reviewed by: gwr@nexenta.com
Reviewed by: peter.tribble@gmail.com
Approved by: gwr@nexenta.com
Diffstat (limited to 'usr/src/lib/libadm/common')
-rw-r--r-- | usr/src/lib/libadm/common/ckdate.c | 10 | ||||
-rw-r--r-- | usr/src/lib/libadm/common/ckitem.c | 17 | ||||
-rw-r--r-- | usr/src/lib/libadm/common/ckpath.c | 10 | ||||
-rw-r--r-- | usr/src/lib/libadm/common/ckstr.c | 12 | ||||
-rw-r--r-- | usr/src/lib/libadm/common/cktime.c | 14 | ||||
-rw-r--r-- | usr/src/lib/libadm/common/getvol.c | 37 | ||||
-rw-r--r-- | usr/src/lib/libadm/common/pkginfo.c | 13 | ||||
-rw-r--r-- | usr/src/lib/libadm/common/pkgparam.c | 14 | ||||
-rw-r--r-- | usr/src/lib/libadm/common/putdev.c | 36 | ||||
-rw-r--r-- | usr/src/lib/libadm/common/putdgrp.c | 185 |
10 files changed, 196 insertions, 152 deletions
diff --git a/usr/src/lib/libadm/common/ckdate.c b/usr/src/lib/libadm/common/ckdate.c index 2b61fbed54..7c0db59beb 100644 --- a/usr/src/lib/libadm/common/ckdate.c +++ b/usr/src/lib/libadm/common/ckdate.c @@ -71,11 +71,11 @@ static char *p_dlm(char *, char); #define TAB ' ' static void -setmsg(char *msg, char *fmt) +setmsg(char *msg, char *fmt, size_t sz) { if ((fmt == NULL) || strcmp(fmt, "%D") == 0) fmt = "%m/%d/%y"; - (void) sprintf(msg, "%s. Format is <%s>.", MESG, fmt); + (void) snprintf(msg, sz, "%s. Format is <%s>.", MESG, fmt); } static char * @@ -234,7 +234,7 @@ ckdate_err(char *fmt, char *error) if ((fmt != NULL) && (fmtcheck(fmt) == 1)) return (4); - setmsg(defmesg, fmt); + setmsg(defmesg, fmt, MSGSIZ); puterror(stdout, defmesg, error); return (0); } @@ -246,7 +246,7 @@ ckdate_hlp(char *fmt, char *help) if ((fmt != NULL) && (fmtcheck(fmt) == 1)) return (4); - setmsg(defmesg, fmt); + setmsg(defmesg, fmt, MSGSIZ); puthelp(stdout, defmesg, help); return (0); } @@ -416,7 +416,7 @@ ckdate(char *date, char *fmt, char *defstr, char *error, char *help, if ((fmt != NULL) && (fmtcheck(fmt) == 1)) return (4); - setmsg(defmesg, fmt); + setmsg(defmesg, fmt, MSGSIZ); (void) sprintf(ept, "[?,q]"); if (!prompt) diff --git a/usr/src/lib/libadm/common/ckitem.c b/usr/src/lib/libadm/common/ckitem.c index 8835f6b23b..d87c51f2c5 100644 --- a/usr/src/lib/libadm/common/ckitem.c +++ b/usr/src/lib/libadm/common/ckitem.c @@ -27,8 +27,10 @@ * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +/* + * Copyright 2010 Nexenta Systems, Inc. All rights reserved. + */ -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */ /*LINTLIBRARY*/ #include <stdio.h> @@ -463,6 +465,7 @@ printmenu(CKMENU *menup) for (i = 1; chp; ++i) { if (!(menup->attr & CKUNNUM)) (void) fprintf(stderr, "%3d ", i); + /* LINTED E_SEC_PRINTF_VAR_FMT */ (void) fprintf(stderr, format, chp->token); if (chp->text) { /* there is text associated with the token */ @@ -473,6 +476,7 @@ printmenu(CKMENU *menup) if (!(menup->attr & CKUNNUM)) (void) fprintf(stderr, "%5s", ""); + /* LINTED E_SEC_PRINTF_VAR_FMT */ (void) fprintf(stderr, format, ""); while (isspace((unsigned char)*pt)) ++pt; @@ -505,17 +509,16 @@ static int getstr(char *strval, char *defstr, char *error, char *help, char *prompt) { char input[MAX_INPUT]; - char *ept, end[MAX_INPUT]; + char end[MAX_INPUT]; - *(ept = end) = '\0'; + *end = '\0'; if (defstr) { - (void) sprintf(ept, "(default: %s) ", defstr); - ept += strlen(ept); + (void) snprintf(end, MAX_INPUT, "(default: %s) ", defstr); } if (ckquit) { - (void) strcat(ept, "[?,??,q]"); + (void) strlcat(end, "[?,??,q]", MAX_INPUT); } else { - (void) strcat(ept, "[?,??]"); + (void) strlcat(end, "[?,??]", MAX_INPUT); } start: diff --git a/usr/src/lib/libadm/common/ckpath.c b/usr/src/lib/libadm/common/ckpath.c index c5ce5b9f15..b005c754a6 100644 --- a/usr/src/lib/libadm/common/ckpath.c +++ b/usr/src/lib/libadm/common/ckpath.c @@ -27,8 +27,10 @@ * Copyright (c) 1996-1998, 2001 by Sun Microsystems, Inc. * All rights reserved. */ +/* + * Copyright 2010 Nexenta Systems, Inc. All rights reserved. + */ -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */ /*LINTLIBRARY*/ #include <stdio.h> @@ -244,7 +246,8 @@ ckpath_err(int pflags, char *error, char *input) if (input) { if (ckpath_val(input, pflags)) { - (void) sprintf(buffer, "Pathname %s.", errstr); + (void) snprintf(buffer, sizeof (buffer), + "Pathname %s.", errstr); puterror(stdout, buffer, error); return; } @@ -311,7 +314,8 @@ start: } if (ckpath_val(input, pflags)) { - (void) sprintf(buffer, "Pathname %s.", errstr); + (void) snprintf(buffer, sizeof (buffer), + "Pathname %s.", errstr); puterror(stderr, buffer, error); goto start; } diff --git a/usr/src/lib/libadm/common/ckstr.c b/usr/src/lib/libadm/common/ckstr.c index e01717f233..b72d6900b0 100644 --- a/usr/src/lib/libadm/common/ckstr.c +++ b/usr/src/lib/libadm/common/ckstr.c @@ -28,8 +28,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <stdio.h> #include <string.h> #include <limits.h> @@ -50,14 +48,14 @@ extern int __step(const char *, const char *); #define ERRMSG2 \ "Pattern matching has failed." #define ERRMSG3 \ - "Please enter a string which contains no imbedded, \ + "Please enter a string which contains no embedded, \ leading or trailing spaces or tabs." #define HLPMSG0 "Please enter a string" #define HLPMSG1 "Please enter a string containing no more than %d characters" #define HLPMSG2 "matches one of the following patterns:" #define HLPMSG3 "matches the following pattern:" -#define HLPMSG4 "contains no imbedded, leading or trailing spaces or tabs." +#define HLPMSG4 "contains no embedded, leading or trailing spaces or tabs." static char *errstr; @@ -119,7 +117,8 @@ ckstr_err(char *regexp[], int length, char *error, char *input) if (input) { if (ckstr_val(regexp, length, input)) { - (void) sprintf(temp, errstr, length); + /* LINTED E_SEC_PRINTF_VAR_FMT */ + (void) snprintf(temp, sizeof (temp), errstr, length); puterror(stdout, temp, error); return; } @@ -178,7 +177,8 @@ start: return (3); } if (ckstr_val(regexp, length, input)) { - (void) sprintf(errbuf, errstr, length); + /* LINTED E_SEC_PRINTF_VAR_FMT */ + (void) snprintf(errbuf, sizeof (errbuf), errstr, length); puterror(stderr, errbuf, error); goto start; } diff --git a/usr/src/lib/libadm/common/cktime.c b/usr/src/lib/libadm/common/cktime.c index 71a5580600..27bdffe9ed 100644 --- a/usr/src/lib/libadm/common/cktime.c +++ b/usr/src/lib/libadm/common/cktime.c @@ -27,8 +27,10 @@ * Copyright (c) 1997,1998 by Sun Microsystems, Inc. * All rights reserved. */ +/* + * Copyright 2010 Nexenta Systems, Inc. All rights reserved. + */ -#pragma ident "%Z%%M% %I% %E% SMI" /*LINTLIBRARY*/ #include <stdio.h> @@ -58,11 +60,11 @@ static int fmtcheck(char *); #define TAB ' ' static void -setmsg(char *msg, char *fmt) +setmsg(char *msg, char *fmt, size_t sz) { if (fmt == NULL) fmt = DEFAULT; - (void) sprintf(msg, "%s <%s>.", ERRMSG, fmt); + (void) snprintf(msg, sz, "%s <%s>.", ERRMSG, fmt); } static char * @@ -281,7 +283,7 @@ cktime_err(char *fmt, char *error) if ((fmt != NULL) && (fmtcheck(fmt) == 1)) return (4); - setmsg(defmesg, fmt); + setmsg(defmesg, fmt, sizeof (defmesg)); puterror(stdout, defmesg, error); return (0); } @@ -293,7 +295,7 @@ cktime_hlp(char *fmt, char *help) if ((fmt != NULL) && (fmtcheck(fmt) == 1)) return (4); - setmsg(defmesg, fmt); + setmsg(defmesg, fmt, sizeof (defmesg)); puthelp(stdout, defmesg, help); return (0); } @@ -355,7 +357,7 @@ cktime(char *tod, char *fmt, char *defstr, char *error, char *help, if (fmt == NULL) fmt = DEFAULT; - setmsg(defmesg, fmt); + setmsg(defmesg, fmt, sizeof (defmesg)); if (!prompt) prompt = "Enter a time of day"; diff --git a/usr/src/lib/libadm/common/getvol.c b/usr/src/lib/libadm/common/getvol.c index f4955073ed..df826fcacc 100644 --- a/usr/src/lib/libadm/common/getvol.c +++ b/usr/src/lib/libadm/common/getvol.c @@ -28,7 +28,6 @@ * All rights reserved. */ -#pragma ident "%Z%%M% %I% %E% SMI" /*LINTLIBRARY*/ #include <stdio.h> @@ -196,7 +195,7 @@ ckilabel(char *label, int flag) } else volname[0] = '\0'; - (void) sprintf(buffer, "/etc/labelit %s", cdevice); + (void) snprintf(buffer, sizeof (buffer), "/etc/labelit %s", cdevice); pp = popen(buffer, "r"); pt = buffer; while ((c = getc(pp)) != EOF) @@ -229,6 +228,7 @@ ckilabel(char *label, int flag) if (strcmp(fsname, pfsname) || strcmp(volname, pvolname)) { /* mismatched label */ if (flag) { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ (void) sprintf(label, "%s,%s", pfsname, pvolname); } else { labelerr(pfsname, pvolname); @@ -260,17 +260,20 @@ wilabel(char *label) (void) strcpy(volname, origvolname); if (IFTAPE(cdevice)) { - (void) sprintf(buffer, "/etc/labelit %s \"%s\" \"%s\" -n 1>&2", + (void) snprintf(buffer, sizeof (buffer), + "/etc/labelit %s \"%s\" \"%s\" -n 1>&2", cdevice, fsname, volname); } else { - (void) sprintf(buffer, "/etc/labelit %s \"%s\" \"%s\" 1>&2", - cdevice, fsname, volname); + (void) snprintf(buffer, sizeof (buffer), + "/etc/labelit %s \"%s\" \"%s\" 1>&2", + cdevice, fsname, volname); } if (system(buffer)) { (void) fprintf(stderr, "\nWrite of label to %s failed.", pname); return (1); } if (label) + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ (void) sprintf(label, "%s,%s", fsname, volname); return (0); } @@ -300,7 +303,7 @@ insert(char *device, char *label, int options, char *prompt) dev_type = devattr(device, "type"); if (prompt) { - (void) strcpy(prmpt, prompt); + (void) strlcpy(prmpt, prompt, sizeof (prmpt)); for (pt = prmpt; *prompt; ) { if ((*prompt == '\\') && (prompt[1] == '%')) prompt++; @@ -326,17 +329,21 @@ insert(char *device, char *label, int options, char *prompt) } *pt = '\0'; } else { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ (void) sprintf(prmpt, "Insert a %s into %s.", voltxt, pname); if (label && (options & DM_ELABEL)) { (void) strcat(prmpt, " The following external label "); + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ (void) sprintf(prmpt+strlen(prmpt), " should appear on the %s:\\n\\t%s", voltxt, label); } if (label && !(options & DM_ELABEL)) { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ (void) sprintf(prmpt+strlen(prmpt), - " The %s should be internally labeled as follows:", - voltxt); + " The %s should be internally labeled as follows:", + voltxt); + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ (void) sprintf(prmpt+strlen(prmpt), "\\n\\t%s\\n", label); } @@ -350,23 +357,28 @@ insert(char *device, char *label, int options, char *prompt) if (options & DM_FORMFS) { if (fmtcmd && *fmtcmd && mkfscmd && *mkfscmd) { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ pt += sprintf(pt, FORMFS_MSG, voltxt); keyword[n++] = "f"; } else if (fmtcmd && *fmtcmd) { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ pt += sprintf(pt, FORMAT_MSG, voltxt); keyword[n++] = "f"; } if (mkfscmd && *mkfscmd) { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ pt += sprintf(pt, MAKEFS_MSG, voltxt); keyword[n++] = "m"; } } else if (options & DM_FORMAT) { if (fmtcmd && *fmtcmd) { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ pt += sprintf(pt, FORMAT_MSG, voltxt); keyword[n++] = "f"; } } if (options & DM_WLABEL) { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ pt += sprintf(pt, WLABEL_MSG, voltxt); keyword[n++] = "w"; } @@ -376,9 +388,11 @@ insert(char *device, char *label, int options, char *prompt) } if (removecmd && *removecmd && dev_type && *dev_type) { if (strcmp(dev_type, "diskette") == 0) { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ pt += sprintf(pt, EJECT_MSG, voltxt); keyword[n++] = "e"; } else { + /* LINTED E_SEC_SPRINTF_UNBOUNDED_COPY */ pt += sprintf(pt, UNLOAD_MSG, voltxt); keyword[n++] = "u"; } @@ -425,7 +439,7 @@ doformat(char *voltxt, char *fmtcmd, char *mkfscmd) if (fmtcmd && *fmtcmd) { (void) fprintf(stderr, "\t[%s]\n", fmtcmd); - (void) sprintf(buffer, "(%s) 1>&2", fmtcmd); + (void) snprintf(buffer, sizeof (buffer), "(%s) 1>&2", fmtcmd); if (system(buffer)) { (void) fprintf(stderr, ERR_FMT, voltxt); return; @@ -433,7 +447,7 @@ doformat(char *voltxt, char *fmtcmd, char *mkfscmd) } if (mkfscmd && *mkfscmd) { (void) fprintf(stderr, "\t[%s]\n", mkfscmd); - (void) sprintf(buffer, "(%s) 1>&2", mkfscmd); + (void) snprintf(buffer, sizeof (buffer), "(%s) 1>&2", mkfscmd); if (system(buffer)) { (void) fprintf(stderr, ERR_MKFS, voltxt); return; @@ -452,7 +466,8 @@ doremovecmd(char *device, int echo) if (removecmd && *removecmd) { if (echo) (void) fprintf(stderr, "\t[%s]\n", removecmd); - (void) sprintf(buffer, "(%s) 1>&2", removecmd); + (void) snprintf(buffer, sizeof (buffer), + "(%s) 1>&2", removecmd); if (system(buffer)) { if (echo) (void) fprintf(stderr, ERR_REMOVE, diff --git a/usr/src/lib/libadm/common/pkginfo.c b/usr/src/lib/libadm/common/pkginfo.c index c6f165a531..1d36c06b1c 100644 --- a/usr/src/lib/libadm/common/pkginfo.c +++ b/usr/src/lib/libadm/common/pkginfo.c @@ -251,11 +251,13 @@ rdconfig(struct pkginfo *info, char *pkginst, char *ckvers) PI_INSTALLED); if (info->status == PI_INSTALLED) { - (void) sprintf(temp, "%s/%s/!I-Lock!", pkgdir, pkginst); + (void) snprintf(temp, sizeof (temp), + "%s/%s/!I-Lock!", pkgdir, pkginst); if (access(temp, 0) == 0) info->status = PI_PARTIAL; else { - (void) sprintf(temp, "%s/%s/!R-Lock!", pkgdir, pkginst); + (void) snprintf(temp, sizeof (temp), + "%s/%s/!R-Lock!", pkgdir, pkginst); if (access(temp, 0) == 0) info->status = PI_PARTIAL; } @@ -287,7 +289,7 @@ fpkginst(char *pkg, ...) static char pkginst[PKGSIZ+1]; static DIR *pdirfp; struct dirent64 *dp; - char *pt, *ckarch, *ckvers; + char *ckarch, *ckvers; va_list ap; va_start(ap, pkg); @@ -376,7 +378,8 @@ compver(char *pkginst, char *version) FILE *fp; char temp[256]; - (void) sprintf(temp, "%s/%s/install/compver", get_PKGLOC(), pkginst); + (void) snprintf(temp, sizeof (temp), + "%s/%s/install/compver", get_PKGLOC(), pkginst); if ((fp = fopen(temp, "r")) == NULL) return (-1); @@ -424,7 +427,7 @@ ckinfo(char *inst, char *arch, char *vers) char *pt, *copy, *value, *myarch, *myvers; int errflg; - (void) sprintf(file, "%s/%s/pkginfo", pkgdir, inst); + (void) snprintf(file, sizeof (file), "%s/%s/pkginfo", pkgdir, inst); if ((fp = fopen(file, "r")) == NULL) return (1); diff --git a/usr/src/lib/libadm/common/pkgparam.c b/usr/src/lib/libadm/common/pkgparam.c index d43f717554..cd7cacfd27 100644 --- a/usr/src/lib/libadm/common/pkgparam.c +++ b/usr/src/lib/libadm/common/pkgparam.c @@ -26,6 +26,10 @@ * Use is subject to license terms. */ +/* + * Copyright 2010 Nexenta Systems, Inc. All rights reserved. + */ + /*LINTLIBRARY*/ /* 5-20-92 newroot support added */ @@ -390,12 +394,14 @@ void set_PKGpaths(char *path) { if (path && *path) { - (void) sprintf(Adm_pkgloc, "%s%s", path, PKGLOC); - (void) sprintf(Adm_pkgadm, "%s%s", path, PKGADM); + (void) snprintf(Adm_pkgloc, sizeof (Adm_pkgloc), + "%s%s", path, PKGLOC); + (void) snprintf(Adm_pkgadm, sizeof (Adm_pkgadm), + "%s%s", path, PKGADM); set_install_root(path); } else { - (void) sprintf(Adm_pkgloc, "%s", PKGLOC); - (void) sprintf(Adm_pkgadm, "%s", PKGADM); + (void) snprintf(Adm_pkgloc, sizeof (Adm_pkgloc), "%s", PKGLOC); + (void) snprintf(Adm_pkgadm, sizeof (Adm_pkgadm), "%s", PKGADM); } canonize_name(Adm_pkgloc); canonize_name(Adm_pkgadm); diff --git a/usr/src/lib/libadm/common/putdev.c b/usr/src/lib/libadm/common/putdev.c index 5d0e7dc562..8ca5bd50cb 100644 --- a/usr/src/lib/libadm/common/putdev.c +++ b/usr/src/lib/libadm/common/putdev.c @@ -26,8 +26,10 @@ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ +/* + * Copyright 2010 Nexenta Systems, Inc. All rights reserved. + */ -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */ /* LINTLIBRARY */ /* @@ -78,12 +80,9 @@ * * TDTABNM Name of the temporary device table (in the * directory of the existing table) - * TDTABNMLN Number of characters added to the directory - * name -- the length of the device table temp name */ #define TDTABNM "%sdevtab.%6.6d" -#define TDTABNMLN 13 /* @@ -190,21 +189,20 @@ opennewdevtab(char **pname) /* A(ptr to temp filename's path) */ *(p+1) = '\0'; dirname = oldname; } else dirname = "./"; - if (buf = malloc(TDTABNMLN + strlen(dirname) + 1)) { - - /* - * Build the name of the temp device table and open the - * file. We must reset the owner, group and perms to those - * of the original devtab file. - */ - (void) sprintf(buf, TDTABNM, dirname, getpid()); - if (fp = fopen(buf, "w")) { - *pname = buf; - (void) fchmod(fileno(fp), sbuf.st_mode & 0777); - (void) fchown(fileno(fp), sbuf.st_uid, sbuf.st_gid); - } else { - free(buf); - } + if (asprintf(&buf, TDTABNM, dirname, getpid()) >= 0) { + + /* + * Build the name of the temp device table and + * open the file. We must reset the owner, group + * and perms to those of the original devtab file. + */ + if (fp = fopen(buf, "w")) { + *pname = buf; + (void) fchmod(fileno(fp), sbuf.st_mode & 0777); + (void) fchown(fileno(fp), sbuf.st_uid, sbuf.st_gid); + } else { + free(buf); + } } /* diff --git a/usr/src/lib/libadm/common/putdgrp.c b/usr/src/lib/libadm/common/putdgrp.c index 856a69468a..c103e0ebcf 100644 --- a/usr/src/lib/libadm/common/putdgrp.c +++ b/usr/src/lib/libadm/common/putdgrp.c @@ -26,8 +26,10 @@ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ +/* + * Copyright 2010 Nexenta Systems, Inc. All rights reserved. + */ -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */ /* LINTLIBRARY */ /* @@ -74,12 +76,9 @@ * L O C A L D E F I N I T I O N S * TDGTABNM Name of the temporary device-group table (in the * directory of the existing table) - * TDGTABNMLN Number of characters added to the directory - * name -- the length of the device-group table temp name */ #define TDGTABNM "%sdgroup.%6.6d" -#define TDGTABNMLN 13 /* @@ -137,49 +136,51 @@ opennewdgrptab(char **pname) /* A(ptr to temp filename's path) */ /* Get the name of the device-group table */ if (oldname = _dgrptabpath()) { - /* - * It is possible for us to have sufficient permissions to create - * the new file without having sufficient permissions to write the - * original dgrptab file. For consistency with the operations which - * modify the original file by writing it directly we require write - * permissions for the original file in order to make a new one. - */ - if ((fd = open(oldname, O_WRONLY)) == -1) - return (NULL); + /* + * It is possible for us to have sufficient + * permissions to create the new file without having + * sufficient permissions to write the original + * dgrptab file. For consistency with the operations + * which modify the original file by writing it + * directly we require write permissions for the + * original file in order to make a new one. + */ + if ((fd = open(oldname, O_WRONLY)) == -1) + return (NULL); - if (fstat64(fd, &sbuf) == -1) { + if (fstat64(fd, &sbuf) == -1) { + (void) close(fd); + return (NULL); + } (void) close(fd); - return (NULL); - } - (void) close(fd); - - /* Get the directory that the device-group table lives in */ - if (p = strrchr(oldname, '/')) { - *(p+1) = '\0'; - dirname = oldname; - } else - dirname = "./"; - /* Get space for the temp dgrptab pathname */ - if (buf = malloc(TDGTABNMLN+strlen(dirname)+1)) { + /* Get the directory that the device-group table lives in */ + if (p = strrchr(oldname, '/')) { + *(p+1) = '\0'; + dirname = oldname; + } else + dirname = "./"; - /* - * Build the name of the temp dgrptab and open the - * file. We must reset the owner, group and perms to those - * of the original dgrptab file. - */ - (void) sprintf(buf, TDGTABNM, dirname, getpid()); - if (fp = fopen(buf, "w")) { - *pname = buf; - (void) fchmod(fileno(fp), sbuf.st_mode & 0777); - (void) fchown(fileno(fp), sbuf.st_uid, sbuf.st_gid); - } else { - free(buf); + /* Get space for the temp dgrptab pathname */ + if (asprintf(&buf, TDGTABNM, dirname, getpid()) >= 0) { + /* + * Build the name of the temp dgrptab and open + * the file. We must reset the owner, group + * and perms to those of the original dgrptab + * file. + */ + if (fp = fopen(buf, "w")) { + *pname = buf; + (void) fchmod(fileno(fp), sbuf.st_mode & 0777); + (void) fchown(fileno(fp), sbuf.st_uid, + sbuf.st_gid); + } else { + free(buf); + } } - } - /* Free the space containing the dgrptab's name */ - free(oldname); + /* Free the space containing the dgrptab's name */ + free(oldname); } /* Finished. Return what we've got */ @@ -243,21 +244,26 @@ mknewdgrptab(char *tempname) /* Ptr to name of temp dgrp tab */ /* Get the dgrptab's pathname */ if (dgrpname = _dgrptabpath()) { - /* Unlink the existing file */ - if (unlink(dgrpname) == 0) { + /* Unlink the existing file */ + if (unlink(dgrpname) == 0) { - /* Make the temp file the real device-group table */ - noerr = (link(tempname, dgrpname) == 0) ? TRUE : FALSE; + /* Make the temp file the real device-group table */ + noerr = (link(tempname, dgrpname) == 0) ? TRUE : FALSE; - /* Remove the temp file */ - if (noerr) noerr = rmnewdgrptab(tempname); + /* Remove the temp file */ + if (noerr) + noerr = rmnewdgrptab(tempname); - } else noerr = FALSE; /* unlink() failed */ + } else { + noerr = FALSE; /* unlink() failed */ + } - /* Free the dgrptab's name */ - free(dgrpname); + /* Free the dgrptab's name */ + free(dgrpname); - } else noerr = FALSE; /* dgrptabpath() failed */ + } else { + noerr = FALSE; /* dgrptabpath() failed */ + } /* Finished. Return success indicator */ return (noerr); @@ -297,48 +303,54 @@ lkdgrptab( noerr = TRUE; if (_opendgrptab(o_mode)) { - /* - * Lock the device-group table (for writing). If it's not - * available, wait until it is, then close and open the - * table (modify and delete change the table!) and try - * to lock it again - */ + /* + * Lock the device-group table (for writing). If it's not + * available, wait until it is, then close and open the + * table (modify and delete change the table!) and try + * to lock it again + */ - /* Build the locking structure */ - lockinfo.l_type = lktype; - lockinfo.l_whence = 0; - lockinfo.l_start = 0L; - lockinfo.l_len = 0L; - olderrno = errno; + /* Build the locking structure */ + lockinfo.l_type = lktype; + lockinfo.l_whence = 0; + lockinfo.l_start = 0L; + lockinfo.l_len = 0L; + olderrno = errno; - /* Keep on going until we lock the file or an error happens */ - while ((fcntl(fileno(oam_dgroup), F_SETLK, &lockinfo) == -1) && - !noerr) { + /* Keep on going until we lock the file or an error happens */ + while ((fcntl(fileno(oam_dgroup), F_SETLK, &lockinfo) == -1) && + !noerr) { - /* - * fcntl() failed. - * If errno=EACCES, it's because the file's locked by someone - * else. Wait for the file to be unlocked, then close and - * reopen the file and try the lock again. - */ + /* + * fcntl() failed. If errno=EACCES, it's + * because the file's locked by someone else. + * Wait for the file to be unlocked, then + * close and reopen the file and try the lock + * again. + */ - if (errno == EACCES) { - if (fcntl(fileno(oam_dgroup), F_SETLKW, &lockinfo) == -1) - noerr = FALSE; - else { - _enddgrptab(); - if (!_opendgrptab(o_mode)) noerr = FALSE; - else errno = olderrno; - } + if (errno == EACCES) { + if (fcntl(fileno(oam_dgroup), F_SETLKW, + &lockinfo) == -1) + noerr = FALSE; + else { + _enddgrptab(); + if (!_opendgrptab(o_mode)) + noerr = FALSE; + else + errno = olderrno; + } - } else noerr = FALSE; /* fcntl() failed hard */ + } else + noerr = FALSE; /* fcntl() failed hard */ - } /* End while (fcntl() && !noerr) */ + } /* End while (fcntl() && !noerr) */ - /* Don't keep file open if an error happened */ - if (!noerr) _enddgrptab(); + /* Don't keep file open if an error happened */ + if (!noerr) _enddgrptab(); - } else noerr = FALSE; /* _opendgrptab() failed */ + } else + noerr = FALSE; /* _opendgrptab() failed */ /* Done */ return (noerr); @@ -499,7 +511,8 @@ _putdgrptabrec( /* Comment or data record? */ - if (rec->comment) count = fputs(rec->dataspace, stream); + if (rec->comment) + count = fputs(rec->dataspace, stream); else { /* |