The POSIX API/nss/nscd
https://code.google.com/p/nsscache/wiki/BackgroundOnNameServiceSwitch
The POSIX API
POSIX is a standard that defines an operating system interface and its environment; describing available library calls, utilities, environment vars, escape sequences, regexps, when to take coffee breaks (aka how long your code takes to compile), etc.
GNU/Linux is (generally) POSIX compliant.
The relevant component of POSIX is the definition of function calls to access directory information -- databases of people/groups/hosts/etc.
Here are some examples of the POSIX API functions, the method in which applications access information in the the system databases.
- get*nam() -> get a database entry by its human readable name
- get*id() -> get a database entry by its computer readable name
- get*ent() -> get the next entry in a database; a mechanism for iterating over the entire database
(The asterisk replaces the short name of the database being accessed.)
These functions get called all the time, for example:
- at login (to find out who you are and what your groups are)
- ls -l (mapping uid/gid of a file to username/group)
- resolving hostnames to IP addresses
- many others: NIS netgroups, automount locations, rpc names, TCP and UDP protocol names
It doesn't matter for the most part that these API calls are made all the time, because when the API was designed, the database that stored this information is a plain text file on the local machine, and accessing that is both fast and 100% reliable (ignoring of course hardware issues on the local machine, at which point you have bigger problems :-)
As we got bigger networks and lots of shared computing infrastructure, we moved to directory services. /etc/hosts stopped scaling, so we got DNS, and it all went downhill from there.
System administrators wanted to get the system databases from other sources like NIS, NIS+, LDAP, Hesiod (gag), DNS, etc. To facilitate that, you want to allow easy runtime configuration changes, i.e. different types of data may need to be stored in different places -- users in/etc/passwd versus hosts in DNS.
First implemented by Sun, this was dubbed the name service switch, or NSS for short.
The Name Service Switch
Perhaps you're familiar with the Name Service Switch configuration file, /etc/nsswitch.conf:
passwd: compat files
group: compat files
shadow: compat files
hosts: files dns
On the right hand side of the colon are the data sources, where NSS will go to retrieve the system database. It progresses left to right, checking each source in turn until the data is found.
On the left hand side of the colon, the groupings of data, the database itself, which we are calling "maps" -- in this example, the passwd database API functions are mapped to the "compat" and "files" data sources.
For our own convenience, this document will refer to both the POSIX API described above, and the GNU libc implementation of the Name Service Switch as both "NSS".

# /etc/nsswitch.conf
passwd: files
When an NSS function is called, the NSS implementation reads its configuration file /etc/nsswitch.conf, which names the library that implements the data retrieval. NSS dynamically loads this library, in this example, libnss_files.so. The correct function within this library is then called, for example _nss_files_getpwuid().
libnss_files then opens and parses /etc/passwd, and returns (typically a struct).
NSS + RFC 2307 LDAP

# /etc/nsswitch.conf
passwd: files ldap
Add in a directory service, and you get a situation familiar to many sysadmins. /etc/nsswitch.conf would now also list ldap in addition to filesin this example.
If NSS were to load libnss_files.so, and find nothing, it would then load libnss_ldap.so. libnss_ldap.so would make a network connection to the LDAP server, perform a query, and convert the LDAP results into the right return structure.
This means that every query will translate into a TCP connection with handshake overhead, possibly over SSL with its crypto overhead, and then do various ASN.1 and BER en- and decodings within the LDAP protocol itself...
Name Service Cache Daemon

