NIS on Ubuntu: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Document the Ubuntu NIS tools segfault (LP #1204530) + the Python GDBM map-build workaround (verified on 24.04))
 
(Document the Ubuntu NIS tools segfault (LP #1204530) + the Python GDBM map-build workaround (verified on 24.04))
 
Line 21: Line 21:
== The Problem ==
== The Problem ==
On Ubuntu, the standard NIS master setup fails in two independent ways:
On Ubuntu, the standard NIS master setup fails in two independent ways:
# `E: Unable to locate package ypserv-source` — the `ypserv-source` package (Debian-only) does not exist on Ubuntu, so the 메이크 기반 맵 빌드 (`[[make]] -C /var/yp`) fails.
# `E: Unable to locate package ypserv-source` — the `ypserv-source` package (Debian-only) does not exist on Ubuntu, so the 메이크 기반 맵 빌드 명령이 실패합니다.
# `ypinit` / `makedbm` / `yppasswd` **segfault** — even with a full `PATH` and a static `/etc/resolv.conf`. `[[strace]]` 추적이 보여 `openat(/etc/resolv.conf)` → a query → `SIGSEGV (SEGV_MAPERR, NULL)`.
# `ypinit` / `makedbm` / `yppasswd` **segfault** — even with a full `PATH` and a static `/etc/resolv.conf`. 시스템 콜 추적이 보여 `openat(/etc/resolv.conf)` → a query → `SIGSEGV (SEGV_MAPERR, NULL)`.


== Root Cause ==
== Root Cause ==

Latest revision as of 10:00, 24 November 2026

NIS on Ubuntu

Overview

Setting up a NIS (네트워크 정보 서비스) master on Ubuntu (22.04 / 24.04). This page documents a known bug in the stock NIS tools on Ubuntu and the verified, non-invasive workaround: building the NIS maps with Python.

Summary

  • What: how to set up a working single-node NIS master on Ubuntu, given that the stock tools (`ypinit`, `makedbm`) are broken there.
  • Why: on Ubuntu the NIS C tools **segfault** (a 리졸버/NSS 라이브러리 버그) and the `ypserv-source` package (the 메이크 기반 맵 소스) **does not exist**, so the standard setup fails.
  • When: deploying NIS (`ypserv`) on Ubuntu 22.04 / 24.04.

Purpose

  • Goal: give operators a verified way to build a working NIS master on Ubuntu without modifying 시스템 네트워크 이름 체계.
  • Scope: single-node NIS master (`ypserv` + `ypbind`) on Ubuntu.
  • Non-goals: NIS replication, NIS+, client-only setup.

Investigation info

  • Investigated: 2026-11-24
  • Source: HPCMATE `nismaster` module debugging on an Ubuntu 24.04 (noble) host
  • Next review: on the next Ubuntu release (25.04)

The Problem

On Ubuntu, the standard NIS master setup fails in two independent ways:

  1. `E: Unable to locate package ypserv-source` — the `ypserv-source` package (Debian-only) does not exist on Ubuntu, so the 메이크 기반 맵 빌드 명령이 실패합니다.
  2. `ypinit` / `makedbm` / `yppasswd` **segfault** — even with a full `PATH` and a static `/etc/resolv.conf`. 시스템 콜 추적이 보여 `openat(/etc/resolv.conf)` → a query → `SIGSEGV (SEGV_MAPERR, NULL)`.

Root Cause

The segfault is a known 라이브러리 버그 (Launchpad #1204530 and kin): the NIS C tools load `libresolv` and, when they resolve a name, the 라이브러리 touches **uninitialized data** and the process crashes. This is not fixable by editing `/etc/hosts`, `/etc/resolv.conf`, or the `PATH` — so the only robust fix is to **not run the C tools**.

Two smaller issues also bite on Ubuntu:

  • `systemctl enable nis` fails — the `nis` package provides no `nis.service` unit; the real daemons are `ypserv` + `ypbind`.
  • A shell redirect `printf ... > /etc/yp.conf` run through `sudo` fails with `Permission denied` (the `>` runs in the unprivileged shell). Use `| tee /etc/yp.conf` instead.

The Solution — build the maps with Python (GDBM)

The `makedbm` output format is **GDBM** (per the `makedbm(8)` manpage: "GDBM is used as database"). Python's `dbm.gnu` writes the same GDBM format, so `ypserv` reads it fine. Each line of `/etc/<map>` becomes one record: **key = first colon field** (username / groupname), **data = the full line** (exactly what `ypcat` prints).

The writer is sent as base64 (avoids every quoting/escaping issue over the SSH channel) and run as root:

import base64
script = (
    'import dbm.gnu as dbm, os\n'
    'DOMAIN = "{domain}"; d = "/var/yp/" + DOMAIN\n'
    'os.makedirs(d, exist_ok=True)\n'
    'for f in os.listdir(d): os.remove(os.path.join(d, f))\n'
    'for m in ("passwd", "group", "shadow"):\n'
    '    src = "/etc/" + m\n'
    '    if not os.path.exists(src): continue\n'
    '    db = dbm.open(d + "/" + m, "n"); n = 0\n'
    '    for line in open(src):\n'
    '        line = line.rstrip("\n")\n'
    '        if not line or line.startswith("#"): continue\n'
    '        db[line.split(":", 1)[0]] = line; n += 1\n'
    '    db.close(); print("built " + m + " (" + str(n) + ")")\n'
).format(domain=DOMAIN)
enc = base64.b64encode(script.encode()).decode()
run_remote("echo " + enc + " | base64 -d | sudo python3 2>&1 || true")

Full Ubuntu recipe (verified on 24.04 / noble)

  1. Install: `apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y ypserv nis python3` (no `ypserv-source`).
  2. Pre-seed `nis` debconf (master role + domain) before install so it stays non-interactive.
  3. `/etc/default/nis`: `NISDOMAIN=<domain>`, `NISSERVER=master`, `NISCLIENT=false` (via `| tee`).
  4. `/etc/hosts`: ensure `<master_ip> <master_name>` is present.
  5. `/etc/yp.conf`: explicit `domain <domain>` + `ypserver <master_ip>` (via `| tee`, NOT `>`). The explicit `domain` line matters — otherwise the yp tools fall back to 커널 도메인.
  6. Build the maps with the Python GDBM writer above.
  7. nsswitch: add `nis` to the `passwd` / `group` / `shadow` lines (idempotent, local-first).
  8. `systemctl enable rpcbind ypserv ypbind && systemctl start rpcbind ypserv ypbind`.
  9. Verify: `ypwhich` returns the master IP and `ypcat passwd` lists users.

Verification

Command Expected (success) Failure means
`sudo ypwhich` returns the master IP `Domain not bound` = maps missing
head` lists real users empty = maps not built

Pitfalls

  • Do not try to "fix" the segfault via `/etc/hosts` / `/etc/resolv.conf` / the `PATH` — it is a `libresolv`/라이브러리 버그; none of that helps. Bypass the C tools.
  • `dbm.gnu.open(path, "n")` creates a single-file GDBM db (no `.dir` / `.pag`); the magic is confirmed readable by `ypserv`.
  • Key = first colon field; data = the whole line (not the remainder after the colon).
  • Rebuilding is idempotent: clear the directory, then rewrite.
  • The map build is non-invasive — it only writes files under `/var/yp/<domain>/`; it does not touch 네트워크 이름 체계나 리졸버.

References

Related Pages