From a149d1dc255e519e85e796b63dc651387fd0d06a Mon Sep 17 00:00:00 2001 From: msw Date: Mar 17 1999 17:39:12 +0000 Subject: fixed /etc/yp.conf, restarts ypbind --- diff --git a/authconfig.c b/authconfig.c index ec39906..0d1eda4 100644 --- a/authconfig.c +++ b/authconfig.c @@ -454,84 +454,93 @@ int rewriteNetworkConfigFile(char enableNis, char *nisDomain) * this function will rewrite /etc/sysconfig/yp.conf to have the new * value for ypserver. If enableNisServer == ' ', removes this field. */ -int rewriteYPConfigFile(char enableNisServer, char *nisServer, char *nisDomain) +int rewriteYPConfigFile(char enableNis, char enableNisServer, + char *nisServer, char *nisDomain) { FILE *f, *f1; char *s, *s2; char buf[250]; int line = 0; - int found = 0; + int ypserverFound = 0, serverFound = 0, domainFound = 0; f = fopen("/etc/yp.conf", "r"); if (!f) { - fprintf(stderr, i18n("%s: cannot open /etc/yp.conf: %s\n"), - progName, strerror(errno)); - return 1; + fprintf(stderr, i18n("%s: cannot open /etc/yp.conf: %s\n"), + progName, strerror(errno)); + return 1; } - + f1 = fopen("/etc/yp.conf-", "w"); if (!f) { - fprintf(stderr, i18n("%s: cannot open /etc/yp.conf- for writing: %s\n"), - progName, strerror(errno)); - return 1; + fprintf(stderr, i18n("%s: cannot open /etc/yp.conf- for writing: %s\n"), + progName, strerror(errno)); + return 1; } - + while ((s2 = fgets(buf, sizeof(buf) - 1, f)) != NULL) { - s = s2; - line++; - - /* first, skip over any leading whitespace and blank lines */ - while (*s && isspace(*s)) - s++; - if (!*s) { - fprintf(f1, s2); - continue; - } - - /* next, skip any lines that are comments */ - if (*s == '#') { - fprintf(f1, s2); - continue; - } - - /* look for the line we want */ - if (!strncmp("ypserver ", s, 9)) { - /* - * OK, now instead of this line we want to write the new line, - * if enableNisServer is '*'. - */ - if (enableNisServer == '*') { - fprintf(f1,"ypserver %s\n",nisServer); - found = 1; + s = s2; + line++; + + /* first, skip over any leading whitespace and blank lines */ + while (*s && isspace(*s)) + s++; + if (!*s) { + fprintf(f1, s2); + continue; } - } else if (!strncmp("server ", s, 7)) { - if (enableNisServer == '*') { - fprintf(f1, "server %s\n",nisServer); - found = 1; + + /* next, skip any lines that are comments */ + if (*s == '#') { + fprintf(f1, s2); + continue; } - } else if (!strncmp("domain ", s, 7)) { - if (enableNisServer == '*') { - fprintf(f1, "domain %s\n",nisDomain); - found = 1; + + if (enableNis == ' ') + continue; + + /* look for the line we want */ + if (!strncmp("ypserver ", s, 9)) { + /* + * OK, now instead of this line we want to write the new line, + * if enableNisServer is '*'. + */ + if (enableNisServer == '*') { + fprintf(f1,"ypserver %s\n",nisServer); + ypserverFound = 1; + } + } else if (!strncmp("server ", s, 7)) { + if (enableNisServer == '*') { + fprintf(f1, "server %s\n",nisServer); + serverFound = 1; + } + } else if (!strncmp("domain ", s, 7)) { + if (enableNisServer == '*') { + fprintf(f1, "domain %s\n",nisDomain); + domainFound = 1; + } + } else { + fprintf(f1, s2); } - } else { - fprintf(f1, "%s",s2); - } } - + /* * here, we write the value if we haven't done so already (it is a new * value for the config file...) */ - if (!found && enableNisServer == '*') { - fprintf(f1, "domain %s\n",nisDomain); - fprintf(f1, "server %s\n",nisServer); - fprintf(f1, "ypserver %s\n",nisServer); - } + if (enableNis == '*') { + if (!serverFound && enableNisServer == '*') + fprintf(f1, "server %s\n",nisServer); + if (!ypserverFound && enableNisServer == '*') + fprintf(f1, "ypserver %s\n",nisServer); + if (!domainFound) + fprintf(f1, "domain %s %s\n",nisDomain, + enableNisServer == ' ' ? "broadcast" : ""); + } + fclose(f); fclose(f1); - + /* rename the temporary file */ unlink("/etc/yp.conf"); rename("/etc/yp.conf-", "/etc/yp.conf"); @@ -548,7 +557,7 @@ int toggleNisService(char enableNis, int nostart) { if (enableNis == '*') { if (!nostart) - system("/etc/rc.d/init.d/ypbind start"); + system("/etc/rc.d/init.d/ypbind restart"); system("/sbin/chkconfig --level 345 ypbind on"); } else { if (!nostart) @@ -839,7 +848,8 @@ int main(int argc, char **argv) { } if (configureNis) { - if (rewriteYPConfigFile(enableNisServer, nisServer, nisDomain)) { + if (rewriteYPConfigFile(enableNis, enableNisServer, + nisServer, nisDomain)) { fprintf(stderr, i18n("%s: critical error writing /etc/yp.conf\n"), progName); return 2; diff --git a/authconfig.spec b/authconfig.spec index 1e568f0..93cf792 100644 --- a/authconfig.spec +++ b/authconfig.spec @@ -1,8 +1,8 @@ Summary: Text-mode tool for setting up NIS and shadow passwords. Name: authconfig -%define version 1.3 +%define version 1.4 Version: %{version} -Release: 2 +Release: 1 Copyright: GPL ExclusiveOS: Linux Group: System Environment/Base @@ -33,6 +33,10 @@ rm -rf $RPM_BUILD_ROOT #%attr(-,root,root)/usr/share/locale/*/LC_MESSAGES/authconfig.mo %changelog +* Wed Mar 17 1999 Matt Wilson +- fixed rewriting /etc/yp.conf +- restarts ypbind so that new changes take effect + * Mon Mar 15 1999 Matt Wilson - just make the NIS part of configuration grayed out if NIS is not installed diff --git a/po/authconfig.pot b/po/authconfig.pot index 2c99758..3e78a4d 100644 --- a/po/authconfig.pot +++ b/po/authconfig.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 1999-03-15 22:17-0500\n" +"POT-Creation-Date: 1999-03-17 12:37-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -19,7 +19,7 @@ msgstr "" msgid "%s: cannot open /etc/sysconfig/network: %s\n" msgstr "" -#: ../authconfig.c:96 ../authconfig.c:467 +#: ../authconfig.c:96 ../authconfig.c:468 #, c-format msgid "%s: cannot open /etc/yp.conf: %s\n" msgstr "" @@ -93,17 +93,17 @@ msgstr "" msgid "%s: cannot open /etc/sysconfig/network- for writing: %s\n" msgstr "" -#: ../authconfig.c:474 +#: ../authconfig.c:475 #, c-format msgid "%s: cannot open /etc/yp.conf- for writing: %s\n" msgstr "" -#: ../authconfig.c:643 +#: ../authconfig.c:652 #, c-format msgid "%s: error opening %s\n" msgstr "" -#: ../authconfig.c:677 +#: ../authconfig.c:686 #, c-format msgid "" "Usage: %s [options]\n" @@ -118,68 +118,68 @@ msgid "" " --help show this screen\n" msgstr "" -#: ../authconfig.c:731 +#: ../authconfig.c:740 #, c-format msgid "%s: bad argument %s: %s\n" msgstr "" -#: ../authconfig.c:738 +#: ../authconfig.c:747 #, c-format msgid "%s: unexpected argument\n" msgstr "" -#: ../authconfig.c:750 +#: ../authconfig.c:759 #, c-format msgid "%s: can only be run as root\n" msgstr "" -#: ../authconfig.c:765 +#: ../authconfig.c:774 #, c-format msgid "%s: critical error reading /etc/sysconfig/network" msgstr "" -#: ../authconfig.c:778 +#: ../authconfig.c:787 #, c-format msgid "%s: critical error reading /etc/yp.conf" msgstr "" -#: ../authconfig.c:795 +#: ../authconfig.c:804 #, c-format msgid "%s: critical error reading /etc/pam.d/passwd\n" msgstr "" -#: ../authconfig.c:804 +#: ../authconfig.c:813 msgid "" " / between elements | selects | next " "screen" msgstr "" -#: ../authconfig.c:815 +#: ../authconfig.c:824 #, c-format msgid "%s: nis domain was set to %s, but dialog was cancelled\n" msgstr "" -#: ../authconfig.c:828 +#: ../authconfig.c:837 #, c-format msgid "return values: nis: %c, nisdomain: %s, shadow: %c, md5: %c\n" msgstr "" -#: ../authconfig.c:836 +#: ../authconfig.c:845 #, c-format msgid "%s: critical error writing /etc/sysconfig/network\n" msgstr "" -#: ../authconfig.c:843 +#: ../authconfig.c:853 #, c-format msgid "%s: critical error writing /etc/yp.conf\n" msgstr "" -#: ../authconfig.c:851 +#: ../authconfig.c:861 #, c-format msgid "%s: critical error turning on NIS service\n" msgstr "" -#: ../authconfig.c:858 +#: ../authconfig.c:868 #, c-format msgid "%s: critical error with shadow password manipulation\n" msgstr ""