summaryrefslogtreecommitdiff
path: root/gnu/services
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-05-29 23:46:35 -0400
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-06-10 23:52:33 -0400
commit85b4dabd94d53f8179f31a42046cd83fc3a352fc (patch)
tree44eccc43dabd037b6a70cb91b7ebf24e56dad646 /gnu/services
parentb8edfdb0083003f6bd8f2fa084743c9ffcf50909 (diff)
services: jami: Modernize to adjust to Shepherd 0.9+ changes.
This partially fixes <https://issues.guix.gnu.org/54786>, allowing the 'jami' and 'jami-provisioning' system tests to pass again. In version 0.9.0, Shepherd constructors are now run concurrently, via cooperative scheduling (Guile Fibers). The Jami service previously relied on blocking sleeps while polling for D-Bus services to become ready after forking a process; this wouldn't work anymore since while blocking the service process wouldn't be given the chance to finish starting. The new reliance on Fibers in Shepherd's fork+exec-command in the helper 'send-dbus' procedure also meant that it wouldn't work outside of Shepherd anymore. Finally, the 'start-service' Shepherd procedure used in the test suite would cause the Jami daemon to be spawned multiple times (a bug introduced in Shepherd 0.9.0). To fix/simplify these problems, this change does the following: 1. Use the Guile AC/D-Bus library for D-Bus communication, which simplify things, such as avoiding the need to fork 'dbus-send' processes. 2. The non-blocking 'sleep' version of Fiber is used for the 'with-retries' waiting syntax. 3. A 'dbus' package variant is used to adjust the session bus configuration, tailoring it for the use case at hand. 4. Avoid start-service in the tests, preferring 'jami-service-available?' for now. * gnu/build/jami-service.scm (parse-dbus-reply, strip-quotes) (deserialize-item, serialize-boolean, dbus-dict->alist) (dbus-array->list, parse-account-ids, parse-account-details) (parse-contacts): Delete procedures. (%send-dbus-binary, %send-dbus-bus, %send-dbus-user, %send-dbus-group) (%send-dbus-debug): Delete parameters. (jami-service-running?): New procedure. (send-dbus/configuration-manager): Rename to... (call-configuration-manager-method): ... this. Turn METHOD into a positional argument. Turn ARGUMENTS into an optional argument. Invoke `call-dbus-method' instead of `send-dbus', adjusting callers accordingly. (get-account-ids, id->account-details, id->account-details) (id->volatile-account-details, username->id, add-account remove-account) (username->contacts, remove-contact, add-contact, set-account-details) (set-all-moderators, username->all-moderators?, username->moderators) (set-moderator): Adjust accordingly. (with-retries, send-dbus, dbus-available-services) (dbus-service-available?): Move to ... * gnu/build/dbus-service.scm: ... this new module. (send-dbus): Rewrite to use the Guile AC/D-Bus library. (%dbus-query-timeout, sleep*): New variables. (%current-dbus-connection): New parameter. (initialize-dbus-connection!, argument->signature-type) (call-dbus-method): New procedures. (dbus-available-services): Adjust accordingly. * gnu/local.mk (GNU_SYSTEM_MODULES): Register new module. * gnu/packages/glib.scm (dbus-for-jami): New variable. * gnu/services/telephony.scm: (jami-configuration)[dbus]: Default to dbus-for-jami. (jami-dbus-session-activation): Write a D-Bus daemon configuration file at '/var/run/jami/session-local.conf'. (jami-shepherd-services): Add the closure of guile-ac-d-bus and guile-fibers as extensions. Adjust imported modules. Remove no longer used parameters. <jami-dbus-session>: Use a PID file, avoiding the need for the manual synchronization. <jami>: Set DBUS_SESSION_BUS_ADDRESS environment variable. Poll using 'jami-service-available?' instead of 'dbus-service-available?'. * gnu/tests/telephony.scm (run-jami-test): Add needed Guile extensions. Set DBUS_SESSION_BUS_ADDRESS environment variable. Adjust all tests to use 'jami-service-available?' to determine if the service is started rather than the now problematic Shepherd's 'start-service'.
Diffstat (limited to 'gnu/services')
-rw-r--r--gnu/services/telephony.scm500
1 files changed, 232 insertions, 268 deletions
diff --git a/gnu/services/telephony.scm b/gnu/services/telephony.scm
index d8ebc7b39d6..3b397054a8f 100644
--- a/gnu/services/telephony.scm
+++ b/gnu/services/telephony.scm
@@ -26,6 +26,7 @@
26 #:use-module (gnu packages admin) 26 #:use-module (gnu packages admin)
27 #:use-module (gnu packages certs) 27 #:use-module (gnu packages certs)
28 #:use-module (gnu packages glib) 28 #:use-module (gnu packages glib)
29 #:use-module (gnu packages guile-xyz)
29 #:use-module (gnu packages jami) 30 #:use-module (gnu packages jami)
30 #:use-module (gnu packages telephony) 31 #:use-module (gnu packages telephony)
31 #:use-module (guix deprecation) 32 #:use-module (guix deprecation)
@@ -231,7 +232,7 @@ SET-ACCOUNT-DETAILS."
231 (file-like libjami) 232 (file-like libjami)
232 "The Jami daemon package to use.") 233 "The Jami daemon package to use.")
233 (dbus 234 (dbus
234 (file-like dbus) 235 (file-like dbus-for-jami)
235 "The D-Bus package to use to start the required D-Bus session.") 236 "The D-Bus package to use to start the required D-Bus session.")
236 (nss-certs 237 (nss-certs
237 (file-like nss-certs) 238 (file-like nss-certs)
@@ -284,7 +285,20 @@ CONFIG, a <jami-configuration> object."
284 #~(begin 285 #~(begin
285 (use-modules (gnu build activation)) 286 (use-modules (gnu build activation))
286 (let ((user (getpwnam "jami"))) 287 (let ((user (getpwnam "jami")))
287 (mkdir-p/perms "/var/run/jami" user #o700))))) 288 (mkdir-p/perms "/var/run/jami" user #o700)
289 ;; Customize the D-Bus policy to allow 'root' to access other users'
290 ;; session bus. Also modify the location of the written PID file,
291 ;; from the default '/var/run/dbus/pid' location. This file is only
292 ;; honored by the 'dbus-for-jami' package variant.
293 (call-with-output-file "/var/run/jami/session-local.conf"
294 (lambda (port)
295 (format port "\
296<busconfig>
297 <pidfile>/var/run/jami/pid</pidfile>
298 <policy context=\"mandatory\">
299 <allow user=\"root\"/>
300 </policy>
301</busconfig>~%")))))))
288 302
289(define (jami-shepherd-services config) 303(define (jami-shepherd-services config)
290 "Return a <shepherd-service> running the Jami daemon." 304 "Return a <shepherd-service> running the Jami daemon."
@@ -292,26 +306,27 @@ CONFIG, a <jami-configuration> object."
292 (nss-certs (jami-configuration-nss-certs config)) 306 (nss-certs (jami-configuration-nss-certs config))
293 (dbus (jami-configuration-dbus config)) 307 (dbus (jami-configuration-dbus config))
294 (dbus-daemon (file-append dbus "/bin/dbus-daemon")) 308 (dbus-daemon (file-append dbus "/bin/dbus-daemon"))
295 (dbus-send (file-append dbus "/bin/dbus-send"))
296 (accounts (jami-configuration-accounts config)) 309 (accounts (jami-configuration-accounts config))
297 (declarative-mode? (not (eq? 'disabled accounts)))) 310 (declarative-mode? (not (eq? 'disabled accounts))))
298 311
299 (with-imported-modules (source-module-closure 312 (with-extensions (list guile-packrat ;used by guile-ac-d-bus
300 '((gnu build jami-service) 313 guile-ac-d-bus
301 (gnu build shepherd) 314 ;; Fibers is needed to provide the non-blocking
302 (gnu system file-systems))) 315 ;; variant of the 'sleep' procedure.
303 316 guile-fibers)
304 (define list-accounts-action 317 (with-imported-modules (source-module-closure
305 (shepherd-action 318 '((gnu build dbus-service)
306 (name 'list-accounts) 319 (gnu build jami-service)
307 (documentation "List the available Jami accounts. Return the account 320 (gnu build shepherd)
321 (gnu system file-systems)))
322
323 (define list-accounts-action
324 (shepherd-action
325 (name 'list-accounts)
326 (documentation "List the available Jami accounts. Return the account
308details alists keyed by their account username.") 327details alists keyed by their account username.")
309 (procedure 328 (procedure
310 #~(lambda _ 329 #~(lambda _
311 (parameterize ((%send-dbus-binary #$dbus-send)
312 (%send-dbus-bus "unix:path=/var/run/jami/bus")
313 (%send-dbus-user "jami")
314 (%send-dbus-group "jami"))
315 ;; Print the accounts summary or long listing, according to 330 ;; Print the accounts summary or long listing, according to
316 ;; user-provided option. 331 ;; user-provided option.
317 (let* ((usernames (get-usernames)) 332 (let* ((usernames (get-usernames))
@@ -341,39 +356,31 @@ details alists keyed by their account username.")
341 accounts) 356 accounts)
342 (display "\n"))) 357 (display "\n")))
343 ;; Return the account-details-list alist. 358 ;; Return the account-details-list alist.
344 (map cons usernames accounts))))))) 359 (map cons usernames accounts))))))
345 360
346 (define list-account-details-action 361 (define list-account-details-action
347 (shepherd-action 362 (shepherd-action
348 (name 'list-account-details) 363 (name 'list-account-details)
349 (documentation "Display the account details of the available Jami 364 (documentation "Display the account details of the available Jami
350accounts in the @code{recutils} format. Return the account details alists 365accounts in the @code{recutils} format. Return the account details alists
351keyed by their account username.") 366keyed by their account username.")
352 (procedure 367 (procedure
353 #~(lambda _ 368 #~(lambda _
354 (parameterize ((%send-dbus-binary #$dbus-send)
355 (%send-dbus-bus "unix:path=/var/run/jami/bus")
356 (%send-dbus-user "jami")
357 (%send-dbus-group "jami"))
358 (let* ((usernames (get-usernames)) 369 (let* ((usernames (get-usernames))
359 (accounts (map-in-order username->account usernames))) 370 (accounts (map-in-order username->account usernames)))
360 (for-each (lambda (account) 371 (for-each (lambda (account)
361 (display (account-details->recutil account)) 372 (display (account-details->recutil account))
362 (display "\n\n")) 373 (display "\n\n"))
363 accounts) 374 accounts)
364 (map cons usernames accounts))))))) 375 (map cons usernames accounts))))))
365 376
366 (define list-contacts-action 377 (define list-contacts-action
367 (shepherd-action 378 (shepherd-action
368 (name 'list-contacts) 379 (name 'list-contacts)
369 (documentation "Display the contacts for each Jami account. Return 380 (documentation "Display the contacts for each Jami account. Return
370an alist containing the contacts keyed by the account usernames.") 381an alist containing the contacts keyed by the account usernames.")
371 (procedure 382 (procedure
372 #~(lambda _ 383 #~(lambda _
373 (parameterize ((%send-dbus-binary #$dbus-send)
374 (%send-dbus-bus "unix:path=/var/run/jami/bus")
375 (%send-dbus-user "jami")
376 (%send-dbus-group "jami"))
377 (let* ((usernames (get-usernames)) 384 (let* ((usernames (get-usernames))
378 (contacts (map-in-order username->contacts usernames))) 385 (contacts (map-in-order username->contacts usernames)))
379 (for-each (lambda (username contacts) 386 (for-each (lambda (username contacts)
@@ -381,19 +388,15 @@ an alist containing the contacts keyed by the account usernames.")
381 username) 388 username)
382 (format #t "~{ - ~a~%~}~%" contacts)) 389 (format #t "~{ - ~a~%~}~%" contacts))
383 usernames contacts) 390 usernames contacts)
384 (map cons usernames contacts))))))) 391 (map cons usernames contacts))))))
385 392
386 (define list-moderators-action 393 (define list-moderators-action
387 (shepherd-action 394 (shepherd-action
388 (name 'list-moderators) 395 (name 'list-moderators)
389 (documentation "Display the moderators for each Jami account. Return 396 (documentation "Display the moderators for each Jami account. Return
390an alist containing the moderators keyed by the account usernames.") 397an alist containing the moderators keyed by the account usernames.")
391 (procedure 398 (procedure
392 #~(lambda _ 399 #~(lambda _
393 (parameterize ((%send-dbus-binary #$dbus-send)
394 (%send-dbus-bus "unix:path=/var/run/jami/bus")
395 (%send-dbus-user "jami")
396 (%send-dbus-group "jami"))
397 (let* ((usernames (get-usernames)) 400 (let* ((usernames (get-usernames))
398 (moderators (map-in-order username->moderators 401 (moderators (map-in-order username->moderators
399 usernames))) 402 usernames)))
@@ -406,12 +409,12 @@ an alist containing the moderators keyed by the account usernames.")
406 (format #t "Moderators for account ~a:~%" username) 409 (format #t "Moderators for account ~a:~%" username)
407 (format #t "~{ - ~a~%~}~%" moderators)))) 410 (format #t "~{ - ~a~%~}~%" moderators))))
408 usernames moderators) 411 usernames moderators)
409 (map cons usernames moderators))))))) 412 (map cons usernames moderators))))))
410 413
411 (define add-moderator-action 414 (define add-moderator-action
412 (shepherd-action 415 (shepherd-action
413 (name 'add-moderator) 416 (name 'add-moderator)
414 (documentation "Add a moderator for a given Jami account. The 417 (documentation "Add a moderator for a given Jami account. The
415MODERATOR contact must be given as its 40 characters fingerprint, while the 418MODERATOR contact must be given as its 40 characters fingerprint, while the
416Jami account can be provided as its registered USERNAME or fingerprint. 419Jami account can be provided as its registered USERNAME or fingerprint.
417 420
@@ -420,21 +423,17 @@ herd add-moderator jami 1dbcb0f5f37324228235564b79f2b9737e9a008f username
420@end example 423@end example
421 424
422Return the moderators for the account known by USERNAME.") 425Return the moderators for the account known by USERNAME.")
423 (procedure 426 (procedure
424 #~(lambda (_ moderator username) 427 #~(lambda (_ moderator username)
425 (parameterize ((%send-dbus-binary #$dbus-send)
426 (%send-dbus-bus "unix:path=/var/run/jami/bus")
427 (%send-dbus-user "jami")
428 (%send-dbus-group "jami"))
429 (set-all-moderators #f username) 428 (set-all-moderators #f username)
430 (add-contact moderator username) 429 (add-contact moderator username)
431 (set-moderator moderator #t username) 430 (set-moderator moderator #t username)
432 (username->moderators username)))))) 431 (username->moderators username)))))
433 432
434 (define ban-contact-action 433 (define ban-contact-action
435 (shepherd-action 434 (shepherd-action
436 (name 'ban-contact) 435 (name 'ban-contact)
437 (documentation "Ban a contact for a given or all Jami accounts, and 436 (documentation "Ban a contact for a given or all Jami accounts, and
438clear their moderator flag. The CONTACT must be given as its 40 characters 437clear their moderator flag. The CONTACT must be given as its 40 characters
439fingerprint, while the Jami account can be provided as its registered USERNAME 438fingerprint, while the Jami account can be provided as its registered USERNAME
440or fingerprint, or omitted. When the account is omitted, CONTACT is banned 439or fingerprint, or omitted. When the account is omitted, CONTACT is banned
@@ -443,31 +442,22 @@ from all accounts.
443@example 442@example
444herd ban-contact jami 1dbcb0f5f37324228235564b79f2b9737e9a008f [username] 443herd ban-contact jami 1dbcb0f5f37324228235564b79f2b9737e9a008f [username]
445@end example") 444@end example")
446 (procedure 445 (procedure
447 #~(lambda* (_ contact #:optional username) 446 #~(lambda* (_ contact #:optional username)
448 (parameterize ((%send-dbus-binary #$dbus-send)
449 (%send-dbus-bus "unix:path=/var/run/jami/bus")
450 (%send-dbus-user "jami")
451 (%send-dbus-group "jami"))
452 (let ((usernames (or (and=> username list) 447 (let ((usernames (or (and=> username list)
453 (get-usernames)))) 448 (get-usernames))))
454 (for-each (lambda (username) 449 (for-each (lambda (username)
455 (set-moderator contact #f username) 450 (set-moderator contact #f username)
456 (remove-contact contact username #:ban? #t)) 451 (remove-contact contact username #:ban? #t))
457 usernames))))))) 452 usernames))))))
458 453
459 (define list-banned-contacts-action 454 (define list-banned-contacts-action
460 (shepherd-action 455 (shepherd-action
461 (name 'list-banned-contacts) 456 (name 'list-banned-contacts)
462 (documentation "List the banned contacts for each accounts. Return 457 (documentation "List the banned contacts for each accounts. Return
463an alist of the banned contacts, keyed by the account usernames.") 458an alist of the banned contacts, keyed by the account usernames.")
464 (procedure 459 (procedure
465 #~(lambda _ 460 #~(lambda _
466 (parameterize ((%send-dbus-binary #$dbus-send)
467 (%send-dbus-bus "unix:path=/var/run/jami/bus")
468 (%send-dbus-user "jami")
469 (%send-dbus-group "jami"))
470
471 (define banned-contacts 461 (define banned-contacts
472 (let ((usernames (get-usernames))) 462 (let ((usernames (get-usernames)))
473 (map cons usernames 463 (map cons usernames
@@ -484,183 +474,157 @@ an alist of the banned contacts, keyed by the account usernames.")
484 username) 474 username)
485 (format #t "~{ - ~a~%~}~%" banned)))) 475 (format #t "~{ - ~a~%~}~%" banned))))
486 banned-contacts) 476 banned-contacts)
487 banned-contacts))))) 477 banned-contacts))))
488 478
489 (define enable-account-action 479 (define enable-account-action
490 (shepherd-action 480 (shepherd-action
491 (name 'enable-account) 481 (name 'enable-account)
492 (documentation "Enable an account. It takes USERNAME as an argument, 482 (documentation "Enable an account. It takes USERNAME as an argument,
493either a registered username or the fingerprint of the account.") 483either a registered username or the fingerprint of the account.")
494 (procedure 484 (procedure
495 #~(lambda (_ username) 485 #~(lambda (_ username)
496 (parameterize ((%send-dbus-binary #$dbus-send) 486 (enable-account username)))))
497 (%send-dbus-bus "unix:path=/var/run/jami/bus") 487
498 (%send-dbus-user "jami") 488 (define disable-account-action
499 (%send-dbus-group "jami")) 489 (shepherd-action
500 (enable-account username)))))) 490 (name 'disable-account)
501 491 (documentation "Disable an account. It takes USERNAME as an
502 (define disable-account-action
503 (shepherd-action
504 (name 'disable-account)
505 (documentation "Disable an account. It takes USERNAME as an
506argument, either a registered username or the fingerprint of the account.") 492argument, either a registered username or the fingerprint of the account.")
507 (procedure 493 (procedure
508 #~(lambda (_ username) 494 #~(lambda (_ username)
509 (parameterize ((%send-dbus-binary #$dbus-send) 495 (disable-account username)))))
510 (%send-dbus-bus "unix:path=/var/run/jami/bus") 496
511 (%send-dbus-user "jami") 497 (list (shepherd-service
512 (%send-dbus-group "jami")) 498 (documentation "Run a D-Bus session for the Jami daemon.")
513 (disable-account username)))))) 499 (provision '(jami-dbus-session))
514 500 (modules `((gnu build shepherd)
515 (list (shepherd-service 501 (gnu build dbus-service)
516 (documentation "Run a D-Bus session for the Jami daemon.") 502 (gnu build jami-service)
517 (provision '(jami-dbus-session)) 503 (gnu system file-systems)
518 (modules `((gnu build shepherd) 504 ,@%default-modules))
519 (gnu build jami-service) 505 ;; The requirement on dbus-system is to ensure other required
520 (gnu system file-systems) 506 ;; activation for D-Bus, such as a /etc/machine-id file.
521 ,@%default-modules)) 507 (requirement '(dbus-system syslogd))
522 ;; The requirement on dbus-system is to ensure other required 508 (start
523 ;; activation for D-Bus, such as a /etc/machine-id file. 509 #~(make-forkexec-constructor/container
524 (requirement '(dbus-system syslogd)) 510 (list #$dbus-daemon "--session"
525 (start 511 "--address=unix:path=/var/run/jami/bus"
526 #~(lambda args 512 "--syslog-only")
527 (define pid 513 #:pid-file "/var/run/jami/pid"
528 ((make-forkexec-constructor/container 514 #:mappings
529 (list #$dbus-daemon "--session" 515 (list (file-system-mapping
530 "--address=unix:path=/var/run/jami/bus" 516 (source "/dev/log") ;for syslog
531 "--nofork" "--syslog-only" "--nopidfile") 517 (target source))
532 #:mappings (list (file-system-mapping 518 (file-system-mapping
533 (source "/dev/log") ;for syslog 519 (source "/var/run/jami")
534 (target source)) 520 (target source)
535 (file-system-mapping 521 (writable? #t)))
536 (source "/var/run/jami") 522 #:user "jami"
537 (target source) 523 #:group "jami"
538 (writable? #t))) 524 #:environment-variables
539 #:user "jami" 525 ;; This is so that the cx.ring.Ring service D-Bus
540 #:group "jami" 526 ;; definition is found by dbus-daemon.
541 #:environment-variables 527 (list (string-append "XDG_DATA_DIRS=" #$jamid "/share"))))
542 ;; This is so that the cx.ring.Ring service D-Bus 528 (stop #~(make-kill-destructor)))
543 ;; definition is found by dbus-send. 529
544 (list (string-append "XDG_DATA_DIRS=" 530 (shepherd-service
545 #$jamid "/share"))))) 531 (documentation "Run the Jami daemon.")
546 532 (provision '(jami))
547 ;; XXX: This manual synchronization probably wouldn't be 533 (actions (list list-accounts-action
548 ;; needed if we were using a PID file, but providing it via a 534 list-account-details-action
549 ;; customized config file with <pidfile> would not override 535 list-contacts-action
550 ;; the one inherited from the base config of D-Bus. 536 list-moderators-action
551 (let ((sock (socket PF_UNIX SOCK_STREAM 0))) 537 add-moderator-action
552 (with-retries 20 1 (catch 'system-error 538 ban-contact-action
553 (lambda () 539 list-banned-contacts-action
554 (connect sock AF_UNIX 540 enable-account-action
555 "/var/run/jami/bus") 541 disable-account-action))
556 (close-port sock) 542 (requirement '(jami-dbus-session))
557 #t) 543 (modules `((ice-9 format)
558 (lambda args 544 (ice-9 ftw)
559 #f)))) 545 (ice-9 match)
560 546 (ice-9 receive)
561 pid)) 547 (srfi srfi-1)
562 (stop #~(make-kill-destructor))) 548 (srfi srfi-26)
563 549 (gnu build dbus-service)
564 (shepherd-service 550 (gnu build jami-service)
565 (documentation "Run the Jami daemon.") 551 (gnu build shepherd)
566 (provision '(jami)) 552 (gnu system file-systems)
567 (actions (list list-accounts-action 553 ,@%default-modules))
568 list-account-details-action 554 (start
569 list-contacts-action 555 #~(lambda args
570 list-moderators-action 556 (define (delete-file-recursively/safe file)
571 add-moderator-action 557 ;; Ensure we're not deleting things outside of
572 ban-contact-action 558 ;; /var/lib/jami. This prevents a possible attack in case
573 list-banned-contacts-action 559 ;; the daemon is compromised and an attacker gains write
574 enable-account-action 560 ;; access to /var/lib/jami.
575 disable-account-action)) 561 (let ((parent-directory (dirname file)))
576 (requirement '(jami-dbus-session)) 562 (if (eq? 'symlink (stat:type (stat parent-directory)))
577 (modules `((ice-9 format) 563 (error "abnormality detected; unexpected symlink found at"
578 (ice-9 ftw) 564 parent-directory)
579 (ice-9 match) 565 (delete-file-recursively file))))
580 (ice-9 receive) 566
581 (srfi srfi-1) 567 (when #$declarative-mode?
582 (srfi srfi-26) 568 ;; Clear the Jami configuration and accounts, to enforce the
583 (gnu build jami-service) 569 ;; declared state.
584 (gnu build shepherd) 570 (catch #t
585 (gnu system file-systems) 571 (lambda ()
586 ,@%default-modules)) 572 (for-each (cut delete-file-recursively/safe <>)
587 (start 573 '("/var/lib/jami/.cache/jami"
588 #~(lambda args 574 "/var/lib/jami/.config/jami"
589 (define (delete-file-recursively/safe file) 575 "/var/lib/jami/.local/share/jami"
590 ;; Ensure we're not deleting things outside of 576 "/var/lib/jami/accounts")))
591 ;; /var/lib/jami. This prevents a possible attack in case 577 (lambda args
592 ;; the daemon is compromised and an attacker gains write 578 #t))
593 ;; access to /var/lib/jami. 579 ;; Copy the Jami account archives from somewhere readable
594 (let ((parent-directory (dirname file))) 580 ;; by root to a place only the jami user can read.
595 (if (eq? 'symlink (stat:type (stat parent-directory))) 581 (let* ((accounts-dir "/var/lib/jami/accounts/")
596 (error "abnormality detected; unexpected symlink found at" 582 (pwd (getpwnam "jami"))
597 parent-directory) 583 (user (passwd:uid pwd))
598 (delete-file-recursively file)))) 584 (group (passwd:gid pwd)))
599 585 (mkdir-p accounts-dir)
600 (when #$declarative-mode? 586 (chown accounts-dir user group)
601 ;; Clear the Jami configuration and accounts, to enforce the 587 (for-each (lambda (f)
602 ;; declared state. 588 (let ((dest (string-append accounts-dir
603 (catch #t 589 (basename f))))
604 (lambda () 590 (copy-file f dest)
605 (for-each (cut delete-file-recursively/safe <>) 591 (chown dest user group)))
606 '("/var/lib/jami/.cache/jami" 592 '#$(and declarative-mode?
607 "/var/lib/jami/.config/jami" 593 (map jami-account-archive accounts)))))
608 "/var/lib/jami/.local/share/jami" 594
609 "/var/lib/jami/accounts"))) 595 ;; Start the daemon.
610 (lambda args 596 (define daemon-pid
611 #t)) 597 ((make-forkexec-constructor/container
612 ;; Copy the Jami account archives from somewhere readable 598 '#$(jami-configuration->command-line-arguments config)
613 ;; by root to a place only the jami user can read. 599 #:mappings
614 (let* ((accounts-dir "/var/lib/jami/accounts/") 600 (list (file-system-mapping
615 (pwd (getpwnam "jami")) 601 (source "/dev/log") ;for syslog
616 (user (passwd:uid pwd)) 602 (target source))
617 (group (passwd:gid pwd))) 603 (file-system-mapping
618 (mkdir-p accounts-dir) 604 (source "/var/lib/jami")
619 (chown accounts-dir user group) 605 (target source)
620 (for-each (lambda (f) 606 (writable? #t))
621 (let ((dest (string-append accounts-dir 607 (file-system-mapping
622 (basename f)))) 608 (source "/var/run/jami")
623 (copy-file f dest) 609 (target source)
624 (chown dest user group))) 610 (writable? #t))
625 '#$(and declarative-mode? 611 ;; Expose TLS certificates for GnuTLS.
626 (map jami-account-archive accounts))))) 612 (file-system-mapping
627 613 (source #$(file-append nss-certs "/etc/ssl/certs"))
628 ;; Start the daemon. 614 (target "/etc/ssl/certs")))
629 (define daemon-pid 615 #:user "jami"
630 ((make-forkexec-constructor/container 616 #:group "jami"
631 '#$(jami-configuration->command-line-arguments config) 617 #:environment-variables
632 #:mappings 618 (list (string-append "DBUS_SESSION_BUS_ADDRESS="
633 (list (file-system-mapping 619 "unix:path=/var/run/jami/bus")
634 (source "/dev/log") ;for syslog 620 ;; Expose TLS certificates for OpenSSL.
635 (target source)) 621 "SSL_CERT_DIR=/etc/ssl/certs"))))
636 (file-system-mapping 622
637 (source "/var/lib/jami") 623 (setenv "DBUS_SESSION_BUS_ADDRESS"
638 (target source) 624 "unix:path=/var/run/jami/bus")
639 (writable? #t))
640 (file-system-mapping
641 (source "/var/run/jami")
642 (target source)
643 (writable? #t))
644 ;; Expose TLS certificates for GnuTLS.
645 (file-system-mapping
646 (source #$(file-append nss-certs "/etc/ssl/certs"))
647 (target "/etc/ssl/certs")))
648 #:user "jami"
649 #:group "jami"
650 #:environment-variables
651 (list (string-append "DBUS_SESSION_BUS_ADDRESS="
652 "unix:path=/var/run/jami/bus")
653 ;; Expose TLS certificates for OpenSSL.
654 "SSL_CERT_DIR=/etc/ssl/certs"))))
655
656 (parameterize ((%send-dbus-binary #$dbus-send)
657 (%send-dbus-bus "unix:path=/var/run/jami/bus")
658 (%send-dbus-user "jami")
659 (%send-dbus-group "jami"))
660 625
661 ;; Wait until the service name has been acquired by D-Bus. 626 ;; Wait until the service name has been acquired by D-Bus.
662 (with-retries 20 1 627 (with-retries 20 1 (jami-service-available?))
663 (dbus-service-available? "cx.ring.Ring"))
664 628
665 (when #$declarative-mode? 629 (when #$declarative-mode?
666 ;; Provision the accounts via the D-Bus API of the daemon. 630 ;; Provision the accounts via the D-Bus API of the daemon.
@@ -717,17 +681,17 @@ argument, either a registered username or the fingerprint of the account.")
717 (map-in-order (cut jami-account-moderators <>) 681 (map-in-order (cut jami-account-moderators <>)
718 accounts)) 682 accounts))
719 '#$(and declarative-mode? 683 '#$(and declarative-mode?
720 (map-in-order jami-account->alist accounts)))))) 684 (map-in-order jami-account->alist accounts)))))
721 685
722 ;; Finally, return the PID of the daemon process. 686 ;; Finally, return the PID of the daemon process.
723 daemon-pid)) 687 daemon-pid))
724 (stop 688 (stop
725 #~(lambda (pid . args) 689 #~(lambda (pid . args)
726 (kill pid SIGKILL) 690 (kill pid SIGKILL)
727 ;; Wait for the process to exit; this prevents overlapping 691 ;; Wait for the process to exit; this prevents overlapping
728 ;; processes when issuing 'herd restart'. 692 ;; processes when issuing 'herd restart'.
729 (waitpid pid) 693 (waitpid pid)
730 #f))))))) 694 #f))))))))
731 695
732(define jami-service-type 696(define jami-service-type
733 (service-type 697 (service-type