@@ -123,6 +123,11 @@ static struct policydb_compat_info policydb_compat[] = {
123123 .sym_num = SYM_NUM ,
124124 .ocon_num = OCON_NUM ,
125125 },
126+ {
127+ .version = POLICYDB_VERSION_FILENAME_TRANS ,
128+ .sym_num = SYM_NUM ,
129+ .ocon_num = OCON_NUM ,
130+ },
126131};
127132
128133static struct policydb_compat_info * policydb_lookup_compat (int version )
@@ -704,6 +709,7 @@ void policydb_destroy(struct policydb *p)
704709 int i ;
705710 struct role_allow * ra , * lra = NULL ;
706711 struct role_trans * tr , * ltr = NULL ;
712+ struct filename_trans * ft , * nft ;
707713
708714 for (i = 0 ; i < SYM_NUM ; i ++ ) {
709715 cond_resched ();
@@ -781,6 +787,15 @@ void policydb_destroy(struct policydb *p)
781787 }
782788 flex_array_free (p -> type_attr_map_array );
783789 }
790+
791+ ft = p -> filename_trans ;
792+ while (ft ) {
793+ nft = ft -> next ;
794+ kfree (ft -> name );
795+ kfree (ft );
796+ ft = nft ;
797+ }
798+
784799 ebitmap_destroy (& p -> policycaps );
785800 ebitmap_destroy (& p -> permissive_map );
786801
@@ -1788,6 +1803,76 @@ static int range_read(struct policydb *p, void *fp)
17881803 return rc ;
17891804}
17901805
1806+ static int filename_trans_read (struct policydb * p , void * fp )
1807+ {
1808+ struct filename_trans * ft , * last ;
1809+ u32 nel , len ;
1810+ char * name ;
1811+ __le32 buf [4 ];
1812+ int rc , i ;
1813+
1814+ if (p -> policyvers < POLICYDB_VERSION_FILENAME_TRANS )
1815+ return 0 ;
1816+
1817+ rc = next_entry (buf , fp , sizeof (u32 ));
1818+ if (rc )
1819+ goto out ;
1820+ nel = le32_to_cpu (buf [0 ]);
1821+
1822+ printk (KERN_ERR "%s: nel=%d\n" , __func__ , nel );
1823+
1824+ last = p -> filename_trans ;
1825+ while (last && last -> next )
1826+ last = last -> next ;
1827+
1828+ for (i = 0 ; i < nel ; i ++ ) {
1829+ rc = - ENOMEM ;
1830+ ft = kzalloc (sizeof (* ft ), GFP_KERNEL );
1831+ if (!ft )
1832+ goto out ;
1833+
1834+ /* add it to the tail of the list */
1835+ if (!last )
1836+ p -> filename_trans = ft ;
1837+ else
1838+ last -> next = ft ;
1839+ last = ft ;
1840+
1841+ /* length of the path component string */
1842+ rc = next_entry (buf , fp , sizeof (u32 ));
1843+ if (rc )
1844+ goto out ;
1845+ len = le32_to_cpu (buf [0 ]);
1846+
1847+ rc = - ENOMEM ;
1848+ name = kmalloc (len + 1 , GFP_KERNEL );
1849+ if (!name )
1850+ goto out ;
1851+
1852+ ft -> name = name ;
1853+
1854+ /* path component string */
1855+ rc = next_entry (name , fp , len );
1856+ if (rc )
1857+ goto out ;
1858+ name [len ] = 0 ;
1859+
1860+ printk (KERN_ERR "%s: ft=%p ft->name=%p ft->name=%s\n" , __func__ , ft , ft -> name , ft -> name );
1861+
1862+ rc = next_entry (buf , fp , sizeof (u32 ) * 4 );
1863+ if (rc )
1864+ goto out ;
1865+
1866+ ft -> stype = le32_to_cpu (buf [0 ]);
1867+ ft -> ttype = le32_to_cpu (buf [1 ]);
1868+ ft -> tclass = le32_to_cpu (buf [2 ]);
1869+ ft -> otype = le32_to_cpu (buf [3 ]);
1870+ }
1871+ rc = 0 ;
1872+ out :
1873+ return rc ;
1874+ }
1875+
17911876static int genfs_read (struct policydb * p , void * fp )
17921877{
17931878 int i , j , rc ;
@@ -2251,6 +2336,10 @@ int policydb_read(struct policydb *p, void *fp)
22512336 lra = ra ;
22522337 }
22532338
2339+ rc = filename_trans_read (p , fp );
2340+ if (rc )
2341+ goto bad ;
2342+
22542343 rc = policydb_index (p );
22552344 if (rc )
22562345 goto bad ;
@@ -3025,6 +3114,43 @@ static int range_write(struct policydb *p, void *fp)
30253114 return 0 ;
30263115}
30273116
3117+ static int filename_trans_write (struct policydb * p , void * fp )
3118+ {
3119+ struct filename_trans * ft ;
3120+ u32 len , nel = 0 ;
3121+ __le32 buf [4 ];
3122+ int rc ;
3123+
3124+ for (ft = p -> filename_trans ; ft ; ft = ft -> next )
3125+ nel ++ ;
3126+
3127+ buf [0 ] = cpu_to_le32 (nel );
3128+ rc = put_entry (buf , sizeof (u32 ), 1 , fp );
3129+ if (rc )
3130+ return rc ;
3131+
3132+ for (ft = p -> filename_trans ; ft ; ft = ft -> next ) {
3133+ len = strlen (ft -> name );
3134+ buf [0 ] = cpu_to_le32 (len );
3135+ rc = put_entry (buf , sizeof (u32 ), 1 , fp );
3136+ if (rc )
3137+ return rc ;
3138+
3139+ rc = put_entry (ft -> name , sizeof (char ), len , fp );
3140+ if (rc )
3141+ return rc ;
3142+
3143+ buf [0 ] = ft -> stype ;
3144+ buf [1 ] = ft -> ttype ;
3145+ buf [2 ] = ft -> tclass ;
3146+ buf [3 ] = ft -> otype ;
3147+
3148+ rc = put_entry (buf , sizeof (u32 ), 4 , fp );
3149+ if (rc )
3150+ return rc ;
3151+ }
3152+ return 0 ;
3153+ }
30283154/*
30293155 * Write the configuration data in a policy database
30303156 * structure to a policy database binary representation
@@ -3135,6 +3261,10 @@ int policydb_write(struct policydb *p, void *fp)
31353261 if (rc )
31363262 return rc ;
31373263
3264+ rc = filename_trans_write (p , fp );
3265+ if (rc )
3266+ return rc ;
3267+
31383268 rc = ocontext_write (p , info , fp );
31393269 if (rc )
31403270 return rc ;
0 commit comments