GNU TeXmacsUser manualReferenceAboutEnglish
The TeXmacs server

1.Starting a server

1.1.From the command line

A server is an ordinary TeXmacs process with server mode enabled. The relevant command line options are parsed in

Texmacs/Texmacs/texmacs.cpp

:

-server

Enable server mode (set_server). At the end of the initialization, server_start is called provided that server_can_start succeeds. The latter refuses to start when GnuTLS is available, the preference "tls-server" is on and no certificate is present.

-port n

Override the preference "server port" (default 6561).

-headless, -H

Run without graphical interface. In headless mode, TeXmacs normally quits after the command line has been processed, but not in server mode.

-reset-server-preferences, -reset-admin-password

Call server-reset-preferences resp. server-reset-admin-password when the server starts. The new administrator password is written to the server log (and shown in an auxiliary buffer when a graphical interface is present).

-delete-server-data

Remove the directory $TEXMACS_HOME_PATH/server with all accounts, files and the server database.

--tls-no-verify

Client side option: skip the verification of server certificates (useful for headless clients which cannot ask the user to trust a self-signed certificate).

A typical invocation on a machine without display is therefore

texmacs -headless -server -port 6561

The environment variable TEXMACS_SERVER_CERT_DIR (default $TEXMACS_HOME_PATH/server) indicates where the certificate cert.pem and the private key key.pem are stored. SIGPIPE is ignored so that a client which aborts its connection does not kill the server.

1.2.From the user interface

In a graphical session, the server is started from the menu Remote\(\rightarrow\)Start server, which calls server-safe-start (

server/server-menu.scm

). If TLS is supported and on but no certificate exists, the user is first offered to create a self-signed certificate (open-certificate-warning in

server-widgets.scm

, which ends up in the glue function generate-self-signed-certificate). The server menu also allows to stop and restart the server and to reset the administrator password or the preferences. See also the user documentation Starting and configuring the server and TLS certificates.

1.3.First start

After the listening socket has been created, server-create-default-admin-account creates an account admin with a random password of 20 characters if no user exists yet. The password is written to the log with level warning; the administrator is expected to change it immediately.

2.Persistent state

All server data are stored below $TEXMACS_HOME_PATH/server:

global.tmdb

The server database, returned by (global-database) (

database/db-base.scm

) and installed by tm-service as the current database of each service (server-database). It contains one entry per user, file, directory, file version list, live document, chat room, chat message, message and notification.

users.scm

An association list from user identifiers to (pseudo name credentials email admin?), cached in the table server-users. User entries also exist in the database (with type "user"); the user identifier is currently the pseudo itself (see server-set-user-info).

pending-users.scm, reset-credentials-users.scm

Accounts waiting for email confirmation and pending credential reset codes.

email-new-account.txt, email-reset-credentials.txt, license.tm

Templates of the emails sent to users and the license document shown to new users. The email templates are copied from progs/server/server-email-*.txt on first use.

Numbered directories

The contents of remote files, live documents and messages. See the remote file system.

The database layer is described in the Scheme modules of

progs/database/

. The points which matter for the server are:

3.Accounts and authentication

3.1.Credentials

A client authenticates with a pseudo and a password after the connection (legacy or TLS) has been established; the transport layer itself is anonymous. On the client, a credential is a list such as (tls-password p) or (legacy-password p); the kind determines the transport used by client-login-then. Passwords are sent in clear inside the encrypted channel.

On the server, credentials are stored in a hidden form (password encoding salt hash …), produced by server-hide-credentials and checked by server-password-correct? in

server/server-authentication.scm

. The supported encodings are listed by server-supported-password-encodings:

pbkdf2

PBKDF2 with HMAC-SHA256 computed by GnuTLS (glue function hash-password-pbkdf2).

sha512, sha256

Crypt-style hashes computed by running openssl passwd -6 resp. -5 as an external process (not available on Windows).

clear

No hashing (used for backward compatibility).

The preference "server password encoding" selects the encoding of new passwords (by default the first supported one, i.e. pbkdf2 when GnuTLS is present). When the preference "server password update" is on, server-password-update rehashes a password with the preferred encoding (and a fresh salt if the old one had the wrong length) at the next successful login.

If "server require strong passwords" is on (the default), new passwords must pass server-strong-password?: at least 10 characters, with a lower case letter, an upper case letter, a digit and a symbol.

