Skip to content
This repository has been archived by the owner on Feb 4, 2019. It is now read-only.

Strcpy concatenates new username to old username length #2

Open
Jnchi opened this issue Dec 14, 2018 · 3 comments
Open

Strcpy concatenates new username to old username length #2

Jnchi opened this issue Dec 14, 2018 · 3 comments
Labels
bug Something isn't working

Comments

@Jnchi
Copy link
Collaborator

Jnchi commented Dec 14, 2018

strcpy(it->pw_name,name); //this may be an issue if previous login name was shorter then new one

Source: libnss_pool.c

@Jnchi Jnchi added the bug Something isn't working label Dec 14, 2018
@Jnchi
Copy link
Collaborator Author

Jnchi commented Dec 17, 2018

define USER_NAME_MAX_LENGTH 32

Source: shadow-maint/shadow#20

@Jnchi
Copy link
Collaborator Author

Jnchi commented Dec 17, 2018

const char *name

strcpy(it->pw_name,name)

Test Case:

pw_name 1001, length 4
name jnchi, length 5

/etc/pool-passwd

1001:!:1001:1001:::/bin/bash

Current Behaviour:

getent passwd jnchi; cat /etc/pool-passwd
jnchix:x:1001:1001:::/bin/bash

See also:

@Jnchi
Copy link
Collaborator Author

Jnchi commented Dec 17, 2018

For now, I'll just add in a check to ensure that pw_passwd is not shorter than name.

Also, added this script, to dynamically generate long pool usernames.

#!/bin/bash
# generate_pool.sh
set -euo pipefail
IFS=$'\n\t'

create_name() {
  echo "pool_$((RANDOM%10000000000000000000000000000000-99999999999999999999999999999999))"
}

# For more info see `man passwd`
create_passwd_entry() {
  local name=$1
  local uid=$2

  # Default `users` group in Debian
  echo "${name}:!:${uid}:100:::/bin/bash"
}

show_usage() {
  echo 'Usage: generate_pool.sh ${pool_size} ${uid_start}'
  echo "           pool_size - number of users in pool"
  echo "           uid_start - first free uid (check /etc/passwd)"
}

main() {
  if [ "$#" -ne 2 ]; then
    show_usage
    exit 1
  fi

  local pool_size="$1"
  local uid_start="$(expr $2 - 1)"

  for i in $(seq ${pool_size}); do
    create_passwd_entry $(create_name) $(expr $uid_start + $i)
  done
}

main $@
sudo ./generate_pool.sh 1 1001 > /etc/pool-passwd && getent passwd jnchi; cat /etc/pool-passwd; cat
/tmp/debug
jnchi:x:1001:100:::/bin/bash
Read line: pool_8814407033341088000
new pool_8814407033341088000
new jnchi
snprintf, when strlen(buffer)=0 and buflen=1024
Adding to pool-passwd: jnchi:x:1001:100:::/bin/bash
checking buffer

Jnchi added a commit that referenced this issue Dec 18, 2018
Jnchi added a commit that referenced this issue Dec 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant