mac_main.c

Go to the documentation of this file.
00001 /*************************************************** */
00002 /* Rule Set Based Access Control                     */
00003 /* Implementation of the Access Control Decision     */
00004 /* Facility (ADF) - Mandatory Access Control         */
00005 /* File: rsbac/adf/mac/main.c                        */
00006 /*                                                   */
00007 /* Author and (c) 1999-2005: Amon Ott <ao@rsbac.org> */
00008 /* MAC_LIGHT Modifications (c) 2000 Stanislav Ievlev */
00009 /*                     and (c) 2001 Amon Ott         */
00010 /*                                                   */
00011 /* Last modified: 09/Feb/2005                        */
00012 /*************************************************** */
00013 
00014 #include <linux/string.h>
00015 #include <rsbac/aci.h>
00016 #include <rsbac/mac.h>
00017 #include <rsbac/adf_main.h>
00018 #include <rsbac/error.h>
00019 #include <rsbac/helpers.h>
00020 #include <rsbac/getname.h>
00021 #include <rsbac/debug.h>
00022 #include <rsbac/rkmem.h>
00023 
00024 /************************************************* */
00025 /*           Global Variables                      */
00026 /************************************************* */
00027 
00028 /************************************************* */
00029 /*          Internal Help functions                */
00030 /************************************************* */
00031 
00032 static enum rsbac_adf_req_ret_t
00033   mac_check_role(rsbac_uid_t owner, enum rsbac_system_role_t role)
00034   {
00035     union rsbac_target_id_t i_tid;
00036     union rsbac_attribute_value_t i_attr_val1;
00037 
00038     i_tid.user = owner;
00039     if (rsbac_get_attr(MAC,
00040                        T_USER,
00041                        i_tid,
00042                        A_mac_role,
00043                        &i_attr_val1,
00044                        TRUE))
00045       {
00046         rsbac_ds_get_error("mac_check_role", A_mac_role);
00047         return(NOT_GRANTED);
00048       }
00049     /* if correct role, then grant */
00050     if (i_attr_val1.system_role == role)
00051       return(GRANTED);
00052     else
00053       {
00054 #ifdef CONFIG_RSBAC_DEBUG
00055         if(rsbac_debug_adf_mac)
00056           {
00057 #ifdef CONFIG_RSBAC_RMSG
00058             rsbac_printk(KERN_DEBUG
00059                    "mac_check_role(): pid %u/%.15s: wrong mac_role %u -> NOT_GRANTED!\n",
00060                    current->pid, current->comm,
00061                    i_attr_val1.system_role);
00062 #endif
00063 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00064             if (!rsbac_nosyslog)
00065 #endif
00066             printk(KERN_DEBUG
00067                    "mac_check_role(): pid %u/%.15s: wrong mac_role %u -> NOT_GRANTED!\n",
00068                    current->pid, current->comm,
00069                    i_attr_val1.system_role);
00070           }
00071 #endif
00072         return(NOT_GRANTED);
00073       }
00074   }
00075 
00076 /* auto_write() */
00077 /* This function builds a decision for write-only access based on      */
00078 /* ss-property and *-property. The Subject is given by process-id pid, */
00079 /* its attributes are taken from the data structures module. */
00080 /* For the object, only security_level is given to become independent  */
00081 /* from different object/target types.                                 */
00082 /* If attribute mac_auto is set, the current_security_level is changed */
00083 /* within min_write and max_read boundaries to allow for more accesses.*/
00084 /* If set_level is TRUE, the current_security_level and read/write     */
00085 /* boundaries are set to appropiate values, otherwise they are only    */
00086 /* checked. This provides only one function for decision and attribute */
00087 /* setting.                                                            */
00088 /* Trusted processes (attr. mac_trusted set) are always granted write  */
00089 /* access.                                                             */
00090 
00091 static enum rsbac_adf_req_ret_t
00092      auto_write_attr(      rsbac_pid_t             pid,
00093                      enum  rsbac_target_t          target,
00094                      union rsbac_target_id_t       tid,
00095                      enum  rsbac_attribute_t       t_level_attr,
00096                      enum  rsbac_attribute_t       t_cat_attr,
00097                            rsbac_boolean_t                 set_level)
00098   {
00099     rsbac_security_level_t        curr_level;
00100     rsbac_mac_category_vector_t   curr_categories;
00101     rsbac_security_level_t        target_sec_level;
00102     rsbac_mac_category_vector_t   target_categories;
00103     union rsbac_target_id_t       i_tid;
00104     union rsbac_attribute_value_t attr_val1;
00105     union rsbac_attribute_value_t attr_val2;
00106     rsbac_mac_process_flags_t     flags;
00107     rsbac_boolean_t                       mac_auto_used_level = FALSE;
00108     rsbac_boolean_t                       mac_auto_used_cat = FALSE;
00109     rsbac_boolean_t                       raise_object_level = FALSE;
00110     rsbac_boolean_t                       raise_object_cat = FALSE;
00111 
00112     /* first check for mac_override, which allows everything */
00113     i_tid.process = pid;
00114     if (rsbac_get_attr(MAC,
00115                        T_PROCESS,
00116                        i_tid,
00117                        A_mac_process_flags,
00118                        &attr_val1,
00119                        FALSE))
00120       { /* failed! */
00121         rsbac_ds_get_error("mac_auto_write", A_none);
00122         return(NOT_GRANTED);
00123       }
00124     flags = attr_val1.mac_process_flags;
00125     if(flags & MAC_override)
00126       return GRANTED;
00127 
00128     /* Get current security level */
00129     if (rsbac_get_attr(MAC,
00130                        T_PROCESS,
00131                        i_tid,
00132                        A_current_sec_level,
00133                        &attr_val1,
00134                        FALSE))
00135       { /* failed! */
00136         rsbac_ds_get_error("mac_auto_write", A_none);
00137         return(NOT_GRANTED);
00138       }
00139     curr_level = attr_val1.security_level;
00140     /* Get current categories */
00141     if (rsbac_get_attr(MAC,
00142                        T_PROCESS,
00143                        i_tid,
00144                        A_mac_curr_categories,
00145                        &attr_val1,
00146                        FALSE))
00147       { /* failed! */
00148         rsbac_ds_get_error("mac_auto_write", A_none);
00149         return(NOT_GRANTED);
00150       }
00151     curr_categories = attr_val1.mac_categories;
00152     /* Get target security level */
00153     if (rsbac_get_attr(MAC,
00154                        target,
00155                        tid,
00156                        t_level_attr,
00157                        &attr_val1,
00158                        TRUE))
00159       { /* failed! */
00160         rsbac_ds_get_error("mac_auto_write", A_none);
00161         return(NOT_GRANTED);
00162       }
00163     target_sec_level = attr_val1.security_level;
00164     /* Get target categories */
00165     if (rsbac_get_attr(MAC,
00166                        target,
00167                        tid,
00168                        t_cat_attr,
00169                        &attr_val1,
00170                        TRUE))
00171       { /* failed! */
00172         rsbac_ds_get_error("mac_auto_write", A_none);
00173         return(NOT_GRANTED);
00174       }
00175     target_categories = attr_val1.mac_categories;
00176 
00177     if(target_sec_level > curr_level)
00178       {
00179         if (rsbac_get_attr(MAC,
00180                            T_PROCESS,
00181                            i_tid,
00182                            A_security_level,
00183                            &attr_val1,
00184                            FALSE))
00185           { /* failed! */
00186             rsbac_ds_get_error("mac_auto_write", A_none);
00187             return(NOT_GRANTED);
00188           }
00189         if(attr_val1.security_level < target_sec_level)
00190           {
00191 #ifdef CONFIG_RSBAC_DEBUG
00192             if(rsbac_debug_adf_mac)
00193               {
00194 #ifdef CONFIG_RSBAC_RMSG
00195                 rsbac_printk(KERN_DEBUG
00196                        "mac_auto_write(): pid %u/%.15s: security_level %u under target_sec_level %u, no override -> NOT_GRANTED!\n",
00197                        current->pid, current->comm,
00198                        attr_val1.security_level, target_sec_level);
00199 #endif
00200 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00201                 if (!rsbac_nosyslog)
00202 #endif
00203                 printk(KERN_DEBUG
00204                        "mac_auto_write(): pid %u/%.15s: security_level %u under target_sec_level %u, no override -> NOT_GRANTED!\n",
00205                        current->pid, current->comm,
00206                        attr_val1.security_level, target_sec_level);
00207               }
00208 #endif
00209             return(NOT_GRANTED);
00210           }
00211         /* curr_level < target_level <= max_level -> need mac_auto, write_up, trusted (at process)
00212            or shared (at object) */
00213         if(flags & MAC_auto)
00214           mac_auto_used_level = TRUE;
00215         else
00216           {
00217             if(   !(flags & MAC_write_up)
00218                && !(flags & MAC_trusted)
00219               )
00220               {
00221                 /* Try mac_file_flags on the target, if FD object */
00222                 switch(target)
00223                   {
00224                     case T_FILE:
00225                     case T_DIR:
00226                     case T_FIFO:
00227                     case T_SYMLINK:
00228                       if (rsbac_get_attr(MAC,
00229                                          target,
00230                                          tid,
00231                                          A_mac_file_flags,
00232                                          &attr_val1,
00233                                          TRUE))
00234                         { /* failed! */
00235                           rsbac_ds_get_error("mac_auto_write", A_none);
00236                           return(NOT_GRANTED);
00237                         }
00238                       if(   (attr_val1.mac_file_flags & MAC_write_up)
00239                          || (attr_val1.mac_file_flags & MAC_trusted)
00240                         )
00241                         {
00242                           break;
00243                         }
00244                       /* fall through */
00245 
00246                     default:
00247 #ifdef CONFIG_RSBAC_DEBUG
00248                       if(rsbac_debug_adf_mac)
00249                         {
00250 #ifdef CONFIG_RSBAC_RMSG
00251                           rsbac_printk(KERN_DEBUG
00252                                  "mac_auto_write(): pid %u/%.15s: current security_level %u under target_sec_level %u, no auto, write_up, trusted -> NOT_GRANTED!\n",
00253                                  current->pid, current->comm,
00254                                  curr_level, target_sec_level);
00255 #endif
00256 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00257                           if (!rsbac_nosyslog)
00258 #endif
00259                           printk(KERN_DEBUG
00260                                  "mac_auto_write(): pid %u/%.15s: current security_level %u under target_sec_level %u, no auto, write_up, trusted -> NOT_GRANTED!\n",
00261                                  current->pid, current->comm,
00262                                  curr_level, target_sec_level);
00263                         }
00264 #endif
00265                       return(NOT_GRANTED);
00266                   }
00267               }
00268           }
00269       }
00270     else
00271     if(target_sec_level < curr_level)
00272       {
00273         if (rsbac_get_attr(MAC,
00274                            T_PROCESS,
00275                            i_tid,
00276                            A_min_security_level,
00277                            &attr_val1,
00278                            FALSE))
00279           { /* failed! */
00280             rsbac_ds_get_error("mac_auto_write", A_none);
00281             return(NOT_GRANTED);
00282           }
00283         if(attr_val1.security_level > target_sec_level)
00284           {
00285 #ifdef CONFIG_RSBAC_DEBUG
00286             if(rsbac_debug_adf_mac)
00287               {
00288 #ifdef CONFIG_RSBAC_RMSG
00289                 rsbac_printk(KERN_DEBUG
00290                        "mac_auto_write(): pid %u/%.15s: min_security_level %u over target_sec_level %u, no override -> NOT_GRANTED!\n",
00291                        current->pid, current->comm,
00292                        attr_val1.security_level, target_sec_level);
00293 #endif
00294 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00295                 if (!rsbac_nosyslog)
00296 #endif
00297                 printk(KERN_DEBUG
00298                        "mac_auto_write(): pid %u/%.15s: min_security_level %u over target_sec_level %u, no override -> NOT_GRANTED!\n",
00299                        current->pid, current->comm,
00300                        attr_val1.security_level, target_sec_level);
00301               }
00302 #endif
00303             return(NOT_GRANTED);
00304           }
00305         /* min_level <= target_level < curr_level -> need mac_auto, write_down or trusted */
00306         if(flags & MAC_auto)
00307           {
00308             /* check max_read boundary */
00309             if (rsbac_get_attr(MAC,
00310                                T_PROCESS,
00311                                i_tid,
00312                                A_max_read_open,
00313                                &attr_val1,
00314                                FALSE))
00315               { /* failed! */
00316                 rsbac_ds_get_error("mac_auto_write", A_none);
00317                 return(NOT_GRANTED);
00318               }
00319             if(attr_val1.security_level > target_sec_level)
00320               {
00321                 if(   !(flags & MAC_write_down)
00322                    && !(flags & MAC_trusted)
00323                   )
00324                   {
00325                     /* Try mac_file_flags on the target, if FD object */
00326                     switch(target)
00327                       {
00328                         case T_FILE:
00329                         case T_DIR:
00330                         case T_FIFO:
00331                         case T_SYMLINK:
00332                           if (rsbac_get_attr(MAC,
00333                                              target,
00334                                              tid,
00335                                              A_mac_file_flags,
00336                                              &attr_val1,
00337                                              TRUE))
00338                             { /* failed! */
00339                               rsbac_ds_get_error("mac_auto_write", A_none);
00340                               return(NOT_GRANTED);
00341                             }
00342                           if(   (attr_val1.mac_file_flags & MAC_write_down)
00343                              || (attr_val1.mac_file_flags & MAC_trusted)
00344                             )
00345                             {
00346                               if(attr_val1.mac_file_flags & MAC_auto)
00347                                 {
00348                                   raise_object_level = TRUE;
00349                                 }
00350                               break;
00351                             }
00352                           /* fall through */
00353 
00354                         default:
00355 #ifdef CONFIG_RSBAC_DEBUG
00356                           if(rsbac_debug_adf_mac)
00357                             {
00358 #ifdef CONFIG_RSBAC_RMSG
00359                               rsbac_printk(KERN_DEBUG
00360                                      "mac_auto_write(): pid %u/%.15s: max_read_open %u over target_sec_level %u, no write_down or trusted -> NOT_GRANTED!\n",
00361                                      current->pid, current->comm,
00362                                      attr_val1.security_level, target_sec_level);
00363 #endif
00364 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00365                               if (!rsbac_nosyslog)
00366 #endif
00367                               printk(KERN_DEBUG
00368                                      "mac_auto_write(): pid %u/%.15s: max_read_open %u over target_sec_level %u, no write_down or trusted -> NOT_GRANTED!\n",
00369                                      current->pid, current->comm,
00370                                      attr_val1.security_level, target_sec_level);
00371                             }
00372 #endif
00373                           return(NOT_GRANTED);
00374                       }
00375                   }
00376               }
00377             else
00378               mac_auto_used_level = TRUE;
00379           }
00380         else
00381           {
00382             if(   !(flags & MAC_write_down)
00383                && !(flags & MAC_trusted)
00384               )
00385               {
00386                 /* Try mac_file_flags on the target, if FD object */
00387                 switch(target)
00388                   {
00389                     case T_FILE:
00390                     case T_DIR:
00391                     case T_FIFO:
00392                     case T_SYMLINK:
00393                       if (rsbac_get_attr(MAC,
00394                                          target,
00395                                          tid,
00396                                          A_mac_file_flags,
00397                                          &attr_val1,
00398                                          TRUE))
00399                         { /* failed! */
00400                           rsbac_ds_get_error("mac_auto_write", A_none);
00401                           return(NOT_GRANTED);
00402                         }
00403                       if(   (attr_val1.mac_file_flags & MAC_write_down)
00404                          || (attr_val1.mac_file_flags & MAC_trusted)
00405                         )
00406                         {
00407                           if(attr_val1.mac_file_flags & MAC_auto)
00408                             {
00409                               raise_object_level = TRUE;
00410                             }
00411                           break;
00412                         }
00413                       /* fall through */
00414 
00415                     default:
00416 #ifdef CONFIG_RSBAC_DEBUG
00417                       if(rsbac_debug_adf_mac)
00418                         {
00419 #ifdef CONFIG_RSBAC_RMSG
00420                           rsbac_printk(KERN_DEBUG
00421                                  "mac_auto_write(): pid %u/%.15s: current security_level %u over target_sec_level %u, no auto, write_down or trusted -> NOT_GRANTED!\n",
00422                                  current->pid, current->comm,
00423                                  curr_level, target_sec_level);
00424 #endif
00425 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00426                           if (!rsbac_nosyslog)
00427 #endif
00428                           printk(KERN_DEBUG
00429                                  "mac_auto_write(): pid %u/%.15s: current security_level %u over target_sec_level %u, no auto, write_down or trusted -> NOT_GRANTED!\n",
00430                                  current->pid, current->comm,
00431                                  curr_level, target_sec_level);
00432                         }
00433 #endif
00434                       return(NOT_GRANTED);
00435                   }
00436               }
00437           }
00438       }
00439 
00440     if((target_categories & curr_categories) != target_categories)
00441       {
00442         if (rsbac_get_attr(MAC,
00443                            T_PROCESS,
00444                            i_tid,
00445                            A_mac_categories,
00446                            &attr_val1,
00447                            FALSE))
00448           { /* failed! */
00449             rsbac_ds_get_error("mac_auto_write", A_none);
00450             return(NOT_GRANTED);
00451           }
00452         if((target_categories & attr_val1.mac_categories) != target_categories)
00453           {
00454 #ifdef CONFIG_RSBAC_DEBUG
00455             if(rsbac_debug_adf_mac)
00456               {
00457                 char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00458 
00459                 if(tmp)
00460                   {
00461                     char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00462 
00463                     if(tmp2)
00464                       {
00465                         u64tostrmac(tmp, attr_val1.mac_categories);
00466                         u64tostrmac(tmp2, target_categories);
00467 #ifdef CONFIG_RSBAC_RMSG
00468                         rsbac_printk(KERN_DEBUG
00469                                "mac_auto_write(): pid %u/%.15s: max_categories %s under target categories %s, no override -> NOT_GRANTED!\n",
00470                                current->pid, current->comm,
00471                                tmp,
00472                                tmp2);
00473 #endif
00474 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00475                         if (!rsbac_nosyslog)
00476 #endif
00477                         printk(KERN_DEBUG
00478                                "mac_auto_write(): pid %u/%.15s: max_categories %s under target categories %s, no override -> NOT_GRANTED!\n",
00479                                current->pid, current->comm,
00480                                tmp,
00481                                tmp2);
00482                         rsbac_kfree(tmp2);
00483                       }
00484                     rsbac_kfree(tmp);
00485                   }
00486               }
00487 #endif
00488             return(NOT_GRANTED);
00489           }
00490         /* curr_categories < target_categories <= max_categories -> need mac_auto, write_up or trusted */
00491         if(flags & MAC_auto)
00492           mac_auto_used_cat = TRUE;
00493         else
00494           {
00495             if(   !(flags & MAC_write_up)
00496                && !(flags & MAC_trusted)
00497               )
00498               {
00499                 /* Try mac_file_flags on the target, if FD object */
00500                 switch(target)
00501                   {
00502                     case T_FILE:
00503                     case T_DIR:
00504                     case T_FIFO:
00505                     case T_SYMLINK:
00506                       if (rsbac_get_attr(MAC,
00507                                          target,
00508                                          tid,
00509                                          A_mac_file_flags,
00510                                          &attr_val1,
00511                                          TRUE))
00512                         { /* failed! */
00513                           rsbac_ds_get_error("mac_auto_write", A_none);
00514                           return(NOT_GRANTED);
00515                         }
00516                       if(   (attr_val1.mac_file_flags & MAC_write_up)
00517                          || (attr_val1.mac_file_flags & MAC_trusted)
00518                         )
00519                         break;
00520                       /* fall through */
00521 
00522                     default:
00523 #ifdef CONFIG_RSBAC_DEBUG
00524                       if(rsbac_debug_adf_mac)
00525                         {
00526                           char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00527 
00528                           if(tmp)
00529                             {
00530                               char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00531 
00532                               if(tmp2)
00533                                 {
00534                                   u64tostrmac(tmp, curr_categories);
00535                                   u64tostrmac(tmp2, target_categories);
00536 #ifdef CONFIG_RSBAC_RMSG
00537                                   rsbac_printk(KERN_DEBUG
00538                                          "mac_auto_write(): pid %u/%.15s: curr_categories %s under target categories %s, no auto, write_up or trusted -> NOT_GRANTED!\n",
00539                                          current->pid, current->comm,
00540                                          tmp,
00541                                          tmp2);
00542 #endif
00543 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00544                                   if (!rsbac_nosyslog)
00545 #endif
00546                                   printk(KERN_DEBUG
00547                                          "mac_auto_write(): pid %u/%.15s: curr_categories %s under target categories %s, no auto, write_up or trusted -> NOT_GRANTED!\n",
00548                                          current->pid, current->comm,
00549                                          tmp,
00550                                          tmp2);
00551                                   rsbac_kfree(tmp2);
00552                                 }
00553                               rsbac_kfree(tmp);
00554                             }
00555                         }
00556 #endif
00557                       return(NOT_GRANTED);
00558                   }
00559               }
00560           }
00561       }
00562     else
00563     if((target_categories & curr_categories) != curr_categories)
00564       {
00565         if (rsbac_get_attr(MAC,
00566                            T_PROCESS,
00567                            i_tid,
00568                            A_mac_min_categories,
00569                            &attr_val1,
00570                            FALSE))
00571           { /* failed! */
00572             rsbac_ds_get_error("mac_auto_write", A_none);
00573             return(NOT_GRANTED);
00574           }
00575         if((target_categories & attr_val1.mac_categories) != attr_val1.mac_categories)
00576           {
00577 #ifdef CONFIG_RSBAC_DEBUG
00578             if(rsbac_debug_adf_mac)
00579               {
00580                 char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00581 
00582                 if(tmp)
00583                   {
00584                     char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00585 
00586                     if(tmp2)
00587                       {
00588                         u64tostrmac(tmp, attr_val1.mac_categories);
00589                         u64tostrmac(tmp2, target_categories);
00590 #ifdef CONFIG_RSBAC_RMSG
00591                         rsbac_printk(KERN_DEBUG
00592                                "mac_auto_write(): pid %u/%.15s: min_categories %s over target categories %s, no override -> NOT_GRANTED!\n",
00593                                current->pid, current->comm,
00594                                tmp,
00595                                tmp2);
00596 #endif
00597 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00598                         if (!rsbac_nosyslog)
00599 #endif
00600                         printk(KERN_DEBUG
00601                                "mac_auto_write(): pid %u/%.15s: min_categories %s over target categories %s, no override -> NOT_GRANTED!\n",
00602                                current->pid, current->comm,
00603                                tmp,
00604                                tmp2);
00605                         rsbac_kfree(tmp2);
00606                       }
00607                     rsbac_kfree(tmp);
00608                   }
00609               }
00610 #endif
00611             return(NOT_GRANTED);
00612           }
00613         /* min_level <= target_level < curr_level -> need mac_auto, write_down or trusted */
00614         if(flags & MAC_auto)
00615           {
00616             /* check max_read boundary */
00617             if (rsbac_get_attr(MAC,
00618                                T_PROCESS,
00619                                i_tid,
00620                                A_max_read_categories,
00621                                &attr_val1,
00622                                FALSE))
00623               { /* failed! */
00624                 rsbac_ds_get_error("mac_auto_write", A_none);
00625                 return(NOT_GRANTED);
00626               }
00627             if((target_categories & attr_val1.mac_categories) != attr_val1.mac_categories)
00628               {
00629                 if(   !(flags & MAC_write_down)
00630                    && !(flags & MAC_trusted)
00631                   )
00632                   {
00633                     /* Try mac_file_flags on the target, if FD object */
00634                     switch(target)
00635                       {
00636                         case T_FILE:
00637                         case T_DIR:
00638                         case T_FIFO:
00639                         case T_SYMLINK:
00640                           if (rsbac_get_attr(MAC,
00641                                              target,
00642                                              tid,
00643                                              A_mac_file_flags,
00644                                              &attr_val1,
00645                                              TRUE))
00646                             { /* failed! */
00647                               rsbac_ds_get_error("mac_auto_write", A_none);
00648                               return(NOT_GRANTED);
00649                             }
00650                           if(   (attr_val1.mac_file_flags & MAC_write_down)
00651                              || (attr_val1.mac_file_flags & MAC_trusted)
00652                             )
00653                             {
00654                               if(attr_val1.mac_file_flags & MAC_auto)
00655                                 {
00656                                   raise_object_cat = TRUE;
00657                                 }
00658                               break;
00659                             }
00660                           /* fall through */
00661 
00662                         default:
00663 #ifdef CONFIG_RSBAC_DEBUG
00664                           if(rsbac_debug_adf_mac)
00665                             {
00666                               char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00667 
00668                               if(tmp)
00669                                 {
00670                                   char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00671 
00672                                   if(tmp2)
00673                                     {
00674                                       u64tostrmac(tmp, attr_val1.mac_categories);
00675                                       u64tostrmac(tmp2, target_categories);
00676 #ifdef CONFIG_RSBAC_RMSG
00677                                       rsbac_printk(KERN_DEBUG
00678                                              "mac_auto_write(): pid %u/%.15s: max_read_categories %s over target categories %s, no write_down or trusted -> NOT_GRANTED!\n",
00679                                              current->pid, current->comm,
00680                                              tmp,
00681                                              tmp2);
00682 #endif
00683 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00684                                       if (!rsbac_nosyslog)
00685 #endif
00686                                       printk(KERN_DEBUG
00687                                              "mac_auto_write(): pid %u/%.15s: max_read_categories %s over target categories %s, no write_down or trusted -> NOT_GRANTED!\n",
00688                                              current->pid, current->comm,
00689                                              tmp,
00690                                              tmp2);
00691                                       rsbac_kfree(tmp2);
00692                                     }
00693                                   rsbac_kfree(tmp);
00694                                 }
00695                             }
00696 #endif
00697                           return(NOT_GRANTED);
00698                       }
00699                   }
00700               }
00701             else
00702               mac_auto_used_cat = TRUE;
00703           }
00704         else
00705           {
00706             if(   !(flags & MAC_write_down)
00707                && !(flags & MAC_trusted)
00708               )
00709               {
00710                 /* Try mac_file_flags on the target, if FD object */
00711                 switch(target)
00712                   {
00713                     case T_FILE:
00714                     case T_DIR:
00715                     case T_FIFO:
00716                     case T_SYMLINK:
00717                       if (rsbac_get_attr(MAC,
00718                                          target,
00719                                          tid,
00720                                          A_mac_file_flags,
00721                                          &attr_val1,
00722                                          TRUE))
00723                         { /* failed! */
00724                           rsbac_ds_get_error("mac_auto_write", A_none);
00725                           return(NOT_GRANTED);
00726                         }
00727                       if(   (attr_val1.mac_file_flags & MAC_write_down)
00728                          || (attr_val1.mac_file_flags & MAC_trusted)
00729                         )
00730                         {
00731                           if(attr_val1.mac_file_flags & MAC_auto)
00732                             {
00733                               raise_object_cat = TRUE;
00734                             }
00735                           break;
00736                         }
00737                       /* fall through */
00738 
00739                     default:
00740 #ifdef CONFIG_RSBAC_DEBUG
00741                       if(rsbac_debug_adf_mac)
00742                         {
00743                           char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00744 
00745                           if(tmp)
00746                             {
00747                               char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00748 
00749                               if(tmp2)
00750                                 {
00751                                   u64tostrmac(tmp, curr_categories);
00752                                   u64tostrmac(tmp2, target_categories);
00753 #ifdef CONFIG_RSBAC_RMSG
00754                                   rsbac_printk(KERN_DEBUG
00755                                          "mac_auto_write(): pid %u/%.15s: curr_categories %s over target categories %s, no auto, write_down or trusted -> NOT_GRANTED!\n",
00756                                          current->pid, current->comm,
00757                                          tmp,
00758                                          tmp2);
00759 #endif
00760 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00761                                   if (!rsbac_nosyslog)
00762 #endif
00763                                   printk(KERN_DEBUG
00764                                          "mac_auto_write(): pid %u/%.15s: curr_categories %s over target categories %s, no auto, write_down or trusted -> NOT_GRANTED!\n",
00765                                          current->pid, current->comm,
00766                                          tmp,
00767                                          tmp2);
00768                                   rsbac_kfree(tmp2);
00769                                 }
00770                               rsbac_kfree(tmp);
00771                             }
00772                         }
00773 #endif
00774                       return(NOT_GRANTED);
00775                   }
00776               }
00777           }
00778       }
00779 
00780     /* grant area */
00781 
00782     /* adjust current_sec_level and min_write_level, */
00783     /* if set_level is true and mac_auto has been used*/
00784     if(   set_level
00785        && (   mac_auto_used_level
00786            || raise_object_level
00787           )
00788       )
00789       {
00790 #ifdef CONFIG_RSBAC_MAC_LOG_LEVEL_CHANGE
00791         {
00792           char * target_type_name;
00793           char * target_id_name;
00794 
00795           target_type_name = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00796           if(target_type_name)
00797             {
00798               #ifdef CONFIG_RSBAC_LOG_FULL_PATH
00799               target_id_name
00800                 = rsbac_kmalloc(CONFIG_RSBAC_MAX_PATH_LEN + RSBAC_MAXNAMELEN);
00801                 /* max. path name len + some extra */
00802               #else
00803               target_id_name = rsbac_kmalloc(2 * RSBAC_MAXNAMELEN);
00804                 /* max. file name len + some extra */
00805               #endif
00806               if(target_id_name)
00807                 {
00808                   get_target_name(target_type_name, target, target_id_name, tid);
00809 
00810                   if(mac_auto_used_level)
00811                     {
00812                       #ifndef CONFIG_RSBAC_RMSG_EXCL
00813                       /* only log to standard syslog, if not disabled by kernel boot parameter */
00814                       #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00815                       if (!rsbac_nosyslog)
00816                       #endif
00817                       printk(KERN_INFO
00818                              "mac_auto_write(): Changing process %u (%.15s, owner %u) current level from %u to %u for %s %s\n",
00819                              pid,
00820                              current->comm,
00821                              current->uid,
00822                              curr_level,
00823                              target_sec_level,
00824                              target_type_name,
00825                              target_id_name);
00826                       #endif
00827                       #ifdef CONFIG_RSBAC_RMSG
00828                       rsbac_printk(KERN_INFO
00829                              "mac_auto_write(): Changing process %u (%.15s, owner %u) current level from %u to %u for %s %s\n",
00830                              pid,
00831                              current->comm,
00832                              current->uid,
00833                              curr_level,
00834                              target_sec_level,
00835                              target_type_name,
00836                              target_id_name);
00837                       #endif
00838                     }
00839                   else
00840                     {
00841                       #ifndef CONFIG_RSBAC_RMSG_EXCL
00842                       /* only log to standard syslog, if not disabled by kernel boot parameter */
00843                       #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00844                       if (!rsbac_nosyslog)
00845                       #endif
00846                       printk(KERN_INFO
00847                              "mac_auto_write(): Process %u (%.15s, owner %u): Raising object level from %u to %u for %s %s\n",
00848                              pid,
00849                              current->comm,
00850                              current->uid,
00851                              target_sec_level,
00852                              curr_level,
00853                              target_type_name,
00854                              target_id_name);
00855                       #endif
00856                       #ifdef CONFIG_RSBAC_RMSG
00857                       rsbac_printk(KERN_INFO
00858                              "mac_auto_write(): Process %u (%.15s, owner %u): Raising object level from %u to %u for %s %s\n",
00859                              pid,
00860                              current->comm,
00861                              current->uid,
00862                              target_sec_level,
00863                              curr_level,
00864                              target_type_name,
00865                              target_id_name);
00866                       #endif
00867                     }
00868                   rsbac_kfree(target_id_name);
00869                 }
00870               rsbac_kfree(target_type_name);
00871             }
00872         }
00873 #endif
00874         if(mac_auto_used_level)
00875           {
00876             i_tid.process = pid;
00877             attr_val1.current_sec_level = target_sec_level;
00878             if (rsbac_get_attr(MAC,
00879                                T_PROCESS,
00880                                i_tid,
00881                                A_min_write_open,
00882                                &attr_val2,
00883                                TRUE))
00884               { /* failed! */
00885                 rsbac_ds_get_error("mac_auto_write", A_none);
00886                 return(NOT_GRANTED);
00887               }
00888             if(attr_val1.min_write_open < attr_val2.min_write_open)
00889               {
00890                 if (rsbac_set_attr(MAC,
00891                                    T_PROCESS,
00892                                    i_tid,
00893                                    A_min_write_open,
00894                                    attr_val1))
00895                   { /* failed! */
00896                     rsbac_ds_set_error("mac_auto_write", A_none);
00897                     return(NOT_GRANTED);
00898                   }
00899               }
00900             if (rsbac_set_attr(MAC,
00901                                T_PROCESS,
00902                                i_tid,
00903                                A_current_sec_level,
00904                                attr_val1))
00905               { /* failed! */
00906                 rsbac_ds_set_error("mac_auto_write", A_none);
00907                 return(NOT_GRANTED);
00908               }
00909           }
00910         else
00911           {
00912             attr_val1.security_level = curr_level;
00913             if (rsbac_set_attr(MAC,
00914                                target,
00915                                tid,
00916                                A_security_level,
00917                                attr_val1))
00918               { /* failed! */
00919                 rsbac_ds_set_error("mac_auto_write", A_none);
00920                 return(NOT_GRANTED);
00921               }
00922           }
00923       }
00924     /* adjust current_categories and min_write_categories, */
00925     /* if set_level is true and mac_auto has been used*/
00926     if(   set_level
00927        && (   mac_auto_used_cat
00928            || raise_object_cat
00929           )
00930       )
00931       {
00932 #ifdef CONFIG_RSBAC_MAC_LOG_LEVEL_CHANGE
00933         {
00934           char * target_type_name = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00935           if(target_type_name)
00936             {
00937               char * target_id_name;
00938 
00939               #ifdef CONFIG_RSBAC_LOG_FULL_PATH
00940               target_id_name
00941                 = rsbac_kmalloc(CONFIG_RSBAC_MAX_PATH_LEN + RSBAC_MAXNAMELEN);
00942                 /* max. path name len + some extra */
00943               #else
00944               target_id_name = rsbac_kmalloc(2 * RSBAC_MAXNAMELEN);
00945                 /* max. file name len + some extra */
00946               #endif
00947               if(target_id_name)
00948                 {
00949                   char * tmp1 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00950                   if(tmp1)
00951                     {
00952                       char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
00953                       if(tmp2)
00954                         {
00955                           get_target_name(target_type_name, target, target_id_name, tid);
00956 
00957                           if(mac_auto_used_cat)
00958                             {
00959                               #ifndef CONFIG_RSBAC_RMSG_EXCL
00960                               /* only log to standard syslog, if not disabled by kernel boot parameter */
00961                               #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00962                               if (!rsbac_nosyslog)
00963                               #endif
00964                               printk(KERN_INFO
00965                                      "mac_auto_write(): Changing process %u (%.15s, owner %u) current categories from %s to %s for %s %s\n",
00966                                      pid,
00967                                      current->comm,
00968                                      current->uid,
00969                                      u64tostrmac(tmp1, curr_categories),
00970                                      u64tostrmac(tmp2, target_categories),
00971                                      target_type_name,
00972                                      target_id_name);
00973                               #endif
00974                               #ifdef CONFIG_RSBAC_RMSG
00975                               rsbac_printk(KERN_INFO
00976                                      "mac_auto_write(): Changing process %u (%.15s, owner %u) current categories from %s to %s for %s %s\n",
00977                                      pid,
00978                                      current->comm,
00979                                      current->uid,
00980                                      u64tostrmac(tmp1, curr_categories),
00981                                      u64tostrmac(tmp2, target_categories),
00982                                      target_type_name,
00983                                      target_id_name);
00984                               #endif
00985                             }
00986                           else
00987                             {
00988                               #ifndef CONFIG_RSBAC_RMSG_EXCL
00989                               /* only log to standard syslog, if not disabled by kernel boot parameter */
00990                               #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
00991                               if (!rsbac_nosyslog)
00992                               #endif
00993                               printk(KERN_INFO
00994                                      "mac_auto_write(): Process %u (%.15s, owner %u): raising current categories from %s to %s for %s %s\n",
00995                                      pid,
00996                                      current->comm,
00997                                      current->uid,
00998                                      u64tostrmac(tmp2, target_categories),
00999                                      u64tostrmac(tmp1, curr_categories),
01000                                      target_type_name,
01001                                      target_id_name);
01002                               #endif
01003                               #ifdef CONFIG_RSBAC_RMSG
01004                               rsbac_printk(KERN_INFO
01005                                      "mac_auto_write(): Process %u (%.15s, owner %u): raising current categories from %s to %s for %s %s\n",
01006                                      pid,
01007                                      current->comm,
01008                                      current->uid,
01009                                      u64tostrmac(tmp2, target_categories),
01010                                      u64tostrmac(tmp1, curr_categories),
01011                                      target_type_name,
01012                                      target_id_name);
01013                               #endif
01014                             }
01015                           rsbac_kfree(tmp2);
01016                         }
01017                       rsbac_kfree(tmp1);
01018                     }
01019                   rsbac_kfree(target_id_name);
01020                 }
01021               rsbac_kfree(target_type_name);
01022             }
01023         }
01024 #endif
01025         if(mac_auto_used_cat)
01026           {
01027             i_tid.process = pid;
01028             attr_val1.mac_categories = target_categories;
01029             if (rsbac_get_attr(MAC,
01030                                T_PROCESS,
01031                                i_tid,
01032                                A_min_write_categories,
01033                                &attr_val2,
01034                                TRUE))
01035               { /* failed! */
01036                 rsbac_ds_get_error("mac_auto_write", A_none);
01037                 return(NOT_GRANTED);
01038               }
01039             if((attr_val1.mac_categories & attr_val2.mac_categories)
01040                != attr_val2.mac_categories
01041               )
01042               {
01043                 if (rsbac_set_attr(MAC,
01044                                    T_PROCESS,
01045                                    i_tid,
01046                                    A_min_write_categories,
01047                                    attr_val1))
01048                   { /* failed! */
01049                     rsbac_ds_set_error("mac_auto_write", A_none);
01050                     return(NOT_GRANTED);
01051                   }
01052               }
01053             if (rsbac_set_attr(MAC,
01054                                T_PROCESS,
01055                                i_tid,
01056                                A_mac_curr_categories,
01057                                attr_val1))
01058               { /* failed! */
01059                 rsbac_ds_set_error("mac_auto_write", A_none);
01060                 return(NOT_GRANTED);
01061               }
01062           }
01063         else
01064           {
01065             attr_val1.mac_categories = curr_categories;
01066             if (rsbac_set_attr(MAC,
01067                                target,
01068                                tid,
01069                                A_mac_categories,
01070                                attr_val1))
01071               { /* failed! */
01072                 rsbac_ds_set_error("mac_auto_write", A_none);
01073                 return(NOT_GRANTED);
01074               }
01075           }
01076       }
01077 
01078     /* Everything done, so return */
01079     return(GRANTED);
01080   }
01081 
01082 static enum rsbac_adf_req_ret_t
01083            auto_write(     rsbac_pid_t             pid,
01084                      enum  rsbac_target_t          target,
01085                      union rsbac_target_id_t       tid,
01086                            rsbac_boolean_t                 set_level)
01087   {
01088     return auto_write_attr(pid,
01089                            target,
01090                            tid,
01091                            A_security_level,
01092                            A_mac_categories,
01093                            set_level);
01094   }
01095 
01096 /* auto_read() */
01097 /* This function works similar to auto_write() */
01098 
01099 static enum rsbac_adf_req_ret_t
01100       auto_read_attr (     rsbac_pid_t             pid,
01101                      enum  rsbac_target_t          target,
01102                      union rsbac_target_id_t       tid,
01103                      enum  rsbac_attribute_t       t_level_attr,
01104                      enum  rsbac_attribute_t       t_cat_attr,
01105                            rsbac_boolean_t                 set_level)
01106   {
01107     rsbac_security_level_t        curr_level;
01108     rsbac_mac_category_vector_t   curr_categories;
01109     rsbac_security_level_t        target_sec_level;
01110     rsbac_mac_category_vector_t   target_categories;
01111     union rsbac_target_id_t       i_tid;
01112     union rsbac_attribute_value_t attr_val1;
01113     union rsbac_attribute_value_t attr_val2;
01114     rsbac_mac_process_flags_t     flags;
01115     rsbac_boolean_t                       mac_auto_used_level = FALSE;
01116     rsbac_boolean_t                       mac_auto_used_cat = FALSE;
01117     rsbac_boolean_t                       set_level_level = FALSE;
01118     rsbac_boolean_t                       set_level_cat = FALSE;
01119 
01120     /* first check for mac_override, which allows everything */
01121     i_tid.process = pid;
01122     if (rsbac_get_attr(MAC,
01123                        T_PROCESS,
01124                        i_tid,
01125                        A_mac_process_flags,
01126                        &attr_val1,
01127                        FALSE))
01128       { /* failed! */
01129         rsbac_ds_get_error("mac_auto_read", A_none);
01130         return(NOT_GRANTED);
01131       }
01132     flags = attr_val1.mac_process_flags;
01133     if(flags & MAC_override)
01134       return GRANTED;
01135 
01136     /* Get current security level */
01137     if (rsbac_get_attr(MAC,
01138                        T_PROCESS,
01139                        i_tid,
01140                        A_current_sec_level,
01141                        &attr_val1,
01142                        FALSE))
01143       { /* failed! */
01144         rsbac_ds_get_error("mac_auto_read", A_none);
01145         return(NOT_GRANTED);
01146       }
01147     curr_level = attr_val1.security_level;
01148     /* Get current categories */
01149     if (rsbac_get_attr(MAC,
01150                        T_PROCESS,
01151                        i_tid,
01152                        A_mac_curr_categories,
01153                        &attr_val1,
01154                        FALSE))
01155       { /* failed! */
01156         rsbac_ds_get_error("mac_auto_read", A_none);
01157         return(NOT_GRANTED);
01158       }
01159     curr_categories = attr_val1.mac_categories;
01160     /* Get target security level */
01161     if (rsbac_get_attr(MAC,
01162                        target,
01163                        tid,
01164                        t_level_attr,
01165                        &attr_val1,
01166                        TRUE))
01167       { /* failed! */
01168         rsbac_ds_get_error("mac_auto_read", A_none);
01169         return(NOT_GRANTED);
01170       }
01171     target_sec_level = attr_val1.security_level;
01172     /* Get target categories */
01173     if (rsbac_get_attr(MAC,
01174                        target,
01175                        tid,
01176                        t_cat_attr,
01177                        &attr_val1,
01178                        TRUE))
01179       { /* failed! */
01180         rsbac_ds_get_error("mac_auto_read", A_none);
01181         return(NOT_GRANTED);
01182       }
01183     target_categories = attr_val1.mac_categories;
01184 
01185     if(target_sec_level > curr_level)
01186       {
01187         if (rsbac_get_attr(MAC,
01188                            T_PROCESS,
01189                            i_tid,
01190                            A_security_level,
01191                            &attr_val1,
01192                            FALSE))
01193           { /* failed! */
01194             rsbac_ds_get_error("mac_auto_read", A_none);
01195             return(NOT_GRANTED);
01196           }
01197         if(attr_val1.security_level < target_sec_level)
01198           {
01199 #ifdef CONFIG_RSBAC_DEBUG
01200             if(rsbac_debug_adf_mac)
01201               {
01202 #ifdef CONFIG_RSBAC_RMSG
01203                 rsbac_printk(KERN_DEBUG
01204                        "mac_auto_read(): pid %u/%.15s: security_level %u under target_sec_level %u, no override -> NOT_GRANTED!\n",
01205                        current->pid, current->comm,
01206                        attr_val1.security_level, target_sec_level);
01207 #endif
01208 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01209                 if (!rsbac_nosyslog)
01210 #endif
01211                 printk(KERN_DEBUG
01212                        "mac_auto_read(): pid %u/%.15s: security_level %u under target_sec_level %u, no override -> NOT_GRANTED!\n",
01213                        current->pid, current->comm,
01214                        attr_val1.security_level, target_sec_level);
01215               }
01216 #endif
01217             return(NOT_GRANTED);
01218           }
01219         /* curr_level < target_level <= max_level -> need mac_auto, read_up or trusted (with read option) */
01220         if(flags & MAC_auto)
01221           {
01222             /* check min_write boundary */
01223             if (rsbac_get_attr(MAC,
01224                                T_PROCESS,
01225                                i_tid,
01226                                A_min_write_open,
01227                                &attr_val1,
01228                                FALSE))
01229               { /* failed! */
01230                 rsbac_ds_get_error("mac_auto_read", A_none);
01231                 return(NOT_GRANTED);
01232               }
01233             if(attr_val1.security_level < target_sec_level)
01234               {
01235                 if(   !(flags & MAC_read_up)
01236 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01237                    && !(flags & MAC_trusted)
01238 #endif
01239                   )
01240                   {
01241                     /* Try mac_file_flags on the target, if FD object */
01242                     switch(target)
01243                       {
01244                         case T_FILE:
01245                         case T_DIR:
01246                         case T_FIFO:
01247                         case T_SYMLINK:
01248                           if (rsbac_get_attr(MAC,
01249                                              target,
01250                                              tid,
01251                                              A_mac_file_flags,
01252                                              &attr_val1,
01253                                              TRUE))
01254                             { /* failed! */
01255                               rsbac_ds_get_error("mac_auto_read", A_none);
01256                               return(NOT_GRANTED);
01257                             }
01258                           if(   (attr_val1.mac_file_flags & MAC_read_up)
01259 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01260                              || (attr_val1.mac_file_flags & MAC_trusted)
01261 #endif
01262                             )
01263                             {
01264                               break;
01265                             }
01266                           /* fall through */
01267 
01268                         default:
01269 #ifdef CONFIG_RSBAC_DEBUG
01270                           if(rsbac_debug_adf_mac)
01271                             {
01272 #ifdef CONFIG_RSBAC_RMSG
01273                               rsbac_printk(KERN_DEBUG
01274                                      "mac_auto_read(): pid %u/%.15s: min_write_open %u under target_sec_level %u, no read_up or trusted -> NOT_GRANTED!\n",
01275                                      current->pid, current->comm,
01276                                      attr_val1.security_level, target_sec_level);
01277 #endif
01278 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01279                               if (!rsbac_nosyslog)
01280 #endif
01281                               printk(KERN_DEBUG
01282                                      "mac_auto_read(): pid %u/%.15s: min_write_open %u under target_sec_level %u, no read_up or trusted -> NOT_GRANTED!\n",
01283                                      current->pid, current->comm,
01284                                      attr_val1.security_level, target_sec_level);
01285                             }
01286 #endif
01287                           return(NOT_GRANTED);
01288                       }
01289                   }
01290               }
01291             else
01292               {
01293                 mac_auto_used_level = TRUE;
01294                 set_level_level = TRUE;
01295               }
01296           }
01297         else
01298           {
01299             if(   !(flags & MAC_read_up)
01300 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01301                && !(flags & MAC_trusted)
01302 #endif
01303               )
01304               {
01305                 /* Try mac_file_flags on the target, if FD object */
01306                 switch(target)
01307                   {
01308                     case T_FILE:
01309                     case T_DIR:
01310                     case T_FIFO:
01311                     case T_SYMLINK:
01312                       if (rsbac_get_attr(MAC,
01313                                          target,
01314                                          tid,
01315                                          A_mac_file_flags,
01316                                          &attr_val1,
01317                                          TRUE))
01318                         { /* failed! */
01319                           rsbac_ds_get_error("mac_auto_read", A_none);
01320                           return(NOT_GRANTED);
01321                         }
01322                       if(   (attr_val1.mac_file_flags & MAC_read_up)
01323 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01324                          || (attr_val1.mac_file_flags & MAC_trusted)
01325 #endif
01326                         )
01327                         {
01328                           break;
01329                         }
01330                       /* fall through */
01331 
01332                     default:
01333 #ifdef CONFIG_RSBAC_DEBUG
01334                       if(rsbac_debug_adf_mac)
01335                         {
01336 #ifdef CONFIG_RSBAC_RMSG
01337                           rsbac_printk(KERN_DEBUG
01338                                  "mac_auto_read(): pid %u/%.15s: current level %u under target_sec_level %u, no auto, read_up or trusted -> NOT_GRANTED!\n",
01339                                  current->pid, current->comm,
01340                                  curr_level, target_sec_level);
01341 #endif
01342 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01343                           if (!rsbac_nosyslog)
01344 #endif
01345                           printk(KERN_DEBUG
01346                                  "mac_auto_read(): pid %u/%.15s: current level %u under target_sec_level %u, no auto, read_up or trusted -> NOT_GRANTED!\n",
01347                                  current->pid, current->comm,
01348                                  curr_level, target_sec_level);
01349                         }
01350 #endif
01351                       return(NOT_GRANTED);
01352                   }
01353               }
01354           }
01355       }
01356     else
01357     if(target_sec_level < curr_level)
01358       {
01359         if(flags & MAC_auto)
01360           {
01361             mac_auto_used_level = TRUE;
01362           }
01363       }
01364     if((target_categories & curr_categories) != target_categories)
01365       {
01366         if (rsbac_get_attr(MAC,
01367                            T_PROCESS,
01368                            i_tid,
01369                            A_mac_categories,
01370                            &attr_val1,
01371                            FALSE))
01372           { /* failed! */
01373             rsbac_ds_get_error("mac_auto_read", A_none);
01374             return(NOT_GRANTED);
01375           }
01376         if((target_categories & attr_val1.mac_categories) != target_categories)
01377           {
01378 #ifdef CONFIG_RSBAC_DEBUG
01379             if(rsbac_debug_adf_mac)
01380               {
01381                 char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01382 
01383                 if(tmp)
01384                   {
01385                     char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01386 
01387                     if(tmp2)
01388                       {
01389                         u64tostrmac(tmp, attr_val1.mac_categories);
01390                         u64tostrmac(tmp2, target_categories);
01391 #ifdef CONFIG_RSBAC_RMSG
01392                         rsbac_printk(KERN_DEBUG
01393                                "mac_auto_write(): pid %u/%.15s: max_categories %s under target categories %s, no override -> NOT_GRANTED!\n",
01394                                current->pid, current->comm,
01395                                tmp,
01396                                tmp2);
01397 #endif
01398 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01399                         if (!rsbac_nosyslog)
01400 #endif
01401                         printk(KERN_DEBUG
01402                                "mac_auto_write(): pid %u/%.15s: max_categories %s under target categories %s, no override -> NOT_GRANTED!\n",
01403                                current->pid, current->comm,
01404                                tmp,
01405                                tmp2);
01406                         rsbac_kfree(tmp2);
01407                       }
01408                     rsbac_kfree(tmp);
01409                   }
01410               }
01411 #endif
01412             return(NOT_GRANTED);
01413           }
01414         /* curr_categories < target_categories <= max_categories -> need mac_auto, read_up or trusted */
01415         if(flags & MAC_auto)
01416           {
01417             /* check min_write boundary */
01418             if (rsbac_get_attr(MAC,
01419                                T_PROCESS,
01420                                i_tid,
01421                                A_min_write_categories,
01422                                &attr_val1,
01423                                FALSE))
01424               { /* failed! */
01425                 rsbac_ds_get_error("mac_auto_read", A_none);
01426                 return(NOT_GRANTED);
01427               }
01428             if((target_categories & attr_val1.mac_categories) != target_categories)
01429               {
01430                 if(   !(flags & MAC_read_up)
01431 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01432                    && !(flags & MAC_trusted)
01433 #endif
01434                   )
01435                   {
01436                     /* Try mac_file_flags on the target, if FD object */
01437                     switch(target)
01438                       {
01439                         case T_FILE:
01440                         case T_DIR:
01441                         case T_FIFO:
01442                         case T_SYMLINK:
01443                           if (rsbac_get_attr(MAC,
01444                                              target,
01445                                              tid,
01446                                              A_mac_file_flags,
01447                                              &attr_val1,
01448                                              TRUE))
01449                             { /* failed! */
01450                               rsbac_ds_get_error("mac_auto_read", A_none);
01451                               return(NOT_GRANTED);
01452                             }
01453                           if(   (attr_val1.mac_file_flags & MAC_read_up)
01454 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01455                              || (attr_val1.mac_file_flags & MAC_trusted)
01456 #endif
01457                             )
01458                             {
01459                               break;
01460                             }
01461                           /* fall through */
01462 
01463                         default:
01464 #ifdef CONFIG_RSBAC_DEBUG
01465                           if(rsbac_debug_adf_mac)
01466                             {
01467                               char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01468 
01469                               if(tmp)
01470                                 {
01471                                   char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01472 
01473                                   if(tmp2)
01474                                     {
01475                                       u64tostrmac(tmp, attr_val1.mac_categories);
01476                                       u64tostrmac(tmp2, target_categories);
01477 #ifdef CONFIG_RSBAC_RMSG
01478                                       rsbac_printk(KERN_DEBUG
01479                                              "mac_auto_write(): pid %u/%.15s: min_write_categories %s under target categories %s, no read_up or trusted with read option -> NOT_GRANTED!\n",
01480                                              current->pid, current->comm,
01481                                              tmp,
01482                                              tmp2);
01483 #endif
01484 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01485                                       if (!rsbac_nosyslog)
01486 #endif
01487                                       printk(KERN_DEBUG
01488                                              "mac_auto_write(): pid %u/%.15s: min_write_categories %s under target categories %s, no read_up or trusted with read option -> NOT_GRANTED!\n",
01489                                              current->pid, current->comm,
01490                                              tmp,
01491                                              tmp2);
01492                                       rsbac_kfree(tmp2);
01493                                     }
01494                                   rsbac_kfree(tmp);
01495                                 }
01496                             }
01497 #endif
01498                           return(NOT_GRANTED);
01499                       }
01500                   }
01501               }
01502             else
01503               {
01504                 mac_auto_used_cat = TRUE;
01505                 set_level_cat = TRUE;
01506               }
01507           }
01508         else
01509           {
01510             if(   !(flags & MAC_read_up)
01511 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01512                && !(flags & MAC_trusted)
01513 #endif
01514               )
01515               {
01516                 /* Try mac_file_flags on the target, if FD object */
01517                 switch(target)
01518                   {
01519                     case T_FILE:
01520                     case T_DIR:
01521                     case T_FIFO:
01522                     case T_SYMLINK:
01523                       if (rsbac_get_attr(MAC,
01524                                          target,
01525                                          tid,
01526                                          A_mac_file_flags,
01527                                          &attr_val1,
01528                                          TRUE))
01529                         { /* failed! */
01530                           rsbac_ds_get_error("mac_auto_read", A_none);
01531                           return(NOT_GRANTED);
01532                         }
01533                       if(   (attr_val1.mac_file_flags & MAC_read_up)
01534 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01535                          || (attr_val1.mac_file_flags & MAC_trusted)
01536 #endif
01537                         )
01538                         {
01539                           break;
01540                         }
01541                       /* fall through */
01542 
01543                     default:
01544 #ifdef CONFIG_RSBAC_DEBUG
01545                       if(rsbac_debug_adf_mac)
01546                         {
01547                           char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01548 
01549                           if(tmp)
01550                             {
01551                               char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01552 
01553                               if(tmp2)
01554                                 {
01555                                   u64tostrmac(tmp, curr_categories);
01556                                   u64tostrmac(tmp2, target_categories);
01557 #ifdef CONFIG_RSBAC_RMSG
01558                                   rsbac_printk(KERN_DEBUG
01559                                          "mac_auto_write(): pid %u/%.15s: curr_categories %s under target categories %s, no auto, read_up or trusted with read option -> NOT_GRANTED!\n",
01560                                          current->pid, current->comm,
01561                                          tmp,
01562                                          tmp2);
01563 #endif
01564 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01565                                   if (!rsbac_nosyslog)
01566 #endif
01567                                   printk(KERN_DEBUG
01568                                          "mac_auto_write(): pid %u/%.15s: curr_categories %s under target categories %s, no auto, read_up or trusted with read option -> NOT_GRANTED!\n",
01569                                          current->pid, current->comm,
01570                                          tmp,
01571                                          tmp2);
01572                                   rsbac_kfree(tmp2);
01573                                 }
01574                               rsbac_kfree(tmp);
01575                             }
01576                         }
01577 #endif
01578                       return(NOT_GRANTED);
01579                   }
01580               }
01581           }
01582       }
01583     else
01584     if((target_categories & curr_categories) != curr_categories)
01585       {
01586         if(flags & MAC_auto)
01587           {
01588             mac_auto_used_level = TRUE;
01589           }
01590       }
01591 
01592     /* grant area */
01593 
01594     /* adjust current_sec_level and max_read_level, */
01595     /* if set_level is true and mac_auto has been used*/
01596     if(set_level && mac_auto_used_level)
01597       {
01598         i_tid.process = pid;
01599         attr_val1.current_sec_level = target_sec_level;
01600         if(set_level_level)
01601           {
01602 #ifdef CONFIG_RSBAC_MAC_LOG_LEVEL_CHANGE
01603             char * target_type_name;
01604             char * target_id_name;
01605 
01606             target_type_name = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01607             if(target_type_name)
01608               {
01609                 #ifdef CONFIG_RSBAC_LOG_FULL_PATH
01610                 target_id_name
01611                   = rsbac_kmalloc(CONFIG_RSBAC_MAX_PATH_LEN + RSBAC_MAXNAMELEN);
01612                   /* max. path name len + some extra */
01613                 #else
01614                 target_id_name = rsbac_kmalloc(2 * RSBAC_MAXNAMELEN);
01615                   /* max. file name len + some extra */
01616                 #endif
01617                 if(target_id_name)
01618                   {
01619                     get_target_name(target_type_name, target, target_id_name, tid);
01620 
01621                       #ifndef CONFIG_RSBAC_RMSG_EXCL
01622                       /* only log to standard syslog, if not disabled by kernel boot parameter */
01623                       #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01624                       if (!rsbac_nosyslog)
01625                       #endif
01626                     printk(KERN_INFO
01627                            "mac_auto_read(): Changing process %u (%.15s, owner %u) current level from %u to %u for %s %s\n",
01628                            pid,
01629                            current->comm,
01630                            current->uid,
01631                            curr_level,
01632                            target_sec_level,
01633                            target_type_name,
01634                            target_id_name);
01635                       #endif
01636                       #ifdef CONFIG_RSBAC_RMSG
01637                     rsbac_printk(KERN_INFO
01638                            "mac_auto_read(): Changing process %u (%.15s, owner %u) current level from %u to %u for %s %s\n",
01639                            pid,
01640                            current->comm,
01641                            current->uid,
01642                            curr_level,
01643                            target_sec_level,
01644                            target_type_name,
01645                            target_id_name);
01646                       #endif
01647                     rsbac_kfree(target_id_name);
01648                   }
01649                 rsbac_kfree(target_type_name);
01650               }
01651 #endif
01652             if(rsbac_set_attr(MAC,
01653                               T_PROCESS,
01654                               i_tid,
01655                               A_current_sec_level,
01656                               attr_val1))
01657               { /* failed! */
01658                 rsbac_ds_set_error("mac_auto_read", A_none);
01659                 return(NOT_GRANTED);
01660               }
01661           }
01662         if (rsbac_get_attr(MAC,
01663                            T_PROCESS,
01664                            i_tid,
01665                            A_max_read_open,
01666                            &attr_val2,
01667                            TRUE))
01668           { /* failed! */
01669             rsbac_ds_get_error("mac_auto_read", A_none);
01670             return(NOT_GRANTED);
01671           }
01672         if(attr_val1.max_read_open > attr_val2.max_read_open)
01673           {
01674             if (rsbac_set_attr(MAC,
01675                                T_PROCESS,
01676                                i_tid,
01677                                A_max_read_open,
01678                                attr_val1))
01679               { /* failed! */
01680                 rsbac_ds_set_error("mac_auto_read", A_none);
01681                 return(NOT_GRANTED);
01682               }
01683           }
01684       }
01685     /* adjust current_categories and max_read_categories, */
01686     /* if set_level is true and mac_auto has been used*/
01687     if(set_level && mac_auto_used_cat)
01688       {
01689         i_tid.process = pid;
01690         attr_val1.mac_categories = target_categories;
01691         if(set_level_cat)
01692           {
01693 #ifdef CONFIG_RSBAC_MAC_LOG_LEVEL_CHANGE
01694             char * target_type_name = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01695             if(target_type_name)
01696               {
01697                 char * target_id_name;
01698 
01699                 #ifdef CONFIG_RSBAC_LOG_FULL_PATH
01700                 target_id_name
01701                   = rsbac_kmalloc(CONFIG_RSBAC_MAX_PATH_LEN + RSBAC_MAXNAMELEN);
01702                   /* max. path name len + some extra */
01703                 #else
01704                 target_id_name = rsbac_kmalloc(2 * RSBAC_MAXNAMELEN);
01705                   /* max. file name len + some extra */
01706                 #endif
01707                 if(target_id_name)
01708                   {
01709                     char * tmp1 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01710                     if(tmp1)
01711                       {
01712                         char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
01713                         if(tmp2)
01714                           {
01715                             get_target_name(target_type_name, target, target_id_name, tid);
01716 
01717                             #ifndef CONFIG_RSBAC_RMSG_EXCL
01718                             /* only log to standard syslog, if not disabled by kernel boot parameter */
01719                             #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01720                             if (!rsbac_nosyslog)
01721                             #endif
01722                             printk(KERN_INFO
01723                                    "mac_auto_read(): Changing process %u (15%s, owner %u) current categories from %s to %s for %s %s\n",
01724                                    pid,
01725                                    current->comm,
01726                                    current->uid,
01727                                    u64tostrmac(tmp1, curr_categories),
01728                                    u64tostrmac(tmp2, target_categories),
01729                                    target_type_name,
01730                                    target_id_name);
01731                             #endif
01732                             #ifdef CONFIG_RSBAC_RMSG
01733                             rsbac_printk(KERN_INFO
01734                                    "mac_auto_read(): Changing process %u (15%s, owner %u) current categories from %s to %s for %s %s\n",
01735                                    pid,
01736                                    current->comm,
01737                                    current->uid,
01738                                    u64tostrmac(tmp1, curr_categories),
01739                                    u64tostrmac(tmp2, target_categories),
01740                                    target_type_name,
01741                                    target_id_name);
01742                             #endif
01743                             rsbac_kfree(tmp2);
01744                           }
01745                         rsbac_kfree(tmp1);
01746                       }
01747                     rsbac_kfree(target_id_name);
01748                   }
01749                 rsbac_kfree(target_type_name);
01750               }
01751 #endif
01752             if(rsbac_set_attr(MAC,
01753                               T_PROCESS,
01754                               i_tid,
01755                               A_mac_curr_categories,
01756                               attr_val1))
01757               { /* failed! */
01758                 rsbac_ds_set_error("mac_auto_read", A_none);
01759                 return(NOT_GRANTED);
01760               }
01761           }
01762         if (rsbac_get_attr(MAC,
01763                            T_PROCESS,
01764                            i_tid,
01765                            A_max_read_categories,
01766                            &attr_val2,
01767                            TRUE))
01768           { /* failed! */
01769             rsbac_ds_get_error("mac_auto_read", A_none);
01770             return(NOT_GRANTED);
01771           }
01772         if((attr_val1.mac_categories & attr_val2.mac_categories)
01773            != attr_val1.mac_categories
01774           )
01775           {
01776             if (rsbac_set_attr(MAC,
01777                                T_PROCESS,
01778                                i_tid,
01779                                A_max_read_categories,
01780                                attr_val1))
01781               { /* failed! */
01782                 rsbac_ds_set_error("mac_auto_read", A_none);
01783                 return(NOT_GRANTED);
01784               }
01785           }
01786       }
01787 
01788     /* Everything done, so return */
01789     return(GRANTED);
01790   }
01791 
01792 static enum rsbac_adf_req_ret_t
01793             auto_read(     rsbac_pid_t             pid,
01794                      enum  rsbac_target_t          target,
01795                      union rsbac_target_id_t       tid,
01796                            rsbac_boolean_t                 set_level)
01797   {
01798     return auto_read_attr(pid,
01799                           target,
01800                           tid,
01801                           A_security_level,
01802                           A_mac_categories,
01803                           set_level);
01804   }
01805 
01806 
01807 /* auto-read-write() */
01808 /* combines auto-read and auto-write */
01809 
01810 static enum rsbac_adf_req_ret_t
01811   auto_read_write_attr(      rsbac_pid_t             pid,
01812                        enum  rsbac_target_t          target,
01813                        union rsbac_target_id_t       tid,
01814                        enum  rsbac_attribute_t       t_level_attr,
01815                        enum  rsbac_attribute_t       t_cat_attr,
01816                              rsbac_boolean_t                 set_level)
01817   {
01818     rsbac_security_level_t        curr_level;
01819     rsbac_mac_category_vector_t   curr_categories;
01820     rsbac_security_level_t        target_sec_level;
01821     rsbac_mac_category_vector_t   target_categories;
01822     union rsbac_target_id_t       i_tid;
01823     union rsbac_attribute_value_t attr_val1;
01824     union rsbac_attribute_value_t attr_val2;
01825     rsbac_mac_process_flags_t     flags;
01826     rsbac_boolean_t                       mac_auto_used_level = FALSE;
01827     rsbac_boolean_t                       mac_auto_used_cat = FALSE;
01828     rsbac_boolean_t                       raise_object_level = FALSE;
01829     rsbac_boolean_t                       raise_object_cat = FALSE;
01830 
01831     /* first check for mac_override, which allows everything */
01832     i_tid.process = pid;
01833     if (rsbac_get_attr(MAC,
01834                        T_PROCESS,
01835                        i_tid,
01836                        A_mac_process_flags,
01837                        &attr_val1,
01838                        FALSE))
01839       { /* failed! */
01840         rsbac_ds_get_error("mac_auto_read_write", A_none);
01841         return(NOT_GRANTED);
01842       }
01843     flags = attr_val1.mac_process_flags;
01844     if(flags & MAC_override)
01845       return GRANTED;
01846 
01847     /* Get current security level */
01848     if (rsbac_get_attr(MAC,
01849                        T_PROCESS,
01850                        i_tid,
01851                        A_current_sec_level,
01852                        &attr_val1,
01853                        FALSE))
01854       { /* failed! */
01855         rsbac_ds_get_error("mac_auto_read_write", A_none);
01856         return(NOT_GRANTED);
01857       }
01858     curr_level = attr_val1.security_level;
01859     /* Get current categories */
01860     if (rsbac_get_attr(MAC,
01861                        T_PROCESS,
01862                        i_tid,
01863                        A_mac_curr_categories,
01864                        &attr_val1,
01865                        FALSE))
01866       { /* failed! */
01867         rsbac_ds_get_error("mac_auto_read_write", A_none);
01868         return(NOT_GRANTED);
01869       }
01870     curr_categories = attr_val1.mac_categories;
01871     /* Get target security level */
01872     if (rsbac_get_attr(MAC,
01873                        target,
01874                        tid,
01875                        t_level_attr,
01876                        &attr_val1,
01877                        TRUE))
01878       { /* failed! */
01879         rsbac_ds_get_error("mac_auto_read_write", A_none);
01880         return(NOT_GRANTED);
01881       }
01882     target_sec_level = attr_val1.security_level;
01883     /* Get target categories */
01884     if (rsbac_get_attr(MAC,
01885                        target,
01886                        tid,
01887                        t_cat_attr,
01888                        &attr_val1,
01889                        TRUE))
01890       { /* failed! */
01891         rsbac_ds_get_error("mac_auto_read_write", A_none);
01892         return(NOT_GRANTED);
01893       }
01894     target_categories = attr_val1.mac_categories;
01895 
01896     if(target_sec_level > curr_level)
01897       {
01898         if (rsbac_get_attr(MAC,
01899                            T_PROCESS,
01900                            i_tid,
01901                            A_security_level,
01902                            &attr_val1,
01903                            FALSE))
01904           { /* failed! */
01905             rsbac_ds_get_error("mac_auto_read_write", A_none);
01906             return(NOT_GRANTED);
01907           }
01908         if(attr_val1.security_level < target_sec_level)
01909           {
01910 #ifdef CONFIG_RSBAC_DEBUG
01911             if(rsbac_debug_adf_mac)
01912               {
01913 #ifdef CONFIG_RSBAC_RMSG
01914                 rsbac_printk(KERN_DEBUG
01915                        "mac_auto_read_write(): pid %u/%.15s: security_level %u under target_sec_level %u, no override -> NOT_GRANTED!\n",
01916                        current->pid, current->comm,
01917                        attr_val1.security_level, target_sec_level);
01918 #endif
01919 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01920                 if (!rsbac_nosyslog)
01921 #endif
01922                 printk(KERN_DEBUG
01923                        "mac_auto_read_write(): pid %u/%.15s: security_level %u under target_sec_level %u, no override -> NOT_GRANTED!\n",
01924                        current->pid, current->comm,
01925                        attr_val1.security_level, target_sec_level);
01926               }
01927 #endif
01928             return(NOT_GRANTED);
01929           }
01930         /* curr_level < target_level <= max_level */
01931         /* -> need mac_auto, (write_up && read_up) or trusted (with read option) */
01932         if(flags & MAC_auto)
01933           {
01934             /* check min_write boundary */
01935             if (rsbac_get_attr(MAC,
01936                                T_PROCESS,
01937                                i_tid,
01938                                A_min_write_open,
01939                                &attr_val1,
01940                                FALSE))
01941               { /* failed! */
01942                 rsbac_ds_get_error("mac_auto_read_write", A_none);
01943                 return(NOT_GRANTED);
01944               }
01945             if(attr_val1.security_level < target_sec_level)
01946               {
01947                 if(   !((flags & MAC_write_up) && (flags & MAC_read_up))
01948 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01949                    && !(flags & MAC_trusted)
01950 #endif
01951                   )
01952                   {
01953                     /* Try mac_file_flags on the target, if FD object */
01954                     switch(target)
01955                       {
01956                         case T_FILE:
01957                         case T_DIR:
01958                         case T_FIFO:
01959                         case T_SYMLINK:
01960                           if (rsbac_get_attr(MAC,
01961                                              target,
01962                                              tid,
01963                                              A_mac_file_flags,
01964                                              &attr_val1,
01965                                              TRUE))
01966                             { /* failed! */
01967                               rsbac_ds_get_error("mac_auto_read_write", A_none);
01968                               return(NOT_GRANTED);
01969                             }
01970                           if(   (   (attr_val1.mac_file_flags & MAC_write_up)
01971                                  && (attr_val1.mac_file_flags & MAC_read_up)
01972                                 )
01973 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
01974                              || (flags & MAC_trusted)
01975 #endif
01976                             )
01977                             {
01978                               break;
01979                             }
01980                           /* fall through */
01981 
01982                         default:
01983 #ifdef CONFIG_RSBAC_DEBUG
01984                           if(rsbac_debug_adf_mac)
01985                             {
01986 #ifdef CONFIG_RSBAC_RMSG
01987                               rsbac_printk(KERN_DEBUG
01988                                      "mac_auto_read_write(): pid %u/%.15s: min_write_open %u under target_sec_level %u, no read_up or trusted -> NOT_GRANTED!\n",
01989                                      current->pid, current->comm,
01990                                      attr_val1.security_level, target_sec_level);
01991 #endif
01992 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
01993                               if (!rsbac_nosyslog)
01994 #endif
01995                               printk(KERN_DEBUG
01996                                      "mac_auto_read_write(): pid %u/%.15s: min_write_open %u under target_sec_level %u, no read_up or trusted -> NOT_GRANTED!\n",
01997                                      current->pid, current->comm,
01998                                      attr_val1.security_level, target_sec_level);
01999                             }
02000 #endif
02001                           return(NOT_GRANTED);
02002                       }
02003                   }
02004               }
02005             else
02006               mac_auto_used_level = TRUE;
02007           }
02008         else
02009           {
02010             if(   !((flags & MAC_write_up) && (flags & MAC_read_up))
02011 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
02012                && !(flags & MAC_trusted)
02013 #endif
02014               )
02015               {
02016                 /* Try mac_file_flags on the target, if FD object */
02017                 switch(target)
02018                   {
02019                     case T_FILE:
02020                     case T_DIR:
02021                     case T_FIFO:
02022                     case T_SYMLINK:
02023                       if (rsbac_get_attr(MAC,
02024                                          target,
02025                                          tid,
02026                                          A_mac_file_flags,
02027                                          &attr_val1,
02028                                          TRUE))
02029                         { /* failed! */
02030                           rsbac_ds_get_error("mac_auto_read_write", A_none);
02031                           return(NOT_GRANTED);
02032                         }
02033                       if(   (   (attr_val1.mac_file_flags & MAC_write_up)
02034                              && (attr_val1.mac_file_flags & MAC_read_up)
02035                             )
02036 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
02037                          || (flags & MAC_trusted)
02038 #endif
02039                         )
02040                         {
02041                           break;
02042                         }
02043                       /* fall through */
02044 
02045                     default:
02046 #ifdef CONFIG_RSBAC_DEBUG
02047                       if(rsbac_debug_adf_mac)
02048                         {
02049 #ifdef CONFIG_RSBAC_RMSG
02050                           rsbac_printk(KERN_DEBUG
02051                                  "mac_auto_read_write(): pid %u/%.15s: current level %u under target_sec_level %u, no auto, (write_up && read_up) or trusted -> NOT_GRANTED!\n",
02052                                  current->pid, current->comm,
02053                                  curr_level, target_sec_level);
02054 #endif
02055 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02056                           if (!rsbac_nosyslog)
02057 #endif
02058                           printk(KERN_DEBUG
02059                                  "mac_auto_read_write(): pid %u/%.15s: current level %u under target_sec_level %u, no auto, (write_up && read_up) or trusted -> NOT_GRANTED!\n",
02060                                  current->pid, current->comm,
02061                                  curr_level, target_sec_level);
02062                         }
02063 #endif
02064                       return(NOT_GRANTED);
02065                   }
02066               }
02067           }
02068       }
02069     else
02070     if(target_sec_level < curr_level)
02071       {
02072         if (rsbac_get_attr(MAC,
02073                            T_PROCESS,
02074                            i_tid,
02075                            A_min_security_level,
02076                            &attr_val1,
02077                            FALSE))
02078           { /* failed! */
02079             rsbac_ds_get_error("mac_auto_read_write", A_none);
02080             return(NOT_GRANTED);
02081           }
02082         if(attr_val1.security_level > target_sec_level)
02083           {
02084 #ifdef CONFIG_RSBAC_DEBUG
02085             if(rsbac_debug_adf_mac)
02086               {
02087 #ifdef CONFIG_RSBAC_RMSG
02088                 rsbac_printk(KERN_DEBUG
02089                        "mac_auto_read_write(): pid %u/%.15s: min_security_level %u over target_sec_level %u, no override -> NOT_GRANTED!\n",
02090                        current->pid, current->comm,
02091                        attr_val1.security_level, target_sec_level);
02092 #endif
02093 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02094                 if (!rsbac_nosyslog)
02095 #endif
02096                 printk(KERN_DEBUG
02097                        "mac_auto_read_write(): pid %u/%.15s: min_security_level %u over target_sec_level %u, no override -> NOT_GRANTED!\n",
02098                        current->pid, current->comm,
02099                        attr_val1.security_level, target_sec_level);
02100               }
02101 #endif
02102             return(NOT_GRANTED);
02103           }
02104         /* min_level <= target_level < curr_level -> need mac_auto, write_down or trusted */
02105         if(flags & MAC_auto)
02106           {
02107             /* check max_read boundary */
02108             if (rsbac_get_attr(MAC,
02109                                T_PROCESS,
02110                                i_tid,
02111                                A_max_read_open,
02112                                &attr_val1,
02113                                FALSE))
02114               { /* failed! */
02115                 rsbac_ds_get_error("mac_auto_read_write", A_none);
02116                 return(NOT_GRANTED);
02117               }
02118             if(attr_val1.security_level > target_sec_level)
02119               {
02120                 if(   !(flags & MAC_write_down)
02121                    && !(flags & MAC_trusted)
02122                   )
02123                   {
02124                     /* Try mac_file_flags on the target, if FD object */
02125                     switch(target)
02126                       {
02127                         case T_FILE:
02128                         case T_DIR:
02129                         case T_FIFO:
02130                         case T_SYMLINK:
02131                           if (rsbac_get_attr(MAC,
02132                                              target,
02133                                              tid,
02134                                              A_mac_file_flags,
02135                                              &attr_val1,
02136                                              TRUE))
02137                             { /* failed! */
02138                               rsbac_ds_get_error("mac_auto_read_write", A_none);
02139                               return(NOT_GRANTED);
02140                             }
02141                           if(   (attr_val1.mac_file_flags & MAC_write_down)
02142                              || (attr_val1.mac_file_flags & MAC_trusted)
02143                             )
02144                             {
02145                               if(attr_val1.mac_file_flags & MAC_auto)
02146                                 {
02147                                   raise_object_level = TRUE;
02148                                 }
02149                               break;
02150                             }
02151                           /* fall through */
02152 
02153                         default:
02154 #ifdef CONFIG_RSBAC_DEBUG
02155                           if(rsbac_debug_adf_mac)
02156                             {
02157 #ifdef CONFIG_RSBAC_RMSG
02158                               rsbac_printk(KERN_DEBUG
02159                                      "mac_auto_read_write(): pid %u/%.15s: max_read_open %u over target_sec_level %u, no write_down or trusted -> NOT_GRANTED!\n",
02160                                      current->pid, current->comm,
02161                                      attr_val1.security_level, target_sec_level);
02162 #endif
02163 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02164                               if (!rsbac_nosyslog)
02165 #endif
02166                               printk(KERN_DEBUG
02167                                      "mac_auto_read_write(): pid %u/%.15s: max_read_open %u over target_sec_level %u, no write_down or trusted -> NOT_GRANTED!\n",
02168                                      current->pid, current->comm,
02169                                      attr_val1.security_level, target_sec_level);
02170                             }
02171 #endif
02172                           return(NOT_GRANTED);
02173                       }
02174                   }
02175               }
02176             else
02177               mac_auto_used_level = TRUE;
02178           }
02179         else
02180           {
02181             if(   !(flags & MAC_write_down)
02182                && !(flags & MAC_trusted)
02183               )
02184               {
02185                 /* Try mac_file_flags on the target, if FD object */
02186                 switch(target)
02187                   {
02188                     case T_FILE:
02189                     case T_DIR:
02190                     case T_FIFO:
02191                     case T_SYMLINK:
02192                       if (rsbac_get_attr(MAC,
02193                                          target,
02194                                          tid,
02195                                          A_mac_file_flags,
02196                                          &attr_val1,
02197                                          TRUE))
02198                         { /* failed! */
02199                           rsbac_ds_get_error("mac_auto_read_write", A_none);
02200                           return(NOT_GRANTED);
02201                         }
02202                       if(   (attr_val1.mac_file_flags & MAC_write_down)
02203                          || (attr_val1.mac_file_flags & MAC_trusted)
02204                         )
02205                         {
02206                           if(attr_val1.mac_file_flags & MAC_auto)
02207                             {
02208                               raise_object_level = TRUE;
02209                             }
02210                           break;
02211                         }
02212                       /* fall through */
02213 
02214                     default:
02215 #ifdef CONFIG_RSBAC_DEBUG
02216                       if(rsbac_debug_adf_mac)
02217                         {
02218 #ifdef CONFIG_RSBAC_RMSG
02219                           rsbac_printk(KERN_DEBUG
02220                                  "mac_auto_read_write(): pid %u/%.15s: current security_level %u over target_sec_level %u, no auto, write_down or trusted -> NOT_GRANTED!\n",
02221                                  current->pid, current->comm,
02222                                  curr_level, target_sec_level);
02223 #endif
02224 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02225                           if (!rsbac_nosyslog)
02226 #endif
02227                           printk(KERN_DEBUG
02228                                  "mac_auto_read_write(): pid %u/%.15s: current security_level %u over target_sec_level %u, no auto, write_down or trusted -> NOT_GRANTED!\n",
02229                                  current->pid, current->comm,
02230                                  curr_level, target_sec_level);
02231                         }
02232 #endif
02233                       return(NOT_GRANTED);
02234                   }
02235               }
02236           }
02237       }
02238     if((target_categories & curr_categories) != target_categories)
02239       {
02240         if (rsbac_get_attr(MAC,
02241                            T_PROCESS,
02242                            i_tid,
02243                            A_mac_categories,
02244                            &attr_val1,
02245                            FALSE))
02246           { /* failed! */
02247             rsbac_ds_get_error("mac_auto_read_write", A_none);
02248             return(NOT_GRANTED);
02249           }
02250         if((target_categories & attr_val1.mac_categories) != target_categories)
02251           {
02252 #ifdef CONFIG_RSBAC_DEBUG
02253             if(rsbac_debug_adf_mac)
02254               {
02255                 char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02256 
02257                 if(tmp)
02258                   {
02259                     char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02260 
02261                     if(tmp2)
02262                       {
02263                         u64tostrmac(tmp, attr_val1.mac_categories);
02264                         u64tostrmac(tmp2, target_categories);
02265 #ifdef CONFIG_RSBAC_RMSG
02266                         rsbac_printk(KERN_DEBUG
02267                                "mac_auto_read_write(): pid %u/%.15s: max_categories %s under target categories %s, no override -> NOT_GRANTED!\n",
02268                                current->pid, current->comm,
02269                                tmp,
02270                                tmp2);
02271 #endif
02272 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02273                         if (!rsbac_nosyslog)
02274 #endif
02275                         printk(KERN_DEBUG
02276                                "mac_auto_read_write(): pid %u/%.15s: max_categories %s under target categories %s, no override -> NOT_GRANTED!\n",
02277                                current->pid, current->comm,
02278                                tmp,
02279                                tmp2);
02280                         rsbac_kfree(tmp2);
02281                       }
02282                     rsbac_kfree(tmp);
02283                   }
02284               }
02285 #endif
02286             return(NOT_GRANTED);
02287           }
02288         /* curr_categories < target_categories <= max_categories */
02289         /* -> need mac_auto, (read_up && write_up) or trusted (with read option) */
02290         if(flags & MAC_auto)
02291           {
02292             /* check min_write boundary */
02293             if (rsbac_get_attr(MAC,
02294                                T_PROCESS,
02295                                i_tid,
02296                                A_min_write_categories,
02297                                &attr_val1,
02298                                FALSE))
02299               { /* failed! */
02300                 rsbac_ds_get_error("mac_auto_read_write", A_none);
02301                 return(NOT_GRANTED);
02302               }
02303             if((target_categories & attr_val1.mac_categories) != target_categories)
02304               {
02305                 if(   !((flags & MAC_write_up) && (flags & MAC_read_up))
02306 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
02307                    && !(flags & MAC_trusted)
02308 #endif
02309                   )
02310                   {
02311                     /* Try mac_file_flags on the target, if FD object */
02312                     switch(target)
02313                       {
02314                         case T_FILE:
02315                         case T_DIR:
02316                         case T_FIFO:
02317                         case T_SYMLINK:
02318                           if (rsbac_get_attr(MAC,
02319                                              target,
02320                                              tid,
02321                                              A_mac_file_flags,
02322                                              &attr_val1,
02323                                              TRUE))
02324                             { /* failed! */
02325                               rsbac_ds_get_error("mac_auto_read_write", A_none);
02326                               return(NOT_GRANTED);
02327                             }
02328                           if(   (   (attr_val1.mac_file_flags & MAC_write_up)
02329                                  && (attr_val1.mac_file_flags & MAC_read_up)
02330                                 )
02331 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
02332                              || (flags & MAC_trusted)
02333 #endif
02334                             )
02335                             {
02336                               break;
02337                             }
02338                           /* fall through */
02339 
02340                         default:
02341 #ifdef CONFIG_RSBAC_DEBUG
02342                           if(rsbac_debug_adf_mac)
02343                             {
02344                               char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02345 
02346                               if(tmp)
02347                                 {
02348                                   char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02349 
02350                                   if(tmp2)
02351                                     {
02352                                       u64tostrmac(tmp, attr_val1.mac_categories);
02353                                       u64tostrmac(tmp2, target_categories);
02354 #ifdef CONFIG_RSBAC_RMSG
02355                                       rsbac_printk(KERN_DEBUG
02356                                              "mac_auto_read_write(): pid %u/%.15s: min_write_categories %s under target categories %s, no (read_up and write_up) or trusted with read option -> NOT_GRANTED!\n",
02357                                              current->pid, current->comm,
02358                                              tmp,
02359                                              tmp2);
02360 #endif
02361 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02362                                       if (!rsbac_nosyslog)
02363 #endif
02364                                       printk(KERN_DEBUG
02365                                              "mac_auto_read_write(): pid %u/%.15s: min_write_categories %s under target categories %s, no (read_up and write_up) or trusted with read option -> NOT_GRANTED!\n",
02366                                              current->pid, current->comm,
02367                                              tmp,
02368                                              tmp2);
02369                                       rsbac_kfree(tmp2);
02370                                     }
02371                                   rsbac_kfree(tmp);
02372                                 }
02373                             }
02374 #endif
02375                           return(NOT_GRANTED);
02376                       }
02377                   }
02378               }
02379             else
02380               mac_auto_used_cat = TRUE;
02381           }
02382         else
02383           {
02384             if(   !((flags & MAC_write_up) && (flags & MAC_read_up))
02385 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
02386                && !(flags & MAC_trusted)
02387 #endif
02388               )
02389               {
02390                 /* Try mac_file_flags on the target, if FD object */
02391                 switch(target)
02392                   {
02393                     case T_FILE:
02394                     case T_DIR:
02395                     case T_FIFO:
02396                     case T_SYMLINK:
02397                       if (rsbac_get_attr(MAC,
02398                                          target,
02399                                          tid,
02400                                          A_mac_file_flags,
02401                                          &attr_val1,
02402                                          TRUE))
02403                         { /* failed! */
02404                           rsbac_ds_get_error("mac_auto_read_write", A_none);
02405                           return(NOT_GRANTED);
02406                         }
02407                       if(   (   (attr_val1.mac_file_flags & MAC_write_up)
02408                              && (attr_val1.mac_file_flags & MAC_read_up)
02409                             )
02410 #ifdef CONFIG_RSBAC_MAC_TRUSTED_READ
02411                          || (flags & MAC_trusted)
02412 #endif
02413                         )
02414                         {
02415                           break;
02416                         }
02417                       /* fall through */
02418 
02419                     default:
02420 #ifdef CONFIG_RSBAC_DEBUG
02421                       if(rsbac_debug_adf_mac)
02422                         {
02423                           char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02424 
02425                           if(tmp)
02426                             {
02427                               char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02428 
02429                               if(tmp2)
02430                                 {
02431                                   u64tostrmac(tmp, curr_categories);
02432                                   u64tostrmac(tmp2, target_categories);
02433 #ifdef CONFIG_RSBAC_RMSG
02434                                   rsbac_printk(KERN_DEBUG
02435                                          "mac_auto_read_write(): pid %u/%.15s: curr_categories %s under target categories %s, no auto, (read_up and write_up) or trusted -> NOT_GRANTED!\n",
02436                                          current->pid, current->comm,
02437                                          tmp,
02438                                          tmp2);
02439 #endif
02440 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02441                                   if (!rsbac_nosyslog)
02442 #endif
02443                                   printk(KERN_DEBUG
02444                                          "mac_auto_read_write(): pid %u/%.15s: curr_categories %s under target categories %s, no auto, (read_up and write_up) or trusted -> NOT_GRANTED!\n",
02445                                          current->pid, current->comm,
02446                                          tmp,
02447                                          tmp2);
02448                                   rsbac_kfree(tmp2);
02449                                 }
02450                               rsbac_kfree(tmp);
02451                             }
02452                         }
02453 #endif
02454                       return(NOT_GRANTED);
02455                   }
02456               }
02457           }
02458       }
02459     else
02460     if((target_categories & curr_categories) != curr_categories)
02461       {
02462         if (rsbac_get_attr(MAC,
02463                            T_PROCESS,
02464                            i_tid,
02465                            A_mac_min_categories,
02466                            &attr_val1,
02467                            FALSE))
02468           { /* failed! */
02469             rsbac_ds_get_error("mac_auto_read_write", A_none);
02470             return(NOT_GRANTED);
02471           }
02472         if((target_categories & attr_val1.mac_categories) != attr_val1.mac_categories)
02473           {
02474 #ifdef CONFIG_RSBAC_DEBUG
02475             if(rsbac_debug_adf_mac)
02476               {
02477                 char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02478 
02479                 if(tmp)
02480                   {
02481                     char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02482 
02483                     if(tmp2)
02484                       {
02485                         u64tostrmac(tmp, attr_val1.mac_categories);
02486                         u64tostrmac(tmp2, target_categories);
02487 #ifdef CONFIG_RSBAC_RMSG
02488                         rsbac_printk(KERN_DEBUG
02489                                "mac_auto_read_write(): pid %u/%.15s: min_categories %s over target categories %s, no override -> NOT_GRANTED!\n",
02490                                current->pid, current->comm,
02491                                tmp,
02492                                tmp2);
02493 #endif
02494 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02495                         if (!rsbac_nosyslog)
02496 #endif
02497                         printk(KERN_DEBUG
02498                                "mac_auto_read_write(): pid %u/%.15s: min_categories %s over target categories %s, no override -> NOT_GRANTED!\n",
02499                                current->pid, current->comm,
02500                                tmp,
02501                                tmp2);
02502                         rsbac_kfree(tmp2);
02503                       }
02504                     rsbac_kfree(tmp);
02505                   }
02506               }
02507 #endif
02508             return(NOT_GRANTED);
02509           }
02510         /* min_level <= target_level < curr_level -> need mac_auto, write_down or trusted */
02511         if(flags & MAC_auto)
02512           {
02513             /* check max_read boundary */
02514             if (rsbac_get_attr(MAC,
02515                                T_PROCESS,
02516                                i_tid,
02517                                A_max_read_categories,
02518                                &attr_val1,
02519                                FALSE))
02520               { /* failed! */
02521                 rsbac_ds_get_error("mac_auto_read_write", A_none);
02522                 return(NOT_GRANTED);
02523               }
02524             if((target_categories & attr_val1.mac_categories) != attr_val1.mac_categories)
02525               {
02526                 if(   !(flags & MAC_write_down)
02527                    && !(flags & MAC_trusted)
02528                   )
02529                   {
02530                     /* Try mac_file_flags on the target, if FD object */
02531                     switch(target)
02532                       {
02533                         case T_FILE:
02534                         case T_DIR:
02535                         case T_FIFO:
02536                         case T_SYMLINK:
02537                           if (rsbac_get_attr(MAC,
02538                                              target,
02539                                              tid,
02540                                              A_mac_file_flags,
02541                                              &attr_val1,
02542                                              TRUE))
02543                             { /* failed! */
02544                               rsbac_ds_get_error("mac_auto_read_write", A_none);
02545                               return(NOT_GRANTED);
02546                             }
02547                           if(   (attr_val1.mac_file_flags & MAC_write_down)
02548                              || (attr_val1.mac_file_flags & MAC_trusted)
02549                             )
02550                             {
02551                               if(attr_val1.mac_file_flags & MAC_auto)
02552                                 {
02553                                   raise_object_cat = TRUE;
02554                                 }
02555                               break;
02556                             }
02557                           /* fall through */
02558 
02559                         default:
02560 #ifdef CONFIG_RSBAC_DEBUG
02561                           if(rsbac_debug_adf_mac)
02562                             {
02563                               char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02564 
02565                               if(tmp)
02566                                 {
02567                                   char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02568 
02569                                   if(tmp2)
02570                                     {
02571                                       u64tostrmac(tmp, attr_val1.mac_categories);
02572                                       u64tostrmac(tmp2, target_categories);
02573 #ifdef CONFIG_RSBAC_RMSG
02574                                       rsbac_printk(KERN_DEBUG
02575                                              "mac_auto_read_write(): pid %u/%.15s: max_read_categories %s over target categories %s, no write_down or trusted -> NOT_GRANTED!\n",
02576                                              current->pid, current->comm,
02577                                              tmp,
02578                                              tmp2);
02579 #endif
02580 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02581                                       if (!rsbac_nosyslog)
02582 #endif
02583                                       printk(KERN_DEBUG
02584                                              "mac_auto_read_write(): pid %u/%.15s: max_read_categories %s over target categories %s, no write_down or trusted -> NOT_GRANTED!\n",
02585                                              current->pid, current->comm,
02586                                              tmp,
02587                                              tmp2);
02588                                       rsbac_kfree(tmp2);
02589                                     }
02590                                   rsbac_kfree(tmp);
02591                                 }
02592                             }
02593 #endif
02594                           return(NOT_GRANTED);
02595                       }
02596                   }
02597               }
02598             else
02599               mac_auto_used_cat = TRUE;
02600           }
02601         else
02602           {
02603             if(   !(flags & MAC_write_down)
02604                && !(flags & MAC_trusted)
02605               )
02606               {
02607                 /* Try mac_file_flags on the target, if FD object */
02608                 switch(target)
02609                   {
02610                     case T_FILE:
02611                     case T_DIR:
02612                     case T_FIFO:
02613                     case T_SYMLINK:
02614                       if (rsbac_get_attr(MAC,
02615                                          target,
02616                                          tid,
02617                                          A_mac_file_flags,
02618                                          &attr_val1,
02619                                          TRUE))
02620                         { /* failed! */
02621                           rsbac_ds_get_error("mac_auto_read_write", A_none);
02622                           return(NOT_GRANTED);
02623                         }
02624                       if(   (attr_val1.mac_file_flags & MAC_write_down)
02625                          || (attr_val1.mac_file_flags & MAC_trusted)
02626                         )
02627                         {
02628                           if(attr_val1.mac_file_flags & MAC_auto)
02629                             {
02630                               raise_object_cat = TRUE;
02631                             }
02632                           break;
02633                         }
02634                       /* fall through */
02635 
02636                     default:
02637 #ifdef CONFIG_RSBAC_DEBUG
02638                       if(rsbac_debug_adf_mac)
02639                         {
02640                           char * tmp = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02641 
02642                           if(tmp)
02643                             {
02644                               char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02645 
02646                               if(tmp2)
02647                                 {
02648                                   u64tostrmac(tmp, curr_categories);
02649                                   u64tostrmac(tmp2, target_categories);
02650 #ifdef CONFIG_RSBAC_RMSG
02651                                   rsbac_printk(KERN_DEBUG
02652                                          "mac_auto_read_write(): pid %u/%.15s: curr_categories %s over target categories %s, no auto, write_down or trusted -> NOT_GRANTED!\n",
02653                                          current->pid, current->comm,
02654                                          tmp,
02655                                          tmp2);
02656 #endif
02657 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02658                                   if (!rsbac_nosyslog)
02659 #endif
02660                                   printk(KERN_DEBUG
02661                                          "mac_auto_read_write(): pid %u/%.15s: curr_categories %s over target categories %s, no auto, write_down or trusted -> NOT_GRANTED!\n",
02662                                          current->pid, current->comm,
02663                                          tmp,
02664                                          tmp2);
02665                                   rsbac_kfree(tmp2);
02666                                 }
02667                               rsbac_kfree(tmp);
02668                             }
02669                         }
02670 #endif
02671                       return(NOT_GRANTED);
02672                   }
02673               }
02674           }
02675       }
02676 
02677     /* grant area */
02678 
02679     /* adjust current_sec_level and min_write_level, */
02680     /* if set_level is true and mac_auto has been used*/
02681     if(   set_level
02682        && (   mac_auto_used_level
02683            || raise_object_level
02684           )
02685       )
02686       {
02687 #ifdef CONFIG_RSBAC_MAC_LOG_LEVEL_CHANGE
02688         {
02689           char * target_type_name;
02690           char * target_id_name;
02691 
02692           target_type_name = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02693           if(target_type_name)
02694             {
02695               #ifdef CONFIG_RSBAC_LOG_FULL_PATH
02696               target_id_name
02697                 = rsbac_kmalloc(CONFIG_RSBAC_MAX_PATH_LEN + RSBAC_MAXNAMELEN);
02698                 /* max. path name len + some extra */
02699               #else
02700               target_id_name = rsbac_kmalloc(2 * RSBAC_MAXNAMELEN);
02701                 /* max. file name len + some extra */
02702               #endif
02703               if(target_id_name)
02704                 {
02705                   get_target_name(target_type_name, target, target_id_name, tid);
02706 
02707                   if(mac_auto_used_level)
02708                     {
02709                       #ifndef CONFIG_RSBAC_RMSG_EXCL
02710                       /* only log to standard syslog, if not disabled by kernel boot parameter */
02711                       #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02712                       if (!rsbac_nosyslog)
02713                       #endif
02714                       printk(KERN_INFO
02715                              "mac_auto_read_write(): Changing process %u (%.15s, owner %u) current level from %u to %u for %s %s\n",
02716                              pid,
02717                              current->comm,
02718                              current->uid,
02719                              curr_level,
02720                              target_sec_level,
02721                              target_type_name,
02722                              target_id_name);
02723                       #endif
02724                       #ifdef CONFIG_RSBAC_RMSG
02725                       rsbac_printk(KERN_INFO
02726                                    "mac_auto_read_write(): Changing process %u (%.15s, owner %u) current level from %u to %u for %s %s\n",
02727                                    pid,
02728                                    current->comm,
02729                                    current->uid,
02730                                    curr_level,
02731                                    target_sec_level,
02732                                    target_type_name,
02733                                    target_id_name);
02734                       #endif
02735                     }
02736                   else
02737                     {
02738                       #ifndef CONFIG_RSBAC_RMSG_EXCL
02739                       /* only log to standard syslog, if not disabled by kernel boot parameter */
02740                       #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02741                       if (!rsbac_nosyslog)
02742                       #endif
02743                       printk(KERN_INFO
02744                              "mac_auto_read_write(): Process %u (%.15s, owner %u): Raising object level from %u to %u for %s %s\n",
02745                              pid,
02746                              current->comm,
02747                              current->uid,
02748                              target_sec_level,
02749                              curr_level,
02750                              target_type_name,
02751                              target_id_name);
02752                       #endif
02753                       #ifdef CONFIG_RSBAC_RMSG
02754                       rsbac_printk(KERN_INFO
02755                              "mac_auto_read_write(): Process %u (%.15s, owner %u): Raising object level from %u to %u for %s %s\n",
02756                              pid,
02757                              current->comm,
02758                              current->uid,
02759                              target_sec_level,
02760                              curr_level,
02761                              target_type_name,
02762                              target_id_name);
02763                       #endif
02764                     }
02765                   rsbac_kfree(target_id_name);
02766                 }
02767               rsbac_kfree(target_type_name);
02768             }
02769         }
02770 #endif
02771         if(mac_auto_used_level)
02772           {
02773             i_tid.process = pid;
02774             attr_val1.current_sec_level = target_sec_level;
02775             if (rsbac_get_attr(MAC,
02776                                T_PROCESS,
02777                                i_tid,
02778                                A_min_write_open,
02779                                &attr_val2,
02780                                TRUE))
02781               { /* failed! */
02782                 rsbac_ds_get_error("mac_auto_read_write", A_none);
02783                 return(NOT_GRANTED);
02784               }
02785             if(attr_val1.min_write_open < attr_val2.min_write_open)
02786               {
02787                 if (rsbac_set_attr(MAC,
02788                                    T_PROCESS,
02789                                    i_tid,
02790                                    A_min_write_open,
02791                                    attr_val1))
02792                   { /* failed! */
02793                     rsbac_ds_set_error("mac_auto_read_write", A_none);
02794                     return(NOT_GRANTED);
02795                   }
02796               }
02797             if (rsbac_get_attr(MAC,
02798                                T_PROCESS,
02799                                i_tid,
02800                                A_max_read_open,
02801                                &attr_val2,
02802                                TRUE))
02803               { /* failed! */
02804                 rsbac_ds_get_error("mac_auto_read_write", A_none);
02805                 return(NOT_GRANTED);
02806               }
02807             if(attr_val1.max_read_open > attr_val2.max_read_open)
02808               {
02809                 if (rsbac_set_attr(MAC,
02810                                    T_PROCESS,
02811                                    i_tid,
02812                                    A_max_read_open,
02813                                    attr_val1))
02814                   { /* failed! */
02815                     rsbac_ds_set_error("mac_auto_read_write", A_none);
02816                     return(NOT_GRANTED);
02817                   }
02818               }
02819             if (rsbac_set_attr(MAC,
02820                                T_PROCESS,
02821                                i_tid,
02822                                A_current_sec_level,
02823                                attr_val1))
02824               { /* failed! */
02825                 rsbac_ds_set_error("mac_auto_read_write", A_none);
02826                 return(NOT_GRANTED);
02827               }
02828           }
02829         else
02830           {
02831             attr_val1.security_level = curr_level;
02832             if (rsbac_set_attr(MAC,
02833                                target,
02834                                tid,
02835                                A_security_level,
02836                                attr_val1))
02837               { /* failed! */
02838                 rsbac_ds_set_error("mac_auto_read_write", A_none);
02839                 return(NOT_GRANTED);
02840               }
02841           }
02842       }
02843     /* adjust current_categories and min_write_categories, */
02844     /* if set_level is true and mac_auto has been used*/
02845     if(   set_level
02846        && (   mac_auto_used_cat
02847            || raise_object_cat
02848           )
02849       )
02850       {
02851 #ifdef CONFIG_RSBAC_MAC_LOG_LEVEL_CHANGE
02852         {
02853           char * target_type_name = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02854           if(target_type_name)
02855             {
02856               char * target_id_name;
02857 
02858               #ifdef CONFIG_RSBAC_LOG_FULL_PATH
02859               target_id_name
02860                 = rsbac_kmalloc(CONFIG_RSBAC_MAX_PATH_LEN + RSBAC_MAXNAMELEN);
02861                 /* max. path name len + some extra */
02862               #else
02863               target_id_name = rsbac_kmalloc(2 * RSBAC_MAXNAMELEN);
02864                 /* max. file name len + some extra */
02865               #endif
02866               if(target_id_name)
02867                 {
02868                   char * tmp1 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02869                   if(tmp1)
02870                     {
02871                       char * tmp2 = rsbac_kmalloc(RSBAC_MAXNAMELEN);
02872                       if(tmp2)
02873                         {
02874                           get_target_name(target_type_name, target, target_id_name, tid);
02875 
02876                           if(mac_auto_used_cat)
02877                             {
02878                               #ifndef CONFIG_RSBAC_RMSG_EXCL
02879                               /* only log to standard syslog, if not disabled by kernel boot parameter */
02880                               #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02881                               if (!rsbac_nosyslog)
02882                               #endif
02883                               printk(KERN_INFO
02884                                      "mac_auto_read_write(): Changing process %u (%.15s, owner %u) current categories from %s to %s for %s %s\n",
02885                                      pid,
02886                                      current->comm,
02887                                      current->uid,
02888                                      u64tostrmac(tmp1, curr_categories),
02889                                      u64tostrmac(tmp2, target_categories),
02890                                      target_type_name,
02891                                      target_id_name);
02892                               #endif
02893                               #ifdef CONFIG_RSBAC_RMSG
02894                               rsbac_printk(KERN_INFO
02895                                      "mac_auto_read_write(): Changing process %u (%.15s, owner %u) current categories from %s to %s for %s %s\n",
02896                                      pid,
02897                                      current->comm,
02898                                      current->uid,
02899                                      u64tostrmac(tmp1, curr_categories),
02900                                      u64tostrmac(tmp2, target_categories),
02901                                      target_type_name,
02902                                      target_id_name);
02903                               #endif
02904                             }
02905                           else
02906                             {
02907                               #ifndef CONFIG_RSBAC_RMSG_EXCL
02908                               /* only log to standard syslog, if not disabled by kernel boot parameter */
02909                               #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
02910                               if (!rsbac_nosyslog)
02911                               #endif
02912                               printk(KERN_INFO
02913                                      "mac_auto_read_write(): Process %u (%.15s, owner %u): raising current categories from %s to %s for %s %s\n",
02914                                      pid,
02915                                      current->comm,
02916                                      current->uid,
02917                                      u64tostrmac(tmp2, target_categories),
02918                                      u64tostrmac(tmp1, curr_categories),
02919                                      target_type_name,
02920                                      target_id_name);
02921                               #endif
02922                               #ifdef CONFIG_RSBAC_RMSG
02923                               rsbac_printk(KERN_INFO
02924                                      "mac_auto_read_write(): Process %u (%.15s, owner %u): raising current categories from %s to %s for %s %s\n",
02925                                      pid,
02926                                      current->comm,
02927                                      current->uid,
02928                                      u64tostrmac(tmp2, target_categories),
02929                                      u64tostrmac(tmp1, curr_categories),
02930                                      target_type_name,
02931                                      target_id_name);
02932                               #endif
02933                             }
02934                           rsbac_kfree(tmp2);
02935                         }
02936                       rsbac_kfree(tmp1);
02937                     }
02938                   rsbac_kfree(target_id_name);
02939                 }
02940               rsbac_kfree(target_type_name);
02941             }
02942         }
02943 #endif
02944         if(mac_auto_used_cat)
02945           {
02946             i_tid.process = pid;
02947             attr_val1.mac_categories = target_categories;
02948             if (rsbac_get_attr(MAC,
02949                                T_PROCESS,
02950                                i_tid,
02951                                A_min_write_categories,
02952                                &attr_val2,
02953                                TRUE))
02954               { /* failed! */
02955                 rsbac_ds_set_error("mac_auto_read_write", A_none);
02956                 return(NOT_GRANTED);
02957               }
02958             if((attr_val1.mac_categories & attr_val2.mac_categories)
02959                != attr_val2.mac_categories
02960               )
02961               {
02962                 if (rsbac_set_attr(MAC,
02963                                    T_PROCESS,
02964                                    i_tid,
02965                                    A_min_write_categories,
02966                                    attr_val1))
02967                   { /* failed! */
02968                     rsbac_ds_set_error("mac_auto_read_write", A_none);
02969                     return(NOT_GRANTED);
02970                   }
02971               }
02972             if (rsbac_get_attr(MAC,
02973                                T_PROCESS,
02974                                i_tid,
02975                                A_max_read_categories,
02976                                &attr_val2,
02977                                TRUE))
02978               { /* failed! */
02979                 rsbac_ds_get_error("mac_auto_read_write", A_none);
02980                 return(NOT_GRANTED);
02981               }
02982             if((attr_val1.mac_categories & attr_val2.mac_categories)
02983                != attr_val1.mac_categories
02984               )
02985               {
02986                 if (rsbac_set_attr(MAC,
02987                                    T_PROCESS,
02988                                    i_tid,
02989                                    A_max_read_categories,
02990                                    attr_val1))
02991                   { /* failed! */
02992                     rsbac_ds_set_error("mac_auto_read_write", A_none);
02993                     return(NOT_GRANTED);
02994                   }
02995               }
02996             if (rsbac_set_attr(MAC,
02997                                T_PROCESS,
02998                                i_tid,
02999                                A_mac_curr_categories,
03000                                attr_val1))
03001               { /* failed! */
03002                 rsbac_ds_set_error("mac_auto_read_write", A_none);
03003                 return(NOT_GRANTED);
03004               }
03005           }
03006         else
03007           {
03008             attr_val1.mac_categories = curr_categories;
03009             if (rsbac_set_attr(MAC,
03010                                target,
03011                                tid,
03012                                A_mac_categories,
03013                                attr_val1))
03014               { /* failed! */
03015                 rsbac_ds_set_error("mac_auto_read_write", A_none);
03016                 return(NOT_GRANTED);
03017               }
03018           }
03019       }
03020 
03021     /* Everything done, so return */
03022     return(GRANTED);
03023   }
03024 
03025 static enum rsbac_adf_req_ret_t
03026       auto_read_write(     rsbac_pid_t             pid,
03027                      enum  rsbac_target_t          target,
03028                      union rsbac_target_id_t       tid,
03029                            rsbac_boolean_t                 set_level)
03030   {
03031     return auto_read_write_attr(pid,
03032                                 target,
03033                                 tid,
03034                                 A_security_level,
03035                                 A_mac_categories,
03036                                 set_level);
03037   }
03038 
03039 /************************************************* */
03040 /*          Externally visible functions           */
03041 /************************************************* */
03042 
03043 enum rsbac_adf_req_ret_t
03044    rsbac_adf_request_mac (enum  rsbac_adf_request_t     request,
03045                                 rsbac_pid_t             caller_pid,
03046                           enum  rsbac_target_t          target,
03047                           union rsbac_target_id_t       tid,
03048                           enum  rsbac_attribute_t       attr,
03049                           union rsbac_attribute_value_t attr_val,
03050                                 rsbac_uid_t             owner)
03051   {
03052     enum  rsbac_adf_req_ret_t result = DO_NOT_CARE;
03053     union rsbac_target_id_t       i_tid;
03054     union rsbac_attribute_value_t i_attr_val1;
03055 #if defined(CONFIG_RSBAC_MAC_NET_OBJ_PROT)
03056     union rsbac_attribute_value_t i_attr_val2;
03057 #endif
03058 
03059     switch (request)
03060       {
03061         case R_ADD_TO_KERNEL:
03062             switch(target)
03063               {
03064                 case T_NONE:
03065                   /* test owner's mac_role */
03066                   return mac_check_role(owner, SR_administrator);
03067 
03068                 /* all other cases are unknown */
03069                 default: return(DO_NOT_CARE);
03070               }
03071 
03072         case R_ALTER:
03073             /* only for IPC */
03074             if (target == T_IPC)
03075               {
03076                 /* and perform auto-write without setting attributes */
03077                 return(auto_write(caller_pid,
03078                                   target,
03079                                   tid,
03080                                   FALSE));
03081               }
03082             else
03083             /* all other targets are unknown */
03084               return (DO_NOT_CARE);
03085             break;
03086 
03087         case R_APPEND_OPEN:
03088             switch(target)
03089               {
03090                 case T_FILE:
03091                 case T_FIFO:
03092                   /* and perform auto-write without setting attributes */
03093                   return(auto_write(caller_pid,
03094                                     target,
03095                                     tid,
03096                                     FALSE));
03097                   break;
03098                 case T_IPC:
03099                   /* and perform auto-write without setting attributes */
03100                   return(auto_write(caller_pid,
03101                                     target,
03102                                     tid,
03103                                     FALSE));
03104                   break;
03105                 case T_DEV:
03106                   /* Only check for devices with mac_check set */
03107                   if (rsbac_get_attr(MAC,
03108                                      T_DEV,
03109                                      tid,
03110                                      A_mac_check,
03111                                      &i_attr_val1,
03112                                      FALSE))
03113                     {
03114                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
03115                       return(NOT_GRANTED);
03116                     }
03117                   if(!i_attr_val1.mac_check)
03118                     return(DO_NOT_CARE);
03119                   /* and perform auto-write without setting attributes */
03120                   return(auto_write(caller_pid,
03121                                     target,
03122                                     tid,
03123                                     FALSE));
03124                   break;
03125                 /* all other cases are unknown */
03126                 default: return(DO_NOT_CARE);
03127               }
03128 
03129         case R_CHANGE_GROUP:
03130             switch(target)
03131               {
03132                 case T_FILE:
03133                 case T_DIR:
03134                 case T_FIFO:
03135                 case T_SYMLINK:
03136                   /* and perform auto-write without setting attributes */
03137                   return(auto_write(caller_pid,
03138                                     target,
03139                                     tid,
03140                                     FALSE));
03141                 case T_IPC:
03142                   /* and perform auto-write without setting attributes */
03143                   return(auto_write(caller_pid,
03144                                     target,
03145                                     tid,
03146                                     FALSE));
03147                   
03148 #if defined(CONFIG_RSBAC_MAC_UM_PROT)
03149                 case T_USER:
03150                   /* Security Officer? */
03151                   return mac_check_role(owner, SR_security_officer);
03152 #endif
03153                 /* We do not care about */
03154                 /* all other cases */
03155                 default: return(DO_NOT_CARE);
03156               }
03157 
03158         case R_CHANGE_OWNER:
03159             switch(target)
03160               {
03161                 case T_FILE:
03162                 case T_DIR:
03163                 case T_FIFO:
03164                 case T_SYMLINK:
03165                   /* and perform auto-write without setting attributes */
03166                   return(auto_write(caller_pid,
03167                                     target,
03168                                     tid,
03169                                     FALSE));
03170 
03171                 case T_IPC:
03172                   return(auto_write(caller_pid,
03173                                     target,
03174                                     tid,
03175                                     FALSE));
03176                   
03177                 /* all other cases are unknown */
03178                 default:
03179                   return(DO_NOT_CARE);
03180               }
03181 
03182         case R_CHDIR:
03183             switch(target)
03184               {
03185                 case T_DIR:
03186                   /* and perform auto-read without setting attributes */
03187                   return(auto_read(caller_pid,
03188                                    target,
03189                                    tid,
03190                                    FALSE));
03191                   break;
03192                 /* all other cases are unknown */
03193                 default: return(DO_NOT_CARE);
03194               }
03195 
03196         case R_CLONE:
03197             if (target == T_PROCESS)
03198               return(GRANTED);
03199             else
03200               return(DO_NOT_CARE);
03201 
03202         case R_CREATE:
03203             switch(target)
03204               {
03205                 /* Creating dir or (pseudo) file IN target dir! */
03206                 case T_DIR: 
03207 #ifdef CONFIG_RSBAC_MAC_LIGHT
03208                   return GRANTED;
03209 #else             
03210                   /* Mode of created item is ignored! */
03211                   /* and perform auto-write without setting attributes */
03212                   return(auto_write(caller_pid,
03213                                     target,
03214                                     tid,
03215                                     FALSE));
03216 #endif
03217                   break;
03218                   
03219 #ifdef CONFIG_RSBAC_MAC_NET_OBJ_PROT
03220                 case T_NETTEMP:
03221                   return mac_check_role(owner, SR_security_officer);
03222 
03223                 case T_NETOBJ:
03224                   /* and perform auto-write without setting attributes */
03225                   return(auto_write_attr(caller_pid,
03226                                          target,
03227                                          tid,
03228                                          A_local_sec_level,
03229                                          A_local_mac_categories,
03230                                          FALSE));
03231 #endif
03232 
03233 #if defined(CONFIG_RSBAC_MAC_UM_PROT)
03234                 case T_USER:
03235                 case T_GROUP:
03236                   /* Security Officer? */
03237                   return mac_check_role(owner, SR_security_officer);
03238 #endif
03239                 /* all other cases are unknown */
03240                 default: return(DO_NOT_CARE);
03241               }
03242 
03243         case R_DELETE:
03244             switch(target)
03245               {
03246                 case T_FILE:
03247                 case T_DIR:
03248                 case T_FIFO:
03249                 case T_SYMLINK:
03250                   /* and perform auto-write without setting attributes */
03251                   return(auto_write(caller_pid,
03252                                     target,
03253                                     tid,
03254                                     FALSE));
03255                   break;
03256                 case T_IPC:
03257                   /* and perform auto-write without setting attributes */
03258                   return(auto_write(caller_pid,
03259                                     target,
03260                                     tid,
03261                                     FALSE));
03262                   break;
03263 
03264 #ifdef CONFIG_RSBAC_MAC_NET_OBJ_PROT
03265                 case T_NETTEMP:
03266                   return mac_check_role(owner, SR_security_officer);
03267 #endif
03268 #if defined(CONFIG_RSBAC_MAC_UM_PROT)
03269                 case T_USER:
03270                 case T_GROUP:
03271                   /* Security Officer? */
03272                   return mac_check_role(owner, SR_security_officer);
03273 #endif
03274 
03275                 /* all other cases are unknown */
03276                 default: return(DO_NOT_CARE);
03277               }
03278 
03279         case R_EXECUTE:
03280             switch(target)
03281               {
03282                 case T_FILE:
03283                   /* and perform auto-read without setting attributes */
03284                   return(auto_read(caller_pid,
03285                                    target,
03286                                    tid,
03287                                    FALSE));
03288 
03289                 /* all other cases are unknown */
03290                 default:
03291                   return(DO_NOT_CARE);
03292               }
03293 
03294         case R_GET_PERMISSIONS_DATA:
03295             switch(target)
03296               {
03297 #if defined(CONFIG_RSBAC_MAC_UM_PROT)
03298                 case T_USER:
03299                 case T_GROUP:
03300                   /* Security Officer? */
03301                   return mac_check_role(owner, SR_security_officer);
03302 #endif
03303                 default:
03304                   return(DO_NOT_CARE);
03305                };
03306 
03307         case R_GET_STATUS_DATA:
03308             switch(target)
03309               {
03310                 case T_SCD:
03311                   /* target rsbaclog? only for secoff */
03312                   if (tid.scd != ST_rsbaclog)
03313                     return(GRANTED);
03314                   /* Secoff? */
03315                   if(mac_check_role(owner, SR_security_officer) == NOT_GRANTED)
03316                     return mac_check_role(owner, SR_auditor);
03317                   else
03318                     return GRANTED;
03319 
03320                 case T_PROCESS:
03321                   /* perform auto-read without setting attributes */
03322                   return(auto_read_attr(caller_pid,
03323                                         target,
03324                                         tid,
03325                                         A_current_sec_level,
03326                                         A_mac_curr_categories,
03327                                         FALSE));
03328 
03329                 default:
03330                   return(DO_NOT_CARE);
03331                };
03332 
03333         case R_LINK_HARD:
03334             switch(target)
03335               {
03336                 case T_FILE:
03337                 case T_FIFO:
03338                 case T_SYMLINK:
03339                   /* and perform auto-write without setting attributes */
03340                   return(auto_write(caller_pid,
03341                                     target,
03342                                     tid,
03343                                     FALSE));
03344                   break;
03345                 /* all other cases are unknown */
03346                 default: return(DO_NOT_CARE);
03347               }
03348 
03349         case R_MODIFY_ACCESS_DATA:
03350             switch(target)
03351               {
03352                 case T_FILE:
03353                 case T_DIR:
03354                 case T_FIFO:
03355                 case T_SYMLINK:
03356                   /* and perform auto-write without setting attributes */
03357                   return(auto_write(caller_pid,
03358                                     target,
03359                                     tid,
03360                                     FALSE));
03361                   break;
03362                 /* all other cases are unknown */
03363                 default: return(DO_NOT_CARE);
03364               }
03365 
03366         case R_MODIFY_ATTRIBUTE:
03367             switch(attr)
03368               {
03369                 case A_security_level:
03370                 case A_local_sec_level:
03371                 case A_remote_sec_level:
03372                 case A_min_security_level:
03373                 case A_mac_categories:
03374                 case A_local_mac_categories:
03375                 case A_remote_mac_categories:
03376                 case A_mac_min_categories:
03377                 case A_pseudo:
03378                 case A_system_role:
03379                 case A_mac_role:
03380                 case A_current_sec_level:
03381                 case A_mac_curr_categories:
03382                 case A_min_write_open:
03383                 case A_max_read_open:
03384                 case A_min_write_categories:
03385                 case A_max_read_categories:
03386                 case A_mac_user_flags:
03387                 case A_mac_process_flags:
03388                 case A_mac_check:
03389                 case A_mac_auto:
03390                 case A_mac_prop_trusted:
03391                 case A_mac_file_flags:
03392                 case A_initial_security_level:
03393                 case A_mac_initial_categories:
03394                 #ifdef CONFIG_RSBAC_MAC_GEN_PROT
03395                 case A_log_array_low:
03396                 case A_log_array_high:
03397                 case A_log_program_based:
03398                 case A_log_user_based:
03399                 case A_symlink_add_uid:
03400                 case A_symlink_add_rc_role:
03401                 case A_linux_dac_disable:
03402                 case A_fake_root_uid:
03403                 case A_audit_uid:
03404                 case A_auid_exempt:
03405                 #endif
03406                 #ifdef CONFIG_RSBAC_MAC_AUTH_PROT
03407                 case A_auth_may_setuid:
03408                 case A_auth_may_set_cap:
03409                 case A_auth_start_uid:
03410                 case A_auth_program_file:
03411                 case A_auth_learn:
03412                 case A_auth_add_f_cap:
03413                 case A_auth_remove_f_cap:
03414                 #endif
03415                 /* All attributes (remove target!) */
03416                 case A_none:
03417                   /* Security Officer? */
03418                   return mac_check_role(owner, SR_security_officer);
03419 
03420                 default:
03421                   return(DO_NOT_CARE);
03422               }
03423 
03424         case R_MODIFY_PERMISSIONS_DATA:
03425             switch(target)
03426               {
03427                 case T_FILE:
03428                 case T_DIR:
03429                 case T_FIFO:
03430                 case T_SYMLINK:
03431                 case T_IPC:
03432                   /* and perform auto-write without setting attributes */
03433                   return(auto_write(caller_pid,
03434                                     target,
03435                                     tid,
03436                                     FALSE));
03437                   break;
03438                   
03439                 case T_SCD:
03440                   #ifdef CONFIG_RSBAC_USER_MOD_IOPERM
03441                   if(tid.scd == ST_ioports)
03442                     return GRANTED;
03443                   #endif
03444                   /* Security Officer? */
03445                   i_tid.user = owner;
03446                   if (rsbac_get_attr(MAC,
03447                                      T_USER,
03448                                      i_tid,
03449                                      A_mac_role,
03450                                      &i_attr_val1,
03451                                      TRUE))
03452                     {
03453                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
03454                       return(NOT_GRANTED);
03455                     }
03456                   /* if sec_officer, then grant */
03457                   if (i_attr_val1.system_role == SR_security_officer)
03458                     return(GRANTED);
03459                   /* For booting: if administrator and ioports, then grant */
03460                   if (   (i_attr_val1.system_role == SR_administrator)
03461                       && (tid.scd == ST_ioports) )
03462                     return(GRANTED);
03463                   else
03464                     return(NOT_GRANTED);
03465 
03466 #if defined(CONFIG_RSBAC_MAC_UM_PROT)
03467                 case T_USER:
03468                 case T_GROUP:
03469                   /* Security Officer? */
03470                   return mac_check_role(owner, SR_security_officer);
03471 #endif
03472 #ifdef CONFIG_RSBAC_ALLOW_DAC_DISABLE
03473                 /* switching Linux DAC */
03474                 case T_NONE:
03475                   /* Security Officer? */
03476                   i_tid.user = owner;
03477                   if (rsbac_get_attr(MAC,
03478                                      T_USER,
03479                                      i_tid,
03480                                      A_mac_role,
03481                                      &i_attr_val1,
03482                                      TRUE))
03483                     {
03484                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
03485                       return(NOT_GRANTED);
03486                     }
03487                   /* if sec_officer, then grant */
03488                   if (i_attr_val1.system_role == SR_security_officer)
03489                     return(GRANTED);
03490                   else
03491                     return(NOT_GRANTED);
03492 #endif
03493 
03494                 /* all other cases are unknown */
03495                 default: return(DO_NOT_CARE);
03496               }
03497 
03498         case R_MODIFY_SYSTEM_DATA:
03499             switch(target)
03500               {
03501                 case T_SCD:
03502                   /* target rlimit? no problem, but needed -> grant */
03503                   if (tid.scd == ST_rlimit)
03504                     return(GRANTED);
03505                   /* Get role */
03506                   i_tid.user = owner;
03507                   if (rsbac_get_attr(MAC,
03508                                      T_USER,
03509                                      i_tid,
03510                                      A_mac_role,
03511                                      &i_attr_val1,
03512                                      TRUE))
03513                     {
03514                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
03515                       return(NOT_GRANTED);
03516                     }
03517                   /* if rsbaclog: grant only for secoff and auditor */
03518                   if(tid.scd == ST_rsbaclog)
03519                     {
03520                       if (   (i_attr_val1.system_role == SR_security_officer)
03521                           || (i_attr_val1.system_role == SR_auditor)
03522                          )
03523                         return(GRANTED);
03524                       else
03525                         return(NOT_GRANTED);
03526                     }
03527                   /* if rsbac_log_remote: grant only for secoff */
03528                   if(tid.scd == ST_rsbac_remote_log)
03529                     {
03530                       if (   (i_attr_val1.system_role == SR_security_officer)
03531                          )
03532                         return(GRANTED);
03533                       else
03534                         return(NOT_GRANTED);
03535                     }
03536                   /* if rsbac: grant for secoff and adminr */
03537                   if(tid.scd == ST_rsbac)
03538                     {
03539                       if (   (i_attr_val1.system_role == SR_security_officer)
03540                           || (i_attr_val1.system_role == SR_administrator)
03541                          )
03542                         return(GRANTED);
03543                       else
03544                         return(NOT_GRANTED);
03545                     }
03546                   /* if administrator, then grant */
03547                   if (i_attr_val1.system_role == SR_administrator)
03548                     return(GRANTED);
03549                   else
03550                     return(NOT_GRANTED);
03551                   
03552 #ifdef CONFIG_RSBAC_MAC_NET_DEV_PROT
03553                 case T_NETDEV:
03554                   return mac_check_role(owner, SR_administrator);
03555 #endif
03556 
03557                 /* all other cases are unknown */
03558                 default: return(DO_NOT_CARE);
03559               }
03560 
03561         case R_MOUNT:
03562             switch(target)
03563               {
03564                 case T_FILE:
03565                 case T_DIR:
03566                 case T_DEV:
03567                   /* test owner's mac_role: Administrator? */
03568 #ifndef CONFIG_RSBAC_MAC_LIGHT
03569                   if(mac_check_role(owner, SR_administrator) == NOT_GRANTED)
03570                     return(NOT_GRANTED);
03571 #endif
03572                   /* test read-write access to mount dir / dev: */
03573                   /* and perform auto-read(-write) without setting of attributes */
03574                   if(   (target == T_DEV)
03575                      && (attr == A_mode)
03576                      && (attr_val.mode & MS_RDONLY))
03577                     return(auto_read(caller_pid,
03578                                      target,
03579                                      tid,
03580                                      FALSE));
03581                   else
03582                     return(auto_read_write(caller_pid,
03583                                            target,
03584                                            tid,
03585                                            FALSE));
03586 
03587                 /* all other cases are unknown */
03588                 default: return(DO_NOT_CARE);
03589               }
03590 
03591         case R_READ:
03592             switch(target)
03593               {
03594                 case T_DIR:
03595 #ifdef CONFIG_RSBAC_RW
03596                 case T_IPC:
03597                 case T_FILE:
03598                 case T_FIFO:
03599 #endif
03600                   /* and perform auto-read without setting attributes */
03601                   return(auto_read(caller_pid,
03602                                    target,
03603                                    tid,
03604                                    FALSE));
03605                   break;
03606 
03607 #ifdef CONFIG_RSBAC_RW
03608                 case T_DEV:
03609                   /* Only check for devices with mac_check set */
03610                   if (rsbac_get_attr(MAC,
03611                                      T_DEV,
03612                                      tid,
03613                                      A_mac_check,
03614                                      &i_attr_val1,
03615                                      FALSE))
03616                     {
03617                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
03618                       return(NOT_GRANTED);
03619                     }
03620                   if(!i_attr_val1.mac_check)
03621                     return(DO_NOT_CARE);
03622                   /* and perform auto-read without setting attributes */
03623                   return(auto_read(caller_pid,
03624                                    target,
03625                                    tid,
03626                                    FALSE));
03627                   break;
03628 #endif
03629 
03630 #if defined(CONFIG_RSBAC_MAC_NET_OBJ_PROT)
03631                 case T_NETTEMP:
03632                   if(mac_check_role(owner, SR_security_officer) == GRANTED)
03633                     return GRANTED;
03634                   return mac_check_role(owner, SR_administrator);
03635 
03636                 case T_NETOBJ:
03637                   /* and perform auto-read without setting attributes */
03638                   return(auto_read_attr(caller_pid,
03639                                         target,
03640                                         tid,
03641                                         A_remote_sec_level,
03642                                         A_remote_mac_categories,
03643                                         FALSE));
03644 #endif
03645 
03646 #if defined(CONFIG_RSBAC_MAC_UM_PROT)
03647                 case T_USER:
03648                 case T_GROUP:
03649                   /* Security Officer or Admin? */
03650                   if(mac_check_role(owner, SR_security_officer) == GRANTED)
03651                     return GRANTED;
03652                   else
03653                     return mac_check_role(owner, SR_administrator);
03654 #endif
03655                 /* all other cases are unknown */
03656                 default: return(DO_NOT_CARE);
03657               }
03658 
03659 
03660         case R_READ_ATTRIBUTE:
03661             switch(attr)
03662               {
03663                 case A_owner:
03664                 case A_security_level:
03665                 case A_local_sec_level:
03666                 case A_remote_sec_level:
03667                 case A_min_security_level:
03668                 case A_mac_categories:
03669                 case A_local_mac_categories:
03670                 case A_remote_mac_categories:
03671                 case A_mac_min_categories:
03672                 case A_pseudo:
03673                 case A_system_role:
03674                 case A_mac_role:
03675                 case A_current_sec_level:
03676                 case A_min_write_open:
03677                 case A_max_read_open:
03678                 case A_mac_user_flags:
03679                 case A_mac_process_flags:
03680                 case A_mac_check:
03681                 case A_mac_auto:
03682                 case A_mac_prop_trusted:
03683                 case A_mac_file_flags:
03684                 case A_initial_security_level:
03685                 case A_mac_initial_categories:
03686                 #ifdef CONFIG_RSBAC_MAC_GEN_PROT
03687                 case A_log_array_low:
03688                 case A_log_array_high:
03689                 case A_log_program_based:
03690                 case A_log_user_based:
03691                 case A_symlink_add_uid:
03692                 case A_fake_root_uid:
03693                 case A_audit_uid:
03694                 case A_auid_exempt:
03695                 #endif
03696                 #ifdef CONFIG_RSBAC_MAC_AUTH_PROT
03697                 case A_auth_may_setuid:
03698                 case A_auth_may_set_cap:
03699                 case A_auth_start_uid:
03700                 case A_auth_program_file:
03701                 case A_auth_learn:
03702                 #endif
03703                   /* Security Officer ot Admin? */
03704                   if(mac_check_role(owner, SR_security_officer) == GRANTED)
03705                     return GRANTED;
03706                   else
03707                     return mac_check_role(owner, SR_administrator);
03708 
03709                 default:
03710                   return(DO_NOT_CARE);
03711               }
03712 
03713         case R_READ_OPEN:
03714             switch(target)
03715               {
03716                 case T_FILE:
03717                 case T_DIR:
03718                 case T_FIFO:
03719                 case T_IPC:
03720                   /* and perform auto-read without setting attributes */
03721                   return(auto_read(caller_pid,
03722                                    target,
03723                                    tid,
03724                                    FALSE));
03725                   break;
03726                 case T_DEV:
03727                   /* Only check for devices with mac_check set */
03728                   if (rsbac_get_attr(MAC,
03729                                      T_DEV,
03730                                      tid,
03731                                      A_mac_check,
03732                                      &i_attr_val1,
03733                                      FALSE))
03734                     {
03735                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
03736                       return(NOT_GRANTED);
03737                     }
03738                   if(!i_attr_val1.mac_check)
03739                     return(DO_NOT_CARE);
03740                   /* and perform auto-read without setting attributes */
03741                   return(auto_read(caller_pid,
03742                                    target,
03743                                    tid,
03744                                    FALSE));
03745                   break;
03746                 /* all other cases are unknown */
03747                 default: return(DO_NOT_CARE);
03748               }
03749 
03750         case R_READ_WRITE_OPEN:
03751             switch(target)
03752               {
03753                 case T_FILE:
03754                 case T_FIFO:
03755                 case T_IPC:
03756                   /* and perform auto-read-write without setting attributes */
03757                   return(auto_read_write(caller_pid,
03758                                          target,
03759                                          tid,
03760                                          FALSE));
03761 
03762                 case T_DEV:
03763                   /* Only check for devices with mac_check set */
03764                   if (rsbac_get_attr(MAC,
03765                                      T_DEV,
03766                                      tid,
03767                                      A_mac_check,
03768                                      &i_attr_val1,
03769                                      FALSE))
03770                     {
03771                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
03772                       return(NOT_GRANTED);
03773                     }
03774                   if(!i_attr_val1.mac_check)
03775                     return(DO_NOT_CARE);
03776                   /* and perform auto-read-write without setting attributes */
03777                   return(auto_read_write(caller_pid,
03778                                          target,
03779                                          tid,
03780                                          FALSE));
03781 
03782                 /* all other cases are unknown */
03783                 default: return(DO_NOT_CARE);
03784               }
03785 
03786         case R_REMOVE_FROM_KERNEL:
03787         case R_SHUTDOWN:
03788             switch(target)
03789               {
03790                 case T_NONE:
03791                   /* test owner's mac_role */
03792                   return mac_check_role(owner, SR_administrator);
03793 
03794                 /* all other cases are unknown */
03795                 default: return(DO_NOT_CARE);
03796               }
03797 
03798         case R_RENAME:
03799             switch(target)
03800               {
03801                 case T_FILE:
03802                 case T_DIR:
03803                 case T_FIFO:
03804                 case T_SYMLINK:
03805                   /* and perform auto-write without setting attributes */
03806                   result = auto_write(caller_pid,
03807                                       target,
03808                                       tid,
03809                                       FALSE);
03810                   /* if parent dir might change, convert inherit to explicit level/cat:
03811                      get and set effective value */
03812                   if(   (   (result == GRANTED)
03813                          || (result == DO_NOT_CARE)
03814                         )
03815                      && (   (attr != A_new_dir_dentry_p)
03816                          || (attr_val.new_dir_dentry_p != tid.file.dentry_p->d_parent)
03817                         )
03818                     )
03819                     {
03820                       if (rsbac_get_attr(MAC,
03821                                          target,
03822                                          tid,
03823                                          A_security_level,
03824                                          &i_attr_val1,
03825                                          TRUE))
03826                         { /* failed! */
03827                           rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
03828                           return(NOT_GRANTED);
03829                         }
03830                       if(rsbac_set_attr(MAC,
03831                                         target,
03832                                         tid,
03833                                         A_security_level,
03834                                         i_attr_val1))
03835                         { /* failed! */
03836                           rsbac_ds_set_error("rsbac_adf_request_mac", A_none);
03837                           return(NOT_GRANTED);
03838                         }
03839                       if (rsbac_get_attr(MAC,
03840                                          target,
03841                                          tid,
03842                                          A_mac_categories,
03843                                          &i_attr_val1,
03844                                          TRUE))
03845                         { /* failed! */
03846                           rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
03847                           return(NOT_GRANTED);
03848                         }
03849                       if(rsbac_set_attr(MAC,
03850                                         target,
03851                                         tid,
03852                                         A_mac_categories,
03853                                         i_attr_val1))
03854                         { /* failed! */
03855                           rsbac_ds_set_error("rsbac_adf_request_mac", A_none);
03856                           return(NOT_GRANTED);
03857                         }
03858                     }
03859                   return result;
03860                   break;
03861 #if defined(CONFIG_RSBAC_MAC_UM_PROT)
03862                 case T_USER:
03863                 case T_GROUP:
03864                   /* Security Officer? */
03865                   return mac_check_role(owner, SR_security_officer);
03866 #endif
03867                 /* all other cases are unknown */
03868                 default: return(DO_NOT_CARE);
03869               }
03870 
03871 
03872         case R_SEARCH:
03873             switch(target)
03874               {
03875                 case T_DIR:
03876                 case T_SYMLINK:
03877                   /* and perform auto-read without setting attributes */
03878                   return(auto_read(caller_pid,
03879                                    target,
03880                                    tid,
03881                                    FALSE));
03882                   break;
03883                 /* all other cases are unknown */
03884                 default: return(DO_NOT_CARE);
03885               }
03886 
03887         case R_SEND_SIGNAL:
03888             switch(target)
03889               {
03890                 case T_PROCESS:
03891                   /* and perform auto-write without setting attributes */
03892                   return(auto_write_attr(caller_pid,
03893                                          target,
03894                                          tid,
03895                                          A_current_sec_level,
03896                                          A_mac_curr_categories,
03897                                          FALSE));
03898 
03899                 /* all other cases are unknown */
03900                 default:
03901                   return(DO_NOT_CARE);
03902               }
03903 
03904 /*      case R_SHUTDOWN: see R_REMOVE_FROM_KERNEL */
03905 
03906         case R_SWITCH_LOG:
03907             switch(target)
03908               {
03909                 case T_NONE:
03910                   /* test owner's mac_role */
03911                   return mac_check_role(owner, SR_security_officer);
03912 
03913                 /* all other cases are unknown */
03914                 default: return(DO_NOT_CARE);
03915               }
03916 
03917         case R_SWITCH_MODULE:
03918             switch(target)
03919               {
03920                 case T_NONE:
03921                   /* we need the switch_target */
03922                   if(attr != A_switch_target)
03923                     return(UNDEFINED);
03924                   /* do not care for other modules */
03925                   if(   (attr_val.switch_target != MAC)
03926                      #ifdef CONFIG_RSBAC_MAC_AUTH_PROT
03927                      && (attr_val.switch_target != AUTH)
03928                      #endif
03929                      #ifdef CONFIG_RSBAC_SOFTMODE
03930                      && (attr_val.switch_target != SOFTMODE)
03931                      #endif
03932                      #ifdef CONFIG_RSBAC_FREEZE
03933                      && (attr_val.switch_target != FREEZE)
03934                      #endif
03935                     )
03936                     return(DO_NOT_CARE);
03937                   /* test owner's mac_role */
03938                   return mac_check_role(owner, SR_security_officer);
03939 
03940                 /* all other cases are unknown */
03941                 default: return(DO_NOT_CARE);
03942               }
03943 
03944         /* notify only, handled by adf-dispatcher */
03945         case R_TERMINATE:
03946             if (target == T_PROCESS)
03947               return(DO_NOT_CARE);
03948             else
03949               return(DO_NOT_CARE);
03950 
03951         case R_TRACE:
03952             switch(target)
03953               {
03954                 case T_PROCESS:
03955                   /* and perform auto-read-write without setting attributes */
03956                   return(auto_read_write_attr(caller_pid,
03957                                               target,
03958                                               tid,
03959                                               A_current_sec_level,
03960                                               A_mac_curr_categories,
03961                                               FALSE));
03962 
03963                 /* all other cases are unknown */
03964                 default:
03965                   return(DO_NOT_CARE);
03966               }
03967 
03968         case R_TRUNCATE:
03969             switch(target)
03970               {
03971                 case T_FILE:
03972                   /* and perform auto-write without setting attributes */
03973                   return(auto_write(caller_pid,
03974                                     target,
03975                                     tid,
03976                                     FALSE));
03977                   break;
03978                 /* all other cases are unknown */
03979                 default: return(DO_NOT_CARE);
03980               }
03981 
03982         case R_UMOUNT:
03983             switch(target)
03984               {
03985                 case T_FILE:
03986                 case T_DIR:
03987                 case T_DEV:
03988 #ifdef CONFIG_RSBAC_MAC_LIGHT
03989                   return(GRANTED);
03990 #else
03991                   return mac_check_role(owner, SR_administrator);
03992 #endif
03993                 /* all other cases are unknown */
03994                 default: return(DO_NOT_CARE);
03995               }
03996 
03997         case R_WRITE:
03998             switch(target)
03999               {
04000                 case T_DIR: 
04001 #ifdef CONFIG_RSBAC_RW
04002                 case T_FILE:
04003                 case T_FIFO:
04004 #endif
04005                   /* Mode of created item is ignored! */
04006                   /* and perform auto-write without setting attributes */
04007                   return(auto_write(caller_pid,
04008                                     target,
04009                                     tid,
04010                                     FALSE));
04011                   
04012 
04013 #ifdef CONFIG_RSBAC_RW
04014                 case T_DEV:
04015                   /* Only check for devices with mac_check set */
04016                   if (rsbac_get_attr(MAC,
04017                                      T_DEV,
04018                                      tid,
04019                                      A_mac_check,
04020                                      &i_attr_val1,
04021                                      FALSE))
04022                     {
04023                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
04024                       return(NOT_GRANTED);
04025                     }
04026                   if(!i_attr_val1.mac_check)
04027                     return(DO_NOT_CARE);
04028                   /* and perform auto-write without setting attributes */
04029                   return(auto_write(caller_pid,
04030                                     target,
04031                                     tid,
04032                                     FALSE));
04033                   break;
04034 #endif
04035 
04036 #if defined(CONFIG_RSBAC_MAC_NET_OBJ_PROT)
04037                 case T_NETTEMP:
04038                   return mac_check_role(owner, SR_security_officer);
04039 
04040                 case T_NETOBJ:
04041                   /* test write access to target: get its sec_level */
04042                   if (rsbac_get_attr(MAC,
04043                                      target,
04044                                      tid,
04045                                      A_remote_sec_level,
04046                                      &i_attr_val1,
04047                                      TRUE))
04048                     {
04049                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
04050                       return(NOT_GRANTED);
04051                     }
04052                   if (rsbac_get_attr(MAC,
04053                                      target,
04054                                      tid,
04055                                      A_remote_mac_categories,
04056                                      &i_attr_val2,
04057                                      TRUE))
04058                     {
04059                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
04060                       return(NOT_GRANTED);
04061                     }
04062                   /* and perform auto-write without setting attributes */
04063                   return(auto_write_attr(caller_pid,
04064                                          target,
04065                                          tid,
04066                                          A_remote_sec_level,
04067                                          A_remote_mac_categories,
04068                                          FALSE));
04069 #endif
04070 
04071 #if defined(CONFIG_RSBAC_MAC_UM_PROT)
04072                 case T_USER:
04073                 case T_GROUP:
04074                   /* Security Officer? */
04075                   return mac_check_role(owner, SR_security_officer);
04076 #endif
04077                 /* all other cases are unknown */
04078                 default: return(DO_NOT_CARE);
04079               }
04080 
04081         case R_WRITE_OPEN:
04082             switch(target)
04083               {
04084                 case T_FILE:
04085                 case T_FIFO:
04086                 case T_IPC:
04087                   /* and perform auto-write without setting attributes */
04088                   return(auto_write(caller_pid,
04089                                     target,
04090                                     tid,
04091                                     FALSE));
04092                   break;
04093                 case T_DEV:
04094                   /* Only check for devices with mac_check set */
04095                   if (rsbac_get_attr(MAC,
04096                                      T_DEV,
04097                                      tid,
04098                                      A_mac_check,
04099                                      &i_attr_val1,
04100                                      FALSE))
04101                     {
04102                       rsbac_ds_get_error("rsbac_adf_request_mac", A_none);
04103                       return(NOT_GRANTED);
04104                     }
04105                   if(!i_attr_val1.mac_check)
04106                     return(DO_NOT_CARE);
04107                   /* and perform auto-write without setting attributes */
04108                   return(auto_write(caller_pid,
04109                                     target,
04110                                     tid,
04111                                     FALSE));
04112                   break;
04113                 /* all other cases are unknown */
04114                 default: return(DO_NOT_CARE);
04115               }
04116 
04117 #if defined(CONFIG_RSBAC_MAC_NET_OBJ_PROT)
04118         case R_BIND:
04119         case R_LISTEN:
04120             switch(target)
04121               {
04122                 case T_NETOBJ:
04123                   /* and perform auto-read-write without setting attributes */
04124                   return(auto_read_write_attr(caller_pid,
04125                                               target,
04126                                               tid,
04127                                               A_local_sec_level,
04128                                               A_local_mac_categories,
04129                                               FALSE));
04130 
04131                 /* all other cases are unknown */
04132                 default: return(DO_NOT_CARE);
04133               }
04134 
04135         case R_ACCEPT:
04136         case R_CONNECT:
04137         case R_SEND:
04138         case R_RECEIVE:
04139             switch(target)
04140               {
04141                 case T_NETOBJ:
04142                   /* and perform auto-read-write without setting attributes */
04143                   return(auto_read_write_attr(caller_pid,
04144                                               target,
04145                                               tid,
04146                                               A_remote_sec_level,
04147                                               A_remote_mac_categories,
04148                                               FALSE));
04149 
04150                 /* all other cases are unknown */
04151                 default: return(DO_NOT_CARE);
04152               }
04153 
04154 #endif /* NET_OBJ_PROT */
04155 
04156 /*********************/
04157         default: return DO_NOT_CARE;
04158       }
04159 
04160     return(result);
04161   } /* end of rsbac_adf_request_mac() */
04162 
04163 
04164 /*****************************************************************************/
04165 /* If the request returned granted and the operation is performed,           */
04166 /* the following function can be called by the AEF to get all aci set        */
04167 /* correctly. For write accesses that are performed fully within the kernel, */
04168 /* this is usually not done to prevent extra calls, including R_CLOSE for    */
04169 /* cleaning up. Because of this, the write boundary is not adjusted - there  */
04170 /* is no user-level writing anyway...                                        */
04171 /* The second instance of target specification is the new target, if one has */
04172 /* been created, otherwise its values are ignored.                           */
04173 /* On success, 0 is returned, and an error from rsbac/error.h otherwise.     */
04174 
04175 int  rsbac_adf_set_attr_mac(
04176                       enum  rsbac_adf_request_t     request,
04177                             rsbac_pid_t             caller_pid,
04178                       enum  rsbac_target_t          target,
04179                       union rsbac_target_id_t       tid,
04180                       enum  rsbac_target_t          new_target,
04181                       union rsbac_target_id_t       new_tid,
04182                       enum  rsbac_attribute_t       attr,
04183                       union rsbac_attribute_value_t attr_val,
04184                             rsbac_uid_t             owner)
04185   {
04186     enum  rsbac_adf_req_ret_t result = DO_NOT_CARE;
04187     union rsbac_target_id_t       i_tid;
04188     union rsbac_attribute_value_t i_attr_val1;
04189     union rsbac_attribute_value_t i_attr_val2;
04190     union rsbac_attribute_value_t i_attr_val3;
04191     union rsbac_attribute_value_t i_attr_val4;
04192     union rsbac_attribute_value_t i_attr_val5;
04193     union rsbac_attribute_value_t i_attr_val6;
04194     union rsbac_attribute_value_t i_attr_val7;
04195     union rsbac_attribute_value_t i_attr_val8;
04196     union rsbac_attribute_value_t i_attr_val9;
04197     rsbac_boolean_t inherit;
04198 
04199     switch (request)
04200       {
04201         case R_APPEND_OPEN:
04202             switch(target)
04203               {
04204                 case T_FILE:
04205                 case T_FIFO:
04206                 case T_IPC:
04207                   /* test write access to target: get its sec_level */
04208                   if(   (target == T_FILE)
04209                      || (target == T_FIFO)
04210                     )
04211                     inherit = TRUE;
04212                   else
04213                     inherit = FALSE;
04214                   if (rsbac_get_attr(MAC,
04215                                      target,
04216                                      tid,
04217                                      A_security_level,
04218                                      &i_attr_val1,
04219                                      inherit))
04220                     {
04221                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04222                       return(-RSBAC_EREADFAILED);
04223                     }
04224                   if (rsbac_get_attr(MAC,
04225                                      target,
04226                                      tid,
04227                                      A_mac_categories,
04228                                      &i_attr_val2,
04229                                      inherit))
04230                     {
04231                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04232                       return(-RSBAC_EREADFAILED);
04233                     }
04234                   /* and perform auto-write with setting attributes */
04235                   result = auto_write(caller_pid,
04236                                       target,
04237                                       tid,
04238                                       TRUE);
04239                   if ((result == GRANTED) || (result == DO_NOT_CARE))
04240                     return(0);
04241                   else
04242                     return(-RSBAC_EDECISIONMISMATCH);
04243                   break;
04244                 case T_DEV:
04245                   /* Only check for devices with mac_check set */
04246                   if (rsbac_get_attr(MAC,
04247                                      T_DEV,
04248                                      tid,
04249                                      A_mac_check,
04250                                      &i_attr_val1,
04251                                      FALSE))
04252                     {
04253                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04254                       return(-RSBAC_EREADFAILED);
04255                     }
04256                   if(!i_attr_val1.mac_check)
04257                     return(0);
04258                   /* and perform auto-write with setting attributes */
04259                   result = auto_write(caller_pid,
04260                                       target,
04261                                       tid,
04262                                       TRUE);
04263                   if ((result == GRANTED) || (result == DO_NOT_CARE))
04264                     return(0);
04265                   else
04266                     return(-RSBAC_EDECISIONMISMATCH);
04267                   break;
04268                 /* all other cases are unknown */
04269                 default: return(0);
04270               }
04271 
04272         case R_CHANGE_OWNER:
04273             switch(target)
04274               {
04275                 /*  Changing process owner affects access decisions, */
04276                 /*  so attributes have to be adjusted.               */
04277                 case T_PROCESS:
04278                   /* For target process there MUST be a new owner specified */
04279                   if (attr != A_owner)
04280                     return(-RSBAC_EINVALIDATTR);
04281 
04282                   /* Get owner-sec-level and mac_categories for new owner */
04283                   i_tid.user = attr_val.owner;
04284                   if (rsbac_get_attr(MAC,
04285                                      T_USER,
04286                                      i_tid,
04287                                      A_security_level,
04288                                      &i_attr_val2,
04289                                      TRUE))
04290                     {
04291                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04292                       return(-RSBAC_EREADFAILED);
04293                     }
04294                   if (rsbac_get_attr(MAC,
04295                                      T_USER,
04296                                      i_tid,
04297                                      A_mac_categories,
04298                                      &i_attr_val3,
04299                                      TRUE))
04300                     {
04301                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04302                       return(-RSBAC_EREADFAILED);
04303                     }
04304                   /* set owner-sec-level and mac_categories for process to new values */
04305                   if (rsbac_set_attr(MAC,
04306                                      T_PROCESS,
04307                                      tid,
04308                                      A_security_level,
04309                                      i_attr_val2))
04310                     {
04311                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04312                       return(-RSBAC_EWRITEFAILED);
04313                     }
04314                   if (rsbac_set_attr(MAC,
04315                                      T_PROCESS,
04316                                      tid,
04317                                      A_mac_categories,
04318                                      i_attr_val3))
04319                     {
04320                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04321                       return(-RSBAC_EWRITEFAILED);
04322                     }
04323                   /* Get min_write_open and min_write_categories of process */
04324                   if (rsbac_get_attr(MAC,
04325                                      T_PROCESS,
04326                                      tid,
04327                                      A_min_write_open,
04328                                      &i_attr_val4,
04329                                      TRUE))
04330                     {
04331                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04332                       return(-RSBAC_EREADFAILED);
04333                     }
04334                   if (rsbac_get_attr(MAC,
04335                                      T_PROCESS,
04336                                      tid,
04337                                      A_min_write_categories,
04338                                      &i_attr_val5,
04339                                      TRUE))
04340                     {
04341                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04342                       return(-RSBAC_EREADFAILED);
04343                     }
04344                   /* adjust min_write_open and min_write_categories, if too high */
04345                   if(i_attr_val2.security_level < i_attr_val4.min_write_open)
04346                     {
04347                       i_attr_val4.min_write_open = i_attr_val2.security_level;
04348                       if(rsbac_set_attr(MAC,
04349                                         T_PROCESS,
04350                                         tid,
04351                                         A_min_write_open,
04352                                         i_attr_val4))
04353                         {
04354                           rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04355                           return(-RSBAC_EWRITEFAILED);
04356                         }
04357                     }
04358                   /* does process have categories in min_write that the new owner has not? */
04359                   /* If yes, throw them out. */
04360                   if ((i_attr_val3.mac_categories & i_attr_val5.mac_categories)
04361                        != i_attr_val5.mac_categories)
04362                     {
04363                       i_attr_val5.mac_categories &= i_attr_val3.mac_categories;
04364                       if(rsbac_set_attr(MAC,
04365                                         T_PROCESS,
04366                                         tid,
04367                                         A_min_write_categories,
04368                                         i_attr_val5))
04369                         {
04370                           rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04371                           return(-RSBAC_EWRITEFAILED);
04372                         }
04373                     }
04374                   /* Get owner-initial-sec-level and mac_initial_categories for new owner */
04375                   /* These values will be adjusted by max_read / min_write and then used as */
04376                   /* new current level/categories. */
04377                   i_tid.user = attr_val.owner;
04378                   if (rsbac_get_attr(MAC,
04379                                      T_USER,
04380                                      i_tid,
04381                                      A_initial_security_level,
04382                                      &i_attr_val6,
04383                                      TRUE))
04384                     {
04385                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04386                       return(-RSBAC_EREADFAILED);
04387                     }
04388                   if (rsbac_set_attr(MAC,
04389                                      T_PROCESS,
04390                                      tid,
04391                                      A_initial_security_level,
04392                                      i_attr_val6))
04393                     {
04394                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04395                       return(-RSBAC_EWRITEFAILED);
04396                     }
04397 #if 0
04398                   /* restrict current_level to be a maximum of min_write */
04399                   if(i_attr_val6.security_level > i_attr_val4.min_write_open)
04400                     i_attr_val6.security_level = i_attr_val4.min_write_open;
04401 #endif
04402                   if (rsbac_get_attr(MAC,
04403                                      T_USER,
04404                                      i_tid,
04405                                      A_mac_initial_categories,
04406                                      &i_attr_val7,
04407                                      TRUE))
04408                     {
04409                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04410                       return(-RSBAC_EREADFAILED);
04411                     }
04412                   if (rsbac_set_attr(MAC,
04413                                      T_PROCESS,
04414                                      tid,
04415                                      A_mac_initial_categories,
04416                                      i_attr_val7))
04417                     {
04418                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04419                       return(-RSBAC_EWRITEFAILED);
04420                     }
04421 #if 0
04422                   /* restrict current_categories to be a maximum of min_write */
04423                   if((i_attr_val7.mac_categories & i_attr_val5.mac_categories) != i_attr_val7.mac_categories)
04424                     i_attr_val7.mac_categories &= i_attr_val5.mac_categories;
04425 #endif
04426                   /* Get owner-min-sec-level and mac_min_categories for new owner */
04427                   i_tid.user = attr_val.owner;
04428                   if (rsbac_get_attr(MAC,
04429                                      T_USER,
04430                                      i_tid,
04431                                      A_min_security_level,
04432                                      &i_attr_val8,
04433                                      TRUE))
04434                     {
04435                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04436                       return(-RSBAC_EREADFAILED);
04437                     }
04438                   if (rsbac_get_attr(MAC,
04439                                      T_USER,
04440                                      i_tid,
04441                                      A_mac_min_categories,
04442                                      &i_attr_val9,
04443                                      TRUE))
04444                     {
04445                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04446                       return(-RSBAC_EREADFAILED);
04447                     }
04448                   /* set owner-sec-level and mac_categories for process to new values */
04449                   /* owner is set by main dispatcher! */
04450                   if (rsbac_set_attr(MAC,
04451                                      T_PROCESS,
04452                                      tid,
04453                                      A_min_security_level,
04454                                      i_attr_val8))
04455                     {
04456                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04457                       return(-RSBAC_EWRITEFAILED);
04458                     }
04459                   if (rsbac_set_attr(MAC,
04460                                      T_PROCESS,
04461                                      tid,
04462                                      A_mac_min_categories,
04463                                      i_attr_val9))
04464                     {
04465                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04466                       return(-RSBAC_EWRITEFAILED);
04467                     }
04468                   /* Get max_read_open and max_read_categories of process */
04469                   if (rsbac_get_attr(MAC,
04470                                      T_PROCESS,
04471                                      tid,
04472                                      A_max_read_open,
04473                                      &i_attr_val4,
04474                                      TRUE))
04475                     {
04476                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04477                       return(-RSBAC_EREADFAILED);
04478                     }
04479                   if (rsbac_get_attr(MAC,
04480                                      T_PROCESS,
04481                                      tid,
04482                                      A_max_read_categories,
04483                                      &i_attr_val5,
04484                                      TRUE))
04485                     {
04486                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04487                       return(-RSBAC_EREADFAILED);
04488                     }
04489                   /* adjust max_read_open and max_read_categories, if too low */
04490                   if (i_attr_val8.security_level > i_attr_val4.max_read_open)
04491                     {
04492                       i_attr_val4.max_read_open = i_attr_val8.security_level;
04493                       if(rsbac_set_attr(MAC,
04494                                         T_PROCESS,
04495                                         tid,
04496                                         A_max_read_open,
04497                                         i_attr_val4))
04498                         {
04499                           rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04500                           return(-RSBAC_EWRITEFAILED);
04501                         }
04502                     }
04503 #if 0
04504                   /* adjust current sec level to a minimum of max_read */
04505                   if(i_attr_val6.security_level < i_attr_val4.max_read_open)
04506                     i_attr_val6.security_level = i_attr_val4.max_read_open;
04507 #endif
04508                   /* but never set it over new max_level or under new min_level */
04509                   if(i_attr_val6.security_level > i_attr_val2.security_level)
04510                     i_attr_val6.security_level = i_attr_val2.security_level;
04511                   else
04512                     if(i_attr_val6.security_level < i_attr_val8.security_level)
04513                       i_attr_val6.security_level = i_attr_val8.security_level;
04514                   if(rsbac_set_attr(MAC,
04515                                     T_PROCESS,
04516                                     tid,
04517                                     A_current_sec_level,
04518                                     i_attr_val6))
04519                     {
04520                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04521                       return(-RSBAC_EWRITEFAILED);
04522                     }
04523 
04524                   /* does new owner have categories in min_categories that the process max_read 
04525                      has not? */
04526                   /* If yes, add them. */
04527                   if ((i_attr_val9.mac_categories & i_attr_val5.mac_categories)
04528                        != i_attr_val9.mac_categories)
04529                     {
04530                       i_attr_val5.mac_categories |= i_attr_val9.mac_categories;
04531                       if(rsbac_set_attr(MAC,
04532                                         T_PROCESS,
04533                                         tid,
04534                                         A_max_read_categories,
04535                                         i_attr_val5))
04536                         {
04537                           rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04538                           return(-RSBAC_EWRITEFAILED);
04539                         }
04540                     }
04541 #if 0
04542                   /* adjust current categories to include all from max_read (from initial) */
04543                   if((i_attr_val7.mac_categories & i_attr_val5.mac_categories) != i_attr_val5.mac_categories)
04544                     i_attr_val7.mac_categories |= i_attr_val5.mac_categories;
04545 #endif
04546                   /* but never set it over new max_cats or under new min_cats */
04547                   if((i_attr_val7.mac_categories & i_attr_val3.mac_categories) != i_attr_val7.mac_categories)
04548                     i_attr_val7.mac_categories &= i_attr_val3.mac_categories;
04549                   else
04550                     if((i_attr_val7.mac_categories & i_attr_val9.mac_categories) != i_attr_val9.mac_categories)
04551                       i_attr_val7.mac_categories |= i_attr_val9.mac_categories;
04552                   if(rsbac_set_attr(MAC,
04553                                     T_PROCESS,
04554                                     tid,
04555                                     A_mac_curr_categories,
04556                                     i_attr_val7))
04557                     {
04558                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04559                       return(-RSBAC_EWRITEFAILED);
04560                     }
04561 
04562                   /* Get mac_user_flags from user */
04563                   i_tid.user = attr_val.owner;
04564                   if (rsbac_get_attr(MAC,
04565                                      T_USER,
04566                                      i_tid,
04567                                      A_mac_user_flags,
04568                                      &i_attr_val3,
04569                                      TRUE))
04570                     {
04571                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04572                       return(-RSBAC_EREADFAILED);
04573                     }
04574                   i_attr_val1.mac_process_flags = i_attr_val3.mac_user_flags;
04575                   /* adjust flags - first get old process flags*/
04576                   if (rsbac_get_attr(MAC,
04577                                      T_PROCESS,
04578                                      tid,
04579                                      A_mac_process_flags,
04580                                      &i_attr_val2,
04581                                      TRUE))
04582                     {
04583                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04584                       return(-RSBAC_EREADFAILED);
04585                     }
04586                   if(   (i_attr_val2.mac_process_flags & MAC_program_auto)
04587                      && (i_attr_val3.mac_user_flags & MAC_allow_auto)
04588                     )
04589                     i_attr_val1.mac_process_flags |= MAC_auto;
04590 
04591                   i_attr_val1.mac_process_flags &= RSBAC_MAC_P_FLAGS;
04592 
04593                   if(!(i_attr_val1.mac_process_flags & MAC_trusted))
04594                     {
04595                       if(rsbac_mac_p_truset_member(caller_pid, attr_val.owner))
04596                         i_attr_val1.mac_process_flags |= MAC_trusted;
04597                     }
04598                   /* Set mac_process_flags on process */
04599                   if (rsbac_set_attr(MAC,
04600                                      T_PROCESS,
04601                                      tid,
04602                                      A_mac_process_flags,
04603                                      i_attr_val1))
04604                     {
04605                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04606                       return(-RSBAC_EWRITEFAILED);
04607                     }
04608                   /* OK, we are ready */
04609                   return(0);
04610 
04611                 /* We do not care about other cases here */
04612                 default:
04613                   return(0);
04614               }
04615 
04616         case R_CLONE:
04617             if (target == T_PROCESS)
04618               {
04619                   /* Get owner from first process (provided on call) */
04620                   i_attr_val1.owner = owner;
04621                   /* Get owner-sec-level from first process */
04622                   if (rsbac_get_attr(MAC,
04623                                      T_PROCESS,
04624                                      tid,
04625                                      A_security_level,
04626                                      &i_attr_val2,
04627                                      FALSE))
04628                     {
04629                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04630                       return(-RSBAC_EREADFAILED);
04631                     }
04632                   /* Get current-sec-level from first process... */
04633                   if (rsbac_get_attr(MAC,
04634                                      T_PROCESS,
04635                                      tid,
04636                                      A_current_sec_level,
04637                                      &i_attr_val3,
04638                                      FALSE))
04639                     {
04640                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04641                       return(-RSBAC_EREADFAILED);
04642                     }
04643                   /* Get min_write_open from first process */
04644                   if (rsbac_get_attr(MAC,
04645                                      T_PROCESS,
04646                                      tid,
04647                                      A_min_write_open,
04648                                      &i_attr_val4,
04649                                      FALSE))
04650                     {
04651                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04652                       return(-RSBAC_EREADFAILED);
04653                     }
04654                   /* Get max_read_open from first process */
04655                   if (rsbac_get_attr(MAC,
04656                                      T_PROCESS,
04657                                      tid,
04658                                      A_max_read_open,
04659                                      &i_attr_val5,
04660                                      FALSE))
04661                     {
04662                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04663                       return(-RSBAC_EREADFAILED);
04664                     }
04665                   /* Get mac_process_flags from first process */
04666                   if (rsbac_get_attr(MAC,
04667                                      T_PROCESS,
04668                                      tid,
04669                                      A_mac_process_flags,
04670                                      &i_attr_val7,
04671                                      FALSE))
04672                     {
04673                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04674                       return(-RSBAC_EREADFAILED);
04675                     }
04676 
04677 #ifdef CONFIG_RSBAC_USE_RSBAC_OWNER
04678                   /* Set owner for new process */
04679                   if (rsbac_set_attr(MAC,
04680                                      T_PROCESS,
04681                                      new_tid,
04682                                      A_owner,
04683                                      i_attr_val1))
04684                     {
04685                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04686                       return(-RSBAC_EWRITEFAILED);
04687                     }
04688 #endif
04689                   /* Set owner_sec_level for new process */
04690                   if (rsbac_set_attr(MAC,
04691                                      T_PROCESS,
04692                                      new_tid,
04693                                      A_security_level,
04694                                      i_attr_val2))
04695                     {
04696                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04697                       return(-RSBAC_EWRITEFAILED);
04698                     }
04699                   /* Set current_sec_level for new process */
04700                   if (rsbac_set_attr(MAC,
04701                                      T_PROCESS,
04702                                      new_tid,
04703                                      A_current_sec_level,
04704                                      i_attr_val3))
04705                     {
04706                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04707                       return(-RSBAC_EWRITEFAILED);
04708                     }
04709                   /* Set min_write_open for new process */
04710                   if (rsbac_set_attr(MAC,
04711                                      T_PROCESS,
04712                                      new_tid,
04713                                      A_min_write_open,
04714                                      i_attr_val4))
04715                     {
04716                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04717                       return(-RSBAC_EWRITEFAILED);
04718                     }
04719                   /* Set max_read_open for new process */
04720                   if (rsbac_set_attr(MAC,
04721                                      T_PROCESS,
04722                                      new_tid,
04723                                      A_max_read_open,
04724                                      i_attr_val5))
04725                     {
04726                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04727                       return(-RSBAC_EWRITEFAILED);
04728                     }
04729                   /* Set mac_process_flags for new process */
04730                   if (rsbac_set_attr(MAC,
04731                                      T_PROCESS,
04732                                      new_tid,
04733                                      A_mac_process_flags,
04734                                      i_attr_val7))
04735                     {
04736                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04737                       return(-RSBAC_EWRITEFAILED);
04738                     }
04739 
04740                   /* Get mac_categories from first process */
04741                   if (rsbac_get_attr(MAC,
04742                                      T_PROCESS,
04743                                      tid,
04744                                      A_mac_categories,
04745                                      &i_attr_val2,
04746                                      FALSE))
04747                     {
04748                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04749                       return(-RSBAC_EREADFAILED);
04750                     }
04751                   /* Get mac_curr_categories from first process... */
04752                   if (rsbac_get_attr(MAC,
04753                                      T_PROCESS,
04754                                      tid,
04755                                      A_mac_curr_categories,
04756                                      &i_attr_val3,
04757                                      FALSE))
04758                     {
04759                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04760                       return(-RSBAC_EREADFAILED);
04761                     }
04762                   /* Get min_write_categories from first process */
04763                   if (rsbac_get_attr(MAC,
04764                                      T_PROCESS,
04765                                      tid,
04766                                      A_min_write_categories,
04767                                      &i_attr_val4,
04768                                      FALSE))
04769                     {
04770                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04771                       return(-RSBAC_EREADFAILED);
04772                     }
04773                   /* Get max_read_categories from first process */
04774                   if (rsbac_get_attr(MAC,
04775                                      T_PROCESS,
04776                                      tid,
04777                                      A_max_read_categories,
04778                                      &i_attr_val5,
04779                                      FALSE))
04780                     {
04781                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04782                       return(-RSBAC_EREADFAILED);
04783                     }
04784                   /* Get initial_sec_level from first process */
04785                   if (rsbac_get_attr(MAC,
04786                                      T_PROCESS,
04787                                      tid,
04788                                      A_initial_security_level,
04789                                      &i_attr_val6,
04790                                      FALSE))
04791                     {
04792                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04793                       return(-RSBAC_EREADFAILED);
04794                     }
04795                   /* Get initial_categories from first process */
04796                   if (rsbac_get_attr(MAC,
04797                                      T_PROCESS,
04798                                      tid,
04799                                      A_mac_initial_categories,
04800                                      &i_attr_val7,
04801                                      FALSE))
04802                     {
04803                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04804                       return(-RSBAC_EREADFAILED);
04805                     }
04806                   /* Set mac_categories for new process */
04807                   if (rsbac_set_attr(MAC,
04808                                      T_PROCESS,
04809                                      new_tid,
04810                                      A_mac_categories,
04811                                      i_attr_val2))
04812                     {
04813                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04814                       return(-RSBAC_EWRITEFAILED);
04815                     }
04816                   /* Set mac_curr_categories for new process */
04817                   if (rsbac_set_attr(MAC,
04818                                      T_PROCESS,
04819                                      new_tid,
04820                                      A_mac_curr_categories,
04821                                      i_attr_val3))
04822                     {
04823                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04824                       return(-RSBAC_EWRITEFAILED);
04825                     }
04826                   /* Set min_write_categories for new process */
04827                   if (rsbac_set_attr(MAC,
04828                                      T_PROCESS,
04829                                      new_tid,
04830                                      A_min_write_categories,
04831                                      i_attr_val4))
04832                     {
04833                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04834                       return(-RSBAC_EWRITEFAILED);
04835                     }
04836                   /* Set max_read_categories for new process */
04837                   if (rsbac_set_attr(MAC,
04838                                      T_PROCESS,
04839                                      new_tid,
04840                                      A_max_read_categories,
04841                                      i_attr_val5))
04842                     {
04843                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04844                       return(-RSBAC_EWRITEFAILED);
04845                     }
04846                   /* Set initial_security_level for new process */
04847                   if (rsbac_set_attr(MAC,
04848                                      T_PROCESS,
04849                                      new_tid,
04850                                      A_initial_security_level,
04851                                      i_attr_val6))
04852                     {
04853                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04854                       return(-RSBAC_EWRITEFAILED);
04855                     }
04856                   /* Set initial_categories for new process */
04857                   if (rsbac_set_attr(MAC,
04858                                      T_PROCESS,
04859                                      new_tid,
04860                                      A_mac_initial_categories,
04861                                      i_attr_val7))
04862                     {
04863                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04864                       return(-RSBAC_EWRITEFAILED);
04865                     }
04866                   /* Get owner-min_sec-level/cat from first process */
04867                   if (rsbac_get_attr(MAC,
04868                                      T_PROCESS,
04869                                      tid,
04870                                      A_min_security_level,
04871                                      &i_attr_val2,
04872                                      FALSE))
04873                     {
04874                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04875                       return(-RSBAC_EREADFAILED);
04876                     }
04877                   if (rsbac_get_attr(MAC,
04878                                      T_PROCESS,
04879                                      tid,
04880                                      A_mac_min_categories,
04881                                      &i_attr_val3,
04882                                      FALSE))
04883                     {
04884                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04885                       return(-RSBAC_EREADFAILED);
04886                     }
04887                   /* Set min_security_level for new process */
04888                   if (rsbac_set_attr(MAC,
04889                                      T_PROCESS,
04890                                      new_tid,
04891                                      A_min_security_level,
04892                                      i_attr_val2))
04893                     {
04894                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04895                       return(-RSBAC_EWRITEFAILED);
04896                     }
04897                   /* Set min_categories for new process */
04898                   if (rsbac_set_attr(MAC,
04899                                      T_PROCESS,
04900                                      new_tid,
04901                                      A_mac_min_categories,
04902                                      i_attr_val3))
04903                     {
04904                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04905                       return(-RSBAC_EWRITEFAILED);
04906                     }
04907                   if (rsbac_mac_copy_pp_truset(tid.process, new_tid.process))
04908                     {
04909 #ifdef CONFIG_RSBAC_RMSG
04910                       rsbac_printk(KERN_WARNING
04911                              "rsbac_adf_set_attr_mac(): rsbac_mac_copy_pp_truset() returned error!\n");
04912 #endif
04913 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
04914                       if (!rsbac_nosyslog)
04915 #endif
04916                       printk(KERN_WARNING
04917                              "rsbac_adf_set_attr_mac(): rsbac_mac_copy_pp_truset() returned error!\n");
04918                       return(-RSBAC_EWRITEFAILED);
04919                     }
04920                 return(0);
04921               }
04922             else
04923               return(0);
04924 
04925         case R_CREATE:
04926             switch(target)
04927               {
04928                 /* Creating dir or (pseudo) file IN target dir! */
04929                 case T_DIR:
04930                   /* Mode of created item is ignored! */
04931                   /* and perform auto-write without(!) setting of attributes - no need */
04932                   /* -> decision consistency check only */
04933                   /* only check, if not MAC_LIGHT */
04934 #ifndef CONFIG_RSBAC_MAC_LIGHT
04935                   result = auto_write(caller_pid,
04936                                       target,
04937                                       tid,
04938                                       FALSE);
04939                   if ((result != GRANTED) && (result != DO_NOT_CARE))
04940                     return(-RSBAC_EDECISIONMISMATCH);
04941 #endif
04942                   /* test write access to target: get its sec_level */
04943                   if (rsbac_get_attr(MAC,
04944                                      T_DIR,
04945                                      tid,
04946                                      A_security_level,
04947                                      &i_attr_val1,
04948                                      TRUE))
04949                     {
04950                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04951                       return(-RSBAC_EREADFAILED);
04952                     }
04953                   if (rsbac_get_attr(MAC,
04954                                      T_DIR,
04955                                      tid,
04956                                      A_mac_categories,
04957                                      &i_attr_val2,
04958                                      TRUE))
04959                     {
04960                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04961                       return(-RSBAC_EREADFAILED);
04962                     }
04963                   /* Get current_sec_level from process (initialized to owner_sec_level)... */
04964                   i_tid.process = caller_pid;
04965                   if (rsbac_get_attr(MAC,
04966                                      T_PROCESS,
04967                                      i_tid,
04968                                      A_current_sec_level,
04969                                      &i_attr_val3,
04970                                      FALSE))
04971                     {
04972                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04973                       return(-RSBAC_EREADFAILED);
04974                     }
04975 #ifdef CONFIG_RSBAC_MAC_SMART_INHERIT
04976                   /* Only set, if different than inherited value */
04977                   if(i_attr_val3.security_level != i_attr_val1.security_level)
04978 #endif
04979                     /* Set security-level for new item */
04980                     if (rsbac_set_attr(MAC,
04981                                        new_target,
04982                                        new_tid,
04983                                        A_security_level,
04984                                        i_attr_val3))
04985                       {
04986                         rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
04987                         return(-RSBAC_EWRITEFAILED);
04988                       }
04989                   /* Get current_categories from process (initialized to owner_categories)... */
04990                   if (rsbac_get_attr(MAC,
04991                                      T_PROCESS,
04992                                      i_tid,
04993                                      A_mac_curr_categories,
04994                                      &i_attr_val3,
04995                                      FALSE))
04996                     {
04997                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
04998                       return(-RSBAC_EREADFAILED);
04999                     }
05000 #ifdef CONFIG_RSBAC_MAC_SMART_INHERIT
05001                   /* Only set, if different than inherited value */
05002                   if(i_attr_val3.mac_categories != i_attr_val2.mac_categories)
05003 #endif
05004                     /* Set mac_categories for new item */
05005                     if (rsbac_set_attr(MAC,
05006                                        new_target,
05007                                        new_tid,
05008                                        A_mac_categories,
05009                                        i_attr_val3))
05010                       {
05011                         rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05012                         return(-RSBAC_EWRITEFAILED);
05013                       }
05014                   return(0);
05015                   break;
05016 
05017                 case T_IPC: 
05018                   i_tid.process = caller_pid;
05019                   /* Get current-sec-level from process... */
05020                   if (rsbac_get_attr(MAC,
05021                                      T_PROCESS,
05022                                      i_tid,
05023                                      A_current_sec_level,
05024                                      &i_attr_val1,
05025                                      FALSE))
05026                     {
05027                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05028                       return(-RSBAC_EREADFAILED);
05029                     }
05030                   /* Set security-level for this ipc item */
05031                   if (rsbac_set_attr(MAC,
05032                                      T_IPC,
05033                                      tid,
05034                                      A_security_level,
05035                                      i_attr_val1))
05036                     {
05037                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05038                       return(-RSBAC_EWRITEFAILED);
05039                     }
05040                   /* Get mac_curr_categories from process... */
05041                   if (rsbac_get_attr(MAC,
05042                                      T_PROCESS,
05043                                      i_tid,
05044                                      A_mac_curr_categories,
05045                                      &i_attr_val1,
05046                                      FALSE))
05047                     {
05048                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05049                       return(-RSBAC_EREADFAILED);
05050                     }
05051                   /* Set curr_categories for new item */
05052                   if (rsbac_set_attr(MAC,
05053                                      T_IPC,
05054                                      tid,
05055                                      A_mac_categories,
05056                                      i_attr_val1))
05057                     {
05058                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05059                       return(-RSBAC_EWRITEFAILED);
05060                     }
05061                   return(0);
05062                   break;
05063 
05064 #ifdef CONFIG_RSBAC_MAC_NET_OBJ_PROT
05065                 case T_NETOBJ:
05066                   i_tid.process = caller_pid;
05067                   /* Get current-sec-level from process... */
05068                   if (rsbac_get_attr(MAC,
05069                                      T_PROCESS,
05070                                      i_tid,
05071                                      A_current_sec_level,
05072                                      &i_attr_val1,
05073                                      FALSE))
05074                     {
05075                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05076                       return(-RSBAC_EREADFAILED);
05077                     }
05078                   /* Set local security-level for this netobj item */
05079                   if (rsbac_set_attr(MAC,
05080                                      target,
05081                                      tid,
05082                                      A_local_sec_level,
05083                                      i_attr_val1))
05084                     {
05085                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05086                       return(-RSBAC_EWRITEFAILED);
05087                     }
05088                   /* Get mac_curr_categories from process... */
05089                   if (rsbac_get_attr(MAC,
05090                                      T_PROCESS,
05091                                      i_tid,
05092                                      A_mac_curr_categories,
05093                                      &i_attr_val1,
05094                                      FALSE))
05095                     {
05096                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05097                       return(-RSBAC_EREADFAILED);
05098                     }
05099                   /* Set local curr_categories for new item */
05100                   if (rsbac_set_attr(MAC,
05101                                      target,
05102                                      tid,
05103                                      A_local_mac_categories,
05104                                      i_attr_val1))
05105                     {
05106                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05107                       return(-RSBAC_EWRITEFAILED);
05108                     }
05109                   return(0);
05110                   break;
05111 #endif
05112 
05113                 /* all other cases are unknown */
05114                 default:
05115                   return(0);
05116               }
05117 
05118         /* removal of targets is done in main adf dispatcher! */
05119         case R_DELETE:
05120             switch(target)
05121               {
05122                 case T_FILE:
05123                 case T_DIR:
05124                 case T_FIFO:
05125                 case T_SYMLINK:
05126                 case T_IPC:
05127                   /* and perform auto-write without(!) setting of attributes */
05128                   /* - no information flow apart from missing file */
05129                   /* -> decision consistency check only */
05130                   result = auto_write(caller_pid,
05131                                       target,
05132                                       tid,
05133                                       FALSE);
05134                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05135                     return(-RSBAC_EDECISIONMISMATCH);
05136                   else
05137                     return(0);
05138                 /* all other cases are unknown */
05139                 default:
05140                   return(0);
05141               }
05142 
05143         case R_EXECUTE:
05144             switch(target)
05145               {
05146                 case T_FILE:
05147                   /* copy trusted user list from file to process */
05148                   if (rsbac_mac_copy_fp_truset(tid.file, caller_pid))
05149                     {
05150 #ifdef CONFIG_RSBAC_RMSG
05151                       rsbac_printk(KERN_WARNING
05152                              "rsbac_adf_set_attr_mac(): rsbac_mac_copy_fp_truset() returned error!\n");
05153 #endif
05154 #ifdef CONFIG_RSBAC_RMSG_NOSYSLOG
05155                       if (!rsbac_nosyslog)
05156 #endif
05157                       printk(KERN_WARNING
05158                              "rsbac_adf_set_attr_mac(): rsbac_mac_copy_fp_truset() returned error!\n");
05159                       return(-RSBAC_EWRITEFAILED);
05160                     }
05161                   /* perform auto-read with setting of attributes */
05162                   result = auto_read(caller_pid,
05163                                      target,
05164                                      tid,
05165                                      TRUE);
05166                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05167                     return(-RSBAC_EDECISIONMISMATCH);
05168 
05169                   /* reset current_sec_level, mac_auto, min_write_open */
05170                   /* and max_read_open for process */
05171                   i_tid.process = caller_pid;
05172 
05173 #ifdef CONFIG_RSBAC_MAC_RESET_CURR
05174                   /* First, set current_sec_level and min_write_open to process owner's initial and seclevel */
05175                   if (rsbac_get_attr(MAC,
05176                                      T_PROCESS,
05177                                      i_tid,
05178                                      A_initial_security_level,
05179                                      &i_attr_val1,
05180                                      TRUE))
05181                     {
05182                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05183                       return(-RSBAC_EREADFAILED);
05184                     }
05185                   if (rsbac_get_attr(MAC,
05186                                      T_PROCESS,
05187                                      i_tid,
05188                                      A_mac_initial_categories,
05189                                      &i_attr_val2,
05190                                      TRUE))
05191                     {
05192                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05193                       return(-RSBAC_EREADFAILED);
05194                     }
05195                   if (rsbac_set_attr(MAC,
05196                                      T_PROCESS,
05197                                      i_tid,
05198                                      A_current_sec_level,
05199                                      i_attr_val1))
05200                     {
05201                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05202                       return(-RSBAC_EWRITEFAILED);
05203                     }
05204                   if (rsbac_set_attr(MAC,
05205                                      T_PROCESS,
05206                                      i_tid,
05207                                      A_mac_curr_categories,
05208                                      i_attr_val2))
05209                     {
05210                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05211                       return(-RSBAC_EWRITEFAILED);
05212                     }
05213 #endif
05214 #if 0
05215                   /* Now, set min_write_open to process owner's seclevel */
05216                   if (rsbac_get_attr(MAC,
05217                                      T_PROCESS,
05218                                      i_tid,
05219                                      A_security_level,
05220                                      &i_attr_val1,
05221                                      TRUE))
05222                     {
05223                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05224                       return(-RSBAC_EREADFAILED);
05225                     }
05226 #endif
05227                   i_attr_val1.min_write_open = SL_max;
05228                   if (rsbac_set_attr(MAC,
05229                                      T_PROCESS,
05230                                      i_tid,
05231                                      A_min_write_open,
05232                                      i_attr_val1))
05233                     {
05234                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05235                       return(-RSBAC_EWRITEFAILED);
05236                     }
05237 #if 0
05238                   /* Next, set min_write_categories to process owner's mac_categories */
05239                   if (rsbac_get_attr(MAC,
05240                                      T_PROCESS,
05241                                      i_tid,
05242                                      A_mac_categories,
05243                                      &i_attr_val2,
05244                                      TRUE))
05245                     {
05246                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05247                       return(-RSBAC_EREADFAILED);
05248                     }
05249 #endif
05250                   i_attr_val2.mac_categories = RSBAC_MAC_MAX_CAT_VECTOR;
05251                   if (rsbac_set_attr(MAC,
05252                                      T_PROCESS,
05253                                      i_tid,
05254                                      A_min_write_categories,
05255                                      i_attr_val2))
05256                     {
05257                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05258                       return(-RSBAC_EWRITEFAILED);
05259                     }
05260                   /* reset max_read boundary */
05261 #if 0
05262                   /* Get owner-min-sec-level and mac_min_categories for owner */
05263                   if (rsbac_get_attr(MAC,
05264                                      T_PROCESS,
05265                                      i_tid,
05266                                      A_min_security_level,
05267                                      &i_attr_val1,
05268                                      TRUE))
05269                     {
05270                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05271                       return(-RSBAC_EREADFAILED);
05272                     }
05273                   if (rsbac_get_attr(MAC,
05274                                      T_PROCESS,
05275                                      i_tid,
05276                                      A_mac_min_categories,
05277                                      &i_attr_val2,
05278                                      TRUE))
05279                     {
05280                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05281                       return(-RSBAC_EREADFAILED);
05282                     }
05283 #endif
05284                   i_attr_val1.max_read_open = SL_min;
05285                   i_attr_val2.mac_categories = RSBAC_MAC_MIN_CAT_VECTOR;
05286                   if (rsbac_set_attr(MAC,
05287                                      T_PROCESS,
05288                                      i_tid,
05289                                      A_max_read_open,
05290                                      i_attr_val1))
05291                     {
05292                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05293                       return(-RSBAC_EWRITEFAILED);
05294                     }
05295                   /* reset category max_read boundary */
05296                   if (rsbac_set_attr(MAC,
05297                                      T_PROCESS,
05298                                      i_tid,
05299                                      A_max_read_categories,
05300                                      i_attr_val2))
05301                     {
05302                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05303                       return(-RSBAC_EWRITEFAILED);
05304                     }
05305                   /* set flags */
05306                   if (rsbac_get_attr(MAC,
05307                                      T_PROCESS,
05308                                      i_tid,
05309                                      A_mac_process_flags,
05310                                      &i_attr_val1,
05311                                      TRUE))
05312                     {
05313                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05314                       return(-RSBAC_EREADFAILED);
05315                     }
05316                   if (rsbac_get_attr(MAC,
05317                                      target,
05318                                      tid,
05319                                      A_mac_auto,
05320                                      &i_attr_val2,
05321                                      TRUE))
05322                     {
05323                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05324                       return(-RSBAC_EREADFAILED);
05325                     }
05326                   if(i_attr_val2.mac_auto)
05327                     {
05328                       i_attr_val1.mac_process_flags |= MAC_program_auto;
05329                       i_tid.user = owner;
05330                       if (rsbac_get_attr(MAC,
05331                                          T_USER,
05332                                          i_tid,
05333                                          A_mac_user_flags,
05334                                          &i_attr_val2,
05335                                          TRUE))
05336                         {
05337                           rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05338                           return(-RSBAC_EREADFAILED);
05339                         }
05340                       if(i_attr_val2.mac_user_flags & MAC_allow_auto)
05341                         i_attr_val1.mac_process_flags |= MAC_auto;
05342                       else
05343                         i_attr_val1.mac_process_flags &= ~MAC_auto;
05344                       i_tid.process = caller_pid;
05345                     }
05346                   else
05347                     {
05348                       i_attr_val1.mac_process_flags &= ~MAC_program_auto;
05349                       i_attr_val1.mac_process_flags &= ~MAC_auto;
05350                     }
05351                   if (rsbac_get_attr(MAC,
05352                                      T_FILE,
05353                                      tid,
05354                                      A_mac_prop_trusted,
05355                                      &i_attr_val3,
05356                                      TRUE))
05357                     {
05358                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05359                       return(-RSBAC_EREADFAILED);
05360                     }
05361                   if(   !(i_attr_val3.mac_prop_trusted)
05362                      || !(i_attr_val1.mac_process_flags & MAC_trusted)
05363                     )
05364                     {
05365                         if(rsbac_mac_p_truset_member(caller_pid, owner))
05366                           i_attr_val1.mac_process_flags |= MAC_trusted;
05367                         else
05368                           {
05369                             i_tid.user = owner;
05370                             if (rsbac_get_attr(MAC,
05371                                                T_USER,
05372                                                i_tid,
05373                                                A_mac_user_flags,
05374                                                &i_attr_val2,
05375                                                TRUE))
05376                               {
05377                                 rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05378                                 return(-RSBAC_EREADFAILED);
05379                               }
05380                             if(i_attr_val2.mac_user_flags & MAC_trusted)
05381                                i_attr_val1.mac_process_flags |= MAC_trusted;
05382                             else
05383                                i_attr_val1.mac_process_flags &= ~MAC_trusted;
05384                             i_tid.process = caller_pid;
05385                           }
05386                     }
05387                   if (rsbac_set_attr(MAC,
05388                                      T_PROCESS,
05389                                      i_tid,
05390                                      A_mac_process_flags,
05391                                      i_attr_val1))
05392                     {
05393                       rsbac_ds_set_error("rsbac_adf_set_attr_mac", A_none);
05394                       return(-RSBAC_EWRITEFAILED);
05395                     }
05396                   return(0);
05397 
05398                 /* all other cases */
05399                 default:
05400                   return(0);
05401               }
05402 
05403         case R_MOUNT:
05404             switch(target)
05405               {
05406                 case T_DIR:
05407                 case T_DEV:
05408                   /* and perform auto-read(-write) with setting of attributes */
05409                   if(   (target == T_DEV)
05410                      && (attr == A_mode)
05411                      && (attr_val.mode & MS_RDONLY))
05412                     result = auto_read(caller_pid,
05413                                        target,
05414                                        tid,
05415                                        TRUE);
05416                   else
05417                     result = auto_read_write(caller_pid,
05418                                              target,
05419                                              tid,
05420                                              TRUE);
05421                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05422                     return(-RSBAC_EDECISIONMISMATCH);
05423                   else
05424                     return(0);
05425 
05426                 /* all other cases are unknown */
05427                 default:
05428                   return(0);
05429               }
05430 
05431         case R_READ:
05432             switch(target)
05433               {
05434                 case T_DIR:
05435 #ifdef CONFIG_RSBAC_RW
05436                 case T_FILE:
05437                 case T_FIFO:
05438                 case T_IPC:
05439 #endif
05440                   /* and perform auto-read with setting of attributes */
05441                   result = auto_read(caller_pid,
05442                                      target,
05443                                      tid,
05444                                      TRUE);
05445                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05446                     return(-RSBAC_EDECISIONMISMATCH);
05447                   return(0);
05448 
05449 #ifdef CONFIG_RSBAC_RW
05450                 case T_DEV:
05451                   /* Only check for devices with mac_check set */
05452                   if (rsbac_get_attr(MAC,
05453                                      T_DEV,
05454                                      tid,
05455                                      A_mac_check,
05456                                      &i_attr_val1,
05457                                      FALSE))
05458                     {
05459                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05460                       return(-RSBAC_EREADFAILED);
05461                     }
05462                   if(!i_attr_val1.mac_check)
05463                     return(0);
05464                   /* and perform auto-read with setting of attributes */
05465                   result = auto_read(caller_pid,
05466                                      target,
05467                                      tid,
05468                                      TRUE);
05469                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05470                     return(-RSBAC_EDECISIONMISMATCH);
05471                   return(0);
05472 #endif
05473 
05474 #ifdef CONFIG_RSBAC_MAC_NET_OBJ_PROT
05475                 case T_NETOBJ:
05476                   /* and perform auto-read with setting of attributes */
05477                   result = auto_read_attr(caller_pid,
05478                                           target,
05479                                           tid,
05480                                           A_remote_sec_level,
05481                                           A_remote_mac_categories,
05482                                           TRUE);
05483                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05484                     return(-RSBAC_EDECISIONMISMATCH);
05485                   return(0);
05486 #endif
05487 
05488                 /* all other cases are unknown */
05489                 default:
05490                   return(0);
05491               }
05492 
05493         case R_READ_OPEN:
05494             switch(target)
05495               {
05496                 case T_FILE:
05497                 case T_DIR:
05498                 case T_FIFO:
05499                 case T_IPC:
05500                   /* and perform auto-read with setting attributes */
05501                   result = auto_read(caller_pid,
05502                                      target,
05503                                      tid,
05504                                      TRUE);
05505                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05506                     return(-RSBAC_EDECISIONMISMATCH);
05507                   return(0);
05508 
05509                 case T_DEV:
05510                   /* Only check for devices with mac_check set */
05511                   if (rsbac_get_attr(MAC,
05512                                      T_DEV,
05513                                      tid,
05514                                      A_mac_check,
05515                                      &i_attr_val1,
05516                                      FALSE))
05517                     {
05518                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05519                       return(-RSBAC_EREADFAILED);
05520                     }
05521                   if(!i_attr_val1.mac_check)
05522                     return(0);
05523                   /* and perform auto-read with setting attributes */
05524                   result = auto_read(caller_pid,
05525                                      target,
05526                                      tid,
05527                                      TRUE);
05528                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05529                     return(-RSBAC_EDECISIONMISMATCH);
05530                   return(0);
05531 
05532                 /* all other cases are unknown */
05533                 default:
05534                   return(0);
05535               }
05536 
05537         case R_READ_WRITE_OPEN:
05538             switch(target)
05539               {
05540                 case T_FILE:
05541                 case T_FIFO:
05542                 case T_IPC:
05543                   /* and perform auto-read-write without setting attributes */
05544                   result = auto_read_write(caller_pid,
05545                                            target,
05546                                            tid,
05547                                            TRUE);
05548                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05549                     return(-RSBAC_EDECISIONMISMATCH);
05550                   return(0);
05551 
05552                 case T_DEV:
05553                   /* Only check for devices with mac_check set */
05554                   if (rsbac_get_attr(MAC,
05555                                      T_DEV,
05556                                      tid,
05557                                      A_mac_check,
05558                                      &i_attr_val1,
05559                                      FALSE))
05560                     {
05561                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05562                       return(-RSBAC_EREADFAILED);
05563                     }
05564                   if(!i_attr_val1.mac_check)
05565                     return(0);
05566                   /* and perform auto-read-write with setting of attributes */
05567                   result = auto_read_write(caller_pid,
05568                                            target,
05569                                            tid,
05570                                            TRUE);
05571                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05572                     return(-RSBAC_EDECISIONMISMATCH);
05573                   return(0);
05574                 /* all other cases are unknown */
05575                 default:
05576                   return(0);
05577               }
05578 
05579         case R_SEARCH:
05580             switch(target)
05581               {
05582                 case T_DIR:
05583                 case T_SYMLINK:
05584                   /* and perform auto-read with setting of attributes */
05585                   result = auto_read(caller_pid,
05586                                      target,
05587                                      tid,
05588                                      TRUE);
05589                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05590                     return(-RSBAC_EDECISIONMISMATCH);
05591                   return(0);
05592                 /* all other cases are unknown */
05593                 default:
05594                   return(0);
05595               }
05596 
05597         case R_TRACE:
05598             switch(target)
05599               {
05600                 case T_PROCESS:
05601                   /* and perform auto-read-write with setting attributes */
05602                   result = auto_read_write_attr(caller_pid,
05603                                                 target,
05604                                                 tid,
05605                                                 A_current_sec_level,
05606                                                 A_mac_curr_categories,
05607                                                 TRUE);
05608                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05609                     return(-RSBAC_EDECISIONMISMATCH);
05610                   return(0);
05611 
05612                 /* all other cases are unknown */
05613                 default:
05614                   return(0);
05615               }
05616 
05617         case R_WRITE:
05618         case R_WRITE_OPEN:
05619             switch(target)
05620               {
05621                 case T_FILE:
05622                 case T_FIFO:
05623                 case T_IPC:
05624                   /* and perform auto-write with setting attributes */
05625                   result = auto_write(caller_pid,
05626                                       target,
05627                                       tid,
05628                                       TRUE);
05629                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05630                     return(-RSBAC_EDECISIONMISMATCH);
05631                   return(0);
05632 
05633                 case T_DEV:
05634                   /* Only check for devices with mac_check set */
05635                   if (rsbac_get_attr(MAC,
05636                                      T_DEV,
05637                                      tid,
05638                                      A_mac_check,
05639                                      &i_attr_val1,
05640                                      FALSE))
05641                     {
05642                       rsbac_ds_get_error("rsbac_adf_set_attr_mac", A_none);
05643                       return(-RSBAC_EREADFAILED);
05644                     }
05645                   if(!i_attr_val1.mac_check)
05646                     return(0);
05647                   /* and perform auto-write with setting attributes */
05648                   result = auto_write(caller_pid,
05649                                       target,
05650                                       tid,
05651                                       TRUE);
05652                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05653                     return(-RSBAC_EDECISIONMISMATCH);
05654                   return(0);
05655 
05656 #ifdef CONFIG_RSBAC_MAC_NET_OBJ_PROT
05657                 case T_NETOBJ:
05658                   /* and perform auto-write with setting attributes */
05659                   result = auto_write_attr(caller_pid,
05660                                            target,
05661                                            tid,
05662                                            A_remote_sec_level,
05663                                            A_remote_mac_categories,
05664                                            TRUE);
05665                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05666                     return(-RSBAC_EDECISIONMISMATCH);
05667                   return(0);
05668 #endif
05669 
05670                 /* all other cases are unknown */
05671                 default:
05672                   return(0);
05673               }
05674 
05675 #ifdef CONFIG_RSBAC_MAC_NET_OBJ_PROT
05676         case R_BIND:
05677         case R_LISTEN:
05678             switch(target)
05679               {
05680                 case T_NETOBJ:
05681                   /* and perform auto-write with setting attributes */
05682                   result = auto_write_attr(caller_pid,
05683                                            target,
05684                                            tid,
05685                                            A_local_sec_level,
05686                                            A_local_mac_categories,
05687                                            TRUE);
05688                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05689                     return(-RSBAC_EDECISIONMISMATCH);
05690                   return(0);
05691 
05692                 /* all other cases are unknown */
05693                 default:
05694                   return(0);
05695               }
05696 
05697         case R_ACCEPT:
05698         case R_CONNECT:
05699         case R_SEND:
05700         case R_RECEIVE:
05701             switch(target)
05702               {
05703                 case T_NETOBJ:
05704                   /* and perform auto-write with setting attributes */
05705                   result = auto_write_attr(caller_pid,
05706                                            target,
05707                                            tid,
05708                                            A_remote_sec_level,
05709                                            A_remote_mac_categories,
05710                                            TRUE);
05711                   if ((result != GRANTED) && (result != DO_NOT_CARE))
05712                     return(-RSBAC_EDECISIONMISMATCH);
05713                   return(0);
05714 
05715                 /* all other cases are unknown */
05716                 default:
05717                   return(0);
05718               }
05719 #endif
05720 
05721 /*********************/
05722         default: return(0);
05723       }
05724 
05725     return(0);
05726   }; /* end of rsbac_adf_set_attr_mac() */
05727 
05728 /* end of rsbac/adf/mac/main.c */

Generated on Fri Jun 17 09:45:19 2005 for RSBAC by  doxygen 1.4.2