int modify_passwd(SSL *ssl,int order) { ACCOUNT user; int ack; modify_passwd_ui(); echo_mode(STDIN_FILENO,ECHO_OFF); /* set echo off */ printf(YELLOW"Old Password: "******"\nNew Passwd: "); fgets(user.passwd,PASSWD_SIZE,stdin); user.passwd[strlen(user.passwd)-1] = '\0'; strcpy(user.name,LOGIN_USER.name); account_send(ssl,user,order); } else { printf(RED"\nPassword error!\n"NONE); } ack = sftpack_recv_ack(ssl,order); if( ack == PASSWD_OK) { printf("\nPasswd modify succeed!\n"); LOGIN_USER=user; } echo_mode(STDIN_FILENO,ECHO_ON); /* set echo off */ return 0; }
int alum_remove(t_element **list, int nbr) { int i; echo_mode(UNSET); raw_mode(SET); if (nbr <= 0) nbr = 1; i = 0; while ((*list)->name[i]) i++; nbr = i - nbr; while (i > nbr && i > 0) i--; if (i >= 0) (*list)->name[i] = '\0'; (*list)->cursor = 1; if ((nbr < 0) || (my_is_instr('|', (*list)->name) == IS_NOT_STR)) { (*list) = del_one_in_list((*list)); if ((*list) == NULL) return (END); (*list)->cursor = 1; } return (0); }
/* handle client login */ int clnt_login(SSL *ssl,int order) { ACCOUNT account; int ret = 0; memset(&account,0,sizeof(account)); login_ui(); login: account_input(account.name,"User name: ",NAME_SIZE); echo_mode(STDIN_FILENO,ECHO_OFF); /* set echo off */ pwloop: account_input(account.passwd,"Password: "******"clear"); logo_ui(); break; /* user not exist */ case USER_ERROR: fprintf(stderr, "%s is not exist!\n", account.name); goto login; /* passwd error */ case PASSWD_ERR: fprintf(stderr, "password error\n"); goto pwloop; /* undefine error */ default: fprintf(stderr,"undefine error\n"); ret = -1;break; } return ret; }
/* handle client register */ int clnt_register(SSL *ssl,int order) { char passwd[PASSWD_SIZE]; int ret = 0; int n,ack; ACCOUNT account; bzero(passwd,sizeof(passwd)); register_ui(); login: account_input(account.name,"New User Name: ",NAME_SIZE); echo_mode(STDIN_FILENO,ECHO_OFF); /* set echo off */ pwloop: account_input(account.passwd,"\nNew Passwd: ",PASSWD_SIZE); account_input(passwd,"\nConfirm New Passwd: ",PASSWD_SIZE); echo_mode(STDIN_FILENO,ECHO_ON); /* set echo on */ if(strcmp(passwd,account.passwd) != 0) { fprintf(stderr,"Passwd isn't matching,confirm failed!\n"); goto pwloop; } else { account_send(ssl,account,order); /* get respond from server */ int n = sftpack_recv_ack(ssl,order); if(n == REGISTER_OK) { printf("%s register succeed!\n",account.name); puts("go to login now!"); } else if(n == USER_EXIST) { fprintf(stderr,"%s is already exist\n",account.name); } } printf("\n"); return n; }
int get_number(void) { int nbr; char buffer[11]; int len; echo_mode(SET); raw_mode(UNSET); my_printf("\ngive number : "); if ((len = read(0, buffer, 10)) < 0) return (ERROR); buffer[len] = 0; nbr = my_getnbr(buffer); return (nbr); }
int main (int argc, char **argv) { GOptionContext *context; GError *error = NULL; const char *mode; gboolean ret; context = g_option_context_new ("MODE - Test GSubprocess stuff"); g_option_context_add_main_entries (context, options, NULL); ret = g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (!ret) { g_printerr ("%s: %s\n", argv[0], error->message); g_error_free (error); return 1; } if (argc < 2) { g_printerr ("MODE argument required\n"); return 1; } mode = argv[1]; if (strcmp (mode, "noop") == 0) return 0; else if (strcmp (mode, "exit1") == 0) return 1; else if (strcmp (mode, "assert-argv0") == 0) { if (strcmp (argv[0], "moocow") == 0) return 0; g_printerr ("argv0=%s != moocow\n", argv[0]); return 1; } else if (strcmp (mode, "echo") == 0) return echo_mode (argc, argv); else if (strcmp (mode, "echo-stdout-and-stderr") == 0) return echo_stdout_and_stderr_mode (argc, argv); else if (strcmp (mode, "cat") == 0) return cat_mode (argc, argv); else if (strcmp (mode, "sleep-forever") == 0) return sleep_forever_mode (argc, argv); else if (strcmp (mode, "write-to-fds") == 0) return write_to_fds (argc, argv); else if (strcmp (mode, "env") == 0) return env_mode (argc, argv); else if (strcmp (mode, "cwd") == 0) return cwd_mode (argc, argv); else if (strcmp (mode, "printenv") == 0) return printenv_mode (argc, argv); else { g_printerr ("Unknown MODE %s\n", argv[1]); return 1; } return TRUE; }