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 filesgroup: compat filesshadow: compat fileshosts: 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.confpasswd: 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.confpasswd: 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.solibnss_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.

时间: 2024-10-15 03:51:21

The POSIX API/nss/nscd的相关文章

POSIX API

POSIX标准总体分析 POSIX,全称为可移植性操作系统接口,是一种关于信息技术的IEEE标准.它包括了系统应用程序接口(API),以及实时扩展(C语言). 该标准的目的是定义了标准的基于UNIX操作系统的系统接口和环境来支持源代码级的可移植性.现在,标准主要提供了依赖C语言的一系列标准服务,再将来的版本中,标准将致力于提供基于不同语言的规范. 该标准对核心需求部分定义了一系列任何编程语言都通用的服务,这一部分服务主要从其功能需求方面阐述,而非定义依赖于编程语言的接口.语言规范主要有两部分组成

消息队列接口API(posix 接口和 system v接口)

消息队列 posix API 消息队列(也叫做报文队列)能够克服早期unix通信机制的一些缺点.信号这种通信方式更像\"即时\"的通信方式,它要求接受信号的进程在某个时间范围内对信号做出反应,因此该信号最多在接受信号进程的生命周期内才有意义,信号所传递的信息是接近于随进程持续的概念(process-persistent):管道及有名管道则是典型的随进程持续IPC,并且,只能传送无格式的字节流无疑会给应用程序开发带来不便,另外,它的缓冲区大小也受到限制消息队列就是一个消息的链表.可以把消

Native Application 开发详解(直接在程序中调用 ntdll.dll 中的 Native API,有内存小、速度快、安全、API丰富等8大优点)

文章目录:                   1. 引子: 2. Native Application Demo 展示: 3. Native Application 简介: 4. Native Application 有何妙用: 5. MJ0011 关于 Native Application 的文章整理: 6. 互联网上其他关于 Native Application 的文章整理: 7. 小结: 1. 引子: 其实在好久以前就看了 MJ0011 翻译的那个<Native 应用程序详细>系列的文

API的概念

时间:2014.07.02 地点:基地 -------------------------------------------------------------------------------- 一.什么是API API(Application Programming Interface)在现代软件中随处可见,目的在于为某个组件的功能提供一个逻辑接口,同时隐藏该模块内部的实现细节.是对问题的抽象,以及客户与解决问题的软件组件之间进行交互的方式.总的来说:API是一个明确定义的接口,它可以为

mingw-w64线程模型:posix vs win32(posix允许使用c++11的std:: thread,但要带一个winpthreads,可能需要额外dll)

我正在安装 mingw-w64 on Windows,有两个选项: win32线程和posix线程. 我知道win32线程和pthreads之间的区别,但是我不明白这两个选项之间的区别. 我怀疑如果我选择了posix线程,它将阻止我调用像CreateThread这样的WinAPI函数. 似乎这个选项指定了哪个程序或者库将使用哪个线程 API,但通过什么? 由 GCC,libstdc++或者其他事物? 我发现:什么区别thread_posixs和 thread_win32 gcc Windows

在 electron-vue 中的 Windows 下的路径问题,path.resolve 替换为 path.posix.join 。

起因很简单,如下代码在 Windows 的 electron-vue 会发生如下问题,别问我为什么,我也很迷茫,有如下相关代码. return path.resolve(this.basePath, routePath) // return path.join(this.basePath, routePath) // return path.posix.join(this.basePath, routePath) return path.resolve(this.basePath, routeP

学习linux前需要了解知识点

1,linux版本号表示: major.minor.release 例:2.4.4,3.10.18 2,发行商: 发行版:开源程序+linux内核 slackware 而后衍生:suse Debian 而后衍生:ubuntu redhat: 而后衍生:Centos(社区版) Fedora Archlinux,Gentoo:源码,可根据需求自动做出优化和定制,但技术较复杂 3, 应用接口: api:application programming interface应用程序接口 包括syscall(

对C语言知识结构的一点思考

很长时间以来,都是在用C语言写东西.也一直在思考,如何能很好的掌握C,查过很多资料,也作过一些尝试,于是整理成此文. 在大部分情况下,我们会写或者使用一个C库,然后被应用程序使用,运行在Linux的系统上.于是,就有了基于C语言的知识结构: App ------------------- C API C, libc ------------------- Posix API Linux Kernel 整体结构大致有上面的三层,五个部分.大致思路是:必须了解上层的需求,和下层能提供的功能. App

解密Redis持久化

本文内容来源于 Redis 作者博文,Redis 作者说,他看到的所有针对 Redis 的讨论中,对 Redis持久化的误解是最大的,于是他写了一篇长文来对 Redis 的持久化进行了系统性的论述.文章非常长,也很值得一看,NoSQLFan 将主要内容简述成本文. 什么是持久化,简单来讲就是将数据放到断电后数据不会丢失的设备中.也就是我们通常理解的硬盘上. 写操作的流程 首先我们来看一下数据库在进行写操作时到底做了哪些事,主要有下面五个过程. 客户端向服务端发送写操作(数据在客户端的内存中) 数