从Unix中的用户名中获取UID和GID? [英] Programatically getting UID and GID from username in Unix?

查看:705
本文介绍了从Unix中的用户名中获取UID和GID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用setuid()和setgid()设置一个程序的相应的ID从根下降特​​权,但使用它们我需要知道我想要更改的用户的uid和gid to。



是否有系统调用来执行此操作?我不想硬编码或从/ etc / passwd解析。



我也想编程,而不是使用:



id -u USERNAME



任何帮助将非常感谢

解决方案

查看 getpwnam() getgrnam()函数。


I'm trying to use setuid() and setgid() to set the respective id's of a program to drop privileges down from root, but to use them I need to know the uid and gid of the user I want to change to.

Is there a system call to do this? I don't want to hardcode it or parse from /etc/passwd .

Also I'd like to do this programatically rather than using:

id -u USERNAME

Any help would be greatly appreciated

解决方案

Have a look at the getpwnam() and getgrnam() functions.

这篇关于从Unix中的用户名中获取UID和GID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