所以我試圖添加一個服務到NSS(名稱服務交換機)。請注意GNU指南有關如何操作here。我一直在遵循該指南。我需要實現一個與passwd數據庫一起工作的服務。將服務添加到名稱服務交換機
我遇到的問題是我的模塊沒有被調用某些功能。讓我複製了一些在這裏我的代碼...
enum nss_status
_nss_myservice_setpwent (void) {
printf("@ %s\n", __FUNCTION__) ;
return NSS_STATUS_SUCCESS ;
} ;
enum nss_status
_nss_myservice_endpwent (void) {
printf("@ %s\n", __FUNCTION__) ;
return NSS_STATUS_SUCCESS ;
} ;
enum nss_status
_nss_myservice_getpwent_r (struct passwd *result, char *buffer,
size_t buflen, int *errnop) {
static int i = 0 ;
if(i++ == 0) {
printf("@ %s\n", __FUNCTION__) ;
return init_result(result, buffer, buflen, errnop) ;
} else {
i = 0 ;
return NSS_STATUS_NOTFOUND ;
}
} ;
enum nss_status
_nss_myservice_getpwbynam (const char *nam, struct passwd *result, char *buffer,
size_t buflen, int *errnop) {
printf("@ %s with name %s\n", __FUNCTION__, nam) ;
return init_result(result, buffer, buflen, errnop) ;
} ;
enum nss_status
_nss_myservice_getpwbynam_r (const char *nam, struct passwd *result, char *buffer,
size_t buflen, int *errnop) {
printf("@ %s with name_r %s\n", __FUNCTION__, nam) ;
return init_result(result, buffer, buflen, errnop) ;
} ;
Init_result是一個內聯函數,只需在結果與虛擬用戶填寫無論什麼PARAMS是。
現在,我有我的/etc/nsswitch.conf的設置如下:
passwd: myservice compat
以及物品是否完整,這裏是我的Makefile。
all:
gcc -fPIC -shared -o libnss_myservice.so.2 -Wl,-soname,libnss_myservice.so.2 myservice.c
install:
sudo install -m 0644 libnss_myservice.so.2 /lib
sudo /sbin/ldconfig -n /lib /usr/lib
clean:
/bin/rf -rf libnss_myservice.so.2
現在安裝此NSS模塊後,我跑在命令行上getent這裏是我的輸出:
[email protected]:~/nss$ getent passwd
@ _nss_myservice_setpwent
@ _nss_myservice_getpwent_r
myuser:mypass:1:1:realname::
root:x:0:0:root:/root:/bin/bash
...
@ _nss_myservice_endpwent
因此,大家可以看到,在工作,我期望的那樣。迭代調用返回用戶,然後調用compat服務,它將從/ etc/passwd返回所有用戶。
問題是當我打電話時,「getent passwd myuser」,我得到2的返回值,「在數據庫中找不到密鑰」。這表明我的_nss_myservice_getpwbynam_r函數沒有被調用。任何想法爲什麼?如果有幫助,我可以提供完整的代碼。
,如果你把它叫做'_nss_myservice_getpwnam_r'而不是麼?只是一個猜測,但我看到有一個'pwd.h'函數稱爲'getpwnam_r' – 2013-05-03 23:07:13