]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - chpass/edit.c
Changes to support full make parallelism (-j<n>) in the world
[pw-darwin.git] / chpass / edit.c
index b0ef308a318871c380250a4075ff3ded53c3b552..ad99822efe1515632a1046c23536e93e66ea289e 100644 (file)
@@ -29,6 +29,8 @@
  * 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$
  */
 
 #ifndef lint
@@ -52,6 +54,9 @@ static char sccsid[] = "@(#)edit.c    8.3 (Berkeley) 4/2/94";
 #include <pw_util.h>
 
 #include "chpass.h"
+#ifdef YP
+#include "pw_yp.h"
+#endif /* YP */
 
 extern char *tempname;
 
@@ -94,8 +99,13 @@ display(fd, pw)
                pw_error(tempname, 1, 1);
 
        (void)fprintf(fp,
+#ifdef YP
+           "#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);
        if (!uid) {
+#endif /* YP */
                (void)fprintf(fp, "Login: %s\n", pw->pw_name);
                (void)fprintf(fp, "Password: %s\n", pw->pw_passwd);
                (void)fprintf(fp, "Uid [#]: %d\n", pw->pw_uid);
@@ -110,11 +120,19 @@ display(fd, pw)
                    *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
        }
        /* Only admin can change "restricted" shells. */
+#ifdef 0
        else if (ok_shell(pw->pw_shell))
                /*
                 * Make shell a restricted field.  Ugly with a
                 * necklace, but there's not much else to do.
                 */
+#else
+       else if ((!list[E_SHELL].restricted && ok_shell(pw->pw_shell)) || !uid)
+               /*
+                * If change not restrict (table.c) and standard shell
+                *      OR if root, then allow editing of shell.
+                */
+#endif
                (void)fprintf(fp, "Shell: %s\n",
                    *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
        else
@@ -126,19 +144,19 @@ display(fd, pw)
          list[E_NAME].save = strdup(p);
        if (!list[E_NAME].restricted || !uid)
          (void)fprintf(fp, "Full Name: %s\n", p ? p : "");
-       
+
         p = strsep(&bp, ",");
        if (p)
          list[E_LOCATE].save = strdup(p);
        if (!list[E_LOCATE].restricted || !uid)
          (void)fprintf(fp, "Location: %s\n", p ? p : "");
-       
+
         p = strsep(&bp, ",");
        if (p)
          list[E_BPHONE].save = strdup(p);
        if (!list[E_BPHONE].restricted || !uid)
          (void)fprintf(fp, "Office Phone: %s\n", p ? p : "");
-       
+
         p = strsep(&bp, ",");
        if (p)
          list[E_HPHONE].save = strdup(p);
@@ -157,8 +175,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);
@@ -168,17 +186,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)) {
@@ -189,7 +209,7 @@ verify(pw)
                                        goto bad;
                                }
                                if (!(p = strchr(buf, ':'))) {
-                                       warnx("line corrupted");
+                                       warnx("line %d corrupted", line);
                                        goto bad;
                                }
                                while (isspace(*++p));
@@ -217,13 +237,18 @@ bad:                                      (void)fclose(fp);
        (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);
 
+       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",
            pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_class,
            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));
 }