Changeset 249
- Timestamp:
- 06/08/05 20:08:15 (3 years ago)
- Files:
-
- op/trunk/main.c (modified) (23 diffs)
- op/trunk/Makefile.am (modified) (1 diff)
- op/trunk/op.1 (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
op/trunk/main.c
r247 r249 74 74 cmd_t *First = NULL; 75 75 var_t *Variables = NULL; 76 struct passwd*realuser = NULL;76 char *realuser = NULL; 77 77 int gargc = -1; 78 78 char **gargv = NULL; … … 202 202 203 203 if (sigprocmask(SIG_BLOCK, &sig_mask, &old_sig_mask)) 204 fatal(1, " Could not set signal mask");204 fatal(1, "could not set signal mask"); 205 205 206 206 gargv = argv; 207 207 gargc = argc; 208 realuser = getpwuid(getuid());209 208 210 209 while (1) { … … 262 261 263 262 if (!read_conf && !read_conf_dir) 264 fatal(1, " Could not open %s or any configuration files in %s", OP_ACCESS, OP_ACCESS_DIR);263 fatal(1, "could not open %s or any configuration files in %s", OP_ACCESS, OP_ACCESS_DIR); 265 264 266 265 if ((pw = getpwuid(getuid())) == NULL) 267 266 exit(1); 268 realuser = getpwuid(getuid());267 realuser = (char*)strdup(pw->pw_name); 269 268 strncpy(user, pw->pw_name, MAXSTRLEN); 270 269 … … 277 276 if (uptr != NULL) { 278 277 if (getuid() != 0) 279 fatal(1, " Permission denied for -u option");278 fatal(1, "permission denied for -u option"); 280 279 } 281 280 } … … 296 295 if (access(argv[argStart], F_OK) != 0) 297 296 if (access(argv[argStart], X_OK) != 0) 298 fatal(1, " Unknown or non executable command");297 fatal(1, "unknown or non executable command"); 299 298 } 300 299 cmd = Find(uptr); 301 300 302 301 if (cmd == NULL) 303 fatal(1, " No such command %s", argv[1]);302 fatal(1, "no such command %s", argv[1]); 304 303 305 304 argc -= argStart; … … 311 310 312 311 if ((num < 0) && ((argc-1) < -num)) 313 fatal(1, "%s: Improper number of arguments", cmd->name);312 fatal(1, "%s: improper number of arguments", cmd->name); 314 313 if ((num > 0) && ((argc-1) != num)) 315 fatal(1, "%s: Improper number of arguments", cmd->name);314 fatal(1, "%s: improper number of arguments", cmd->name); 316 315 if (num <0) 317 316 num = -num; … … 319 318 pcmd_s = format_cmd(argc, argv, cmd_s, MAXSTRLEN); 320 319 if (Verify(new, num, argc, argv) < 0) 321 fatal(0, "%s: Permission denied by op", cmd->name);320 fatal(0, "%s: permission denied by op", cmd->name); 322 321 323 322 return Go(new, num, argc, argv); … … 697 696 if (regexec(reg1,argv[j]) == 1) break; 698 697 } 699 if (cp == NULL) return logger(LOG_ERR, "%s: Argument %i (%s) did not pass wildcard constraint", cmd->name, j, argv[j]);698 if (cp == NULL) return logger(LOG_ERR, "%s: argument %i (%s) did not pass wildcard constraint", cmd->name, j, argv[j]); 700 699 } 701 700 } … … 745 744 } 746 745 } 747 if (cp == NULL) return logger(LOG_ERR, "%s: Argument '%s' did not pass constraint '%s'", cmd->name, argv[val], np);746 if (cp == NULL) return logger(LOG_ERR, "%s: argument '%s' did not pass constraint '%s'", cmd->name, argv[val], np); 748 747 } 749 748 return 0; … … 873 872 strcat(new_envp[curenv], xauth); 874 873 if (curenv + 1 >= MAXENV) 875 fatal(1, "%s: Environment length exceeded",cmd->name);874 fatal(1, "%s: environment length exceeded",cmd->name); 876 875 ++curenv; 877 876 /* Propagate $DISPLAY to new environment */ … … 880 879 strcat(new_envp[curenv], getenv("DISPLAY")); 881 880 if (curenv + 1 >= MAXENV) 882 fatal(1, "%s: Environment length exceeded",cmd->name);881 fatal(1, "%s: environment length exceeded",cmd->name); 883 882 ++curenv; 884 883 } … … 972 971 if (strncmp(cmd->opts[i] + 1, environ[j], cp - environ[j]) == 0) { 973 972 if (curenv + 1 >= MAXENV) 974 fatal(1, "%s: Environment length exceeded",cmd->name);973 fatal(1, "%s: environment length exceeded",cmd->name); 975 974 new_envp[curenv++] = environ[j]; 976 975 break; … … 981 980 for (i = 0; environ[i] != NULL; i++) { 982 981 if (curenv + 1 >= MAXENV) 983 fatal(1, "%s: Environment length exceeded",cmd->name);982 fatal(1, "%s: environment length exceeded",cmd->name); 984 983 new_envp[curenv++] = environ[i]; 985 984 } … … 999 998 if (cmd->opts[i][0] == '$' && strchr(cmd->opts[i], '=') != NULL) { 1000 999 if (curenv + 1 >= MAXENV) 1001 fatal(1, "%s: Environment length exceeded",cmd->name);1000 fatal(1, "%s: environment length exceeded",cmd->name); 1002 1001 new_envp[curenv++] = cmd->opts[i] + 1; 1003 1002 continue; … … 1005 1004 } 1006 1005 new_envp[curenv] = NULL; 1006 1007 /* --------------------------------------------------- */ 1008 /* fowner constraint must respect the syntax : */ 1009 /* fowner=user:group,... */ 1010 /* Notice : user and/or group are regular expressions */ 1011 /* --------------------------------------------------- */ 1012 1013 if ((cp = FindOpt(cmd, "fowner")) != NULL) { 1014 struct passwd * pwbuf; 1015 struct group * grbuf; 1016 struct stat statbuf; 1017 char * ptr; 1018 char usergroup[MAXSTRLEN]; 1019 1020 /* Get user and group name of the owner of the file */ 1021 stat(cmd->args[0],&statbuf); 1022 1023 pwbuf = getpwuid(statbuf.st_uid); 1024 if (pwbuf == NULL) 1025 fatal(1,"%s: no identified user for uid %d", cmd->name, statbuf.st_uid); 1026 grbuf = getgrgid(statbuf.st_gid); 1027 if (grbuf == NULL) 1028 fatal(1,"%s: no identified group for gid %d", cmd->name, statbuf.st_gid); 1029 1030 if (strlen(pwbuf->pw_name) + strlen(grbuf->gr_name) + 1 >= MAXSTRLEN) 1031 fatal(1, "%s: user/group string buffer length exceeded", cmd->name); 1032 strcpy(usergroup, pwbuf->pw_name); 1033 strcat(usergroup, ":"); 1034 strcat(usergroup, grbuf->gr_name); 1035 1036 /* check users,groups candidates */ 1037 1038 for (cp = GetField(cp, str, MAXSTRLEN - 5); cp != NULL; cp = GetField(cp, str, MAXSTRLEN - 5)) { 1039 regexp *reg1 = NULL; 1040 char regstr[MAXSTRLEN]; 1041 1042 ptr=strchr(str,':'); 1043 if (ptr == NULL) 1044 fatal(1,"%s: fowner argument must respect the user:group format", cmd->name); 1045 1046 strcpy(regstr, "^("); 1047 strcat(regstr, str); 1048 strcat(regstr, ")$"); 1049 1050 if ((reg1 = regcomp(regstr)) == NULL) 1051 return logger(LOG_ERR, "Invalid regex '%s'", str); 1052 1053 if ((regexec(reg1, usergroup) == 1)) 1054 break; 1055 } 1056 if (cp == NULL) 1057 fatal(1,"%s: file %s (%s) did not pass ownership constraints", 1058 cmd->name, cmd->args[0], usergroup); 1059 } 1060 1061 /* ---------------------------------------------------------------------- */ 1062 /* fperms constraint must respect the syntax : */ 1063 /* fperms=NNNN,MMMM,... where NNNN and MMMM are octal representation of */ 1064 /* the target requested authorised permissions */ 1065 /* Notice : NNNN and MMMM can be regular expressions */ 1066 /* ---------------------------------------------------------------------- */ 1067 1068 if ((cp = FindOpt(cmd, "fperms")) != NULL) { 1069 struct stat buf; 1070 char mode[5]; 1071 1072 stat(cmd->args[0],&buf); 1073 snprintf(mode, 5, "%o", buf.st_mode & 07777); 1074 1075 for (cp = GetField(cp, str, MAXSTRLEN - 5); cp != NULL; cp = GetField(cp, str, MAXSTRLEN - 5)) { 1076 regexp *reg1 = NULL; 1077 char regstr[MAXSTRLEN]; 1078 1079 strcpy(regstr, "^("); 1080 strcat(regstr, str); 1081 strcat(regstr, ")$"); 1082 1083 if ((reg1 = regcomp(regstr)) == NULL) 1084 return logger(LOG_ERR, "Invalid regex '%s'", str); 1085 1086 if (regexec(reg1,mode) == 1) 1087 break; 1088 } 1089 if (cp == NULL) 1090 fatal(1,"%s: file %s (%s) did not pass permissions constraints", 1091 cmd->name, cmd->args[0],mode); 1092 } 1007 1093 1008 1094 if (strcmp("MAGIC_SHELL", cmd->args[0]) == 0) { … … 1013 1099 if (environ[i] != NULL) { 1014 1100 if (curarg >= MAXARG - 1) 1015 fatal(1, "%s: Argument length exceeded",cmd->name);1101 fatal(1, "%s: argument length exceeded",cmd->name); 1016 1102 new_argv[curarg++] = environ[i] + 6; 1017 1103 } else { 1018 fatal(1, " No shell");1104 fatal(1, "%s: no shell", cmd->name); 1019 1105 } 1020 1106 1021 1107 if (argc != 1) { 1022 1108 if (curarg >= MAXARG - 1) 1023 fatal(1, "%s: Argument length exceeded",cmd->name);1109 fatal(1, "%s: argument length exceeded",cmd->name); 1024 1110 new_argv[curarg++] = "-c"; 1025 1111 … … 1028 1114 1029 1115 if ((cp = (char *)malloc(len + 10)) == NULL) 1030 fatal(1, " Unable to create buffer");1116 fatal(1, "%s: unable to create buffer", cmd->name); 1031 1117 1032 1118 len = 0; … … 1038 1124 } 1039 1125 if (curarg >= MAXARG - 1) 1040 fatal(1, "%s: Argument length exceeded",cmd->name);1126 fatal(1, "%s: argument length exceeded",cmd->name); 1041 1127 new_argv[curarg++] = cp; 1042 1128 } … … 1049 1135 if (np[1] == '*') { 1050 1136 if (curarg + argc >= MAXARG - 1) 1051 fatal(1, "%s: Argument length exceeded",cmd->name);1137 fatal(1, "%s: argument length exceeded",cmd->name); 1052 1138 for (j = 1; j < argc; j++) 1053 1139 new_argv[curarg++] = argv[j]; … … 1057 1143 fatal(1, "%s Referenced argument out of range",cmd->name); 1058 1144 if (curarg >= MAXARG - 1) 1059 fatal(1, "%s: Argument length exceeded",cmd->name);1145 fatal(1, "%s: argument length exceeded",cmd->name); 1060 1146 new_argv[curarg++] = argv[atoi(np + 1)]; 1061 1147 } … … 1115 1201 if (cp == NULL) { 1116 1202 if (curarg >= MAXARG - 1) 1117 fatal(1, "%s: Argument length exceeded",cmd->name);1203 fatal(1, "%s: argument length exceeded",cmd->name); 1118 1204 new_argv[curarg++] = cmd->args[i]; 1119 1205 continue; … … 1127 1213 1128 1214 if (sigprocmask(SIG_SETMASK, &old_sig_mask, NULL)) 1129 fatal(1, " Could not restore signal mask");1215 fatal(1, "could not restore signal mask"); 1130 1216 if ((i = execve(new_argv[0], new_argv, new_envp)) < 0) { 1131 1217 perror("execve"); … … 1197 1283 if (level >= minimum_logging_level) return -1; 1198 1284 1199 if (realuser) username = realuser ->pw_name;1285 if (realuser) username = realuser; 1200 1286 1201 1287 vstrnprintf(buffer2, MAXSTRLEN, format, args); op/trunk/Makefile.am
r248 r249 2 2 op_SOURCES=atov.c defs.h lex.l main.c regexp.c regexp.h util.c 3 3 man_MANS=op.1 4 EXTRA_DIST=op.conf op.conf.complex op.list.in op.pam op.paper 4 EXTRA_DIST=op.conf op.conf.complex op.list.in op.pam op.paper op.1 5 5 #README 6 6 op/trunk/op.1
r248 r249 184 184 still be logged. 185 185 .TP 186 .B fowner 187 Specifies the owner and group of the target command executable as a list of 188 regular expression in the form 189 .I user:group 190 If the executable ownership does not match, the command will not be executed. 191 .TP 192 .B fperms 193 As with 194 .I fowner 195 but matches against the octal permissions of the executable. 196 .TP 186 197 .B xauth 187 198 Attempt to propagate the X authority entry for the current display to the new
