|
Lines 39-44
Link Here
|
| 39 |
#include <ctype.h> |
39 |
#include <ctype.h> |
| 40 |
#include <sys/param.h> |
40 |
#include <sys/param.h> |
| 41 |
#include <sysexits.h> |
41 |
#include <sysexits.h> |
|
|
42 |
#include <pwd.h> |
| 42 |
|
43 |
|
| 43 |
/* The help file for the user mgmt screen */ |
44 |
/* The help file for the user mgmt screen */ |
| 44 |
#define USER_HELPFILE "usermgmt" |
45 |
#define USER_HELPFILE "usermgmt" |
|
Lines 69-74
Link Here
|
| 69 |
umemb[UMEMB_FIELD_LEN], |
70 |
umemb[UMEMB_FIELD_LEN], |
| 70 |
homedir[HOMEDIR_FIELD_LEN], |
71 |
homedir[HOMEDIR_FIELD_LEN], |
| 71 |
shell[SHELL_FIELD_LEN]; |
72 |
shell[SHELL_FIELD_LEN]; |
|
|
73 |
|
| 72 |
#define CLEAR(v) memset(v, 0, sizeof v) |
74 |
#define CLEAR(v) memset(v, 0, sizeof v) |
| 73 |
|
75 |
|
| 74 |
static int okbutton, cancelbutton; |
76 |
static int okbutton, cancelbutton; |
|
Lines 150-155
Link Here
|
| 150 |
{ NULL }, |
152 |
{ NULL }, |
| 151 |
}; |
153 |
}; |
| 152 |
|
154 |
|
|
|
155 |
/* The NIS user configuration menu. */ |
| 156 |
static Layout NISuserLayout[] = { |
| 157 |
#define LAYOUT_UNAME 0 |
| 158 |
{ 3, 6, UT_NAMESIZE, UT_NAMESIZE + 1, |
| 159 |
"Login ID:", "The login name of the new user (appended with a '+')", |
| 160 |
uname, STRINGOBJ, NULL }, |
| 161 |
#define LAYOUT_UID 1 |
| 162 |
{ 3, 23, 8, UID_FIELD_LEN - 1, |
| 163 |
"UID:", "The numerical ID for this user (leave blank to use server's setting)", |
| 164 |
uid, STRINGOBJ, NULL }, |
| 165 |
#define LAYOUT_UGROUP 2 |
| 166 |
{ 3, 33, 8, UGROUP_FIELD_LEN - 1, |
| 167 |
"Group:", "The login group name for this user (leave blank to use server's setting)", |
| 168 |
ugroup, STRINGOBJ, NULL }, |
| 169 |
#define LAYOUT_GECOS 4 |
| 170 |
{ 8, 6, 33, GECOS_FIELD_LEN - 1, |
| 171 |
"Full name:", "The user's full name (comment)", |
| 172 |
gecos, STRINGOBJ, NULL }, |
| 173 |
#define LAYOUT_UMEMB 5 |
| 174 |
{ 8, 43, 15, UMEMB_FIELD_LEN - 1, |
| 175 |
"Member groups:", "The groups this user belongs to (i.e. gets access rights for)", |
| 176 |
umemb, STRINGOBJ, NULL }, |
| 177 |
#define LAYOUT_HOMEDIR 6 |
| 178 |
{ 13, 6, 20, HOMEDIR_FIELD_LEN - 1, |
| 179 |
"Home directory:", "The user's home directory (leave blank to use server's setting)", |
| 180 |
homedir, STRINGOBJ, NULL }, |
| 181 |
#define LAYOUT_SHELL 7 |
| 182 |
{ 13, 29, 29, SHELL_FIELD_LEN - 1, |
| 183 |
"Login shell:", "The user's login shell (leave blank to use server's setting)", |
| 184 |
shell, STRINGOBJ, NULL }, |
| 185 |
#define LAYOUT_U_OKBUTTON 8 |
| 186 |
{ 18, 15, 0, 0, |
| 187 |
"OK", "Select this if you are happy with these settings", |
| 188 |
&okbutton, BUTTONOBJ, NULL }, |
| 189 |
#define LAYOUT_U_CANCELBUTTON 9 |
| 190 |
{ 18, 35, 0, 0, |
| 191 |
"CANCEL", "Select this if you wish to cancel this screen", |
| 192 |
&cancelbutton, BUTTONOBJ, NULL }, |
| 193 |
{ NULL }, |
| 194 |
}; |
| 195 |
|
| 153 |
/* whine */ |
196 |
/* whine */ |
| 154 |
static void |
197 |
static void |
| 155 |
feepout(char *msg) |
198 |
feepout(char *msg) |
|
Lines 654-667
Link Here
|
| 654 |
{ |
697 |
{ |
| 655 |
WINDOW *ds_win, *save; |
698 |
WINDOW *ds_win, *save; |
| 656 |
ComposeObj *obj = NULL; |
699 |
ComposeObj *obj = NULL; |
| 657 |
int n = 0, cancel = FALSE, ret; |
700 |
int n = 0, cancel = FALSE, isNIS, ret; |
| 658 |
int max, firsttime = TRUE; |
701 |
int max, firsttime = TRUE; |
|
|
702 |
Layout *layout; |
| 659 |
|
703 |
|
| 660 |
if (RunningAsInit && !strstr(variable_get(SYSTEM_STATE), "install")) { |
704 |
if (RunningAsInit && !strstr(variable_get(SYSTEM_STATE), "install")) { |
| 661 |
msgConfirm("This option may only be used after the system is installed, sorry!"); |
705 |
msgConfirm("This option may only be used after the system is installed, sorry!"); |
| 662 |
return DITEM_FAILURE; |
706 |
return DITEM_FAILURE; |
| 663 |
} |
707 |
} |
| 664 |
|
708 |
|
|
|
709 |
isNIS=(int)self->data; |
| 710 |
layout = isNIS ? NISuserLayout : userLayout; |
| 711 |
|
| 665 |
save = savescr(); |
712 |
save = savescr(); |
| 666 |
dialog_clear_norefresh(); |
713 |
dialog_clear_norefresh(); |
| 667 |
|
714 |
|
|
Lines 689-713
Link Here
|
| 689 |
CLEAR(shell); |
736 |
CLEAR(shell); |
| 690 |
|
737 |
|
| 691 |
/* Some more initialisation before we go into the main input loop */ |
738 |
/* Some more initialisation before we go into the main input loop */ |
| 692 |
obj = initLayoutDialog(ds_win, userLayout, USER_DIALOG_X, USER_DIALOG_Y, &max); |
739 |
obj = initLayoutDialog(ds_win, layout, USER_DIALOG_X, USER_DIALOG_Y, &max); |
| 693 |
|
740 |
|
| 694 |
reenter: |
741 |
reenter: |
| 695 |
cancelbutton = okbutton = 0; |
742 |
cancelbutton = okbutton = 0; |
| 696 |
if (firsttime) { |
743 |
if (firsttime && !isNIS) { |
| 697 |
/* fill in the blanks, well, just the GID */ |
744 |
/* fill in the blanks, well, just the GID */ |
| 698 |
completeUser(); |
745 |
completeUser(); |
| 699 |
RefreshStringObj(userLayout[LAYOUT_UID].obj); |
746 |
RefreshStringObj(layout[LAYOUT_UID].obj); |
| 700 |
RefreshStringObj(userLayout[LAYOUT_UGROUP].obj); |
747 |
RefreshStringObj(layout[LAYOUT_UGROUP].obj); |
| 701 |
RefreshStringObj(userLayout[LAYOUT_GECOS].obj); |
748 |
RefreshStringObj(layout[LAYOUT_GECOS].obj); |
| 702 |
RefreshStringObj(userLayout[LAYOUT_UMEMB].obj); |
749 |
RefreshStringObj(layout[LAYOUT_UMEMB].obj); |
| 703 |
RefreshStringObj(userLayout[LAYOUT_HOMEDIR].obj); |
750 |
RefreshStringObj(layout[LAYOUT_HOMEDIR].obj); |
| 704 |
RefreshStringObj(userLayout[LAYOUT_SHELL].obj); |
751 |
RefreshStringObj(layout[LAYOUT_SHELL].obj); |
| 705 |
firsttime = FALSE; |
752 |
firsttime = FALSE; |
| 706 |
} |
753 |
} |
| 707 |
|
754 |
|
| 708 |
while (layoutDialogLoop(ds_win, userLayout, &obj, &n, max, &cancelbutton, &cancel)); |
755 |
while (layoutDialogLoop(ds_win, layout, &obj, &n, max, &cancelbutton, &cancel)); |
| 709 |
|
756 |
|
| 710 |
if (!cancel && !verifyUserSettings(ds_win)) |
757 |
if (isNIS && !cancel && !NISverifyUserSettings(ds_win)) |
|
|
758 |
goto reenter; |
| 759 |
else if (!cancel && !verifyUserSettings(ds_win)) |
| 711 |
goto reenter; |
760 |
goto reenter; |
| 712 |
|
761 |
|
| 713 |
/* Clear this crap off the screen */ |
762 |
/* Clear this crap off the screen */ |
|
Lines 716-727
Link Here
|
| 716 |
use_helpfile(NULL); |
765 |
use_helpfile(NULL); |
| 717 |
|
766 |
|
| 718 |
if (!cancel) { |
767 |
if (!cancel) { |
| 719 |
addUser(ds_win); |
768 |
if (isNIS) |
| 720 |
ret = DITEM_SUCCESS; |
769 |
NISAddUser(ds_win); |
|
|
770 |
else |
| 771 |
addUser(ds_win); |
| 772 |
ret = DITEM_SUCCESS | DITEM_RESTORE; |
| 721 |
} |
773 |
} |
| 722 |
else |
774 |
else |
| 723 |
ret = DITEM_FAILURE; |
775 |
ret = DITEM_FAILURE; |
| 724 |
restorescr(save); |
776 |
restorescr(save); |
|
|
777 |
|
| 725 |
return ret; |
778 |
return ret; |
| 726 |
} |
779 |
} |
| 727 |
|
780 |
|
|
|
781 |
/* |
| 782 |
* The above code uses 'pw', which complains about the special characters [+@] |
| 783 |
* that appear in NIS names. Hence special NIS functions are created to write |
| 784 |
* directly to master.passwd instead. |
| 785 |
*/ |
| 786 |
|
| 787 |
static int |
| 788 |
NISUserExist(char *login,FILE *passwdfp) |
| 789 |
{ |
| 790 |
char pwline[256]; |
| 791 |
|
| 792 |
rewind(passwdfp); |
| 793 |
while (fgets(&pwline[0],256,passwdfp) != NULL) { |
| 794 |
if (!strncmp(login,pwline,strlen(login))) { |
| 795 |
/* An entry already exists for this user */ |
| 796 |
return 1; |
| 797 |
} |
| 798 |
} |
| 799 |
return 0; |
| 800 |
} |
| 801 |
|
| 802 |
int |
| 803 |
NISAddUsers(dialogMenuItem *self) |
| 804 |
{ |
| 805 |
FILE *fptr; |
| 806 |
long fpos; |
| 807 |
|
| 808 |
WINDOW *w = savescr(); |
| 809 |
|
| 810 |
dialog_clear_norefresh(); |
| 811 |
|
| 812 |
/* Check to see if global NIS entry already exists */ |
| 813 |
fptr = fopen(_PATH_MASTERPASSWD,"a+"); |
| 814 |
if (! fptr) { |
| 815 |
msgConfirm("Could not open master password file."); |
| 816 |
return DITEM_FAILURE; |
| 817 |
} |
| 818 |
fpos=ftell(fptr); |
| 819 |
|
| 820 |
/* If there are no global NIS entries, add one. */ |
| 821 |
if (!NISUserExist("+",fptr)) { |
| 822 |
msgConfirm("This option will import the entire NIS passwd map. All users with NIS\n" |
| 823 |
"accounts on your network will be able to logon to your system. If this\n" |
| 824 |
"is not desireable you should import individual NIS accounts instead.\n"); |
| 825 |
|
| 826 |
fseek(fptr,fpos,SEEK_SET); |
| 827 |
fprintf(fptr,"+:::::::::\n"); |
| 828 |
fclose(fptr); |
| 829 |
msgNotify("Remaking password file: %s", _PATH_MASTERPASSWD); |
| 830 |
vsystem("pwd_mkdb -p %s", _PATH_MASTERPASSWD); |
| 831 |
msgNotify("Password file rebuilt."); |
| 832 |
} else { |
| 833 |
msgConfirm("There is already a global NIS entry. Password file untouched."); |
| 834 |
fclose(fptr); |
| 835 |
} |
| 836 |
|
| 837 |
|
| 838 |
restorescr(w); |
| 839 |
return DITEM_SUCCESS | DITEM_RESTORE; |
| 840 |
} |
| 841 |
|
| 842 |
void |
| 843 |
NISAddUser(WINDOW *ds_win) |
| 844 |
{ |
| 845 |
FILE *fptr; |
| 846 |
long fpos; |
| 847 |
|
| 848 |
WINDOW *w = savescr(); |
| 849 |
|
| 850 |
dialog_clear_norefresh(); |
| 851 |
|
| 852 |
/* Check to see if global NIS entry already exists */ |
| 853 |
fptr = fopen(_PATH_MASTERPASSWD,"a+"); |
| 854 |
if (! fptr) { |
| 855 |
msgConfirm("Could not open master password file."); |
| 856 |
return; |
| 857 |
} |
| 858 |
fpos=ftell(fptr); |
| 859 |
|
| 860 |
/* If there are no global NIS entries, add one. */ |
| 861 |
if (!NISUserExist(uname,fptr)) { |
| 862 |
fseek(fptr,fpos,SEEK_SET); |
| 863 |
fprintf(fptr,"%s:%s:%s:%s::0:0:%s:%s:%s\n",uname,passwd,uid,ugroup,gecos,homedir,shell); |
| 864 |
fclose(fptr); |
| 865 |
msgNotify("Remaking password file: %s", _PATH_MASTERPASSWD); |
| 866 |
vsystem("pwd_mkdb -p %s", _PATH_MASTERPASSWD); |
| 867 |
msgConfirm("User successfully added!"); |
| 868 |
} else { |
| 869 |
msgConfirm("User %s already exists!",uname); |
| 870 |
fclose(fptr); |
| 871 |
} |
| 872 |
|
| 873 |
restorescr(w); |
| 874 |
} |
| 875 |
|
| 876 |
int |
| 877 |
NISverifyUserSettings(WINDOW *ds_win) |
| 878 |
{ |
| 879 |
char *cp; |
| 880 |
WINDOW *save; |
| 881 |
int rv; |
| 882 |
|
| 883 |
if (strlen(uname) == 0) { |
| 884 |
feepout("The user name field must not be empty!"); |
| 885 |
return 0; |
| 886 |
} |
| 887 |
if ((uname[0] != '+') && (uname[0] != '-')) { |
| 888 |
feepout("Valid NIS user names must start with a '+' or '-'!"); |
| 889 |
return 0; |
| 890 |
} |
| 891 |
if (strlen(shell) > 0) { |
| 892 |
while((cp = getusershell()) != NULL) |
| 893 |
if (strcmp(cp, shell) == 0) |
| 894 |
break; |
| 895 |
endusershell(); |
| 896 |
if (cp == NULL) { |
| 897 |
save = savescr(); |
| 898 |
rv = msgYesNo("Warning:\n\n" |
| 899 |
"The requested shell \"%s\" is not\n" |
| 900 |
"a valid user shell.\n\n" |
| 901 |
"Use it anyway?\n", shell); |
| 902 |
restorescr(save); |
| 903 |
wrefresh(ds_win); |
| 904 |
if (rv != DITEM_SUCCESS) |
| 905 |
return 0; |
| 906 |
} |
| 907 |
|
| 908 |
} |
| 909 |
|
| 910 |
if (strlen(umemb) > 0) { |
| 911 |
if (strpbrk(umemb, " \t") != NULL) { |
| 912 |
feepout("The member groups list must not contain any whitespace;\n" |
| 913 |
"use commas to separate the names."); |
| 914 |
return 0; |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
return 1; |
| 919 |
} |