3.2.Login

The service remote-login (

server/server-base.scm

) finds the user with server-find-user, verifies the password with server-password-authentified? and, on success, calls server-login-uid, which records the login time and address, resets the failure counter and stores the association between the connection and the user in server-logged-table (in both directions). Later services retrieve the user with (server-get-user envelope), which returns #f for anonymous connections. The answers are strings: "ready", "pending" (account awaiting confirmation), "user not found", or an error message.

Brute force attacks are limited by server-can-login-uid?: after "server failed login limit" (default 3) failures, logins are refused until "server failed login delay" seconds (default 3600) have elapsed since the last failure. Accounts can also be suspended (server-suspend-user) or marked as deleted.

On the client, client-login-home (

client-widgets.scm

) performs the complete sequence: connect and log in (client-login-then), register the connection with add-active-connection, send the protocol version, fetch the account information, record the account in the client database (user-database "remote") (client-notify-account), open the remote home directory and pull pending notifications. Passwords may be stored in the TeXmacs wallet; the tmfs load handler of remote files uses wallet-get to log in automatically when a document on a server without active connection is opened.

3.3.Account creation, confirmation and reset

3.4.Administration

Users with the admin flag may read and modify the server preferences remotely (remote-admin-preferences, remote-set-preferences, remote-admin-preferences-form; see

client/client-remote-config.scm

), list the accounts (remote-get-accounts) and evaluate arbitrary Scheme expressions on the server with remote-eval. The latter is equivalent to shell access to the server account and should be kept in mind when granting administrator rights. Each preference guarding a service is a string "on" or "off" declared with define-preferences; see Server preferences for the user level description. Anonymous clients may retrieve the preferences listed in server-all-preferences together with the license through remote-public-preferences, unless disabled by the corresponding "server public: …" preference.

4.Logging

(server-log-write level message) accepts the syslog levels emergency, alert, critical, error, warning, notice, info and debug. In headless mode it calls the glue function server-log-write-int, which uses syslog on Unix (

Plugins/Unix/unix_server_log.cpp

), os_log on macOS (subsystem org.texmacs.logging), and the corresponding modules for Windows; when standard output is a terminal the messages are printed instead. With a graphical interface, the messages go to the debug console channels server-error, server-warning and server-debug.

5.Chat rooms, mail boxes and notifications

Chat rooms (

server/server-chat.scm

) are database entries of type "chat-room"; messages are entries of type "chat-message" with fields "action", "from", "to" (the room), "message" and a time stamp. Documents sent to a room (action "send") are stored in the repository as separate entries of type "message", whereas the action "share" stores the URL of the shared resource together with its identifier in "resource-id", so that the link can still be resolved after renaming (resolve-resource-id). Each user has a private room mail-pseudo, which is the mail box.

The server caches the messages of each room in chat-room-messages and remembers which connections have the room open in chat-room-present. When a message is posted (remote-send-message, remote-send), chat-room-notify appends it to the cache and pushes it to all present clients with the call-back chat-room-receive. Messages to a mail box also create a notification: a database entry of type "notification" owned by the recipient, pushed immediately with client-push-notifications if the recipient is logged in, and otherwise retrieved at the next login with remote-pending-notifications. Clients acknowledge notifications with remote-ack-notifications, which deletes them on the server. See also Messages and chat rooms and Shared resources.

6.The tree cache

Documents with many large images or graphics are expensive to transmit again and again. Since protocol version 1, the server replaces such subtrees by references into a content addressed cache.

7.Backups

server/server-backup.scm

implements optional periodic snapshots of $TEXMACS_HOME_PATH/server with rsync. When "server service backup" is on and "server backup destination" is set, server-backup-register schedules server-backup-run every "server backup interval" hours (again using :on-cpu-idle). Each run creates a directory named after the current date and time in the destination and calls rsync -a --partial --link-dest=previous, so that unchanged files are hard links into the previous snapshot. server-backup-prune then keeps the newest snapshot per hour, day, month and year up to the counts given by the "server backup keep …" preferences. The comments in the module explain why running rsync on a live server is considered safe (the database is flushed in the idle cycle, file contents are write-once and users.scm is atomically rewritten).

8.Security considerations

The following points should be kept in mind when deploying a server or modifying the code. Some of them are known limitations of the current implementation.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".