shadow api를 이용하여 /etc/shadow file 제정방법좀 알고 싶습니다.!!!!!!!
shadow api를 이용해서 /etc/shadow file를 제어하려고합니다.
shadow api는 man에서 찾아보면 이런것들이 있는데요.. file정보를 읽는 것은 될것같은데,
특정 user의 특정 field 예를들어서 sp_lstchg를 고치러면 어떻게 해야되는지 모르겠네요.
혹시 아시는 분 있으시면 알려주세요..제가 구현하고싶은 내용은 administrator가 계정을
추가했을때 그계정으로최초접속시 passwd를 변경하게 하고싶습니다.
그래서 last field를 0으로 하면 되더라구여..근데 그걸 코드로 구현하려니까
잘모르겠습니다. 아시는분들 제발알려주세요!!
shadow manipulates the contents of the shadow password
file, /etc/shadow. The structure in the #include file is
struct spwd {
char *sp_namp; /* user login name */
char *sp_pwdp; /* encrypted password */
long sp_lstchg; /* last password change */
int sp_min; /* days until change allowed. */
int sp_max; /* days before change required */
int sp_warn; /* days warning for expiration */
int sp_inact; /* days before account inactive
*/
int sp_expire; /* date when account expires */
int sp_flag; /* reserved for future use */
}
struct spwd *getspent();
struct spwd *getspnam(char *name);
void setspent();
void endspent();
struct spwd *fgetspent(FILE *fp);
struct spwd *sgetspent(char *cp);
int putspent(struct spwd *p, FILE *fp);
int lckpwdf();
int ulckpwdf();
int set_lastfield_shadowfile(char * use_name)
{
struct spwd *spwd;
while((user_spwd = getspent()) !=NULL)
{
if(user_spwd = getspnam(user_name))
{
printf("%s %s %s %s %s %s %s %s\n",
spwd->sp_namp,
spwd->sp_lstchg,
spwd->sp_min,
spwd->sp_max,
spwd->sp_warn,
spwd->sp_inact,
spwd->sp_expire,
spwd->sp_flag);
}
}
}
간단히..
-e, --expire Immediately expire an account's password. This in effect can force a user to change his/her password at the user's next login.
코드로 짜시려면... 대략 이런 스타일로..(?) ;;
맨 위에 옵션은...
passwd 명령의 man 페이지 입니다.. ;;
(code 태그가 있었군요.. ;;)
댓글 달기