During the great famine of Egypt, Yosef imposed numerous laws on the people of Egypt as well as the surrounding nations. Since Yosef had stored all the grain for the past seven years, he now had the power to sell it to the people and impose any laws that he saw fit. With every law Yosef decreed he also had an ulterior motive.
It states in the Midrash that the seven fruitful years suddenly came to a stop. It stopped so suddenly that even when people were in the middle of enjoying their meals the food on their tables suddenly became all moldy. All the food was no longer edible except for that which belonged to Yosef. The people came crying to Yosef demanding food. Yosef said he would give it to them on the condition that the Mitzrim would give up all their idol worshipping, and thank Hashem for the food which Hashem allowed them to have. The Egyptians refused. When the Egyptians came back to Yosef, he made a different condition. He said that the only way they would get food is if they gave themselves a Brit Milah. This time the Mitzrim went to Paroh to complain. Paroh told them to go to Yosef. They retorted that they had already done this and that Yosef demanded such unspeakable things. When Paroh demanded to be told what Yosef had demanded, they told Paroh, "He asked us to circumcise ourselves. Why did you appoint a Jew over us?"
"Fools!" Paroh answered, "did Yosef not tell you that there would be a famine after the seven good years?! Why did you not stock your food?!" They replied that they did, but all of it became moldy and inedible. When Paroh heard this he yelled at them saying, "How can you not listen to Yosef?! If he has the power to decree when food will spoil, maybe he has the power to kill all of us! Even if he asks you to cut your flesh, you must still do it." The Egyptians had no choice but to circumcise themselves (see Rashi to מא:נו and מדרש רבה צא:ה).
Why did Yosef ask the Egyptians to circumcise themselves? Yosef did this in preparation for the Egyptian exile. Yosef knew that Bnai Yisrael would be slaves in Egypt for 012 years. Yosef feared they might neglect the mitzvah of Brit Mila due to assimilation into the Egyptian culture. Therefore he told the mitzrim to circumcise themselves so Bnai Israel would not feel embarrassed about their Mila but would continue to fulfill the mitzvah.
It was not only Egypt that suffered during the famine, but all the neighboring countries as well. It struck Phoenicia, Arabia, and Eretz Canaan. Everyone suffered from the food shortage and it appeared that the only place one could get food was from Yosef (ברשאית רבה ד:ו). Therefore, Yosef's first rule was that grains would be sold to any needy person of any nation. This was mainly done for reasons of Chesed. This was an unheard of innovation. Usually when a country had a surplus of food they would go to great lengths to make sure other countries didn't get their grain.
The rest of the laws were as follows: Food may only go to the master and not the slave. Only the master of the house or family member could purchase food for the household. No one could receive more then the load which his donkey could carry. Grain could only be purchased for family use. The identities of foreigners trying to come into the land to buy grain must be established and recorded on file. Menashe the son of Yosef will be chief arbiter of all sales (מדרש רבה צא:ד).
All the Mitzrim admired Yosef for his shrewdness and circumspection in distributing the grain justly by means of his new legislation. Little did they know he also had motives for innovating these laws.
The reason he allowed other countries to buy food was because he wanted to meet his brothers, and in this way they would come to Mitzrayim to collect the grain they needed. Yosef feared that when his brothers tried to collect their grain, they might send slaves or messengers. In his second rule he made sure that only a family member would purchase the grain. Since Yosef wanted to meet all of his brothers, he decreed that one can only purchase as much as his donkey can hold. Therefore they would send everyone, trying to purchase as much grain as possible. In order to make sure that Yaakov and his family did not get their grains from outside sources, Yosef instituted that no grain that was bought from him may be resold.
The fifth rule was created in order for Yosef to know when his brothers would arrive. Therefore, Yosef placed a guard by each border crossing. Each guard's task was to write down the names of all the people that entered the land. Later that night, Menashe would give the list to Yosef and he would see who had arrived that day.
We see from these laws the wisdom of Yosef and the great lengths to which he went to find out about his family. Yosef wanted to reunite his family and afford his brothers a chance to do Teshuvah. Once Yehudah indicated in Parshat VaYigash, that he would not sell Binyamin, Yosef revealed himself. His brothers did Teshuvah and now the family can be reunited. We should all learn from Yosef's wisdom and strive just as hard to reconcile our own family problems.