GB | BIG5
|
| 首頁 > 編程技術 > 其它 > 正文 |
 |
| Linux程式設計-30.使用者資訊管理(pwd) |
| http://www.openchess.org/noitatsko/programming/ (2001-05-27 21:04:00) |
pwd.h
--------------------------------------------------------------------------------
要存取使用者帳號資訊,可以使用pwd.h來取用/etc/passwd內的資訊。
POSIX.1中把/etc/passwd稱為user database file.
在POSIX.1中其實僅定義了五個欄位,不過在SVR4及4.3+BSD中,都支援七個欄位。
--------------------------------------------------------------------------------
struct passwd
{
char * pw_name; /* Username, POSIX.1 */
char * pw_passwd; /* Password */
__uid_t pw_uid; /* User ID, POSIX.1 */
__gid_t pw_gid; /* Group ID, POSIX.1 */
char * pw_gecos; /* Real Name or Comment field */
char * pw_dir; /* Home directory, POSIX.1 */
char * pw_shell; /* Shell Program, POSIX.1 */
};
--------------------------------------------------------------------------------
當您需要取得有關某個使用者的資訊時,大致上有以下幾個函數可以使用:
--------------------------------------------------------------------------------
struct passwd * getpwuid(uid_t uid);
當您知道使用者的uid(user id)時,可以透過getpwuid來得知所有關於該使用者的相關資訊。
--------------------------------------------------------------------------------
struct passwd * getpwnam(char * name);
當您知道使用者名稱時,可以透過getpwnam來得知所有關於該使用者的相關資訊。
--------------------------------------------------------------------------------
int getpw(uid_t uid, char *buf);
當您僅需要取得使用者的密碼進行比對時,可以使用getpw。
--------------------------------------------------------------------------------
另外,有存取一系列使用者資訊的方法。
--------------------------------------------------------------------------------
FILE * pwdopen(void);
開啟password檔案。
--------------------------------------------------------------------------------
struct passwd * pwdread(FILE * stream,struct passwd *p);
讀取一個使用者資訊進來,填到p中,返回p為成功,NULL為失敗。
--------------------------------------------------------------------------------
void setpwent(void);
將讀取資料流重設到起點。
--------------------------------------------------------------------------------
void endpwent(void);
關閉password檔案資料流。
--------------------------------------------------------------------------------
struct passwd * getpwent(void);
讀取一個使用者資訊進來,有必要的話,則將進行開檔動作。
--------------------------------------------------------------------------------
struct passwd * fgetpwent(FILE * stream);
從檔案中讀取一個使用者資訊進來。
--------------------------------------------------------------------------------
int putpwent(struct passwd *p,FILE *f);
將一個使用者資訊寫入檔案中。
--------------------------------------------------------------------------------
struct passwd * pwdalloc(void);
配置一個記憶體區塊給passwd用。
--------------------------------------------------------------------------------
(http://www.fanqiang.com)
進入【UNIX論壇】
|
|
| 相關文章 |
Linux程式設計-31.工作群資訊管理(grp) (2001-05-27 22:08:00) Linux程式設計-30.使用者資訊管理(pwd) (2001-05-27 21:04:00) Linux程式設計-29.時間處理 (2001-05-27 20:10:01) Linux程式設計-28.GNU Make (2001-05-27 19:00:00) Linux程式設計-27.GNU Debugger (2001-05-27 18:08:01) Linux程式設計-26.PIPE (2001-05-27 17:04:00) Linux程式設計-25.Message Queues (2001-05-27 16:10:00) Linux程式設計-24.Semaphores (2001-05-27 15:00:00) Linux程式設計-23.共享記憶體(Shared Memory) (2001-05-27 14:08:00) Linux程式設計-20.getopt (2001-05-27 13:04:00)
|
===更多相關=== |
|
|
 |
★ 樊強制作 歡迎分享 ★ |