So we also typically run a caching daemon, provided by GNU libc, called nscd.
It's accessed via a UNIX socket, and though poorly demonstrated by this diagram, loads the nss modules itself in order to act as a hit-and-miss cache.
It has several threads to that it can respond to several requests at the same time.
If the cache has the response, it returns it straight away. If not, it dlopens the NSS module, e.g. libnss_ldap.so, waits for the reply, caches it, and then returns it.
The POSIX API/nss/nscd的更多相关文章
- 消息队列接口API(posix 接口和 system v接口)
消息队列 posix API 消息队列(也叫做报文队列)能够克服早期unix通信机制的一些缺点.信号这种通信方式更像\"即时\"的通信方式,它要求接受信号的进程在某个时间范围内对信 ...
- API 设计 POSIX File API
小结: 1. https://mp.weixin.qq.com/s/qWrSyzJ54YEw8sLCxAEKlA API 设计最佳实践的思考 谷朴 阿里技术 昨天 阿里妹导读:API 是模块或者子 ...
- system v和posix的共享内存对比 & 共享内存位置
参考 http://www.startos.com/linux/tips/2011012822078.html 1)Linux和所有的UNIX操作系统都允许通过共享内存在应用程序之间共享存储空间. 2 ...
- VxWorks 6.9 内核编程指导之读书笔记 -- POSIX
POSIX能力 VxWorks扩展了POSIX,为了移植,VxWorks提供了额外的POSIX接口作为可选组件.VxWorks实现了POSIX 1003.1(POSIX .1)一些传统接口以及POSI ...
- Native Application 开发详解(直接在程序中调用 ntdll.dll 中的 Native API,有内存小、速度快、安全、API丰富等8大优点)
文章目录: 1. 引子: 2. Native Application Demo 展示: 3. Native Application 简介: 4. Native Ap ...
- [转] 阿里研究员谷朴:API 设计最佳实践的思考
API是软件系统的核心,而软件系统的复杂度Complexity是大规模软件系统能否成功最重要的因素.但复杂度Complexity并非某一个单独的问题能完全败坏的,而是在系统设计尤其是API设计层面很多 ...
- Xenomai 3 POSIX
Xenomai 3在架构设计上确实优先Xenomai 2,至少对开发者来说,少维护了不少东西,看下面两张图就知道了 第一张图是Xenomai2的,第二张图是Xenomai3的,Xenomai3在内核中 ...
- mingw-w64线程模型:posix vs win32(posix允许使用c++11的std:: thread,但要带一个winpthreads,可能需要额外dll)
我正在安装 mingw-w64 on Windows,有两个选项: win32线程和posix线程. 我知道win32线程和pthreads之间的区别,但是我不明白这两个选项之间的区别. 我怀疑如果我 ...
- MingGW Posix VS Win32 - 明瓜娃的毒因
MinGW-posix和win32纠缠的瓜娃子 官方首席佛偈(SourceForge)的官网下载页 法克油啊,让我一个小白情何以堪. 盘TA wiki posix wiki中文-UNIX API标准 ...
随机推荐
- users命令详解
基础命令学习目录 原文链接:https://blog.csdn.net/m0_38132420/article/details/78861464 users命令用于显示当前登录系统所有的用户的用户列表 ...
- PHP Filter 函数 日常可用
PHP Filter 函数 PHP Filesystem PHP FTP PHP Filter 简介 PHP 过滤器用于对来自非安全来源的数据(比如用户输入)进行验证和过滤. 安装 filter 函数 ...
- 第十二周作业_PSP总结报告
回顾1 (1)回想一下你曾经对计算机专业的畅想 当初你是如何做出选择计算机专业的决定的?经过一个学期,你的看法改变了么,为什么? 你认为过去接触到的课程是否符合你对计算机专业的期待,为什么?经过一个学 ...
- JAVA第一次实验 ——凯撒密码
课程:Java程序设计 班级:1352 姓名:黄伟业 学号:20135215 成绩: 指导教师:娄嘉鹏 实验日期:2015.4.15 实验密级: 预习程度: 实验时间:19: ...
- prototype原型(待完善)
模式:prototype 解决向量的深浅克隆 #pragma once #ifndef _PROTOTYPE_H_ #define _PROTOTYPE_H_ class Prototype{ pu ...
- b7
组员:陈锦谋 过去两天完成了哪些任务: 细节最后完善 明日计划: 无 还剩下哪些任务: 无 有哪些困难: 暂无 有哪些收获和疑问: 无
- ssh框架配置数据源 数据库连接没有正常释放
通过多天的改bug 对数据源这个东西了解多了.. 我发现 spring+hibernate下 申请数据库连接是在一个action方法内 也就是说 action 里面有三个 service方 ...
- 一个简单的加减乘除自动生成小程序(JAVA)
在学习软件工程的时候,遇到一个这样的问题,一个程序员的儿子上小学二年级,老师让家长每天出30道加减题目给学生做,由于家长是个程序员,所以呢,他就自己写了个程序实现,我们可爱的老师于是也叫我们写了一个类 ...
- Xcode7~8版本过渡导致的问题
现有项目是早期Xcode7编写的,一直到现在还是使用Xcode7编写.近期一位用户手机下载App出现闪退现象,该用户手机系统(iPhone 6 iOS8.1.2)经查实是由于CoreFoundatio ...
- jQuery之_事件绑定与解绑
使用jQuery实现事件的绑定和解绑 就是所谓的事件操作. 1. 事件绑定(2种): * eventName(function(){}) 绑定对应事件名的监听, 例如:$('#div').click( ...