diff options
author | jkh <jkh@FreeBSD.org> | 1997-01-03 06:32:39 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1997-01-03 06:32:39 +0000 |
commit | ea0a75ee129d9998ed792e26f9256aa68fcf5bea (patch) | |
tree | 896ba9fcb9176c55630520639c25dbe04e995774 /usr.sbin/sysinstall/anonFTP.c | |
parent | b755851a75932ff275e1d0b9fd2283b881a80139 (diff) | |
download | FreeBSD-src-ea0a75ee129d9998ed792e26f9256aa68fcf5bea.zip FreeBSD-src-ea0a75ee129d9998ed792e26f9256aa68fcf5bea.tar.gz |
Do something I've wanted to do for quite some time - collapse all the
common layout code into some work functions and make all the layout-using
routine adopt them. Also reorganize includes and generally clean up.
Diffstat (limited to 'usr.sbin/sysinstall/anonFTP.c')
-rw-r--r-- | usr.sbin/sysinstall/anonFTP.c | 187 |
1 files changed, 25 insertions, 162 deletions
diff --git a/usr.sbin/sysinstall/anonFTP.c b/usr.sbin/sysinstall/anonFTP.c index cdd40fc..e62b8aa 100644 --- a/usr.sbin/sysinstall/anonFTP.c +++ b/usr.sbin/sysinstall/anonFTP.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: anonFTP.c,v 1.17 1996/09/06 05:58:27 jkh Exp $ + * $Id: anonFTP.c,v 1.18 1996/12/09 08:22:09 jkh Exp $ * * Copyright (c) 1995 * Coranth Gryphon. All rights reserved. @@ -36,20 +36,10 @@ * */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> +#include "sysinstall.h" #include <sys/param.h> -#include <string.h> -#include <dialog.h> -#include <sys/types.h> #include <pwd.h> #include <grp.h> -#include "ui_objects.h" -#include "dir.h" -#include "dialog.priv.h" -#include "colors.h" -#include "sysinstall.h" /* This doesn't change until FTP itself changes */ @@ -95,55 +85,36 @@ static int okbutton, cancelbutton; #define ANONFTP_DIALOG_WIDTH COLS - 16 #define ANONFTP_DIALOG_HEIGHT LINES - 2 -/* The screen layout structure */ -typedef struct _layout { - int y; /* x & Y co-ordinates */ - int x; - int len; /* The size of the dialog on the screen */ - int maxlen; /* How much the user can type in ... */ - char *prompt; /* The string for the prompt */ - char *help; /* The display for the help line */ - void *var; /* The var to set when this changes */ - int type; /* The type of the dialog to create */ - void *obj; /* The obj pointer returned by libdialog */ -} Layout; - static Layout layout[] = { +#define LAYOUT_UID 0 { 2, 3, 8, ANONFTP_UID_LEN - 1, "UID:", "What user ID to assign to FTP Admin", tconf.uid, STRINGOBJ, NULL }, -#define LAYOUT_UID 1 - +#define LAYOUT_GROUP 1 { 2, 15, 15, ANONFTP_GROUP_LEN - 1, "Group:", "Group name that ftp process belongs to", tconf.group, STRINGOBJ, NULL }, -#define LAYOUT_GROUP 2 - +#define LAYOUT_COMMENT 2 { 2, 35, 24, ANONFTP_COMMENT_LEN - 1, "Comment:", "Password file comment for FTP Admin", tconf.comment, STRINGOBJ, NULL }, -#define LAYOUT_COMMENT 3 - +#define LAYOUT_HOMEDIR 3 { 9, 10, 43, ANONFTP_HOMEDIR_LEN - 1, "FTP Root Directory:", "The top directory to chroot to when doing anonymous ftp", tconf.homedir, STRINGOBJ, NULL }, -#define LAYOUT_HOMEDIR 4 - +#define LAYOUT_UPLOAD 4 { 14, 20, 22, ANONFTP_UPLOAD_LEN - 1, "Upload Subdirectory:", "Designated sub-directory that holds uploads", tconf.upload, STRINGOBJ, NULL }, -#define LAYOUT_UPLOAD 5 - +#define LAYOUT_OKBUTTON 5 { 19, 15, 0, 0, "OK", "Select this if you are happy with these settings", &okbutton, BUTTONOBJ, NULL }, -#define LAYOUT_OKBUTTON 6 - +#define LAYOUT_CANCELBUTTON 6 { 19, 35, 0, 0, "CANCEL", "Select this if you wish to cancel this screen", &cancelbutton, BUTTONOBJ, NULL }, -#define LAYOUT_CANCELBUTTON 7 { NULL }, }; @@ -194,7 +165,7 @@ createFtpUser(void) if (tpw->pw_uid != FTP_UID) msgConfirm("FTP user already exists with a different uid."); - return (DITEM_SUCCESS); /* succeeds if already exists */ + return DITEM_SUCCESS; /* succeeds if already exists */ } sprintf(pwline, "%s::%s:%d::0:0:%s:%s:/bin/date\n", FTP_NAME, tconf.uid, gid, tconf.comment, tconf.homedir); @@ -202,13 +173,13 @@ createFtpUser(void) fptr = fopen(_PATH_MASTERPASSWD,"a"); if (! fptr) { msgConfirm("Could not open master password file."); - return (DITEM_FAILURE); + return DITEM_FAILURE; } fprintf(fptr, pwline); fclose(fptr); msgNotify("Remaking password file: %s", _PATH_MASTERPASSWD); vsystem("pwd_mkdb -p %s", _PATH_MASTERPASSWD); - return (DITEM_SUCCESS); + return DITEM_SUCCESS; } /* This is it - how to get the setup values */ @@ -216,38 +187,28 @@ static int anonftpOpenDialog(void) { WINDOW *ds_win; - ComposeObj *obj = NULL; - ComposeObj *first, *last; - int n=0, quit=FALSE, cancel=FALSE, ret; + ComposeObj *obj = NULL; + int n = 0, cancel = FALSE; int max; - char help[FILENAME_MAX]; char title[80]; /* We need a curses window */ - ds_win = newwin(LINES, COLS, 0, 0); - if (ds_win == 0) { + if (!(ds_win = openLayoutDialog(ANONFTP_HELPFILE, " Anonymous FTP Configuration ", + ANONFTP_DIALOG_X, ANONFTP_DIALOG_Y, ANONFTP_DIALOG_WIDTH, ANONFTP_DIALOG_HEIGHT))) { beep(); msgConfirm("Cannot open anonymous ftp dialog window!!"); - return(DITEM_FAILURE); + return DITEM_FAILURE; } - /* Say where our help comes from */ - systemHelpFile(ANONFTP_HELPFILE, help); - use_helpfile(help); - - /* Setup a nice screen for us to splat stuff onto */ - draw_box(ds_win, ANONFTP_DIALOG_Y, ANONFTP_DIALOG_X, ANONFTP_DIALOG_HEIGHT, ANONFTP_DIALOG_WIDTH, dialog_attr, border_attr); - wattrset(ds_win, dialog_attr); - mvwaddstr(ds_win, ANONFTP_DIALOG_Y, ANONFTP_DIALOG_X + 20, " Anonymous FTP Configuration "); - - draw_box(ds_win, ANONFTP_DIALOG_Y + 7, ANONFTP_DIALOG_X + 8, ANONFTP_DIALOG_HEIGHT - 11, ANONFTP_DIALOG_WIDTH - 17, + /* Draw a sub-box for the path configuration */ + draw_box(ds_win, ANONFTP_DIALOG_Y + 7, ANONFTP_DIALOG_X + 8, + ANONFTP_DIALOG_HEIGHT - 11, ANONFTP_DIALOG_WIDTH - 17, dialog_attr, border_attr); wattrset(ds_win, dialog_attr); sprintf(title, " Path Configuration "); mvwaddstr(ds_win, ANONFTP_DIALOG_Y + 7, ANONFTP_DIALOG_X + 22, title); /** Initialize the config Data Structure **/ - bzero(&tconf, sizeof(tconf)); SAFE_STRCPY(tconf.group, FTP_GROUP); @@ -256,110 +217,12 @@ anonftpOpenDialog(void) SAFE_STRCPY(tconf.homedir, FTP_HOMEDIR); sprintf(tconf.uid, "%d", FTP_UID); - /* Loop over the layout list, create the objects, and add them - onto the chain of objects that dialog uses for traversal*/ - - n = 0; -#define lt layout[n] - - while (lt.help != NULL) { - switch (lt.type) { - case STRINGOBJ: - lt.obj = NewStringObj(ds_win, lt.prompt, lt.var, - lt.y + ANONFTP_DIALOG_Y, lt.x + ANONFTP_DIALOG_X, - lt.len, lt.maxlen); - break; - - case BUTTONOBJ: - lt.obj = NewButtonObj(ds_win, lt.prompt, lt.var, - lt.y + ANONFTP_DIALOG_Y, lt.x + ANONFTP_DIALOG_X); - break; - - default: - msgFatal("Don't support this object yet!"); - } - AddObj(&obj, lt.type, (void *) lt.obj); - n++; - } - max = n - 1; - - /* Find the last object we can traverse to */ - last = obj; - while (last->next) - last = last->next; - - /* Find the first object in the list */ - first = obj; - while (first->prev) - first = first->prev; - /* Some more initialisation before we go into the main input loop */ - n = 0; - cancelbutton = 0; - cancel = FALSE; - okbutton = 0; - - /* Incoming user data - DUCK! */ - while (!quit) { - char help_line[80]; - int i, len = strlen(lt.help); - - /* Display the help line at the bottom of the screen */ - for (i = 0; i < 79; i++) - help_line[i] = (i < len) ? lt.help[i] : ' '; - help_line[i] = '\0'; - use_helpline(help_line); - display_helpline(ds_win, LINES - 1, COLS - 1); - - /* Ask for libdialog to do its stuff */ - ret = PollObj(&obj); - - /* Handle special case stuff that libdialog misses. Sigh */ - switch (ret) { - /* Bail out */ - case SEL_ESC: - quit = TRUE, cancel=TRUE; - break; - - /* This doesn't work for list dialogs. Oh well. Perhaps - should special case the move from the OK button ``up'' - to make it go to the interface list, but then it gets - awkward for the user to go back and correct screw up's - in the per-interface section */ - - case KEY_DOWN: - case SEL_CR: - case SEL_TAB: - if (n < max) - ++n; - else - n = 0; - break; - - /* The user has pressed enter over a button object */ - case SEL_BUTTON: - quit = TRUE; - if (cancelbutton) - cancel = TRUE; - break; - - case KEY_UP: - case SEL_BACKTAB: - if (n) - --n; - else - n = max; - break; - - case KEY_F(1): - display_helpfile(); - - /* They tried some key combination we don't support - tell them! */ - default: - beep(); - } - } - + obj = initLayoutDialog(ds_win, layout, ANONFTP_DIALOG_X, ANONFTP_DIALOG_Y, &max); + + cancelbutton = okbutton = 0; + while (layoutDialogLoop(ds_win, layout, &obj, &n, max, &cancelbutton, &cancel)); + /* Clear this crap off the screen */ dialog_clear_norefresh(); use_helpfile(NULL); |