]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - chpass/edit.c
Close PR #10264. Don't bail directly out of passwd/chpass in my_yp_match().
[pw-darwin.git] / chpass / edit.c
index 2968c84fa3d4d0baf2d588d5af468d1bad3ce677..83cd2c8b786127ac7b3e206a21aded77ef7a8efe 100644 (file)
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ *     $Id: edit.c,v 1.12 1998/12/06 22:58:14 archie Exp $
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)edit.c     8.3 (Berkeley) 4/2/94";
+static const char sccsid[] = "@(#)edit.c       8.3 (Berkeley) 4/2/94";
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -101,7 +103,7 @@ display(fd, pw)
            "#Changing %s information for %s.\n", _use_yp ? "NIS" : "user database", pw->pw_name);
        if (!uid && (!_use_yp || suser_override)) {
 #else
-           "#Changing user database information for %s.\n", pw->pw_name)
+           "#Changing user database information for %s.\n", pw->pw_name);
        if (!uid) {
 #endif /* YP */
                (void)fprintf(fp, "Login: %s\n", pw->pw_name);
@@ -147,7 +149,7 @@ display(fd, pw)
        if (p)
          list[E_LOCATE].save = strdup(p);
        if (!list[E_LOCATE].restricted || !uid)
-         (void)fprintf(fp, "Location: %s\n", p ? p : "");
+         (void)fprintf(fp, "Office Location: %s\n", p ? p : "");
 
         p = strsep(&bp, ",");
        if (p)
@@ -161,6 +163,11 @@ display(fd, pw)
        if (!list[E_HPHONE].restricted || !uid)
          (void)fprintf(fp, "Home Phone: %s\n", p ? p : "");
 
+       if (bp!=NULL)
+         list[E_OTHER].save = strdup(bp);
+       if (!list[E_OTHER].restricted || !uid)
+         (void)fprintf(fp, "Other information: %s\n", bp ? bp : "");
+
        (void)fchown(fd, getuid(), getgid());
        (void)fclose(fp);
 }
@@ -173,8 +180,8 @@ verify(pw)
        char *p;
        struct stat sb;
        FILE *fp;
-       int len;
-       char buf[LINE_MAX];
+       int len, line;
+       static char buf[LINE_MAX];
 
        if (!(fp = fopen(tempname, "r")))
                pw_error(tempname, 1, 1);
@@ -184,17 +191,19 @@ verify(pw)
                warnx("corrupted temporary file");
                goto bad;
        }
+       line = 0;
        while (fgets(buf, sizeof(buf), fp)) {
+               line++;
                if (!buf[0] || buf[0] == '#')
                        continue;
                if (!(p = strchr(buf, '\n'))) {
-                       warnx("line too long");
+                       warnx("line %d too long", line);
                        goto bad;
                }
                *p = '\0';
                for (ep = list;; ++ep) {
                        if (!ep->prompt) {
-                               warnx("unrecognized field");
+                               warnx("unrecognized field on line %d", line);
                                goto bad;
                        }
                        if (!strncasecmp(buf, ep->prompt, ep->len)) {
@@ -205,7 +214,7 @@ verify(pw)
                                        goto bad;
                                }
                                if (!(p = strchr(buf, ':'))) {
-                                       warnx("line corrupted");
+                                       warnx("line %d corrupted", line);
                                        goto bad;
                                }
                                while (isspace(*++p));
@@ -227,11 +236,16 @@ bad:                                      (void)fclose(fp);
 
        /* Build the gecos field. */
        len = strlen(list[E_NAME].save) + strlen(list[E_BPHONE].save) +
-           strlen(list[E_HPHONE].save) + strlen(list[E_LOCATE].save) + 4;
+           strlen(list[E_HPHONE].save) + strlen(list[E_LOCATE].save) +
+           strlen(list[E_OTHER].save) + 4;
        if (!(p = malloc(len)))
                err(1, NULL);
-       (void)sprintf(pw->pw_gecos = p, "%s,%s,%s,%s", list[E_NAME].save,
-           list[E_LOCATE].save, list[E_BPHONE].save, list[E_HPHONE].save);
+       (void)sprintf(pw->pw_gecos = p, "%s,%s,%s,%s,%s", list[E_NAME].save,
+           list[E_LOCATE].save, list[E_BPHONE].save, list[E_HPHONE].save,
+           list[E_OTHER].save);
+
+       while ((len = strlen(pw->pw_gecos)) && pw->pw_gecos[len - 1] == ',')
+               pw->pw_gecos[len - 1] = '\0';
 
        if (snprintf(buf, sizeof(buf),
            "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s",
@@ -239,7 +253,9 @@ bad:                                        (void)fclose(fp);
            pw->pw_change, pw->pw_expire, pw->pw_gecos, pw->pw_dir,
            pw->pw_shell) >= sizeof(buf)) {
                warnx("entries too long");
+               free(p);
                return (0);
        }
+       free(p);
        return (pw_scan(buf, pw));
 }