Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=e918406c6ac4aa34df624790f2f650cbc66fbd52
commit e918406c6ac4aa34df624790f2f650cbc66fbd52 Author: James Buren <[email protected]> Date: Fri Sep 7 02:43:58 2012 -0500 implement root password change in postconfig diff --git a/src/postconfig.c b/src/postconfig.c index 8b34eb6..34ff3f9 100644 --- a/src/postconfig.c +++ b/src/postconfig.c @@ -9,7 +9,7 @@ static bool is_root_setup(void) char *pwd = 0; bool result = false; - file = fopen("/etc/shadow","rb"); + file = fopen("etc/shadow","rb"); if(file == 0) { @@ -45,7 +45,7 @@ static bool is_user_setup(void) char *gid = 0; bool result = false; - file = fopen("/etc/passwd","rb"); + file = fopen("etc/passwd","rb"); if(file == 0) { @@ -79,6 +79,22 @@ static bool is_user_setup(void) return result; } +static bool root_action(struct account *account) +{ + char command[_POSIX_ARG_MAX] = {0}; + + if(account == 0 || account->user == 0 || account->password == 0) + { + errno = EINVAL; + fprintf(logfile,"%s: %s\n",__func__,strerror(errno)); + return false; + } + + snprintf(command,_POSIX_ARG_MAX,"echo '%s:%s' | chpasswd",account->user,account->password); + + return execute(command,INSTALL_ROOT,0); +} + static void account_free(struct account *account) { if(account == 0) @@ -103,9 +119,23 @@ static bool postconfig_run(void) { struct account account = {0}; + if(chdir(INSTALL_ROOT) == -1) + { + fprintf(logfile,"%s: %s\n",__func__,strerror(errno)); + return false; + } + if(!is_root_setup() && !ui_window_root(&account)) return false; + if(!root_action(&account)) + { + account_free(&account); + return false; + } + + account_free(&account); + return true; } _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
