Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,9 @@ install(PROGRAMS ${CMAKE_SOURCE_DIR}/packaging/dataserver/ecce-server-tui
install(DIRECTORY ${CMAKE_SOURCE_DIR}/packaging/dataserver/tui/ecce_server_tui
DESTINATION lib
COMPONENT tui)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/packaging/dataserver/ecce-change-password
DESTINATION server/cgi-bin
COMPONENT server)
install(FILES ${CMAKE_SOURCE_DIR}/packaging/dataserver/httpd.conf.ecce
DESTINATION server/httpd-conf
COMPONENT server)
Expand Down
11 changes: 8 additions & 3 deletions docs/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,14 @@ on that server. It is saved with the server entry and included when exporting
or importing a JSON configuration profile; connecting still prompts for that
account's password. Profiles do not include passwords. The Organizer hook
`prefs data cert PEM [PNG]` loads a certificate for the first listed HTTPS
server and reports `loaded:<installed pin path>` or an error.
server and reports `loaded:<installed pin path>` or an error. Select an HTTPS
ECCE server and choose **Change Password** to set a new password; the dialog
checks the current password through the server's TLS-authenticated endpoint
and updates this session's cached credential after success. The button is
disabled without a selected HTTPS ECCE server.
`tests/apps/prefs_data_test.py` (ctest `apps_prefs_data`) covers the data server
dialog, username persistence, and valid or invalid certificate files.
dialog, username persistence, button enablement, and valid or invalid
certificate files.

### Portable configuration profiles and server administration

Expand Down Expand Up @@ -2146,7 +2151,7 @@ calculation.
| `ecce-diagnose [-o directory] [run-directory]` | Collects what is needed to diagnose a problem into one text file, `ecce-diagnostics-<host>-<time>.txt`; on macOS it also copies the newest five crash reports of ECCE's programs from the last 7 days (`~/Library/Logs/DiagnosticReports`, `/Library/Logs/DiagnosticReports`) into `crash-reports/` beside it. Help > Report a Problem... logs each step on stderr as `Report a Problem: ...` (Organizer hook `reportproblem`). Changes nothing and collects no passwords, but the file holds host names, user names and paths: read it before attaching it to an issue. `ecce --bug` runs it too |
| `ecce-remote-setup <server-host> [data-port]` | Points this client installation at a central server; run once per client installation, as the owner of the installation. Users then start `ecce -remote` |
| `ecce-dataserver-start`, `ecce-dataserver-status`, `ecce-dataserver-stop` | Start, check and stop this user's data server (`ecce-dataserver-stop --if-unused` refuses while another session or a job still uses it) |
| `ecce-dataserver-adduser` | Add an account to this user's data server (`-b USER PASS [FIRST] [LAST]` or `--stdin USER [FIRST] [LAST]` without prompts) |
| `ecce-dataserver-adduser` | Add an account to this user's data server (`-b USER PASS [FIRST] [LAST]` or `--stdin USER [FIRST] [LAST]` without prompts); `--passwd USER` changes an existing account's password from stdin or interactively |
| `ecce-site-publish [DIR]` | Copy this install's site machine list to where the data server serves it to `-remote` clients |

## Checking a result
Expand Down
9 changes: 9 additions & 0 deletions docs/claude/services/packaging-dataserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ issues: []
`httpd.conf.ecce`), the WebDAV "ECCE Server" — structure library,
basis-set library, saved calculation data, and (as of this fork) help
content and the help CGI backend all served from here, port 8096.

The package also installs `ecce-change-password` under `$ECCE_HOME/server/cgi-bin`
and copies it into each server owner's `~/.ECCE/dataserver/cgi-bin`. Apache
exposes it only when TLS is configured, requires Basic authentication against
that data server's `users` file, and
the handler runs `ecce-dataserver-adduser --passwd REMOTE_USER` with the new
password on stdin. The old password is checked by Apache before the CGI runs.
`ecce-dataserver-start` refreshes this package-managed CGI on each invocation
so server package upgrades reach existing data-server directories.
8 changes: 6 additions & 2 deletions docs/claude/services/per-user-server-offers-an-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ only), then logs in with it. The password goes on stdin, never argv (`-b`
shows it in `ps`); the tool's stderr is shown on failure. A central server
(`ECCE_REMOTE_SERVER`) is never offered either: its accounts are the
administrator's, and a refused login there names the administrator's command
`ecce-dataserver-adduser --passwd NAME`. The per-user broker is a Unix socket
and anonymous, so there is no second password list.
`ecce-dataserver-adduser --passwd NAME`. For a TLS-enabled packaged server,
the separate `/cgi-bin/ecce-change-password` endpoint authenticates the
user's current password through Apache and then calls
`ecce-dataserver-adduser --passwd USER` with the new password on stdin. The
per-user broker is a Unix socket and anonymous, so there is no second password
list.
Test hooks: `ECCE_TEST_AUTH_ANSWER=login:USER:PASS` fills the login window
and answers Yes; `=reset:USER:PASS` presses Forgot password... once and
enters PASS; both log `reset offered|not offered` and a refused login's
Expand Down
6 changes: 6 additions & 0 deletions docs/claude/services/prefs-data-hook-preserves-paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ into a nonexistent directory. The first `snap` returns `not saved`; a failed
save inside the Add Server modal dialog can leave subsequent commands with
no answer. This is a path parsing failure, not a missing Data page.

