diff options
author | Peter Wemm <peter@FreeBSD.org> | 1998-01-26 03:09:57 +0000 |
---|---|---|
committer | Peter Wemm <peter@FreeBSD.org> | 1998-01-26 03:09:57 +0000 |
commit | 57e58c3aa7a2477ce7fa56bfea9d927b4eb43ccd (patch) | |
tree | a9812ba7ade0fde6f62c1626b45d522ba104c314 /contrib/cvs/src/login.c | |
parent | 3398c9be05502e12d986ef6e89739df1dc9ba9e6 (diff) | |
download | src-57e58c3aa7a2477ce7fa56bfea9d927b4eb43ccd.tar.gz src-57e58c3aa7a2477ce7fa56bfea9d927b4eb43ccd.zip |
Import cvs-1.9.23 as at 19980123. There are a number of really nice
things fixed in here, including the '-ko' vs. -A problem with
remote cvs which caused all files with -ko to be resent each time
(which is damn painful over a modem, I can tell you). It also found a
heap of stray empty directories that should have been pruned with the -P
flag to cvs update but were not for some reason.
It also has the fully integrated rcs and diff, so no more fork/exec
overheads for rcs,ci,patch,diff,etc. This means that it parses the control
data in the rcs files only once rather than twice or more.
If the 'cvs diff' vs. Index thing is going to be fixed for future patch
compatability, this is the place to do it.
Notes
Notes:
svn path=/vendor/cvs/dist/; revision=32785
Diffstat (limited to 'contrib/cvs/src/login.c')
-rw-r--r-- | contrib/cvs/src/login.c | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/contrib/cvs/src/login.c b/contrib/cvs/src/login.c index cc277a6ef0de..4ffce36d0fd9 100644 --- a/contrib/cvs/src/login.c +++ b/contrib/cvs/src/login.c @@ -75,6 +75,7 @@ construct_cvspass_filename () static const char *const login_usage[] = { "Usage: %s %s\n", + "(Specify the --help global option for a list of other help options)\n", NULL }; @@ -112,6 +113,7 @@ login (argc, argv) char *linebuf = (char *) NULL; size_t linebuf_len; int root_len, already_entered = 0; + int line_length; if (argc < 0) usage (login_usage); @@ -121,7 +123,7 @@ login (argc, argv) error (0, 0, "can only use pserver method with `login' command"); error (1, 0, "CVSROOT: %s", CVSroot_original); } - + if (! CVSroot_username) { error (0, 0, "CVSROOT \"%s\" is not fully-qualified.", @@ -143,11 +145,7 @@ login (argc, argv) cvs_password = xstrdup (typed_password); - if (connect_to_pserver (NULL, NULL, 1) == 0) - { - /* The password is wrong, according to the server. */ - error (1, 0, "incorrect password"); - } + connect_to_pserver (NULL, NULL, 1, 0); /* IF we have a password for this "[user@]host:/path" already * THEN @@ -171,7 +169,7 @@ login (argc, argv) if (fp != NULL) { /* Check each line to see if we have this entry already. */ - while (getline (&linebuf, &linebuf_len, fp) >= 0) + while ((line_length = getline (&linebuf, &linebuf_len, fp)) >= 0) { if (strncmp (CVSroot_original, linebuf, root_len) == 0) { @@ -179,8 +177,11 @@ login (argc, argv) break; } } - fclose (fp); + if (fclose (fp) < 0) + error (0, errno, "cannot close %s", passfile); } + else if (!existence_error (errno)) + error (0, errno, "cannot open %s", passfile); if (already_entered) { @@ -219,22 +220,35 @@ login (argc, argv) /* I'm not paranoid, they really ARE out to get me: */ chmod (passfile, 0600); - while (getline (&linebuf, &linebuf_len, fp) >= 0) + while ((line_length = getline (&linebuf, &linebuf_len, fp)) >= 0) { if (strncmp (CVSroot_original, linebuf, root_len)) - fprintf (tmp_fp, "%s", linebuf); + { + if (fprintf (tmp_fp, "%s", linebuf) == EOF) + error (0, errno, "cannot write %s", tmp_name); + } else - fprintf (tmp_fp, "%s %s\n", CVSroot_original, - typed_password); - + { + if (fprintf (tmp_fp, "%s %s\n", CVSroot_original, + typed_password) == EOF) + error (0, errno, "cannot write %s", tmp_name); + } } + if (line_length < 0 && !feof (fp)) + error (0, errno, "cannot read %s", passfile); if (linebuf) free (linebuf); - fclose (tmp_fp); - fclose (fp); + if (fclose (tmp_fp) < 0) + error (0, errno, "cannot close %s", tmp_name); + if (fclose (fp) < 0) + error (0, errno, "cannot close %s", passfile); + + /* FIXME: rename_file would make more sense (e.g. almost + always faster). */ copy_file (tmp_name, passfile); unlink_file (tmp_name); chmod (passfile, 0600); + free (tmp_name); } } @@ -249,8 +263,10 @@ login (argc, argv) return 1; } - fprintf (fp, "%s %s\n", CVSroot_original, typed_password); - fclose (fp); + if (fprintf (fp, "%s %s\n", CVSroot_original, typed_password) == EOF) + error (0, errno, "cannot write %s", passfile); + if (fclose (fp) < 0) + error (0, errno, "cannot close %s", passfile); } /* Utter, total, raving paranoia, I know. */ @@ -276,6 +292,7 @@ get_cvs_password () size_t linebuf_len; FILE *fp; char *passfile; + int line_length; /* If someone (i.e., login()) is calling connect_to_pserver() out of context, then assume they have supplied the correct, scrambled @@ -324,7 +341,7 @@ get_cvs_password () root_len = strlen (CVSroot_original); /* Check each line to see if we have this entry already. */ - while (getline (&linebuf, &linebuf_len, fp) >= 0) + while ((line_length = getline (&linebuf, &linebuf_len, fp)) >= 0) { if (strncmp (CVSroot_original, linebuf, root_len) == 0) { @@ -333,6 +350,10 @@ get_cvs_password () break; } } + if (line_length < 0 && !feof (fp)) + error (0, errno, "cannot read %s", passfile); + if (fclose (fp) < 0) + error (0, errno, "cannot close %s", passfile); if (found_it) { @@ -362,6 +383,7 @@ get_cvs_password () static const char *const logout_usage[] = { "Usage: %s %s\n", + "(Specify the --help global option for a list of other help options)\n", NULL }; @@ -378,6 +400,7 @@ logout (argc, argv) char *linebuf = (char *) NULL; size_t linebuf_len; int root_len, found = 0; + int line_length; if (argc < 0) usage (logout_usage); @@ -430,17 +453,25 @@ logout (argc, argv) /* Check each line to see if we have this entry. */ /* Copy only those lines that do not match this entry */ - while (getline (&linebuf, &linebuf_len, fp) >= 0) + while ((line_length = getline (&linebuf, &linebuf_len, fp)) >= 0) { - if (strncmp (CVSroot_original, linebuf, root_len)) - fprintf (tmp_fp, "%s", linebuf); + if (strncmp (CVSroot_original, linebuf, root_len)) + { + if (fprintf (tmp_fp, "%s", linebuf) == EOF) + error (0, errno, "cannot write %s", tmp_name); + } else - found = TRUE; + found = 1; } + if (line_length < 0 && !feof (fp)) + error (0, errno, "cannot read %s", passfile); + if (linebuf) free (linebuf); - fclose (fp); - fclose (tmp_fp); + if (fclose (fp) < 0) + error (0, errno, "cannot close %s", passfile); + if (fclose (tmp_fp) < 0) + error (0, errno, "cannot close %s", tmp_name); if (! found) { @@ -449,6 +480,8 @@ logout (argc, argv) } else { + /* FIXME: rename_file would make more sense (e.g. almost + always faster). */ copy_file (tmp_name, passfile); unlink_file (tmp_name); chmod (passfile, 0600); |