| 1 | # Copyright 1999-2011 Gentoo Foundation |
1 | # Copyright 1999-2011 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.3 2011/10/27 07:49:53 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.4 2011/10/31 17:39:52 vapier Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: user.eclass |
5 | # @ECLASS: user.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # base-system@gentoo.org (Linux) |
7 | # base-system@gentoo.org (Linux) |
| 8 | # Joe Jezak <josejx@gmail.com> (OS X) |
8 | # Joe Jezak <josejx@gmail.com> (OS X) |
| … | |
… | |
| 387 | groupadd -r ${opts} ${egroup} || die "enewgroup failed" |
387 | groupadd -r ${opts} ${egroup} || die "enewgroup failed" |
| 388 | ;; |
388 | ;; |
| 389 | esac |
389 | esac |
| 390 | export SANDBOX_ON="${oldsandbox}" |
390 | export SANDBOX_ON="${oldsandbox}" |
| 391 | } |
391 | } |
| 392 | |
|
|
| 393 | # Gets the home directory for the specified user |
|
|
| 394 | # it's a wrap around egetent as the position of the home directory in the line |
|
|
| 395 | # varies depending on the os used. |
|
|
| 396 | # |
|
|
| 397 | # To use that, inherit eutils, not portability! |
|
|
| 398 | egethome() { |
|
|
| 399 | local pos |
|
|
| 400 | |
|
|
| 401 | case ${CHOST} in |
|
|
| 402 | *-darwin*|*-freebsd*|*-dragonfly*) |
|
|
| 403 | pos=9 |
|
|
| 404 | ;; |
|
|
| 405 | *) # Linux, NetBSD, OpenBSD, etc... |
|
|
| 406 | pos=6 |
|
|
| 407 | ;; |
|
|
| 408 | esac |
|
|
| 409 | |
|
|
| 410 | egetent passwd $1 | cut -d: -f${pos} |
|
|
| 411 | } |
|
|
| 412 | |
|
|
| 413 | # Gets the shell for the specified user |
|
|
| 414 | # it's a wrap around egetent as the position of the home directory in the line |
|
|
| 415 | # varies depending on the os used. |
|
|
| 416 | # |
|
|
| 417 | # To use that, inherit eutils, not portability! |
|
|
| 418 | egetshell() { |
|
|
| 419 | local pos |
|
|
| 420 | |
|
|
| 421 | case ${CHOST} in |
|
|
| 422 | *-darwin*|*-freebsd*|*-dragonfly*) |
|
|
| 423 | pos=10 |
|
|
| 424 | ;; |
|
|
| 425 | *) # Linux, NetBSD, OpenBSD, etc... |
|
|
| 426 | pos=7 |
|
|
| 427 | ;; |
|
|
| 428 | esac |
|
|
| 429 | |
|
|
| 430 | egetent passwd "$1" | cut -d: -f${pos} |
|
|
| 431 | } |
|
|
| 432 | |
|
|
| 433 | # Returns true if specified user has a shell that precludes logins |
|
|
| 434 | # on whichever operating system. |
|
|
| 435 | is-login-disabled() { |
|
|
| 436 | |
|
|
| 437 | case $(egetshell "$1") in |
|
|
| 438 | /bin/false|/usr/bin/false|/sbin/nologin|/usr/sbin/nologin) |
|
|
| 439 | return 0 ;; |
|
|
| 440 | *) |
|
|
| 441 | return 1 ;; |
|
|
| 442 | esac |
|
|
| 443 | } |
|
|