WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to create an extension for a daemon (user creation)  (Read 1796 times)

Offline destroyedlolo

  • Jr. Member
  • **
  • Posts: 50
    • destroyedlolo's website
How to create an extension for a daemon (user creation)
« on: November 15, 2022, 03:19:17 PM »
Hello,

I'm building an extension for a daemon ... and for security reason, I would like this daemon to run with a dedicated user.

What would be the smarter way to create this issuer ? Add user in the /tmp/package/usr/local/tce.installed script ?

Thanks

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: How to create an extension for a daemon (user creation)
« Reply #1 on: November 15, 2022, 06:15:20 PM »
Hi destroyedlolo
The tce.installed script sounds like a good place. I would do something like this:
Code: [Select]
if ! cat /etc/passwd | cut -d: -f1 | grep -q SpecialUser
then
    add user SpecialUser
    any additional commands required if adding a user
fi

The first line tests if  SpecialUser  already exists on the system. If it doesn't, then
the user gets added.

Offline destroyedlolo

  • Jr. Member
  • **
  • Posts: 50
    • destroyedlolo's website
Re: How to create an extension for a daemon (user creation)
« Reply #2 on: November 16, 2022, 01:00:14 AM »
Thanks for the confirmation and the code : I'll do it :)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: How to create an extension for a daemon (user creation)
« Reply #3 on: November 16, 2022, 05:55:48 AM »
Hi destroyedlolo
Remember,  usr/local/tce.installed/ExtensionName  is a script. So
don't forget to include:
Code: [Select]
#!/bin/shon the first line.

Offline destroyedlolo

  • Jr. Member
  • **
  • Posts: 50
    • destroyedlolo's website
Re: How to create an extension for a daemon (user creation)
« Reply #4 on: November 16, 2022, 10:01:35 AM »
Hum, my user is
Code: [Select]
daemon:x:100:65534:Linux User,,,:/tmp:/bin/false
and my command is :
Code: [Select]
su -c '/usr/local/sbin/PubSysFigures -Hbpi.chez.moi -s30' daemon
but when I'm launching from my shell
Code: [Select]
sudo su -c '/usr/local/sbin/PubSysFigures -Hbpi.chez.moi -s30' daemonthe process is not launched and
Code: [Select]
$ echo $?
1

Do you what can create this issue ?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: How to create an extension for a daemon (user creation)
« Reply #5 on: November 16, 2022, 11:01:09 AM »
Hi destroyedlolo
Hum, my user is
Code: [Select]
daemon:x:100:65534:Linux User,,,:/tmp:/bin/false ...
I think at least part of your problem might be that  /bin/false.  It should probably
be /bin/sh.

Take a look at the  addUser  function in  /etc/init.d/tc-config  for guidance on
adding a user.

Also, based on this help message:
Code: [Select]
tc@E310:~$ su --help
BusyBox v1.29.3 (2018-11-21 15:31:19 UTC) multi-call binary.

Usage: su [-lmp] [-] [-s SH] [USER [SCRIPT ARGS / -c 'CMD' ARG0 ARGS]]

Run shell under USER   by default, root

        -,-l    Clear environment, go to home dir, run shell as login shell
        -p,-m   Do not set new $HOME, $SHELL, $USER, $LOGNAME
        -c CMD  Command to pass to 'sh -c'
        -s SH   Shell to use instead of user's default
tc@E310:~$
it looks like maybe the  USER  should come before the  command.

Offline destroyedlolo

  • Jr. Member
  • **
  • Posts: 50
    • destroyedlolo's website
[Solved] How to create an extension for a daemon (user creation)
« Reply #6 on: November 16, 2022, 01:58:52 PM »
It was /bin/false to avoid interactive login (as technical account only) ... but it seems su needs a valid account.

So thanks for all your help : I've been able to submit my PubSysFigures, a daemon that publish system load to MQTT flow. I'm planing to publish as well disk usage.

My usage is to integrate it in my home automation to check which machines is running (kids  ;)) and if healthy  :)
« Last Edit: November 16, 2022, 02:01:13 PM by destroyedlolo »

Offline destroyedlolo

  • Jr. Member
  • **
  • Posts: 50
    • destroyedlolo's website
Re: How to create an extension for a daemon (user creation)
« Reply #7 on: December 28, 2022, 10:18:01 AM »
Hello,

Hum, why can't I find my package in the repository ?

If I go to http://www.tinycorelinux.net/13.x/x86/tcz/, I can find it listed, but if I'm trying to loading it using tce-load, it is not found. Going to a mirror like http://mirror1.ku.ac.th/tinycore/13.x/x86/tcz/, it's the same  :(

And it's the same for minidlna or GNU screen I submitted few weeks back as well.
« Last Edit: December 28, 2022, 10:20:09 AM by destroyedlolo »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10957
Re: How to create an extension for a daemon (user creation)
« Reply #8 on: December 28, 2022, 11:12:21 PM »
Perhaps you are using some other version/other mirror/made a typo?
The only barriers that can stop you are the ones you create yourself.

Offline destroyedlolo

  • Jr. Member
  • **
  • Posts: 50
    • destroyedlolo's website
Re: How to create an extension for a daemon (user creation)
« Reply #9 on: December 29, 2022, 10:31:10 AM »
Well, I think it was a punctual problem as now it's working  ::)