bacularis/bacularis-common

bacularis.users file written without proper line ending

Closed this issue · 4 comments

The Bacularis setup (via web interface) writes the user/password details in a file in /etc/bacularis/Web/bacularis.users (same for API). However that file has no proper line ending (aka end-of-line, aka eol). On Linux (UNIX) systems I'm expecting a linefeed \n at the end of each line.

BTW. You should probably use PHP_EOL instead of \n.

	public function prepareUserPwdFile(array $osprofile, $type)
	{
		$pwd = $this->getModule('crypto')->getHashedPassword($osprofile['bacularis_admin_pwd']);
		$creds = [$osprofile['bacularis_admin_user'], $pwd];
		$fbody = implode(':', $creds) . PHP_EOL;

I'm not a PHP programmer, so please check this for yourself.

Another example where this may apply

	public function saveUserConfig($all_users)
	{
		$users = [];
		foreach ($all_users as $user => $pwd) {
			$users[] = "$user:$pwd";
		}
		$usersToFile = implode(PHP_EOL, $users) . PHP_EOL;
		$old_umask = umask(0);
		umask(0077);
		$result = file_put_contents($this->getConfigPath(), $usersToFile, LOCK_EX) !== false;

Hello @keestux,

Thank you for your detailed report.

Indeed, in the user files the EOL characters in the last lines are missing.

We will fix it. Thanks for catching it.

For the PHP_EOL, sure, in PHP this is the better way. We use this constant in other places.

Best regards,
Marcin Haba (gani)

Hello @keestux,

This issue has been fixed and it will be available in the next release.

The last end-of-line character in bacularis.users files will be added on first user save action on the web interface after upgrading.

Thanks!

Best regards,
Marcin Haba (gani)