int login_changepwd(const char *u, const char *oldpwd, const char *newpwd, int *rc) { if (nochangepass()) return -1; *rc= -1; if (changepw("webmail", u, oldpwd, newpwd) == 0) { *rc=0; } return 0; }
int dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me) { int i; struct dg_cmdpart *tmp = queue; char *p1; char *p2; int played = 0; if (!queue) return 1; p1 = (char *)malloc(1024); p2 = (char *)malloc(1024); if (!p1 || !p2) return 1; return_from_submenu = 0; while (tmp && !return_from_submenu) { if (tmp->param1) strcpy(p1, dgl_format_str(game, me, tmp->param1, NULL)); if (tmp->param2) strcpy(p2, dgl_format_str(game, me, tmp->param2, NULL)); switch (tmp->cmd) { default: break; case DGLCMD_RAWPRINT: if (p1) fprintf(stdout, "%s", p1); break; case DGLCMD_MKDIR: if (p1 && (access(p1, F_OK) != 0)) mkdir(p1, 0755); break; case DGLCMD_UNLINK: if (p1 && (access(p1, F_OK) == 0)) unlink(p1); break; case DGLCMD_CHDIR: if (p1) { if (chdir(p1) == -1) { debug_write("chdir-command failed"); graceful_exit(123); } } break; case DGLCMD_IF_NX_CP: if (p1 && p2) { FILE *tmpfile; tmpfile = fopen(p2, "r"); if (tmpfile) { fclose(tmpfile); break; } } /* else fall through to cp */ case DGLCMD_CP: if (p1 && p2) { FILE *cannedf, *newfile; char buf[1024]; size_t bytes; /* FIXME: use nethack-themed error messages here, as per write_canned_rcfile() */ if (!(cannedf = fopen (p1, "r"))) break; if (!(newfile = fopen (p2, "w"))) break; while ((bytes = fread (buf, 1, 1024, cannedf)) > 0) { if (fwrite (buf, 1, bytes, newfile) != bytes) { if (ferror (newfile)) { fclose (cannedf); fclose (newfile); break; } } } fclose (cannedf); fclose (newfile); chmod (p2, default_fmode); } break; case DGLCMD_EXEC: if (p1 && p2) { pid_t child; char *myargv[3]; myargv[0] = p1; myargv[1] = p2; myargv[2] = 0; clear(); refresh(); endwin(); idle_alarm_set_enabled(0); child = fork(); if (child == -1) { perror("fork"); debug_write("exec-command fork failed"); graceful_exit(114); } else if (child == 0) { execvp(p1, myargv); exit(0); } else waitpid(child, NULL, 0); idle_alarm_set_enabled(1); initcurses(); check_retard(1); } break; case DGLCMD_SETENV: if (p1 && p2) mysetenv(p1, p2, 1); break; case DGLCMD_CHPASSWD: if (loggedin) changepw(1); break; case DGLCMD_CHMAIL: if (loggedin) change_email(); break; case DGLCMD_WATCH_MENU: inprogressmenu(-1); break; case DGLCMD_LOGIN: if (!loggedin) loginprompt(0); if (loggedin) runmenuloop(dgl_find_menu(get_mainmenu_name())); break; case DGLCMD_REGISTER: if (!loggedin && globalconfig.allow_registration) newuser(); break; case DGLCMD_QUIT: debug_write("command: quit"); graceful_exit(0); /* break; */ case DGLCMD_SUBMENU: if (p1) runmenuloop(dgl_find_menu(p1)); break; case DGLCMD_RETURN: return_from_submenu = 1; break; case DGLCMD_PLAY_IF_EXIST: if (!(loggedin && me && p1 && p2)) break; { FILE *tmpfile; tmpfile = fopen(p2, "r"); if (tmpfile) { fclose(tmpfile); } else break; } /* else fall through to playgame */ case DGLCMD_PLAYGAME: if (loggedin && me && p1 && !played) { int userchoice, i; char *tmpstr; for (userchoice = 0; userchoice < num_games; userchoice++) { if (!strcmp(myconfig[userchoice]->game_id, p1) || !strcmp(myconfig[userchoice]->game_name, p1) || !strcmp(myconfig[userchoice]->shortname, p1)) { if (purge_stale_locks(userchoice)) { if (myconfig[userchoice]->rcfile) { if (access (dgl_format_str(userchoice, me, myconfig[userchoice]->rc_fmt, NULL), R_OK) == -1) write_canned_rcfile (userchoice, dgl_format_str(userchoice, me, myconfig[userchoice]->rc_fmt, NULL)); } setproctitle("%s [playing %s]", me->username, myconfig[userchoice]->shortname); clear(); refresh(); endwin (); /* first run the generic "do these when a game is started" commands */ dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_GAMESTART], userchoice, me); /* then run the game-specific commands */ dgl_exec_cmdqueue(myconfig[userchoice]->cmdqueue, userchoice, me); /* fix the variables in the arguments */ for (i = 0; i < myconfig[userchoice]->num_args; i++) { tmpstr = strdup(dgl_format_str(userchoice, me, myconfig[userchoice]->bin_args[i], NULL)); free(myconfig[userchoice]->bin_args[i]); myconfig[userchoice]->bin_args[i] = tmpstr; } signal(SIGWINCH, SIG_DFL); signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); signal(SIGTERM, SIG_DFL); idle_alarm_set_enabled(0); /* launch program */ ttyrec_main (userchoice, me->username, dgl_format_str(userchoice, me, myconfig[userchoice]->ttyrecdir, NULL), gen_ttyrec_filename()); idle_alarm_set_enabled(1); played = 1; /* lastly, run the generic "do these when a game is left" commands */ signal (SIGHUP, catch_sighup); signal (SIGINT, catch_sighup); signal (SIGQUIT, catch_sighup); signal (SIGTERM, catch_sighup); signal(SIGWINCH, sigwinch_func); dgl_exec_cmdqueue(myconfig[userchoice]->postcmdqueue, userchoice, me); dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_GAMEEND], userchoice, me); setproctitle ("%s", me->username); initcurses (); check_retard(1); /* reset retard counter */ } break; } } } break; } tmp = tmp->next; } free(p1); free(p2); return 0; }