The hook also supports `prefs data select NAME` for selecting a server row
and reporting whether **Change Password** is enabled, plus
`prefs data password-button` to report its current enablement. Only HTTPS
ECCE server rows enable the action; SSH folders and unselected rows leave it
disabled.

The defect was present when the hook was introduced in `a8df2a960`.
`apps_prefs_data` includes an underscore-containing screenshot filename;
setting `ECCE_SHOTS_DIR` to a directory containing underscores exercises the
Expand Down
2 changes: 2 additions & 0 deletions include/wxgui/GlobalPrefs.H
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private:
void OnAddServer(wxCommandEvent& event);
void OnEditServer(wxCommandEvent& event);
void OnRemoveServer(wxCommandEvent& event);
void OnChangeServerPassword(wxCommandEvent& event);
void OnServerSelect(wxListEvent& event);
bool loadServerCertificate(const string& address, const string& path,
string& error);
Expand Down Expand Up @@ -177,6 +178,7 @@ private:
ewxButton* p_addServer;
ewxButton* p_editServer;
ewxButton* p_removeServer;
ewxButton* p_changeServerPassword;
ewxButton* p_saveConfiguration;
ewxButton* p_loadConfiguration;

Expand Down
118 changes: 118 additions & 0 deletions packaging/dataserver/ecce-change-password
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env python3
"""Authenticated HTTPS endpoint for changing the current ECCE account password.

Apache authenticates REMOTE_USER against the data server's users file before
this CGI runs. The new password arrives in a small JSON POST body and is
passed to ecce-dataserver-adduser over stdin, never in argv or a URL.
"""

import json
import os
from pathlib import Path
import re
import subprocess
import sys


MAX_BODY = 16384
MAX_PASSWORD_BYTES = 4096
USER_RE = re.compile(r"^[A-Za-z0-9]+$")


def respond(status, message=""):
body = json.dumps({"ok": status == 200, "message": message}).encode("utf-8")
sys.stdout.buffer.write(
("Status: %d\r\n" % status).encode("ascii")
+ b"Content-Type: application/json; charset=utf-8\r\n"
+ b"Cache-Control: no-store\r\n"
+ b"Content-Length: %d\r\n\r\n" % len(body)
+ body
)


def main():
if os.environ.get("HTTPS", "").lower() != "on":
respond(403, "Password changes require HTTPS.")
return
if os.environ.get("REQUEST_METHOD", "") != "POST":
respond(405, "POST required.")
return

user = os.environ.get("REMOTE_USER", "")
if not USER_RE.fullmatch(user):
respond(401, "Authentication required.")
return

content_type = os.environ.get("CONTENT_TYPE", "").split(";", 1)[0].strip().lower()
if content_type != "application/json":
respond(415, "Content-Type must be application/json.")
return
try:
length = int(os.environ.get("CONTENT_LENGTH", ""))
except ValueError:
length = -1
if length <= 0 or length > MAX_BODY:
respond(413, "Invalid request size.")
return

raw = sys.stdin.buffer.read(length)
if len(raw) != length:
respond(400, "Incomplete request body.")
return
try:
payload = json.loads(raw.decode("utf-8"))
except (UnicodeDecodeError, json.JSONDecodeError):
respond(400, "Invalid JSON request.")
return
if not isinstance(payload, dict) or set(payload) != {"newPassword"}:
respond(400, "Expected a newPassword field.")
return
password = payload["newPassword"]
if not isinstance(password, str):
respond(400, "The new password must be text.")
return
try:
encoded = password.encode("utf-8")
except UnicodeEncodeError:
respond(400, "The new password is invalid.")
return
if (not encoded or len(encoded) > MAX_PASSWORD_BYTES or "\n" in password
or "\r" in password or "\x00" in password):
respond(400, "The new password is empty or invalid.")
return

