15368db27SMaxim Konovalov 25368db27SMaxim KonovalovAbout unix_cmsg 3*b5718158SSergey Kandaurov=============== 45368db27SMaxim Konovalov 5*b5718158SSergey KandaurovThis program is a collection of regression tests for ancillary data 6*b5718158SSergey Kandaurov(control information) for PF_LOCAL sockets (local domain or Unix domain 7*b5718158SSergey Kandaurovsockets). There are tests for stream and datagram sockets. 85368db27SMaxim Konovalov 9*b5718158SSergey KandaurovUsually each test does following steps: creates Server, forks Client, 10*b5718158SSergey KandaurovClient sends something to Server, Server verifies whether everything is 11*b5718158SSergey Kandaurovcorrect in received message(s). 125368db27SMaxim Konovalov 135368db27SMaxim KonovalovIt is better to change the owner of unix_cmsg to some safe user 14*b5718158SSergey Kandaurov(eg. nobody:nogroup) and set SUID and SGID bits, else some tests that 15*b5718158SSergey Kandaurovcheck credentials can give correct results for wrong implementation. 16*b5718158SSergey Kandaurov 17*b5718158SSergey KandaurovIt is better to run this program by a user that belongs to more 18*b5718158SSergey Kandaurovthan 16 groups. 195368db27SMaxim Konovalov 205368db27SMaxim KonovalovAvailable options 215368db27SMaxim Konovalov================= 225368db27SMaxim Konovalov 23*b5718158SSergey Kandaurovusage: unix_cmsg [-dh] [-n num] [-s size] [-t type] [-z value] [testno] 245368db27SMaxim Konovalov 25*b5718158SSergey Kandaurov Options are: 26*b5718158SSergey Kandaurov -d Output debugging information 27*b5718158SSergey Kandaurov -h Output the help message and exit 28*b5718158SSergey Kandaurov -n num Number of messages to send 29*b5718158SSergey Kandaurov -s size Specify size of data for IPC 30*b5718158SSergey Kandaurov -t type Specify socket type (stream, dgram) for tests 31*b5718158SSergey Kandaurov -z value Do not send data in a message (bit 0x1), do not send 32*b5718158SSergey Kandaurov data array associated with a cmsghdr structure (bit 0x2) 33*b5718158SSergey Kandaurov testno Run one test by its number (require the -t option) 345368db27SMaxim Konovalov 35*b5718158SSergey KandaurovDescription 36*b5718158SSergey Kandaurov=========== 375368db27SMaxim Konovalov 38*b5718158SSergey KandaurovIf Client sends something to Server, then it sends 5 messages by default. 39*b5718158SSergey KandaurovNumber of messages can be changed in the -n command line option. Number 40*b5718158SSergey Kandaurovof messages will be given as N in the following descriptions. 415368db27SMaxim Konovalov 42*b5718158SSergey KandaurovIf Client sends something to Server, then it sends some data (few bytes) 43*b5718158SSergey Kandaurovin each message by default. The size of this data can be changed by the -s 44*b5718158SSergey Kandaurovcommand line option. The "-s 0" command line option means, that Client will 45*b5718158SSergey Kandaurovsend zero bytes represented by { NULL, 0 } value of struct iovec{}, referenced 46*b5718158SSergey Kandaurovby the msg_iov field from struct msghdr{}. The "-z 1" or "-z 3" command line 47*b5718158SSergey Kandaurovoption means, that Client will send zero bytes represented by the NULL value 48*b5718158SSergey Kandaurovin the msg_iov field from struct msghdr{}. 495368db27SMaxim Konovalov 50*b5718158SSergey KandaurovIf Client sends some ancillary data object, then this ancillary data object 51*b5718158SSergey Kandaurovalways has associated data array by default. The "-z 2" or "-z 3" option 52*b5718158SSergey Kandaurovmeans, that Client will not send associated data array if possible. 535368db27SMaxim Konovalov 545368db27SMaxim KonovalovFor SOCK_STREAM sockets: 555368db27SMaxim Konovalov----------------------- 565368db27SMaxim Konovalov 575368db27SMaxim Konovalov 1: Sending, receiving cmsgcred 585368db27SMaxim Konovalov 59*b5718158SSergey Kandaurov Client connects to Server and sends N messages with SCM_CREDS ancillary 60*b5718158SSergey Kandaurov data object. Server should receive N messages, each message should 61*b5718158SSergey Kandaurov have SCM_CREDS ancillary data object followed by struct cmsgcred{}. 625368db27SMaxim Konovalov 63*b5718158SSergey Kandaurov 2: Receiving sockcred (listening socket) 645368db27SMaxim Konovalov 65*b5718158SSergey Kandaurov Server creates a listening stream socket and sets the LOCAL_CREDS 66*b5718158SSergey Kandaurov socket option for it. Client connects to Server two times, each time 67*b5718158SSergey Kandaurov it sends N messages. Server accepts two connections and receives N 68*b5718158SSergey Kandaurov messages from each connection. The first message from each connection 69*b5718158SSergey Kandaurov should have SCM_CREDS ancillary data object followed by struct sockcred{}, 70*b5718158SSergey Kandaurov next messages from the same connection should not have ancillary data. 715368db27SMaxim Konovalov 72*b5718158SSergey Kandaurov 3: Receiving sockcred (accepted socket) 735368db27SMaxim Konovalov 74*b5718158SSergey Kandaurov Client connects to Server. Server accepts connection and sets the 75*b5718158SSergey Kandaurov LOCAL_CREDS socket option for just accepted socket. Client sends N 76*b5718158SSergey Kandaurov messages to Server. Server should receive N messages, the first 77*b5718158SSergey Kandaurov message should have SCM_CREDS ancillary data object followed by 78*b5718158SSergey Kandaurov struct sockcred{}, next messages should not have ancillary data. 795368db27SMaxim Konovalov 805368db27SMaxim Konovalov 4: Sending cmsgcred, receiving sockcred 815368db27SMaxim Konovalov 82*b5718158SSergey Kandaurov Server creates a listening stream socket and sets the LOCAL_CREDS 83*b5718158SSergey Kandaurov socket option for it. Client connects to Server and sends N messages 84*b5718158SSergey Kandaurov with SCM_CREDS ancillary data object. Server should receive N messages, 85*b5718158SSergey Kandaurov the first message should have SCM_CREDS ancillary data object followed 86*b5718158SSergey Kandaurov by struct sockcred{}, each of next messages should have SCM_CREDS 87*b5718158SSergey Kandaurov ancillary data object followed by struct cmsgcred{}. 885368db27SMaxim Konovalov 89*b5718158SSergey Kandaurov 5: Sending, receiving timeval 905368db27SMaxim Konovalov 91*b5718158SSergey Kandaurov Client connects to Server and sends message with SCM_TIMESTAMP ancillary 92*b5718158SSergey Kandaurov data object. Server should receive one message with SCM_TIMESTAMP 93*b5718158SSergey Kandaurov ancillary data object followed by struct timeval{}. 94*b5718158SSergey Kandaurov 95*b5718158SSergey Kandaurov 6: Sending, receiving bintime 96*b5718158SSergey Kandaurov 97*b5718158SSergey Kandaurov Client connects to Server and sends message with SCM_BINTIME ancillary 98*b5718158SSergey Kandaurov data object. Server should receive one message with SCM_BINTIME 99*b5718158SSergey Kandaurov ancillary data object followed by struct bintime{}. 100*b5718158SSergey Kandaurov 101*b5718158SSergey Kandaurov 7: Checking cmsghdr.cmsg_len 102*b5718158SSergey Kandaurov 103*b5718158SSergey Kandaurov Client connects to Server and tries to send several messages with 104*b5718158SSergey Kandaurov SCM_CREDS ancillary data object that has wrong cmsg_len field in its 105*b5718158SSergey Kandaurov struct cmsghdr{}. All these attempts should fail, since cmsg_len 106*b5718158SSergey Kandaurov in all requests is less than CMSG_LEN(0). 107*b5718158SSergey Kandaurov 108*b5718158SSergey Kandaurov 8: Check LOCAL_PEERCRED socket option 109*b5718158SSergey Kandaurov 110*b5718158SSergey Kandaurov This test does not use ancillary data, but can be implemented here. 111*b5718158SSergey Kandaurov Client connects to Server. Both Client and Server verify that 112*b5718158SSergey Kandaurov credentials of the peer are correct using LOCAL_PEERCRED socket option. 1135368db27SMaxim Konovalov 1145368db27SMaxim KonovalovFor SOCK_DGRAM sockets: 1155368db27SMaxim Konovalov---------------------- 1165368db27SMaxim Konovalov 1175368db27SMaxim Konovalov 1: Sending, receiving cmsgcred 1185368db27SMaxim Konovalov 119*b5718158SSergey Kandaurov Client connects to Server and sends N messages with SCM_CREDS ancillary 120*b5718158SSergey Kandaurov data object. Server should receive N messages, each message should 121*b5718158SSergey Kandaurov have SCM_CREDS ancillary data object followed by struct cmsgcred{}. 1225368db27SMaxim Konovalov 1235368db27SMaxim Konovalov 2: Receiving sockcred 1245368db27SMaxim Konovalov 125*b5718158SSergey Kandaurov Server creates datagram socket and sets the LOCAL_CREDS socket option 126*b5718158SSergey Kandaurov for it. Client sends N messages to Server. Server should receive N 127*b5718158SSergey Kandaurov messages, each message should have SCM_CREDS ancillary data object 128*b5718158SSergey Kandaurov followed by struct sockcred{}. 1295368db27SMaxim Konovalov 1305368db27SMaxim Konovalov 3: Sending cmsgcred, receiving sockcred 1315368db27SMaxim Konovalov 132*b5718158SSergey Kandaurov Server creates datagram socket and sets the LOCAL_CREDS socket option 133*b5718158SSergey Kandaurov for it. Client sends N messages with SCM_CREDS ancillary data object 134*b5718158SSergey Kandaurov to Server. Server should receive N messages, the first message should 135*b5718158SSergey Kandaurov have SCM_CREDS ancillary data object followed by struct sockcred{}, 136*b5718158SSergey Kandaurov each of next messages should have SCM_CREDS ancillary data object 137*b5718158SSergey Kandaurov followed by struct cmsgcred{}. 1385368db27SMaxim Konovalov 139*b5718158SSergey Kandaurov 4: Sending, receiving timeval 1405368db27SMaxim Konovalov 141*b5718158SSergey Kandaurov Client sends one message with SCM_TIMESTAMP ancillary data object 142*b5718158SSergey Kandaurov to Server. Server should receive one message with SCM_TIMESTAMP 143*b5718158SSergey Kandaurov ancillary data object followed by struct timeval{}. 144*b5718158SSergey Kandaurov 145*b5718158SSergey Kandaurov 5: Sending, receiving bintime 146*b5718158SSergey Kandaurov 147*b5718158SSergey Kandaurov Client sends one message with SCM_BINTIME ancillary data object 148*b5718158SSergey Kandaurov to Server. Server should receive one message with SCM_BINTIME 149*b5718158SSergey Kandaurov ancillary data object followed by struct bintime{}. 150*b5718158SSergey Kandaurov 151*b5718158SSergey Kandaurov 6: Checking cmsghdr.cmsg_len 152*b5718158SSergey Kandaurov 153*b5718158SSergey Kandaurov Client tries to send Server several messages with SCM_CREDS ancillary 154*b5718158SSergey Kandaurov data object that has wrong cmsg_len field in its struct cmsghdr{}. 155*b5718158SSergey Kandaurov All these attempts should fail, since cmsg_len in all requests is less 156*b5718158SSergey Kandaurov than CMSG_LEN(0). 1575368db27SMaxim Konovalov 1585368db27SMaxim Konovalov- Andrey Simonenko 159*b5718158SSergey Kandaurovandreysimonenko@users.sourceforge.net 160