我有一個文件的參數(特別是用戶標識和groupid)使用stat
命令讀取,我工作在一個網絡上,用戶和組在ldap服務器上指定。如何獲取groupname當我有groupid
我已經得到命令getent passwd userid
的結果中的用戶名。
現在我的想法是獲得組名getent group groupid
,但這是行不通的。
任何人都可以告訴我哪裏有我的錯誤或我如何獲得組名?
謝謝!
我有一個文件的參數(特別是用戶標識和groupid)使用stat
命令讀取,我工作在一個網絡上,用戶和組在ldap服務器上指定。如何獲取groupname當我有groupid
我已經得到命令getent passwd userid
的結果中的用戶名。
現在我的想法是獲得組名getent group groupid
,但這是行不通的。
任何人都可以告訴我哪裏有我的錯誤或我如何獲得組名?
謝謝!
撇開您提供錯誤的組ID的可能性,此 可能是LDAP設置中的一個錯誤,它表現爲反向組解析而不是 的工作。這可以通過一個簡單的「文件」 設置來實現。
的getent(1)條規定:
group When no key is provided, use setgrent(3), getgrent(3), and
endgrent(3) to enumerate the group database. When one or
more key arguments are provided, pass each numeric key to
getgrgid(3) and each nonnumeric key to getgrnam(3) and
display the result.
這可能意味着getgrgid(3)你的設置失敗。
爲了測試這個編譯這個程序(getgrgid_test.c)以 「讓getgrgid_test」:
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
int
main(int argc, char **argv)
{
int gid;
struct group *g;
if (argc != 2) {
fprintf(stderr, "Invalid number of positional arguments\n");
fprintf(stderr, "Usage getgrid_test GID\n");
return 1;
}
gid = atoi(argv[1]);
g = getgrgid(gid);
if (g == NULL) {
fprintf(stderr, "gid %d not found\n", gid);
return 1;
}
printf("%s\n", g->gr_name);
return 0;
}
然後用你的GID像這樣運行:
getgrgid_test GID
如果它不產生一個組名稱報告給您的系統管理員。
否則,如果確實有效,但「getent group GID」沒有,這是「getent」中的一個錯誤 。
你可能有一個配置問題,即要麼你沒有得到這樣一行:
group: files ldap
在
。
或您在ldap服務器上的羣組信息是一種沒有羣組ID號碼的形式,例如類型爲groupOfNames
,groupOfUniqueNames
而不是類型posixGroup
。
只有posixGroup具有適當的屬性,允許它在linux/unix中用作有效組(即需要匹配的組ID號)。在這種情況下,ldap服務器不會返回有效的組。
你可以有一個完美的功能ldap配置沒有任何或所有的遠程組在getent group
的輸出中。
適用於SLES 11.2。 – jwilleke 2013-04-23 14:27:43