ecce_home = os.environ.get("ECCE_HOME", "/opt/ecce")
helper = os.path.join(ecce_home, "bin", "ecce-dataserver-adduser")
if not os.path.isfile(helper) or not os.access(helper, os.X_OK):
respond(503, "Password changes are not available on this server.")
return

# The CGI lives at ~/.ECCE/dataserver/cgi-bin/ecce-change-password.
# Derive the owner's home rather than trusting Apache's possibly unset
# or generic HOME environment variable.
user_home = str(Path(__file__).resolve().parents[3])
env = os.environ.copy()
env["HOME"] = user_home
env["ECCE_REALUSERHOME"] = user_home
try:
result = subprocess.run(
[helper, "--passwd", user],
input=encoded + b"\n",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=30,
env=env,
check=False,
)
except (OSError, subprocess.TimeoutExpired):
respond(500, "The password could not be changed.")
return
if result.returncode != 0:
# Avoid exposing account-file or helper details to remote callers.
respond(400, "The password could not be changed.")
return
respond(200, "Password changed.")


if __name__ == "__main__":
main()
20 changes: 18 additions & 2 deletions packaging/dataserver/ecce-dataserver-start
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,27 @@ mkdir -p "$STATEDIR/logs" "$STATEDIR/cgi-bin"
# attempted). Use ecce-dataserver-adduser to actually add an account.
[ -f "$STATEDIR/users" ] || : > "$STATEDIR/users"

# The password-change CGI is package-managed and refreshed on every start,
# including when Apache is already running. Requests execute it per
# invocation, and the handler keeps no state.
PASSWORD_CGI_SRC="$ECCE_HOME/server/cgi-bin/ecce-change-password"
if [ -x "$PASSWORD_CGI_SRC" ]; then
if ! cmp -s "$PASSWORD_CGI_SRC" "$STATEDIR/cgi-bin/ecce-change-password"; then
if ! cp "$PASSWORD_CGI_SRC" "$STATEDIR/cgi-bin/ecce-change-password.new" ||
! chmod 755 "$STATEDIR/cgi-bin/ecce-change-password.new" ||
! mv -f "$STATEDIR/cgi-bin/ecce-change-password.new" \
"$STATEDIR/cgi-bin/ecce-change-password"; then
rm -f "$STATEDIR/cgi-bin/ecce-change-password.new"
echo "ecce-dataserver-start: could not install the password-change CGI" >&2
exit 1
fi
fi
fi

# Seed the context-sensitive help CGI scripts (toolhelp/cshelp -- see
# CMakeLists.txt's ecce_help_cgi_patch step for how these get patched for
# this install) the first time only, same idempotency rule as the
# DocumentRoot seed above. The account-creation CGI this same cgi-bin/
# could eventually also host is deliberately still not seeded here.
# DocumentRoot seed above.
HELP_CGI_SRC="$ECCE_HOME/data/client/WebHelp/EcceHelp/cgi-bin"
if [ ! -e "$STATEDIR/cgi-bin/EcceHelp" ] && [ -d "$HELP_CGI_SRC" ]; then
cp -r "$HELP_CGI_SRC" "$STATEDIR/cgi-bin/EcceHelp"
Expand Down
16 changes: 16 additions & 0 deletions packaging/dataserver/httpd.conf.ecce
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ LogLevel error
ScriptAlias /cgi-bin/ "##HTTPDROOT##/cgi-bin/"
</IfModule>

# Pass the installation prefix from the process that started this per-user
# Apache instance; the CGI never accepts an executable path from a request.
<IfModule env_module>
PassEnv ECCE_HOME
</IfModule>

<Directory "##HTTPDROOT##/cgi-bin">
AllowOverride None
Options None
Expand Down Expand Up @@ -462,4 +468,14 @@ BrowserMatch "^Mozilla/5\.25 Netscape/5\.0" redirect-carefully
SSLCertificateKeyFile "##TLSDIR##/server.key"
SSLProtocol -all +TLSv1.2 +TLSv1.3
</VirtualHost>

# The current password is checked by Apache against the data server's
# htpasswd file. This block is removed when TLS is not configured.
<Files "ecce-change-password">
AuthName "ECCE password change"
AuthType Basic
AuthUserFile "##HTTPDROOT##/users"
Require valid-user
SSLRequireSSL
</Files>
#TLS-END
Loading
Loading